-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(logs): MetricFilter exposes extracted Metric object (#8556)
It is convention to expose metrics on AWS constructs, but metric filters currently do not. This PR adds a `metric()` API that creates a metric from a metric filter with the same name and namespace. The user can specify what statistic to use, or it will default to average over 5 minutes. fixes #1353 ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
- Loading branch information
Showing
5 changed files
with
181 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
packages/@aws-cdk/aws-logs/test/integ.expose-metric.expected.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
{ | ||
"Resources": { | ||
"LogGroupF5B46931": { | ||
"Type": "AWS::Logs::LogGroup", | ||
"Properties": { | ||
"RetentionInDays": 731 | ||
}, | ||
"UpdateReplacePolicy": "Delete", | ||
"DeletionPolicy": "Delete" | ||
}, | ||
"MetricFilter1B93B6E5": { | ||
"Type": "AWS::Logs::MetricFilter", | ||
"Properties": { | ||
"FilterPattern": "{ $.latency = \"*\" }", | ||
"LogGroupName": { | ||
"Ref": "LogGroupF5B46931" | ||
}, | ||
"MetricTransformations": [ | ||
{ | ||
"MetricName": "Latency", | ||
"MetricNamespace": "MyApp", | ||
"MetricValue": "$.latency" | ||
} | ||
] | ||
} | ||
}, | ||
"alarmfrommetricfilterF546D67D": { | ||
"Type": "AWS::CloudWatch::Alarm", | ||
"Properties": { | ||
"ComparisonOperator": "GreaterThanOrEqualToThreshold", | ||
"EvaluationPeriods": 2, | ||
"MetricName": "Latency", | ||
"Namespace": "MyApp", | ||
"Period": 300, | ||
"Statistic": "Average", | ||
"Threshold": 100 | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { Alarm } from '@aws-cdk/aws-cloudwatch'; | ||
import { App, RemovalPolicy, Stack, StackProps } from '@aws-cdk/core'; | ||
import { FilterPattern, LogGroup, MetricFilter } from '../lib'; | ||
|
||
/* | ||
* Stack verification steps: | ||
* | ||
* -- aws cloudwatch describe-alarms --alarm-name-prefix aws-cdk-expose-metric-integ | ||
* has Namespace of `MyApp` and Statistic of `Average` | ||
*/ | ||
|
||
class ExposeMetricIntegStack extends Stack { | ||
constructor(scope: App, id: string, props?: StackProps) { | ||
super(scope, id, props); | ||
|
||
const logGroup = new LogGroup(this, 'LogGroup', { | ||
removalPolicy: RemovalPolicy.DESTROY, | ||
}); | ||
|
||
/// !show | ||
const mf = new MetricFilter(this, 'MetricFilter', { | ||
logGroup, | ||
metricNamespace: 'MyApp', | ||
metricName: 'Latency', | ||
filterPattern: FilterPattern.exists('$.latency'), | ||
metricValue: '$.latency', | ||
}); | ||
|
||
new Alarm(this, 'alarm from metric filter', { | ||
metric: mf.metric(), | ||
threshold: 100, | ||
evaluationPeriods: 2, | ||
}); | ||
|
||
/// !hide | ||
} | ||
} | ||
|
||
const app = new App(); | ||
new ExposeMetricIntegStack(app, 'aws-cdk-expose-metric-integ'); | ||
app.synth(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters