Skip to content

Commit

Permalink
feat(cloudwatch): liveData in GraphWidget (#8579)
Browse files Browse the repository at this point in the history
CDK is missing support for `liveData` property in GraphWidget. The properties are defined [here](https://docs.aws.amazon.com/AmazonCloudWatch/latest/APIReference/CloudWatch-Dashboard-Body-Structure.html) under "Metric Widget Object."

The optional properties `period` and `stat` are also not supported in Cloudwatch currently. I wonder if there are use cases for those as well.

This PR adds `liveData` to `GraphWidgetProps` and defaults to `false`. It fixes #8376 .

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
kaizencc authored Jun 18, 2020
1 parent 4b68655 commit 831092e
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
11 changes: 11 additions & 0 deletions packages/@aws-cdk/aws-cloudwatch/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,17 @@ dashboard.addWidgets(new GraphWidget({
}));
```

The graph can publish live data within the last minute that has not been fully aggregated.

```ts
dashboard.addWidgets(new GraphWidget({
// ...
// ...

liveData: true,
}));
```

### Alarm widget

An alarm widget shows the graph and the alarm line of a single alarm:
Expand Down
8 changes: 8 additions & 0 deletions packages/@aws-cdk/aws-cloudwatch/lib/graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,13 @@ export interface GraphWidgetProps extends MetricWidgetProps {
* @default - bottom
*/
readonly legendPosition?: LegendPosition;

/**
* Whether the graph should show live data
*
* @default false
*/
readonly liveData?: boolean;
}

/**
Expand Down Expand Up @@ -218,6 +225,7 @@ export class GraphWidget extends ConcreteWidget {
right: this.props.rightYAxis !== undefined ? this.props.rightYAxis : undefined,
},
legend: this.props.legendPosition !== undefined ? { position: this.props.legendPosition } : undefined,
liveData: this.props.liveData,
},
}];
}
Expand Down
31 changes: 31 additions & 0 deletions packages/@aws-cdk/aws-cloudwatch/test/test.graphs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,37 @@ export = {
test.done();
},

'specify liveData property on graph'(test: Test) {
// WHEN
const stack = new Stack();
const widget = new GraphWidget({
title: 'My live graph',
left: [
new Metric({ namespace: 'CDK', metricName: 'Test' }),
],
liveData: true,
});

// THEN
test.deepEqual(stack.resolve(widget.toJson()), [{
type: 'metric',
width: 6,
height: 6,
properties: {
view: 'timeSeries',
title: 'My live graph',
region: { Ref: 'AWS::Region' },
metrics: [
['CDK', 'Test'],
],
liveData: true,
yAxis: {},
},
}]);

test.done();
},

'can use imported alarm with graph'(test: Test) {
// GIVEN
const stack = new Stack();
Expand Down

0 comments on commit 831092e

Please sign in to comment.