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(cloudwatch): period of each metric in usingMetrics for MathExpression is ignored #30986

Merged
merged 10 commits into from
Dec 11, 2024

Conversation

go-to-k
Copy link
Contributor

@go-to-k go-to-k commented Jul 31, 2024

Issue # (if applicable)

Closes #.

Reason for this change

The usingMetrics property (Record<string, IMetric>) in MathExpressionProps has Metric objects with a period.

On the other hand, in the MathExpression construct, the period of each metric in the usingMetrics is ignored and instead overridden by the period of the MathExpression. Even if the period of the MathExpression is not specified, it is overridden by its default value.

https://github.com/aws/aws-cdk/blob/main/packages/aws-cdk-lib/aws-cloudwatch/lib/metric.ts#L606-L608

However the statement is not written in the JSDoc.

https://github.com/aws/aws-cdk/blob/main/packages/aws-cdk-lib/aws-cloudwatch/lib/metric.ts#L566

new MathExpression({
  expression: "m1+m2",
  label: "AlbErrors",
  usingMetrics: {
    m1: metrics.custom("HTTPCode_ELB_500_Count", {
      period: Duration.minutes(1), // <- ignored and overridden by default value `Duration.minutes(5)` of `period` in the `MathExpressionOptions`
      statistic: "Sum",
      label: "HTTPCode_ELB_500_Count",
    }),
    m2: metrics.custom("HTTPCode_ELB_502_Count", {
      period: Duration.minutes(1), // <- ignored and overridden by default value `Duration.minutes(5)` of `period` in the `MathExpressionOptions`
      statistic: "Sum",
      label: "HTTPCode_ELB_502_Count",
    }),
  },
}),

Description of changes

The current documentation could be confusing to users, so add this description. Also added warnings in the situation.

Description of how you validated changes

Checklist


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@aws-cdk-automation aws-cdk-automation requested a review from a team July 31, 2024 09:34
@github-actions github-actions bot added p2 distinguished-contributor [Pilot] contributed 50+ PRs to the CDK labels Jul 31, 2024
@aws-cdk-automation aws-cdk-automation added the pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. label Jul 31, 2024
@go-to-k go-to-k changed the title docs(cloudwatch): add description that period of each metric is ignored in math expression docs(cloudwatch): add description that period of each metric in usingMetrics for MathExpression is ignored Jul 31, 2024
This was referenced Aug 1, 2024
Copy link
Contributor

@kaizencc kaizencc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In addition to this, what if we added a warning annotation anytime we find ourselves overwriting a different value? it's a little sinister to override a value and not tell the user when we do it.

packages/aws-cdk-lib/aws-cloudwatch/lib/metric.ts Outdated Show resolved Hide resolved
@kaizencc kaizencc changed the title docs(cloudwatch): add description that period of each metric in usingMetrics for MathExpression is ignored docs(cloudwatch): explain when period of each metric in usingMetrics for MathExpression is ignored Sep 4, 2024
@aws-cdk-automation aws-cdk-automation removed the pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. label Sep 4, 2024
@mergify mergify bot dismissed kaizencc’s stale review September 5, 2024 08:41

Pull request has been modified.

@go-to-k go-to-k force-pushed the docs/cloudwatch-math-expression-usingmetrics branch from 13f3459 to b8b2ae0 Compare September 5, 2024 09:27
@aws-cdk-automation aws-cdk-automation added the pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. label Sep 5, 2024
@go-to-k
Copy link
Contributor Author

go-to-k commented Sep 5, 2024

@kaizencc

Thanks for your review.

In addition to this, what if we added a warning annotation anytime we find ourselves overwriting a different value? it's a little sinister to override a value and not tell the user when we do it.

I added: 712e937

I have two questions:

  1. Should I change the PR title from docs(cloudwatch): ... to something else? (I thought this PR was not docs because warning process added.) Or, should PRs be separated?

  2. We can't warn only if the period in usingMetrics is set to the same value as the default value (Duration.minutes(5)), is there a problem?

It is correct usage to not specify a value for period (in usingMetrics), so we do not want to raise a warning in that case. However, if the period is not specified, it is overwritten with a default value, so we cannot determine whether the user has specified that value or if it has been overwritten. Therefore, warnings cannot be raised only in this case.

712e937#diff-289bad9fd897ab7808c177ad955a23faf18615ff8434f82b50fa0aeb54985de6R941

for example:

new MathExpression({
  expression:  'm1',
  label: 'AlbErrors',
  usingMetrics: {
    m1: metrics.custom('HTTPCode_ELB_500_Count', {
      period: Duration.minutes(5), // <- This is equal to the default value for `period`. So it is the same as not having specified.
      statistic: 'Sum',
      label: 'HTTPCode_ELB_500_Count',
    }),
  },
  period: Duration.minutes(3),
});

@go-to-k
Copy link
Contributor Author

go-to-k commented Sep 12, 2024

Hi, @kaizencc

