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

all: Add Redis configuration parameters #81

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion cmd/frontend/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,11 @@ func main() {
var cacher frontend.Cacher
if cfg.RedisCacheHost != "" {
addr := cfg.RedisCacheHost + ":" + cfg.RedisCachePort
redisClient = redis.NewClient(&redis.Options{Addr: addr})
redisClient = redis.NewClient(&redis.Options{
Addr: addr,
Password: cfg.RedisCachePassword,
DB: cfg.RedisCacheDB,
})
if err := redisClient.Ping(ctx).Err(); err != nil {
log.Errorf(ctx, "redis at %s: %v", addr, err)
} else {
Expand Down
8 changes: 5 additions & 3 deletions cmd/worker/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,14 +166,14 @@ func main() {
}

func getCacheRedis(ctx context.Context, cfg *config.Config) *redis.Client {
return getRedis(ctx, cfg.RedisCacheHost, cfg.RedisCachePort, 0, 6*time.Second)
return getRedis(ctx, cfg.RedisCacheHost, cfg.RedisCachePort, cfg.RedisCachePassword, cfg.RedisCacheDB, 0, 6*time.Second)
}

func getBetaCacheRedis(ctx context.Context, cfg *config.Config) *redis.Client {
return getRedis(ctx, cfg.RedisBetaCacheHost, cfg.RedisCachePort, 0, 6*time.Second)
return getRedis(ctx, cfg.RedisBetaCacheHost, cfg.RedisCachePort, cfg.RedisCachePassword, cfg.RedisCacheDB, 0, 6*time.Second)
}

func getRedis(ctx context.Context, host, port string, writeTimeout, readTimeout time.Duration) *redis.Client {
func getRedis(ctx context.Context, host, port, password string, db int, writeTimeout, readTimeout time.Duration) *redis.Client {
if host == "" {
return nil
}
Expand All @@ -186,5 +186,7 @@ func getRedis(ctx context.Context, host, port string, writeTimeout, readTimeout
DialTimeout: dialTimeout,
WriteTimeout: writeTimeout,
ReadTimeout: readTimeout,
Password: password,
DB: db,
})
}
4 changes: 3 additions & 1 deletion doc/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Pkgsite uses these environment variables:

| Environment Variable | Description |
| ------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|--------------------------------------| ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| GO_DISCOVERY_AUTH_VALUES | Set of values that could be set on the AuthHeader, in order to bypass checks by the cache. |
| GO_DISCOVERY_CONFIG_BUCKET | Bucket use for dynamic configuration (gs://bucket/object) GO_DISCOVERY_CONFIG_DYNAMIC must be set if GO_DISCOVERY_CONFIG_BUCKET is set. |
| GO_DISCOVERY_CONFIG_DYNAMIC | File that experiments are read from. Can be set locally using devtools/cmd/create_experiment_config/main.go. |
Expand Down Expand Up @@ -34,6 +34,8 @@ Pkgsite uses these environment variables:
| GO_DISCOVERY_QUOTA_RECORD_ONLY | Part of QuotaSettings -- Record data about blocking, but do not actually block. This is a \*bool, so we can distinguish "not present" from "false" in an override. |
| GO_DISCOVERY_REDIS_HOST | Configuration for redis page cache. |
| GO_DISCOVERY_REDIS_PORT | Configuration for redis page cache. |
| GO_DISCOVERY_REDIS_PASSWORD | Configuration for redis page cache. |
| GO_DISCOVERY_REDIS_DB | Configuration for redis page cache. |
| GO_DISCOVERY_SERVE_STATS | ServeStats determines whether the server has an endpoint that serves statistics for benchmarking or other purposes. |
| GO_DISCOVERY_SERVICE | GAE app service ID. Used for Kubernetes in the private repo. Set in run_local in queue configuration in private repo. Used to identify service in the logs. |
| GO_DISCOVERY_TESTDB | When running `go test ./...`, database tests will not run if you don't have postgres running. To run these tests, set `GO_DISCOVERY_TESTDB=true`. |
Expand Down
3 changes: 2 additions & 1 deletion internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ type Config struct {
DBPassword string `json:"-" yaml:"-"`

// Configuration for redis page cache.
RedisCacheHost, RedisBetaCacheHost, RedisCachePort string
RedisCacheHost, RedisBetaCacheHost, RedisCachePort, RedisCachePassword string
RedisCacheDB int

// UseProfiler specifies whether to enable Stackdriver Profiler.
UseProfiler bool
Expand Down
2 changes: 2 additions & 0 deletions internal/config/serverconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ func Init(ctx context.Context) (_ *config.Config, err error) {
RedisCacheHost: os.Getenv("GO_DISCOVERY_REDIS_HOST"),
RedisBetaCacheHost: os.Getenv("GO_DISCOVERY_REDIS_BETA_HOST"),
RedisCachePort: GetEnv("GO_DISCOVERY_REDIS_PORT", "6379"),
RedisCachePassword: GetEnv("GO_DISCOVERY_REDIS_PASSWORD", ""),
RedisCacheDB: GetEnvInt(ctx, "GO_DISCOVERY_REDIS_DB", 0),
Quota: config.QuotaSettings{
Enable: os.Getenv("GO_DISCOVERY_ENABLE_QUOTA") == "true",
QPS: GetEnvInt(ctx, "GO_DISCOVERY_QUOTA_QPS", 10),
Expand Down