mirror of
https://github.com/weaveworks/scope.git
synced 2026-07-16 03:49:52 +00:00
Pass in memcache client
This commit is contained in:
@@ -23,14 +23,12 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
hourField = "hour"
|
||||
tsField = "ts"
|
||||
reportField = "report"
|
||||
reportCacheSize = (15 / 3) * 10 * 5 // (window size * report rate) * number of hosts per user * number of users
|
||||
reportCacheExpiration = 15 * time.Second
|
||||
memcacheExpiration = 15 // seconds
|
||||
memcacheUpdateInterval = 1 * time.Minute
|
||||
natsTimeout = 10 * time.Second
|
||||
hourField = "hour"
|
||||
tsField = "ts"
|
||||
reportField = "report"
|
||||
reportCacheSize = (15 / 3) * 10 * 5 // (window size * report rate) * number of hosts per user * number of users
|
||||
reportCacheExpiration = 15 * time.Second
|
||||
natsTimeout = 10 * time.Second
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -130,8 +128,8 @@ func NewDynamoDBCollector(
|
||||
userIDer UserIDer,
|
||||
dynamoDBConfig *aws.Config, tableName string,
|
||||
s3Store *S3Store,
|
||||
natsHost,
|
||||
memcachedHost string, memcachedTimeout time.Duration, memcachedService string,
|
||||
natsHost string,
|
||||
memcacheClient *MemcacheClient,
|
||||
) (DynamoDBCollector, error) {
|
||||
var nc *nats.Conn
|
||||
if natsHost != "" {
|
||||
@@ -142,22 +140,6 @@ func NewDynamoDBCollector(
|
||||
}
|
||||
}
|
||||
|
||||
var memcacheClient *MemcacheClient
|
||||
if memcachedHost != "" {
|
||||
var err error
|
||||
memcacheClient, err = NewMemcacheClient(memcachedHost, 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
|
||||
}
|
||||
}
|
||||
|
||||
return &dynamoDBCollector{
|
||||
db: dynamodb.New(session.New(dynamoDBConfig)),
|
||||
s3: s3Store,
|
||||
|
||||
27
prog/app.go
27
prog/app.go
@@ -27,6 +27,11 @@ import (
|
||||
"github.com/weaveworks/scope/probe/docker"
|
||||
)
|
||||
|
||||
const (
|
||||
memcacheExpiration = 15 // seconds
|
||||
memcacheUpdateInterval = 1 * time.Minute
|
||||
)
|
||||
|
||||
var (
|
||||
requestDuration = prometheus.NewSummaryVec(prometheus.SummaryOpts{
|
||||
Namespace: "scope",
|
||||
@@ -100,11 +105,29 @@ func collectorFactory(userIDer multitenant.UserIDer, collectorURL, s3URL, natsHo
|
||||
return nil, err
|
||||
}
|
||||
bucketName := strings.TrimPrefix(s3.Path, "/")
|
||||
s3Store := multitenant.NewS3Client(s3Config, bucketName)
|
||||
tableName := strings.TrimPrefix(parsed.Path, "/")
|
||||
s3Store := multitenant.NewS3Client(s3Config, bucketName)
|
||||
var memcacheClient *multitenant.MemcacheClient
|
||||
if memcachedHostname != "" {
|
||||
memcacheClient, err = 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
|
||||
}
|
||||
}
|
||||
dynamoCollector, err := multitenant.NewDynamoDBCollector(
|
||||
userIDer, dynamoDBConfig, tableName, &s3Store, natsHostname,
|
||||
memcachedHostname, memcachedTimeout, memcachedService,
|
||||
memcacheClient,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
Reference in New Issue
Block a user