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

docs(cloudwatch): explain when period of each metric in usingMetrics for MathExpression is ignored #30986

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

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.

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
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.

Comment on lines 229 to 231
* The `period` of each Metric object is ignored and instead overridden by
* the `period` of this math expression object. Even if the `period` of the
* math expression is not specified, it is overridden by its default value.
Copy link
Contributor

Choose a reason for hiding this comment

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

haha i find this comment you've added to be confusing too :). Your PR description makes more sense than this, it might be helpful to even add an example or something here -- its not clear to me when and how i would know if my period is being overwritten.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've rewritten it, what do you think?

b8b2ae0

Copy link
Contributor

Choose a reason for hiding this comment

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

the example is awesome! thanks so much

@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),
});

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

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

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

@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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
distinguished-contributor [Pilot] contributed 50+ PRs to the CDK p2 pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants