Fixes to memcache support (#1628)

* Fix errors discovered in dev

* Log an error rather than aborting when memcache doesn't resolve
* Initialize map correctly

* Review tweaks
This commit is contained in:
Jonathan Lange
2016-07-04 11:00:11 +01:00
committed by Tom Wilkie
parent 682edd37e4
commit 96520d7a46
2 changed files with 5 additions and 16 deletions

View File

@@ -55,7 +55,7 @@ type MemcacheClient struct {
// NewMemcacheClient creates a new MemcacheClient that gets its server list
// from SRV and updates the server list on a regular basis.
func NewMemcacheClient(host string, timeout time.Duration, service string, updateInterval time.Duration, expiration int32) (*MemcacheClient, error) {
func NewMemcacheClient(host string, timeout time.Duration, service string, updateInterval time.Duration, expiration int32) *MemcacheClient {
var servers memcache.ServerList
client := memcache.NewFromSelector(&servers)
client.Timeout = timeout
@@ -70,12 +70,12 @@ func NewMemcacheClient(host string, timeout time.Duration, service string, updat
}
err := newClient.updateMemcacheServers()
if err != nil {
return nil, err
log.Errorf("Error setting memcache servers to '%v': %v", host, err)
}
newClient.wait.Add(1)
go newClient.updateLoop(updateInterval)
return newClient, nil
return newClient
}
// Stop the memcache client.
@@ -169,7 +169,7 @@ func (c *MemcacheClient) FetchReports(keys []string) (map[string]report.Report,
}(key)
}
var reports map[string]report.Report
reports := map[string]report.Report{}
for i := 0; i < len(keys)-len(missing); i++ {
r := <-ch
if r.report == nil {

View File

@@ -109,21 +109,10 @@ func collectorFactory(userIDer multitenant.UserIDer, collectorURL, s3URL, natsHo
s3Store := multitenant.NewS3Client(s3Config, bucketName)
var memcacheClient *multitenant.MemcacheClient
if memcachedHostname != "" {
memcacheClient, err = multitenant.NewMemcacheClient(
memcacheClient = multitenant.NewMemcacheClient(
memcachedHostname, memcachedTimeout, memcachedService,
memcacheUpdateInterval, memcacheExpiration,
)
if err != nil {
// TODO(jml): Ideally, we wouldn't abort here, we would instead
// log errors when we try to use the memcache & fail to do so, as
// aborting here introduces ordering dependencies into our
// deployment.
//
// Note: this error only happens when either the memcachedHost
// or any of the SRV records that it points to fail to
// resolve.
return nil, err
}
}
awsCollector, err := multitenant.NewAWSCollector(
multitenant.AWSCollectorConfig{