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

feat(cloudwatch): add support for yAxis to graph #2406

Merged
merged 6 commits into from
May 24, 2019
Merged
Show file tree
Hide file tree
Changes from all 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
76 changes: 42 additions & 34 deletions packages/@aws-cdk/aws-cloudwatch/lib/graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,39 @@ export interface MetricWidgetProps {
readonly height?: number;
}

/**
* Properties for a Y-Axis
*/
export interface YAxisProps {
/**
* The min value
*
* @default 0
*/
readonly min?: number;

/**
* The max value
*
* @default No maximum value
*/
readonly max?: number;

/**
* The label
*
* @default No label
*/
readonly label?: string;

/**
* Whether to show units
*
* @default true
*/
readonly showUnits?: boolean;
}

/**
* Properties for an AlarmWidget
*/
Expand All @@ -45,11 +78,9 @@ export interface AlarmWidgetProps extends MetricWidgetProps {
readonly alarm: Alarm;

/**
* Range of left Y axis
*
* @default 0..automatic
* Left Y axis
*/
readonly leftAxisRange?: YAxisRange;
readonly leftYAxis?: YAxisProps;
}

/**
Expand Down Expand Up @@ -78,7 +109,7 @@ export class AlarmWidget extends ConcreteWidget {
alarms: [this.props.alarm.alarmArn]
},
yAxis: {
left: this.props.leftAxisRange !== undefined ? this.props.leftAxisRange : { min: 0 }
left: this.props.leftYAxis !== undefined ? this.props.leftYAxis : undefined
}
}
}];
Expand Down Expand Up @@ -115,18 +146,14 @@ export interface GraphWidgetProps extends MetricWidgetProps {
readonly stacked?: boolean;

/**
* Range of left Y axis
*
* @default 0..automatic
* Left Y axis
*/
readonly leftAxisRange?: YAxisRange;
readonly leftYAxis?: YAxisProps;

/**
* Range of right Y axis
*
* @default 0..automatic
* Right Y axis
*/
readonly rightAxisRange?: YAxisRange;
readonly rightYAxis?: YAxisProps;
}

/**
Expand Down Expand Up @@ -158,8 +185,8 @@ export class GraphWidget extends ConcreteWidget {
(this.props.rightAnnotations || []).map(mapAnnotation('right')))
},
yAxis: {
left: this.props.leftAxisRange !== undefined ? this.props.leftAxisRange : { min: 0 },
right: this.props.rightAxisRange !== undefined ? this.props.rightAxisRange : { min: 0 },
left: this.props.leftYAxis !== undefined ? this.props.leftYAxis : undefined,
right: this.props.rightYAxis !== undefined ? this.props.rightYAxis : undefined,
}
}
}];
Expand Down Expand Up @@ -204,25 +231,6 @@ export class SingleValueWidget extends ConcreteWidget {
}
}

/**
* A minimum and maximum value for either the left or right Y axis
*/
export interface YAxisRange {
/**
* The minimum value
*
* @default Automatic
*/
readonly min?: number;

/**
* The maximum value
*
* @default Automatic
*/
readonly max?: number;
}

