Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UI not using correct value for ID #278

Closed
oliverisaac opened this issue Jul 15, 2019 · 5 comments
Closed

UI not using correct value for ID #278

oliverisaac opened this issue Jul 15, 2019 · 5 comments

Comments

@oliverisaac
Copy link

oliverisaac commented Jul 15, 2019

In a fresh flagr install, the flag ID type of int8 is too large for Chrome/JSON: the when the JSON is converted from a string to an object in the UI the bigint is down-sampled and the value lost.

This results in an error message of cannot find flag 469096912275144700. record not found (When the correct record ID would be: 469096912275144706)

Expected Behavior

The ID should be passed as a string to the UI in the JSON so it can be displayed properly. Alternatively, we could switch to int4 for the ID's instead of int8. (In postgres parlance)

Current Behavior

ID's are downsampled by JS in the UI, so that 469096912275144706 becomes 469096912275144700

Possible Solution

Need to use smaller integers or switch to passing strings.

Steps to Reproduce (for bugs)

Using postgres:
Add a new flag in the UI.
Click on your new flag.

Context

UI is unusable.

Your Environment

  • Version used (flagr version): 1.1.4 and "latest"
  • Server type and version: docker image connecting to cockroachdb/postgres
  • Operating System and version (uname -a): coreos

Screen Shot 2019-07-15 at 5 15 06 PM

@oliverisaac
Copy link
Author

I now have flagr working with cockroachDB.

The short of it is that cockroachdb uses high-value ( > 2^53 ) integers for their unique row ID's ( https://www.cockroachlabs.com/docs/stable/sql-faqs.html#how-do-i-auto-generate-unique-row-ids-in-cockroachdb ) which Javascript/JSON.parse() does not support (https://stackoverflow.com/a/9643650).

The solution was to create a sequence for each unique ID and then use that: https://www.cockroachlabs.com/docs/stable/create-sequence.html#create-a-table-with-a-sequence

Our flags will now increment as we create them starting at 1 and we should be fine as long as we use less than 2^53 flags...

@oliverisaac
Copy link
Author

This is the SQL I used to create the tables:

CREATE SEQUENCE constraints_seq;
CREATE TABLE constraints (
	id INT8 NOT NULL DEFAULT nextval('constraints_seq'),
	created_at TIMESTAMPTZ NULL,
	updated_at TIMESTAMPTZ NULL,
	deleted_at TIMESTAMPTZ NULL,
	segment_id INT8 NULL,
	property STRING NULL,
	operator STRING NULL,
	value STRING NULL,
	CONSTRAINT "primary" PRIMARY KEY (id ASC),
	INDEX idx_constraints_deleted_at (deleted_at ASC),
	INDEX idx_constraint_segmentid (segment_id ASC),
	FAMILY "primary" (id, created_at, updated_at, deleted_at, segment_id, property, operator, value)
);

CREATE SEQUENCE distributions_seq;
CREATE TABLE distributions (
	id INT8 NOT NULL DEFAULT nextval('distributions_seq'),
	created_at TIMESTAMPTZ NULL,
	updated_at TIMESTAMPTZ NULL,
	deleted_at TIMESTAMPTZ NULL,
	segment_id INT8 NULL,
	variant_id INT8 NULL,
	variant_key STRING NULL,
	percent INT8 NULL,
	bitmap STRING NULL,
	CONSTRAINT "primary" PRIMARY KEY (id ASC),
	INDEX idx_distributions_deleted_at (deleted_at ASC),
	INDEX idx_distribution_segmentid (segment_id ASC),
	INDEX idx_distribution_variantid (variant_id ASC),
	FAMILY "primary" (id, created_at, updated_at, deleted_at, segment_id, variant_id, variant_key, percent, bitmap)
);

CREATE SEQUENCE flag_entity_types_seq;
CREATE TABLE flag_entity_types (
	id INT8 NOT NULL DEFAULT nextval('flag_entity_types_seq'),
	created_at TIMESTAMPTZ NULL,
	updated_at TIMESTAMPTZ NULL,
	deleted_at TIMESTAMPTZ NULL,
	key VARCHAR(64) NULL,
	CONSTRAINT "primary" PRIMARY KEY (id ASC),
	INDEX idx_flag_entity_types_deleted_at (deleted_at ASC),
	UNIQUE INDEX flag_entity_type_key (key ASC),
	FAMILY "primary" (id, created_at, updated_at, deleted_at, key)
);

