Repository navigation
Namespace Redis keys; read DB user and name from Consul - #8
Merged
Merged
Conversation
Environments that share a Postgres or Redis server need to keep their data apart. The deploy template hardcoded the database user and name, and every Redis key and the live-update channel used one fixed set of names. store.Redis wraps the client and carries a namespace set once from redis.namespace (or SYNAPSE_REDIS_NAMESPACE). The live publisher and hub, the OAuth token cache, the rate limiter and the Telegram connect flow name their keys and channels through rdb.Name. An empty namespace leaves every name unchanged. The deploy template now reads pg_user and pg_dbname with the same KEY helper as pg_password, and redis_namespace as an optional key. The keys must exist in Consul before this release is deployed, or the render fails at startup.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Lets environments that share a Postgres or Redis server keep their data apart, so Synapse test can run next to prod.
Why
Synapse test is being added on the same Postgres and Redis servers as prod. The template hardcoded
user: synapse/dbname: synapse, and Redis used one fixed set of names. A Redis database number would not have been enough: pub/sub ignores it, so the live inbox channelsynapse:inbox:<user_id>would have been shared between environments.How
store.Rediswraps the go-redis client and carries aNamespaceset once fromredis.namespace(envSYNAPSE_REDIS_NAMESPACE).store.NewRedisandstore.NewRedisClientread it from config, so no component is told the namespace separately.rdb.Name: the live publisher and hub (live.Channel(ns, userID)), the OAuth token cache, the rate limiter (including the Telegram buckets) and the Telegram connect keys.deploy/config.yaml.ctmplreadspg_userandpg_dbnamewith the sameKEYhelper aspg_password, andredis_namespacewithOPTKEY(optional).cmd/ingestnow builds its client withstore.NewRedisClient, with the same options as before.Flags and config
redis.namespace(SYNAPSE_REDIS_NAMESPACE), default empty.pg_userandpg_dbname. For prod and beta they aresynapseandsynapse, the current values.redis_namespace.KEYDOESNOTEXIST_pg_userandrun-synapse-commandrefuses to start.Testing
TestConnectKeysFollowTheNamespace.TestPublishGoesToTheNamespacedChannelandTestHubOnlyHearsItsOwnNamespace(live),TestMBIntrospector_CacheKeyFollowsNamespace(OAuth),TestBucketsStayInsideTheirNamespace(rate limit).e2e), so any component that ignores it fails a test. Full suite passes.namespace: ""line; with the test values it renderssynapse_testandnamespace: "test". This did not use the real consul-template.gofmt,go vetandgo vet -tags integrationare clean.Reviewer guide
About 390 lines across 28 files. Suggested order:
internal/store/redis.goandinternal/store/namespace.go: the client wrapper and the one helper.internal/live,internal/oauth,internal/ratelimit,internal/adapter/telegram: each now names keys throughrdb.Name.deploy/config.yaml.ctmpl,config.example.yaml,internal/config.