question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

(aws-cloudwatch): Missing ids when creating math expressions

See original GitHub issue

There’s no way to assign an ID to a metric in CDK at this point. If you’re creating multiple math expressions within a single dashboard widget, the IDs for the math expressions are missing, and you’ll see that they have the same IDs in the CloudWatch Dashboard, and the metrics in the dashboard widget will be messed up.

Reproduction Steps

new cloudWatch.GraphWidget({
    left: [
        new MathExpression(...),
        new MathExpression(...),
        new MathExpression(...)
    ]
});

The generated CloudFormation file doesn’t contain ID for MathExpression (see example below). After deployed, in the CloudWatch, we’ll see that all the math expressions are assigned with the same ID, and the dashboard widget shows incorrect metrics

{ "label": "percentage", "expression": "m1 / m2", "region": "us-east-1" }

What did you expect to happen?

  • There should be a way to auto or manually set the ID for MathExpression
  • The above example should finally contain an id, something like
{ "label": "percentage", "expression": "m1 / m2", "region": "us-east-1", id: "e1" }

What actually happened?

The generated Math Expression widget doesn’t have an id

{ "label": "percentage", "expression": "m1 / m2", "region": "us-east-1" }

Environment

  • CDK CLI Version : any
  • Framework Version: 1.95
  • Node.js Version: any
  • OS : any
  • Language (Version): TypeScript (but I think this issue is in all the languages)

Other


This is 🐛 Bug Report

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
adam-kiss-sgcommented, Nov 12, 2021

If any1 else is still facing this issue: I managed to hack around it in python, something similar could work in other languages as well:

helper class:

class MyMetric(aws_cloudwatch.Metric):
    def __init__(self, *args, **kwargs):
        super(MyMetric, self).__init__(*args, **kwargs)
    
    def addProperties(self, props):
        self.props = props
        return self
    
    def to_metric_config(self) -> aws_cloudwatch.MetricConfig:
        result = super(MyMetric, self).to_metric_config()
        if not hasattr(self, "props"):
            return result
        
        if "rendering_properties" in result._values:
            result._values["rendering_properties"].update(self.props)
        else:
            result._values["rendering_properties"] = self.props
        return result

Usage: Replace: aws_cloudwatch.Metric(namespace="AWS/EC2", metric_name="NetworkIn") with: MyMetric(namespace="AWS/EC2", metric_name="NetworkIn").addProperties({"id": "yourid", "visible": false})

0reactions
github-actions[bot]commented, Apr 12, 2022

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see. If you need more assistance, please either tag a team member or open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using metric math - Amazon CloudWatch
Function Arguments Return type* Supported for cross‑account? ABS TS. TS TS. TS ✓ ANOMALY_DETECTION_BAND TS. TS, S TS AVG TS. TS S. TS ✓
Read more >
Creating a CloudWatch alarm based on a metric math ...
You can't create an alarm based on the SEARCH expression. This is because search expressions return multiple time series, and an alarm based...
Read more >
Create a metric math alarm using Amazon CloudWatch
In this blog post, you'll create an alarm for a metric math expression that calculates the AWS Lambda error rate. You want to...
Read more >
Using Amazon CloudWatch metrics math to monitor and scale ...
Metric math enables you to query multiple CloudWatch metrics and use math expressions to create new time series based on these metrics.
Read more >
Amazon CloudWatch concepts - AWS Documentation
You can't retrieve statistics for the following dimensions or if you specify no dimensions. (The exception is by using the metric math SEARCH...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found