Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{
"Resources": {
"DashCCD7F836": {
"Type": "AWS::CloudWatch::Dashboard",
"Properties": {
"DashboardBody": {
"Fn::Join": [
"",
[
"{\"widgets\":[{\"type\":\"metric\",\"width\":6,\"height\":6,\"x\":0,\"y\":0,\"properties\":{\"view\":\"timeSeries\",\"title\":\"Metrics with id and visible properties\",\"region\":\"",
{
"Ref": "AWS::Region"
},
"\",\"metrics\":[[\"CDK/Test\",\"Metric1\",{\"label\":\"Visible metric with custom ID\",\"id\":\"custom_metric_id\",\"visible\":true}],[\"CDK/Test\",\"Metric2\",{\"label\":\"Hidden metric for calculations\",\"id\":\"hidden_metric_id\",\"visible\":false}],[\"CDK/Test\",\"Metric3\",{\"label\":\"Metric with only ID\",\"id\":\"id_only_metric\"}],[\"CDK/Test\",\"Metric4\",{\"label\":\"Metric with only visible\",\"visible\":true}],[\"CDK/Test\",\"Metric5\",{\"label\":\"Right side hidden metric\",\"id\":\"right_hidden_id\",\"visible\":false,\"yAxis\":\"right\"}]],\"yAxis\":{}}}]}"
]
]
}
}
}
},
"Parameters": {
"BootstrapVersion": {
"Type": "AWS::SSM::Parameter::Value<String>",
"Default": "/cdk-bootstrap/hnb659fds/version",
"Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]"
}
},
"Rules": {
"CheckBootstrapVersion": {
"Assertions": [
{
"Assert": {
"Fn::Not": [
{
"Fn::Contains": [
[
"1",
"2",
"3",
"4",
"5"
],
{
"Ref": "BootstrapVersion"
}
]
}
]
},
"AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI."
}
]
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { App, Stack, StackProps } from 'aws-cdk-lib';
import { IntegTest } from '@aws-cdk/integ-tests-alpha';
import { Dashboard, Metric, GraphWidget } from 'aws-cdk-lib/aws-cloudwatch';

class DashboardWithMetricIdAndVisibleIntegrationTest extends Stack {
Copy link
Member

Choose a reason for hiding this comment

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

The integration test is good, but it doesn't demonstrate the primary use case of using the id property with math expressions as described in the issue. Improve the integration test to include a math expression that references metrics by their IDs, which would better validate the actual use case.

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 have made some changes to include usage of ID of predefined metrics inside math expression.

constructor(scope: App, id: string, props?: StackProps) {
super(scope, id, props);

const dashboard = new Dashboard(this, 'Dash');

const widget = new GraphWidget({
title: 'Metrics with id and visible properties',
left: [
new Metric({
namespace: 'CDK/Test',
metricName: 'Metric1',
label: 'Visible metric with custom ID',
id: 'custom_metric_id',
visible: true,
}),

new Metric({
namespace: 'CDK/Test',
metricName: 'Metric2',
label: 'Hidden metric for calculations',
id: 'hidden_metric_id',
visible: false,
}),

new Metric({
namespace: 'CDK/Test',
metricName: 'Metric3',
label: 'Metric with only ID',
id: 'id_only_metric',
}),

new Metric({
namespace: 'CDK/Test',
metricName: 'Metric4',
label: 'Metric with only visible',
visible: true,
}),
],
right: [
new Metric({
namespace: 'CDK/Test',
metricName: 'Metric5',
label: 'Right side hidden metric',
id: 'right_hidden_id',
visible: false,
}),
],
});

dashboard.addWidgets(widget);
}
}

const app = new App();
new IntegTest(app, 'cdk-integ-dashboard-with-metric-id-and-visible', {
testCases: [new DashboardWithMetricIdAndVisibleIntegrationTest(app, 'DashboardWithMetricIdAndVisibleIntegrationTest')],
});
33 changes: 33 additions & 0 deletions packages/aws-cdk-lib/aws-cloudwatch/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,39 @@ const metric = new cloudwatch.Metric({
});
```

### Metric ID
Copy link
Member

Choose a reason for hiding this comment

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

It doesn't provide a complete example showing how to use the id property with math expressions, which is the primary use case mentioned in the issue. Expand the documentation to include a complete example showing how to use the id property with math expressions, similar to the use case described in the issue.


Metrics can be assigned a unique identifier using the `id` property. This is
useful when referencing metrics in math expressions:

```ts
const metric = new cloudwatch.Metric({
namespace: 'AWS/Lambda',
metricName: 'Invocations',
dimensionsMap: {
FunctionName: 'MyFunction'
},
id: 'invocations'
});
```

The `id` must start with a lowercase letter and can only contain letters, numbers, and underscores.

### Metric Visible
Metrics can be hidden from dashboard graphs using the `visible` property:

```ts
declare const fn: lambda.Function;

const metric = fn.metricErrors({
visible: false
});
```

By default, all metrics are visible (`visible: true`). Setting `visible: false`
hides the metric from dashboard visualizations while still allowing it to be
used in math expressions given that it has an `id` set to it.

### Metric Math

Math expressions are supported by instantiating the `MathExpression` class.
Expand Down
Loading
Loading