Have you had a chance to look at the comment?

#30986 (comment)

@go-to-k
Copy link
Contributor Author

go-to-k commented Sep 26, 2024

@kaizencc

Could you please take a look at the comment? Do you have any good ideas to share?

@go-to-k go-to-k requested a review from kaizencc September 29, 2024 17:37
@go-to-k
Copy link
Contributor Author

go-to-k commented Nov 5, 2024

@kaizencc Could you take a look at it again?

Copy link
Contributor

@kaizencc kaizencc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hi @go-to-k :). sorry for the super long delay. to answer your questions:

  1. i think the title should be now a fix. i'll leave it to you to update.
  2. i think this is ok. it's better than nothing.

happy to approve once you update! i think the change to default.ts-fixture is unnecessary but i might be wrong.

@@ -2,6 +2,7 @@
import { Construct } from 'constructs';
import { Stack, Duration } from 'aws-cdk-lib';
import * as cloudwatch from 'aws-cdk-lib/aws-cloudwatch';
import * as elbv2 from 'aws-cdk-lib/aws-elasticloadbalancingv2';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think this is unnecessary?

Copy link
Contributor Author

@go-to-k go-to-k Dec 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @kaizencc !

I think it is necessary here, could you check it?

#30986 (comment)

* Example:
*
* ```ts
* declare const metrics: elbv2.IApplicationLoadBalancerMetrics;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

got it! thanks :)

@go-to-k go-to-k changed the title docs(cloudwatch): explain when period of each metric in usingMetrics for MathExpression is ignored fix(cloudwatch): period of each metric in usingMetrics for MathExpression is ignored Dec 4, 2024
Copy link
Collaborator

@aws-cdk-automation aws-cdk-automation left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pull request linter has failed. See the aws-cdk-automation comment below for failure reasons. If you believe this pull request should receive an exemption, please comment and provide a justification.

A comment requesting an exemption should contain the text Exemption Request. Additionally, if clarification is needed add Clarification Request to a comment.

@aws-cdk-automation aws-cdk-automation removed the pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. label Dec 4, 2024
@go-to-k
Copy link
Contributor Author

go-to-k commented Dec 4, 2024

Exemption Request: This PR could be covered by unit tests.

@aws-cdk-automation aws-cdk-automation added pr-linter/exemption-requested The contributor has requested an exemption to the PR Linter feedback. pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. labels Dec 4, 2024
@go-to-k
Copy link
Contributor Author

go-to-k commented Dec 4, 2024

@kaizencc

I also changed the PR title to fix....

@go-to-k go-to-k requested a review from kaizencc December 4, 2024 07:01
@kaizencc kaizencc added pr-linter/exempt-integ-test The PR linter will not require integ test changes and removed pr-linter/exemption-requested The contributor has requested an exemption to the PR Linter feedback. labels Dec 9, 2024
@aws-cdk-automation aws-cdk-automation dismissed their stale review December 9, 2024 15:40

✅ Updated pull request passes all PRLinter validations. Dismissing previous PRLinter review.

@aws-cdk-automation aws-cdk-automation removed the pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. label Dec 9, 2024
Copy link
Contributor

mergify bot commented Dec 9, 2024

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@kaizencc
Copy link
Contributor

kaizencc commented Dec 9, 2024

@Mergifyio refresh

Copy link
Contributor

mergify bot commented Dec 9, 2024

refresh

✅ Pull request refreshed

@go-to-k
Copy link
Contributor Author

go-to-k commented Dec 10, 2024

@Mergifyio update

Copy link
Contributor

mergify bot commented Dec 10, 2024

update

✅ Branch has been successfully updated

Copy link

codecov bot commented Dec 10, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 78.67%. Comparing base (4937ee1) to head (9cbfba5).

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #30986      +/-   ##
==========================================
+ Coverage   78.66%   78.67%   +0.01%     
==========================================
  Files         107      107              
  Lines        7237     7237              
  Branches     1329     1329              
==========================================
+ Hits         5693     5694       +1     
+ Misses       1358     1357       -1     
  Partials      186      186              
Flag Coverage Δ
suite.unit 78.67% <ø> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
packages/aws-cdk 78.67% <ø> (+0.01%) ⬆️

Copy link
Contributor

mergify bot commented Dec 10, 2024

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

Copy link
Contributor

mergify bot commented Dec 10, 2024

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildv2Project1C6BFA3F-wQm2hXv2jqQv
  • Commit ID: 9cbfba5
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@mergify mergify bot merged commit 59e96a3 into aws:main Dec 11, 2024
17 checks passed
Copy link
Contributor

mergify bot commented Dec 11, 2024

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

Copy link

Comments on closed issues and PRs are hard for our team to see.
If you need help, please open a new issue that references this one.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 11, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
distinguished-contributor [Pilot] contributed 50+ PRs to the CDK p2 pr-linter/exempt-integ-test The PR linter will not require integ test changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants