From c8e6405220948a1d1a5b6fd4eb4e1460c94b5e5e Mon Sep 17 00:00:00 2001 From: Zachary Wasserman Date: Thu, 15 Dec 2016 16:13:23 -0800 Subject: [PATCH] Use redis for distributed query results when not in dev mode (#653) - Add appropriate configs for Redis - Use the Redis pubsub store by default, inmem in dev mode --- cli/serve.go | 10 +++++++++- server/config/config.go | 15 +++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/cli/serve.go b/cli/serve.go index e91bf575d0..e9e9452ffa 100644 --- a/cli/serve.go +++ b/cli/serve.go @@ -93,7 +93,15 @@ the way that the kolide server works. } } - svc, err := service.NewService(ds, pubsub.NewInmemQueryResults(), logger, config, mailService, clock.C) + var resultStore kolide.QueryResultStore + if devMode { + resultStore = pubsub.NewInmemQueryResults() + } else { + redisPool := pubsub.NewRedisPool(config.Redis.Address, config.Redis.Password) + resultStore = pubsub.NewRedisQueryResults(redisPool) + } + + svc, err := service.NewService(ds, resultStore, logger, config, mailService, clock.C) if err != nil { initFatal(err, "initializing service") } diff --git a/server/config/config.go b/server/config/config.go index 98f0b53db2..41c42e6e6a 100644 --- a/server/config/config.go +++ b/server/config/config.go @@ -22,6 +22,12 @@ type MysqlConfig struct { Database string } +// RedisConfig defines configs related to Redis +type RedisConfig struct { + Address string + Password string +} + // ServerConfig defines configs related to the Kolide server type ServerConfig struct { Address string @@ -79,6 +85,7 @@ type LoggingConfig struct { // updated to set and retrieve the configurations as appropriate. type KolideConfig struct { Mysql MysqlConfig + Redis RedisConfig Server ServerConfig Auth AuthConfig App AppConfig @@ -97,6 +104,10 @@ func (man Manager) addConfigs() { man.addConfigString("mysql.password", "kolide") man.addConfigString("mysql.database", "kolide") + // Redis + man.addConfigString("redis.address", "localhost:6379") + man.addConfigString("redis.password", "") + // Server man.addConfigString("server.address", "0.0.0.0:8080") man.addConfigString("server.cert", "./tools/osquery/kolide.crt") @@ -148,6 +159,10 @@ func (man Manager) LoadConfig() KolideConfig { Password: man.getConfigString("mysql.password"), Database: man.getConfigString("mysql.database"), }, + Redis: RedisConfig{ + Address: man.getConfigString("redis.address"), + Password: man.getConfigString("redis.password"), + }, Server: ServerConfig{ Address: man.getConfigString("server.address"), Cert: man.getConfigString("server.cert"),