File tree Expand file tree Collapse file tree 3 files changed +8
-1
lines changed
packages/@aws-cdk/aws-logs Expand file tree Collapse file tree 3 files changed +8
-1
lines changed Original file line number Diff line number Diff line change 1+ import cloudwatch = require( '@aws-cdk/aws-cloudwatch' ) ;
12import cdk = require( '@aws-cdk/cdk' ) ;
23import { LogStream } from './log-stream' ;
34import { cloudformation } from './logs.generated' ;
@@ -96,6 +97,7 @@ export abstract class LogGroupRef extends cdk.Construct {
9697 * @param jsonField JSON field to extract (example: '$.myfield')
9798 * @param metricNamespace Namespace to emit the metric under
9899 * @param metricName Name to emit the metric under
100+ * @returns A Metric object representing the extracted metric
99101 */
100102 public extractMetric ( jsonField : string , metricNamespace : string , metricName : string ) {
101103 new MetricFilter ( this , `${ metricNamespace } _${ metricName } ` , {
@@ -105,6 +107,8 @@ export abstract class LogGroupRef extends cdk.Construct {
105107 filterPattern : FilterPattern . exists ( jsonField ) ,
106108 metricValue : jsonField
107109 } ) ;
110+
111+ return new cloudwatch . Metric ( { metricName, namespace : metricNamespace } ) ;
108112 }
109113}
110114
Original file line number Diff line number Diff line change 5959 "pkglint" : " ^0.12.0"
6060 },
6161 "dependencies" : {
62+ "@aws-cdk/aws-cloudwatch" : " ^0.12.0" ,
6263 "@aws-cdk/aws-iam" : " ^0.12.0" ,
6364 "@aws-cdk/cdk" : " ^0.12.0"
6465 },
Original file line number Diff line number Diff line change @@ -100,7 +100,7 @@ export = {
100100 const lg = new LogGroup ( stack , 'LogGroup' ) ;
101101
102102 // WHEN
103- lg . extractMetric ( '$.myField' , 'MyService' , 'Field' ) ;
103+ const metric = lg . extractMetric ( '$.myField' , 'MyService' , 'Field' ) ;
104104
105105 // THEN
106106 expect ( stack ) . to ( haveResource ( 'AWS::Logs::MetricFilter' , {
@@ -114,6 +114,8 @@ export = {
114114 }
115115 ]
116116 } ) ) ;
117+ test . equal ( metric . namespace , 'MyService' ) ;
118+ test . equal ( metric . metricName , 'Field' ) ;
117119
118120 test . done ( ) ;
119121 }
You can’t perform that action at this time.
0 commit comments