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

(aws-dynamodb): Cannot alarm on metricThrottledRequestsForOperations due to Alarm limits #24509

Open
straygar opened this issue Mar 8, 2023 · 7 comments
Labels
@aws-cdk/aws-dynamodb Related to Amazon DynamoDB bug This issue is a bug. p2

Comments

@straygar
Copy link

straygar commented Mar 8, 2023

Describe the bug

"metricThrottledRequestsForOperations" uses a math experession behind the hood to get the metric. By default, operations is set to cover everything (which is good). However, since there are more than 10 operations, trying to create a CloudWatch Alarm with all operations results in the following error on sync:

Error: Alarms on math expressions cannot contain more than 10 individual metrics

Would it be possible to change how the metrics are fetched to avoid this?

Expected Behavior

I can create an alarm on table.metricThrottledRequestsForOperations()

Current Behavior

Trying to create a CloudWatch Alarm with all operations results in the following error on sync:

Error: Alarms on math expressions cannot contain more than 10 individual metrics

Reproduction Steps

const app = new App();
const stack = new Stack(app);
const table = new Table(stack, 'Table', {
    partitionKey: {
        name: 'pk',
        type: AttributeType.STRING
    },
});
const alarm = new Alarm(stack, 'Alarm', {
  metric: table.metricThrottledRequestsForOperations(),
  evaluationPeriods: 1,
  threshold: 1,
});

Possible Solution

Use a SEARCH() math expression or SQL style query and aggregate with SUM in sumMetricForOperation, to find all throttled metrics for the table.

Example:

new MathExpression({
  expression: `
    SELECT SUM(ThrottledRequests)
    FROM "AWS/DynamoDB"
    WHERE TableName = '${table.name}'
  `
});

Additional Information/Context

No response

CDK CLI Version

2.60.0

Framework Version

No response

Node.js Version

18

OS

MacOS

Language

Typescript

Language Version

No response

Other information

No response

@straygar straygar added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Mar 8, 2023
@github-actions github-actions bot added the @aws-cdk/aws-dynamodb Related to Amazon DynamoDB label Mar 8, 2023
@pahud
Copy link
Contributor

pahud commented Mar 8, 2023

This limit is described here:

(Optional) If you want to add another metric to a metric math expression, you can use the search box to find a specific metric. You can add as many as 10 metrics to a metric math expression.

I'll try reproduce this in my account.

@pahud pahud added investigating This issue is being investigated and/or work is in progress to resolve the issue. needs-reproduction This issue needs reproduction. and removed needs-triage This issue or PR still needs to be triaged. labels Mar 8, 2023
@pahud pahud self-assigned this Mar 8, 2023
@pahud pahud added the p2 label Mar 15, 2023
@jbm00n
Copy link

jbm00n commented Mar 23, 2023

Same issue with metricSystemErrorsForOperations. We basically just want to trigger an alarm based on the SystemErrors metric from the AWS/DynamoDB namespace. Is there another way to do this? (other than manipulating the MathExpression)

const alarm = new cloudwatch.Alarm(this, "MyAlarm", {
      evaluationPeriods: 1,      
      metric: table.metricSystemErrorsForOperations({        
        period: cdk.Duration.seconds(60),
        unit: cloudwatch.Unit.COUNT,
        statistic: cloudwatch.Stats.SUM,        
      }),
      threshold: 0,
      comparisonOperator: cloudwatch.ComparisonOperator.GREATER_THAN_THRESHOLD,
    });

@juarezzz
Copy link

You can pass an option with the operations you want your alarm to listen to. Like this:

import { Operation } from 'aws-cdk-lib/aws-dynamodb';
import { Alarm } from 'aws-cdk-lib/aws-cloudwatch';

const alarm = new Alarm(stack, 'Alarm', {
  metric: table.metricThrottledRequestsForOperations({
          operations: [
            Operation.PUT_ITEM,
            Operation.BATCH_WRITE_ITEM,
            Operation.QUERY,
          ],
   }),
  evaluationPeriods: 1,
  threshold: 1,
});

@pwteneyck
Copy link

You can pass an option with the operations you want your alarm to listen to

You can, but the point here is that the default value that CDK uses for table.metricThrottledRequestsForOperations results in a build error

@straygar
Copy link
Author

straygar commented Mar 6, 2024

I think this is solved by: #29341

Should we close this issue?

Edit: actually nevermind, I think that limit bump is for metrics per alarm, and not math expressions.

@pahud
Copy link
Contributor

pahud commented Aug 7, 2024

Does this issue still exist as we merged #29341 ?

@pahud pahud added response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. and removed investigating This issue is being investigated and/or work is in progress to resolve the issue. needs-reproduction This issue needs reproduction. labels Aug 7, 2024
@pahud pahud removed their assignment Aug 7, 2024
@straygar
Copy link
Author

straygar commented Aug 9, 2024

@pahud I suggested the same in the comment above, but no it doesn't fix it. Math expressions still have a limit of 10.

Alarms based on metric math expressions can have up to 10 metrics. (source)

Unless you suggest that this task should be to rewrite the metric so that it doesn't use metric math somehow?

@github-actions github-actions bot removed the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label Aug 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-dynamodb Related to Amazon DynamoDB bug This issue is a bug. p2
Projects
None yet
Development

No branches or pull requests

5 participants