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(aws-logs): extractMetric() returns Metric object #939

Merged
merged 1 commit into from
Oct 16, 2018
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
4 changes: 4 additions & 0 deletions packages/@aws-cdk/aws-logs/lib/log-group.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import cloudwatch = require('@aws-cdk/aws-cloudwatch');
import cdk = require('@aws-cdk/cdk');
import { LogStream } from './log-stream';
import { cloudformation } from './logs.generated';
Expand Down Expand Up @@ -96,6 +97,7 @@ export abstract class LogGroupRef extends cdk.Construct {
* @param jsonField JSON field to extract (example: '$.myfield')
* @param metricNamespace Namespace to emit the metric under
* @param metricName Name to emit the metric under
* @returns A Metric object representing the extracted metric
*/
public extractMetric(jsonField: string, metricNamespace: string, metricName: string) {
new MetricFilter(this, `${metricNamespace}_${metricName}`, {
Expand All @@ -105,6 +107,8 @@ export abstract class LogGroupRef extends cdk.Construct {
filterPattern: FilterPattern.exists(jsonField),
metricValue: jsonField
});

return new cloudwatch.Metric({ metricName, namespace: metricNamespace });
}
}

Expand Down
1 change: 1 addition & 0 deletions packages/@aws-cdk/aws-logs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
"pkglint": "^0.12.0"
},
"dependencies": {
"@aws-cdk/aws-cloudwatch": "^0.12.0",
"@aws-cdk/aws-iam": "^0.12.0",
"@aws-cdk/cdk": "^0.12.0"
},
Expand Down
4 changes: 3 additions & 1 deletion packages/@aws-cdk/aws-logs/test/test.loggroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export = {
const lg = new LogGroup(stack, 'LogGroup');

// WHEN
lg.extractMetric('$.myField', 'MyService', 'Field');
const metric = lg.extractMetric('$.myField', 'MyService', 'Field');

// THEN
expect(stack).to(haveResource('AWS::Logs::MetricFilter', {
Expand All @@ -114,6 +114,8 @@ export = {
}
]
}));
test.equal(metric.namespace, 'MyService');
test.equal(metric.metricName, 'Field');

test.done();
}
Expand Down