Configuration type for AWS collector

This commit is contained in:
Jonathan Lange
2016-06-30 17:01:58 +01:00
parent baacaa8cc5
commit 9e0f0c51b9
2 changed files with 26 additions and 16 deletions

View File

@@ -94,6 +94,16 @@ type ReportStore interface {
FetchReports([]string) (map[string]report.Report, []string, error)
}
// AWSCollectorConfig has everything we need to make an AWS collector.
type AWSCollectorConfig struct {
UserIDer UserIDer
DynamoDBConfig *aws.Config
DynamoTable string
S3Store *S3Store
NatsHost string
MemcacheClient *MemcacheClient
}
type awsCollector struct {
userIDer UserIDer
db *dynamodb.DynamoDB
@@ -124,30 +134,24 @@ type watchKey struct {
// NewAWSCollector the elastic reaper of souls
// https://github.com/aws/aws-sdk-go/wiki/common-examples
func NewAWSCollector(
userIDer UserIDer,
dynamoDBConfig *aws.Config, tableName string,
s3Store *S3Store,
natsHost string,
memcacheClient *MemcacheClient,
) (AWSCollector, error) {
func NewAWSCollector(config AWSCollectorConfig) (AWSCollector, error) {
var nc *nats.Conn
if natsHost != "" {
if config.NatsHost != "" {
var err error
nc, err = nats.Connect(natsHost)
nc, err = nats.Connect(config.NatsHost)
if err != nil {
return nil, err
}
}
return &awsCollector{
db: dynamodb.New(session.New(dynamoDBConfig)),
s3: s3Store,
userIDer: userIDer,
tableName: tableName,
db: dynamodb.New(session.New(config.DynamoDBConfig)),
s3: config.S3Store,
userIDer: config.UserIDer,
tableName: config.DynamoTable,
merger: app.NewSmartMerger(),
inProcess: newInProcessStore(reportCacheSize, reportCacheExpiration),
memcache: memcacheClient,
memcache: config.MemcacheClient,
nats: nc,
waiters: map[watchKey]*nats.Subscription{},
}, nil

View File

@@ -126,8 +126,14 @@ func collectorFactory(userIDer multitenant.UserIDer, collectorURL, s3URL, natsHo
}
}
awsCollector, err := multitenant.NewAWSCollector(
userIDer, dynamoDBConfig, tableName, &s3Store, natsHostname,
memcacheClient,
multitenant.AWSCollectorConfig{
UserIDer: userIDer,
DynamoDBConfig: dynamoDBConfig,
DynamoTable: tableName,
S3Store: &s3Store,
NatsHost: natsHostname,
MemcacheClient: memcacheClient,
},
)
if err != nil {
return nil, err