Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix incorrectly named dynamo events scaling policy #50907

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 34 additions & 15 deletions lib/events/dynamoevents/dynamoevents.go
Original file line number Diff line number Diff line change
Expand Up @@ -437,14 +437,14 @@ func (l *Log) configureTable(ctx context.Context, svc *applicationautoscaling.Cl
readDimension: autoscalingtypes.ScalableDimensionDynamoDBTableReadCapacityUnits,
writeDimension: autoscalingtypes.ScalableDimensionDynamoDBTableWriteCapacityUnits,
resourceID: fmt.Sprintf("table/%s", l.Tablename),
readPolicy: fmt.Sprintf("%s-write-target-tracking-scaling-policy", l.Tablename),
readPolicy: fmt.Sprintf("%s-read-target-tracking-scaling-policy", l.Tablename),
writePolicy: fmt.Sprintf("%s-write-target-tracking-scaling-policy", l.Tablename),
},
{
readDimension: autoscalingtypes.ScalableDimensionDynamoDBIndexReadCapacityUnits,
writeDimension: autoscalingtypes.ScalableDimensionDynamoDBIndexWriteCapacityUnits,
resourceID: fmt.Sprintf("table/%s/index/%s", l.Tablename, indexTimeSearchV2),
readPolicy: fmt.Sprintf("%s/index/%s-write-target-tracking-scaling-policy", l.Tablename, indexTimeSearchV2),
readPolicy: fmt.Sprintf("%s/index/%s-read-target-tracking-scaling-policy", l.Tablename, indexTimeSearchV2),
writePolicy: fmt.Sprintf("%s/index/%s-write-target-tracking-scaling-policy", l.Tablename, indexTimeSearchV2),
},
}
Expand Down Expand Up @@ -472,20 +472,39 @@ func (l *Log) configureTable(ctx context.Context, svc *applicationautoscaling.Cl

// Define scaling policy. Defines the ratio of {read,write} consumed capacity to
// provisioned capacity DynamoDB will try and maintain.
if _, err := svc.PutScalingPolicy(ctx, &applicationautoscaling.PutScalingPolicyInput{
PolicyName: aws.String(p.readPolicy),
PolicyType: autoscalingtypes.PolicyTypeTargetTrackingScaling,
ResourceId: aws.String(p.resourceID),
ScalableDimension: p.readDimension,
ServiceNamespace: autoscalingtypes.ServiceNamespaceDynamodb,
TargetTrackingScalingPolicyConfiguration: &autoscalingtypes.TargetTrackingScalingPolicyConfiguration{
PredefinedMetricSpecification: &autoscalingtypes.PredefinedMetricSpecification{
PredefinedMetricType: autoscalingtypes.MetricTypeDynamoDBReadCapacityUtilization,
for i := 0; i < 2; i++ {
if _, err := svc.PutScalingPolicy(ctx, &applicationautoscaling.PutScalingPolicyInput{
PolicyName: aws.String(p.readPolicy),
PolicyType: autoscalingtypes.PolicyTypeTargetTrackingScaling,
ResourceId: aws.String(p.resourceID),
ScalableDimension: p.readDimension,
ServiceNamespace: autoscalingtypes.ServiceNamespaceDynamodb,
TargetTrackingScalingPolicyConfiguration: &autoscalingtypes.TargetTrackingScalingPolicyConfiguration{
PredefinedMetricSpecification: &autoscalingtypes.PredefinedMetricSpecification{
PredefinedMetricType: autoscalingtypes.MetricTypeDynamoDBReadCapacityUtilization,
},
TargetValue: aws.Float64(l.ReadTargetValue),
},
TargetValue: aws.Float64(l.ReadTargetValue),
},
}); err != nil {
return trace.Wrap(convertError(err))
}); err != nil {
// The read policy name was accidentally changed to match the write policy in 17.0.0-17.1.4. This
// prevented upgrading a cluster with autoscaling enabled from v16 to v17. To resolve in
// a backwards compatible way, the read policy name was restored, however, any new clusters that
// were created between 17.0.0 and 17.1.4 need to have the misnamed policy deleted and recreated
// with the correct name.
if i == 1 || !strings.Contains(err.Error(), "ValidationException: Only one TargetTrackingScaling policy for a given metric specification is allowed.") {
return trace.Wrap(convertError(err))
}

l.logger.DebugContext(ctx, "Fixing incorrectly named scaling policy")
if _, err := svc.DeleteScalingPolicy(ctx, &applicationautoscaling.DeleteScalingPolicyInput{
PolicyName: aws.String(p.writePolicy),
ResourceId: aws.String(p.resourceID),
ScalableDimension: p.readDimension,
ServiceNamespace: autoscalingtypes.ServiceNamespaceDynamodb,
}); err != nil {
return trace.Wrap(convertError(err))
}
}
}

if _, err := svc.PutScalingPolicy(ctx, &applicationautoscaling.PutScalingPolicyInput{
Expand Down
Loading