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

feat: (sqlite) support namespace at storage level, mostly for flags #1368

Merged
merged 13 commits into from
Mar 1, 2023

Conversation

markphelps
Copy link
Collaborator

@markphelps markphelps commented Feb 27, 2023

feat: (sqlite) wip support namespace at storage level, mostly for flags

fixes: FLI-237

basic storage code for adding namespaces for flags/variants. ONLY works with SQLite, other dbs will come once SQLite is fully implemented to prevent wasted effort

@codecov-commenter
Copy link

codecov-commenter commented Feb 27, 2023

Codecov Report

❗ No coverage uploaded for pull request base (namespaces@1de474e). Click here to learn what that means.
The diff coverage is n/a.

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

@@              Coverage Diff              @@
##             namespaces    #1368   +/-   ##
=============================================
  Coverage              ?   79.73%           
=============================================
  Files                 ?       45           
  Lines                 ?     3568           
  Branches              ?        0           
=============================================
  Hits                  ?     2845           
  Misses                ?      577           
  Partials              ?      146           

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@markphelps markphelps changed the title feat: (sqlite) wip support namespace at storage level, mostly for flags feat: (sqlite) support namespace at storage level, mostly for flags Feb 28, 2023
@markphelps markphelps marked this pull request as ready for review February 28, 2023 19:22
@markphelps markphelps requested a review from a team as a code owner February 28, 2023 19:22
k = fmt.Sprintf("f:%s:%s", namespaceKey, key)
} else {
k = fmt.Sprintf("f:%s", key)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The backwards compatibility here refers to other dbs as a data source other than sqlite correct? Or is there more it is referring to?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

its backward compatability for the cache key. since redis is an external cache I wanted to still have a cache hit for flags that were cached before this namespace addition

Copy link
Member

@GeorgeMac GeorgeMac left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change looks good, just had a couple style suggestions and mainly one open question.

Is it possible that we could forgo adding namespaces to things already scoped to other already namespaced resources?

Just thinking outloud. It is a little disconcerting that we have to lift and shift a whole table.
But I suspect there is no way around it. Even if we went v2 we would have to help folks migrate and do something similar. This is definitely something to keep pondering on (the migration process to a namespaced future).

config/migrations/sqlite3/6_create_namespaces.up.sql Outdated Show resolved Hide resolved
internal/storage/sql/common/flag.go Outdated Show resolved Hide resolved
internal/storage/sql/common/flag.go Outdated Show resolved Hide resolved
config/migrations/sqlite3/6_create_namespaces.up.sql Outdated Show resolved Hide resolved
@markphelps markphelps requested a review from GeorgeMac March 1, 2023 14:30
Copy link
Member

@GeorgeMac GeorgeMac left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The namespace tendrils are coming.
One take it or leave it. Plus I like your suggestion in the TODO in the tests to cover more than one namespace (more than just default). Otherwise, this change looks good to me.

From("flags").
Where(sq.Eq{"\"key\"": key}).QueryRowContext(ctx).Scan(
Where(sq.And{sq.Eq{"namespace_key": namespaceKey}, sq.Eq{"\"key\"": key}}).QueryRowContext(ctx).Scan(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Take it or leave it: I think you can do this in a few places:

Suggested change
Where(sq.And{sq.Eq{"namespace_key": namespaceKey}, sq.Eq{"\"key\"": key}}).QueryRowContext(ctx).Scan(
Where(sq.Eq{"namespace_key": namespaceKey, \"key\"": key}).QueryRowContext(ctx).Scan(

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked just incase and it does perform conjunction with each key / value pair expression:
https://github.com/Masterminds/squirrel/blob/v1.5.3/expr.go#L205

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah i may go ahead and do that in a seperate PR and just take care of all the ANDs because its used in a quite a few places

Copy link
Contributor

@yquansah yquansah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code looks smooth.

@markphelps markphelps merged commit b3d7489 into namespaces Mar 1, 2023
@markphelps markphelps deleted the namespaces-flags-storage branch March 1, 2023 17:36
markphelps added a commit that referenced this pull request Apr 5, 2023
* feat: (sqlite) support namespace at storage level, mostly for flags (#1368)

* feat: (sqlite) wip support namespace at storage level, mostly for flags

* chore: rename down namespace file correctly

* chore: fix server/flag_test.go

* chore: redo migration to use temp_tables for composite keys

* chore: just use TODO for now for down migration

* chore: comments

* chore: wip namespace protos

* chore: better err messages

* Update internal/storage/sql/common/flag.go

Co-authored-by: George <[email protected]>

* chore: fix tests

* chore: split into seperate migrations

* chore: more error messages

* chore: rm println statment

---------

Co-authored-by: George <[email protected]>

* feat: Namespaces segments storage (#1369)

* feat: (sqlite) add namespace support for rules storage (#1371)

* feat: (sqlite) eval storage namespace support (#1372)

* Namespaces storage (#1383)

* feat: wip namespace storage

* chore: add tests; storage impl

* chore: appease the linter

* chore: less sleepy

* Namespaces mysql (#1386)

* feat: wip namespace storage

* chore: add tests; storage impl

* chore: appease the linter

* feat: (wip) add namespace mysql migrations

* chore: rename migrations

* chore: rm empty migrations for the moment

* chore: less sleepy

* chore: 6 bytes for timestamp

* chore: add rules migration

* chore: add migration comments, revert local config

* chore: reset mysql example

* Namespaces postgres (#1388)

* feat: (wip) postgres ddl

* chore: fix tests

* chore: disable container logging unless verbose env var passed

* Namespaces cockroach (#1390)

* feat: cockroachdb migrations

* chore: fix migrations for cockroach

* chore: namespaces down migrations (#1396)

* Namespaces: flags storage tests (#1406)

* Namespaces: segments storage tests (#1408)

* chore: add segment namespace storage tests

* chore: regen protos

* chore: ignore sdk dir when fmting

* chore: add remaining storage layer tests (#1412)

* feat: add namespaces server mappings (#1415)

* chore: add remaining storage layer tests

* feat: add namespaces server mappings

* chore: add back default namespace to otel metrics

* chore: fix middleware test

* Namespaces rpc (#1421)

* feat: check for protected or flags existing when deleting a namespace (#1422)

* feat: add namespaces server impl

* chore: spacing

* chore: rm ability to set protected

* feat: check for protected or flags existing when deleting a namespace

* chore: fix test

* chore: add test for non-existing delete

* feat(hack/build): add cases for namespace scoped integration tests (#1436)

* chore: regenerate protobuf

* feat(rpc/flipt): configure gateway routes for namespaces

* feat(hack/build): add cases for namespace scoped integration tests

* chore(rpc/flipt): remove TODO

* chore(hack/build): use random string for namespace key

* test(hack/build): ensure default namespace cannot be deleted

* test(hack/build): ensure default namespace is protected but updateable

* test(hack/build): ensure namespace with flags cannot be deleted

* feat: add check for rule namespaced errors

* fix: namespace segment REST API routes were not correct (#1445)

* feat: add distribution test for cross-namespace entities

* feat: leave namespace check to distribution

* feat: generate namespaced scoped routes for distributions

* chore: address changes in regards to error messaging

* chore: abstract out the two types of DistributionRequests

* fix(migrations/sqlite): reorder to ensure we copy all data before drop (#1446)

* fix(migrations/sqlite): reorder to ensure we copy all data before drop

* fix(migrations/sqlite): copy distributions into temp table before dropping everything

* chore: do joins on the query and make error messages match

* chore: merge main into namespaces (#1448)

* chore(deps): bump go.opentelemetry.io/otel/exporters/zipkin (#1440)

Bumps [go.opentelemetry.io/otel/exporters/zipkin](https://github.com/open-telemetry/opentelemetry-go) from 1.13.0 to 1.14.0.
- [Release notes](https://github.com/open-telemetry/opentelemetry-go/releases)
- [Changelog](https://github.com/open-telemetry/opentelemetry-go/blob/main/CHANGELOG.md)
- [Commits](open-telemetry/opentelemetry-go@v1.13.0...v1.14.0)

---
updated-dependencies:
- dependency-name: go.opentelemetry.io/otel/exporters/zipkin
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* feat(github): dagger based integrations tests github workflow (#1428)

* feat(github): install dagger based ITs as action workflow

* fix(github): add workdir to mage action

* chore(hack/build): bump dagger to 0.5.1

* chore: enable daggers experimental gha cache

* chore(hack/build): reword test log lines

* fix(github): move env var from legacy to experimental tests

* chore(hack/build): arbitrary change to trigger rebuild

* chore(github): remove experimental dagger cache env var

* feat(hack/build): direct integration test flipt logs into directory

* chore: empty commit to trigger CI

* chore(hack/build): log error when failing to copy flipt logs

* chore(hack/build): adding log line to integration test start

* fix(github): stop caching entire hack build directory

* refactor(hack/build): organize integration cases into test case struct

* refactor(github): remove legacy API workflows and replace with dagger mage task

* chore(hack/build): use protocolPorts map for test case iteration

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* chore: add missing namespace metrics (#1450)

* chore: allow testing of namespaces ui branch for build

* chore: rm down migrations (#1449)

* chore: wip rm down migrations

* chore: fix tests

* chore: fix tests; cleanup

* chore: use new migrator on import if drop specified

* chore: fix drop before import for sqlite

* chore: move mysql fk disable into migrator down method

* chore: codecov's last chance

* feat(cmd): import and export namespace flag (#1452)

* refactor(export): promote namespace to NewExporter argument

* refactor(export): use GRPC service interface as exporter dependency

* feat(export): support --export-from-address remote flipt address flag

* refactor(cmd): share config as argument not global state

* refactor(cmd/export): move command boostrapping from main.go to export.go

* refactor(cmd): move signal trapping into main

* refactor(cmd/import): move command boostrapping from main.go to import.go

* refactor(ext): expose namespace as argument to NewImporter

* feat(cmd/import): support remote import via --import-to-address

* refactor(hack/build): restructure testing packages

* refactor(hack/build): create import and export integration tests

* feat(hack/build): more import integration test cases

* feat(cmd/export): support --namespace flag

* chore: go mod tidy

* fix(cmd): do not close db early in import/export

* refactor(cmd): rename import/export flags to --address and --token

* refactor(cmd/import): move server config into server.go

* fix(cmd/import): pass namespace key as name on create

* fix(hack/build): assert returned namespace name is as expected

* chore: validation logic for namespace requests (#1457)

* chore: validation logic for namespace requests

* chore: fix import command to use the namespace key as the name as well

* chore: rm TODO comments in exporter

* chore: mage proto

* chore: update changelog for future namespace release; add mage proto lint check (#1460)

* chore: trigger lint build

* chore: rm mage proto check for now as its not working

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: George <[email protected]>
Co-authored-by: Yoofi Quansah <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
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

Successfully merging this pull request may close these issues.

4 participants