CREATE SEQUENCE flag_snapshots_seq;
CREATE TABLE flag_snapshots (
	id INT8 NOT NULL DEFAULT nextval('flag_snapshots_seq'),
	created_at TIMESTAMPTZ NULL,
	updated_at TIMESTAMPTZ NULL,
	deleted_at TIMESTAMPTZ NULL,
	flag_id INT8 NULL,
	updated_by STRING NULL,
	flag STRING NULL,
	CONSTRAINT "primary" PRIMARY KEY (id ASC),
	INDEX idx_flag_snapshots_deleted_at (deleted_at ASC),
	INDEX idx_flagsnapshot_flagid (flag_id ASC),
	FAMILY "primary" (id, created_at, updated_at, deleted_at, flag_id, updated_by, flag)
);

CREATE SEQUENCE flags_seq;
CREATE TABLE flags (
	id INT8 NOT NULL DEFAULT nextval('flags_seq'),
	created_at TIMESTAMPTZ NULL,
	updated_at TIMESTAMPTZ NULL,
	deleted_at TIMESTAMPTZ NULL,
	key VARCHAR(64) NULL,
	description STRING NULL,
	created_by STRING NULL,
	updated_by STRING NULL,
	enabled BOOL NULL,
	snapshot_id INT8 NULL,
	notes STRING NULL,
	data_records_enabled BOOL NULL,
	entity_type STRING NULL,
	CONSTRAINT "primary" PRIMARY KEY (id ASC),
	INDEX idx_flags_deleted_at (deleted_at ASC),
	UNIQUE INDEX idx_flag_key (key ASC),
	FAMILY "primary" (id, created_at, updated_at, deleted_at, key, description, created_by, updated_by, enabled, snapshot_id, notes, data_records_enabled, entity_type)
);

CREATE SEQUENCE segments_seq;
CREATE TABLE segments (
	id INT8 NOT NULL DEFAULT nextval('segments_seq'),
	created_at TIMESTAMPTZ NULL,
	updated_at TIMESTAMPTZ NULL,
	deleted_at TIMESTAMPTZ NULL,
	flag_id INT8 NULL,
	description STRING NULL,
	rank INT8 NULL,
	rollout_percent INT8 NULL,
	CONSTRAINT "primary" PRIMARY KEY (id ASC),
	INDEX idx_segments_deleted_at (deleted_at ASC),
	INDEX idx_segment_flagid (flag_id ASC),
	FAMILY "primary" (id, created_at, updated_at, deleted_at, flag_id, description, rank, rollout_percent)
);

CREATE SEQUENCE users_seq;
CREATE TABLE users (
	id INT8 NOT NULL DEFAULT nextval('users_seq'),
	created_at TIMESTAMPTZ NULL,
	updated_at TIMESTAMPTZ NULL,
	deleted_at TIMESTAMPTZ NULL,
	email STRING NULL,
	CONSTRAINT "primary" PRIMARY KEY (id ASC),
	INDEX idx_users_deleted_at (deleted_at ASC),
	FAMILY "primary" (id, created_at, updated_at, deleted_at, email)
);

CREATE SEQUENCE variants_seq;
CREATE TABLE variants (
	id INT8 NOT NULL DEFAULT nextval('variants_seq'),
	created_at TIMESTAMPTZ NULL,
	updated_at TIMESTAMPTZ NULL,
	deleted_at TIMESTAMPTZ NULL,
	flag_id INT8 NULL,
	key STRING NULL,
	attachment STRING NULL,
	CONSTRAINT "primary" PRIMARY KEY (id ASC),
	INDEX idx_variants_deleted_at (deleted_at ASC),
	INDEX idx_variant_flagid (flag_id ASC),
	FAMILY "primary" (id, created_at, updated_at, deleted_at, flag_id, key, attachment)
);

@zhouzhuojie
Copy link
Collaborator

Interesting usage of CockroachDB. Does it play nicely with GORM? Does the AutoMigrate work on CockroachDB?

I think flagr is delegating to DB for flag id generation, same applies to segment id, variant id, and flagr_snapshot id. It was designed for databases with sequence ids generator.

@oliverisaac
Copy link
Author

Yeah, so far Cockroach has been fine to work with for Flagr. We haven't really battle-tested it but getting it up and running with Cockroach was a non-issue once I manually created the DB. Gorm migrate hasn't complained about anything yet.

@zhouzhuojie
Copy link
Collaborator

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants