Skip to content

Commit 66e5485

Browse files
committed
Only enable auto scale if passed ApplicationAutoScale url
1 parent b01a1e3 commit 66e5485

File tree

3 files changed

+26
-26
lines changed

3 files changed

+26
-26
lines changed

cmd/table-manager/main.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ func main() {
2828
util.RegisterFlags(&serverConfig, &storageConfig, &schemaConfig)
2929
flag.Parse()
3030

31+
if schemaConfig.ChunkTables.WriteScaleEnabled && storageConfig.ApplicationAutoScaling.URL != nil {
32+
log.Fatal("WriteScale is enabled but no ApplicationAutoScaling URL has been provided")
33+
}
34+
3135
tableClient, err := storage.NewTableClient(storageConfig)
3236
if err != nil {
3337
log.Fatalf("Error initializing DynamoDB table client: %v", err)

pkg/chunk/aws_storage_client.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414

1515
"github.com/aws/aws-sdk-go/aws"
1616
"github.com/aws/aws-sdk-go/aws/awserr"
17+
"github.com/aws/aws-sdk-go/aws/client"
1718
"github.com/aws/aws-sdk-go/aws/credentials"
1819
"github.com/aws/aws-sdk-go/aws/request"
1920
"github.com/aws/aws-sdk-go/aws/session"
@@ -103,15 +104,17 @@ func init() {
103104

104105
// DynamoDBConfig specifies config for a DynamoDB database.
105106
type DynamoDBConfig struct {
106-
DynamoDB util.URLValue
107-
APILimit float64
107+
DynamoDB util.URLValue
108+
APILimit float64
109+
ApplicationAutoScaling util.URLValue
108110
}
109111

110112
// RegisterFlags adds the flags required to config this to the given FlagSet
111113
func (cfg *DynamoDBConfig) RegisterFlags(f *flag.FlagSet) {
112114
f.Var(&cfg.DynamoDB, "dynamodb.url", "DynamoDB endpoint URL with escaped Key and Secret encoded. "+
113115
"If only region is specified as a host, proper endpoint will be deduced. Use inmemory:///<table-name> to use a mock in-memory implementation.")
114116
f.Float64Var(&cfg.APILimit, "dynamodb.api-limit", 2.0, "DynamoDB table management requests per second limit.")
117+
f.Var(&cfg.ApplicationAutoScaling, "applicationautoscaling.url", "ApplicationAutoscaling endpoint URL with escaped Key and Secret encoded.")
115118
}
116119

117120
// AWSStorageConfig specifies config for storing data on AWS.
@@ -806,6 +809,15 @@ func recordDynamoError(tableName string, err error, operation string) {
806809

807810
// dynamoClientFromURL creates a new DynamoDB client from a URL.
808811
func dynamoClientFromURL(awsURL *url.URL) (dynamodbiface.DynamoDBAPI, error) {
812+
dynamoDBSession, err := awsSessionFromURL(awsURL)
813+
if err != nil {
814+
return nil, err
815+
}
816+
return dynamodb.New(dynamoDBSession), nil
817+
}
818+
819+
// awsSessionFromURL creates a new aws session from a URL.
820+
func awsSessionFromURL(awsURL *url.URL) (client.ConfigProvider, error) {
809821
if awsURL == nil {
810822
return nil, fmt.Errorf("no URL specified for DynamoDB")
811823
}
@@ -817,7 +829,7 @@ func dynamoClientFromURL(awsURL *url.URL) (dynamodbiface.DynamoDBAPI, error) {
817829
if err != nil {
818830
return nil, err
819831
}
820-
return dynamodb.New(session.New(config)), nil
832+
return session.New(config), nil
821833
}
822834

823835
// awsConfigFromURL returns AWS config from given URL. It expects escaped AWS Access key ID & Secret Access Key to be

pkg/chunk/dynamodb_table_client.go

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,15 @@ package chunk
22

33
import (
44
"fmt"
5-
"net/url"
6-
"strings"
75
"time"
86

97
"github.com/aws/aws-sdk-go/aws"
108
"github.com/aws/aws-sdk-go/aws/awserr"
11-
"github.com/aws/aws-sdk-go/aws/session"
129
"github.com/aws/aws-sdk-go/service/applicationautoscaling"
1310
"github.com/aws/aws-sdk-go/service/applicationautoscaling/applicationautoscalingiface"
1411
"github.com/aws/aws-sdk-go/service/dynamodb"
1512
"github.com/aws/aws-sdk-go/service/dynamodb/dynamodbiface"
1613
"github.com/prometheus/client_golang/prometheus"
17-
"github.com/prometheus/common/log"
1814
"golang.org/x/net/context"
1915
"golang.org/x/time/rate"
2016

@@ -49,9 +45,13 @@ func NewDynamoDBTableClient(cfg DynamoDBConfig) (TableClient, error) {
4945
return nil, err
5046
}
5147

52-
applicationAutoScaling, err := applicationAutoScalingClientFromURL(cfg.DynamoDB.URL)
53-
if err != nil {
54-
return nil, err
48+
var applicationAutoScaling applicationautoscalingiface.ApplicationAutoScalingAPI
49+
if cfg.ApplicationAutoScaling.URL != nil {
50+
session, err := awsSessionFromURL(cfg.ApplicationAutoScaling.URL)
51+
if err != nil {
52+
return nil, err
53+
}
54+
applicationAutoScaling = applicationautoscaling.New(session)
5555
}
5656

5757
return dynamoTableClient{
@@ -61,22 +61,6 @@ func NewDynamoDBTableClient(cfg DynamoDBConfig) (TableClient, error) {
6161
}, nil
6262
}
6363

64-
// applicationAutoScalingClientFromURL creates a new ApplicationAuthScaling client from a URL.
65-
func applicationAutoScalingClientFromURL(awsURL *url.URL) (applicationautoscalingiface.ApplicationAutoScalingAPI, error) {
66-
if awsURL == nil {
67-
return nil, fmt.Errorf("no URL specified for DynamoDB")
68-
}
69-
path := strings.TrimPrefix(awsURL.Path, "/")
70-
if len(path) > 0 {
71-
log.Warnf("Ignoring DynamoDB URL path: %v.", path)
72-
}
73-
config, err := awsConfigFromURL(awsURL)
74-
if err != nil {
75-
return nil, err
76-
}
77-
return applicationautoscaling.New(session.New(config)), nil
78-
}
79-
8064
func (d dynamoTableClient) backoffAndRetry(ctx context.Context, fn func(context.Context) error) error {
8165
if d.limiter != nil { // Tests will have a nil limiter.
8266
d.limiter.Wait(ctx)

0 commit comments

Comments
 (0)