From 60e14c1dc2df0abb4c6b9553e409c753e83873c4 Mon Sep 17 00:00:00 2001 From: Jonathan Lange Date: Thu, 14 Jul 2016 18:46:50 +0100 Subject: [PATCH] Plumb through an option for compression --- app/multitenant/memcache_client.go | 11 ++++++----- prog/app.go | 16 +++++++++------- prog/main.go | 23 +++++++++++++---------- 3 files changed, 28 insertions(+), 22 deletions(-) diff --git a/app/multitenant/memcache_client.go b/app/multitenant/memcache_client.go index fe4ec8f5d..9809f950c 100644 --- a/app/multitenant/memcache_client.go +++ b/app/multitenant/memcache_client.go @@ -58,11 +58,12 @@ type MemcacheClient struct { // MemcacheConfig defines how a MemcacheClient should be constructed. type MemcacheConfig struct { - Host string - Service string - Timeout time.Duration - UpdateInterval time.Duration - Expiration time.Duration + Host string + Service string + Timeout time.Duration + UpdateInterval time.Duration + Expiration time.Duration + CompressionLevel int } // NewMemcacheClient creates a new MemcacheClient that gets its server list diff --git a/prog/app.go b/prog/app.go index 0642676e8..e444db4ad 100644 --- a/prog/app.go +++ b/prog/app.go @@ -81,7 +81,7 @@ func awsConfigFromURL(url *url.URL) (*aws.Config, error) { return config, nil } -func collectorFactory(userIDer multitenant.UserIDer, collectorURL, s3URL, natsHostname, memcachedHostname string, memcachedTimeout time.Duration, memcachedService string, memcachedExpiration, window time.Duration, createTables bool) (app.Collector, error) { +func collectorFactory(userIDer multitenant.UserIDer, collectorURL, s3URL, natsHostname, memcachedHostname string, memcachedTimeout time.Duration, memcachedService string, memcachedExpiration time.Duration, memcachedCompressionLevel int, window time.Duration, createTables bool) (app.Collector, error) { if collectorURL == "local" { return app.NewCollector(window), nil } @@ -114,11 +114,12 @@ func collectorFactory(userIDer multitenant.UserIDer, collectorURL, s3URL, natsHo if memcachedHostname != "" { memcacheClient = multitenant.NewMemcacheClient( multitenant.MemcacheConfig{ - Host: memcachedHostname, - Timeout: memcachedTimeout, - Expiration: memcachedExpiration, - UpdateInterval: memcacheUpdateInterval, - Service: memcachedService, + Host: memcachedHostname, + Timeout: memcachedTimeout, + Expiration: memcachedExpiration, + UpdateInterval: memcacheUpdateInterval, + Service: memcachedService, + CompressionLevel: memcachedCompressionLevel, }, ) } @@ -214,7 +215,8 @@ func appMain(flags appFlags) { collector, err := collectorFactory( userIDer, flags.collectorURL, flags.s3URL, flags.natsHostname, flags.memcachedHostname, - flags.memcachedTimeout, flags.memcachedService, flags.memcachedExpiration, flags.window, flags.awsCreateTables) + flags.memcachedTimeout, flags.memcachedService, flags.memcachedExpiration, flags.memcachedCompressionLevel, + flags.window, flags.awsCreateTables) if err != nil { log.Fatalf("Error creating collector: %v", err) return diff --git a/prog/main.go b/prog/main.go index 7e9aed1f6..4998ed465 100644 --- a/prog/main.go +++ b/prog/main.go @@ -1,6 +1,7 @@ package main import ( + "compress/gzip" "flag" "fmt" "net" @@ -100,16 +101,17 @@ type appFlags struct { containerName string dockerEndpoint string - collectorURL string - s3URL string - controlRouterURL string - pipeRouterURL string - natsHostname string - memcachedHostname string - memcachedTimeout time.Duration - memcachedService string - memcachedExpiration time.Duration - userIDHeader string + collectorURL string + s3URL string + controlRouterURL string + pipeRouterURL string + natsHostname string + memcachedHostname string + memcachedTimeout time.Duration + memcachedService string + memcachedExpiration time.Duration + memcachedCompressionLevel int + userIDHeader string awsCreateTables bool consulInf string @@ -195,6 +197,7 @@ func main() { flag.DurationVar(&flags.app.memcachedTimeout, "app.memcached.timeout", 100*time.Millisecond, "Maximum time to wait before giving up on memcached requests.") flag.DurationVar(&flags.app.memcachedExpiration, "app.memcached.expiration", 2*15*time.Second, "How long reports stay in the memcache.") flag.StringVar(&flags.app.memcachedService, "app.memcached.service", "memcached", "SRV service used to discover memcache servers.") + flag.IntVar(&flags.app.memcachedCompressionLevel, "app.memcached.compression", gzip.DefaultCompression, "How much to compress reports stored in memcached.") flag.StringVar(&flags.app.userIDHeader, "app.userid.header", "", "HTTP header to use as userid") flag.BoolVar(&flags.app.awsCreateTables, "app.aws.create.tables", false, "Create the tables in DynamoDB")