/**
* Horizontal annotation to be added to a graph
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"Arn"
]
},
"\"]},\"yAxis\":{\"left\":{\"min\":0}}}},{\"type\":\"metric\",\"width\":6,\"height\":6,\"x\":0,\"y\":8,\"properties\":{\"view\":\"timeSeries\",\"title\":\"More messages in queue with alarm annotation\",\"region\":\"",
"\"]},\"yAxis\":{}}},{\"type\":\"metric\",\"width\":6,\"height\":6,\"x\":0,\"y\":8,\"properties\":{\"view\":\"timeSeries\",\"title\":\"More messages in queue with alarm annotation\",\"region\":\"",
{
"Ref": "AWS::Region"
},
Expand All @@ -56,7 +56,7 @@
"QueueName"
]
},
"\",{\"yAxis\":\"left\",\"period\":300,\"stat\":\"Average\"}]],\"annotations\":{\"horizontal\":[{\"label\":\"ApproximateNumberOfMessagesVisible >= 100 for 3 datapoints within 15 minutes\",\"value\":100,\"yAxis\":\"left\"}]},\"yAxis\":{\"left\":{\"min\":0},\"right\":{\"min\":0}}}},{\"type\":\"metric\",\"width\":6,\"height\":3,\"x\":0,\"y\":14,\"properties\":{\"view\":\"singleValue\",\"title\":\"Current messages in queue\",\"region\":\"",
"\",{\"yAxis\":\"left\",\"period\":300,\"stat\":\"Average\"}]],\"annotations\":{\"horizontal\":[{\"label\":\"ApproximateNumberOfMessagesVisible >= 100 for 3 datapoints within 15 minutes\",\"value\":100,\"yAxis\":\"left\"}]},\"yAxis\":{}}},{\"type\":\"metric\",\"width\":6,\"height\":3,\"x\":0,\"y\":14,\"properties\":{\"view\":\"singleValue\",\"title\":\"Current messages in queue\",\"region\":\"",
{
"Ref": "AWS::Region"
},
Expand Down
4 changes: 2 additions & 2 deletions packages/@aws-cdk/aws-cloudwatch/test/test.dashboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export = {
DashboardBody: { "Fn::Join": [ "", [
"{\"widgets\":[{\"type\":\"metric\",\"width\":1,\"height\":1,\"x\":0,\"y\":0,\"properties\":{\"view\":\"timeSeries\",\"region\":\"",
{ Ref: "AWS::Region" },
"\",\"metrics\":[],\"annotations\":{\"horizontal\":[]},\"yAxis\":{\"left\":{\"min\":0},\"right\":{\"min\":0}}}}]}"
"\",\"metrics\":[],\"annotations\":{\"horizontal\":[]},\"yAxis\":{}}}]}"
]]}
}));

Expand Down Expand Up @@ -113,7 +113,7 @@ export = {
"{\"start\":\"-9H\",\"end\":\"2018-12-17T06:00:00.000Z\",\"periodOverride\":\"inherit\",\
\"widgets\":[{\"type\":\"metric\",\"width\":1,\"height\":1,\"x\":0,\"y\":0,\"properties\":{\"view\":\"timeSeries\",\"region\":\"",
{ Ref: "AWS::Region" },
"\",\"metrics\":[],\"annotations\":{\"horizontal\":[]},\"yAxis\":{\"left\":{\"min\":0},\"right\":{\"min\":0}}}}]}"
"\",\"metrics\":[],\"annotations\":{\"horizontal\":[]},\"yAxis\":{}}}]}"
]]}
}));

Expand Down
57 changes: 51 additions & 6 deletions packages/@aws-cdk/aws-cloudwatch/test/test.graphs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export = {
['CDK', 'Tast', { yAxis: 'right', period: 300, stat: 'Average' }]
],
annotations: { horizontal: [] },
yAxis: { left: { min: 0 }, right: { min: 0 } }
yAxis: {}
}
}]);

Expand All @@ -56,7 +56,7 @@ export = {
['CDK', 'Test', { yAxis: 'left', period: 300, stat: 'Average', label: 'MyMetric', color: '000000' }],
],
annotations: { horizontal: [] },
yAxis: { left: { min: 0 }, right: { min: 0 } }
yAxis: {}
}
}]);

Expand All @@ -83,7 +83,7 @@ export = {
region: { Ref: 'AWS::Region' },
metrics: [
['CDK', 'Test', { yAxis: 'left', period: 300, stat: 'Average' }],
],
]
}
}]);

Expand Down Expand Up @@ -115,7 +115,7 @@ export = {
annotations: {
alarms: [{ 'Fn::GetAtt': [ 'Alarm7103F465', 'Arn' ] }]
},
yAxis: { left: { min: 0 } }
yAxis: {}
}
}]);

Expand Down Expand Up @@ -157,7 +157,7 @@ export = {
fill: 'below',
label: 'this is the annotation',
}] },
yAxis: { left: { min: 0 }, right: { min: 0 } }
yAxis: {}
}
}]);

Expand Down Expand Up @@ -199,7 +199,52 @@ export = {
label: 'Test >= 1000 for 2 datapoints within 10 minutes',
}]
},
yAxis: { left: { min: 0 }, right: { min: 0 } }
yAxis: {}
}
}]);

test.done();
},

'add yAxis to graph'(test: Test) {
// WHEN
const stack = new Stack();
const widget = new GraphWidget({
title: 'My fancy graph',
left: [
new Metric({ namespace: 'CDK', metricName: 'Test' })
],
right: [
new Metric({ namespace: 'CDK', metricName: 'Tast' })
],
leftYAxis: ({
label: "Left yAxis",
max: 100
}),
rightYAxis: ({
label: "Right yAxis",
min: 10,
showUnits: false
})
});

// THEN
test.deepEqual(stack.node.resolve(widget.toJson()), [{
type: 'metric',
width: 6,
height: 6,
properties: {
view: 'timeSeries',
title: 'My fancy graph',
region: { Ref: 'AWS::Region' },
metrics: [
['CDK', 'Test', { yAxis: 'left', period: 300, stat: 'Average' }],
['CDK', 'Tast', { yAxis: 'right', period: 300, stat: 'Average' }]
],
annotations: { horizontal: [] },
yAxis: {
left: { label: "Left yAxis", max: 100 },
right: { label: "Right yAxis", min: 10, showUnits: false } }
}
}]);

Expand Down