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' ) ;
1
2
import cdk = require( '@aws-cdk/cdk' ) ;
2
3
import { LogStream } from './log-stream' ;
3
4
import { cloudformation } from './logs.generated' ;
@@ -96,6 +97,7 @@ export abstract class LogGroupRef extends cdk.Construct {
96
97
* @param jsonField JSON field to extract (example: '$.myfield')
97
98
* @param metricNamespace Namespace to emit the metric under
98
99
* @param metricName Name to emit the metric under
100
+ * @returns A Metric object representing the extracted metric
99
101
*/
100
102
public extractMetric ( jsonField : string , metricNamespace : string , metricName : string ) {
101
103
new MetricFilter ( this , `${ metricNamespace } _${ metricName } ` , {
@@ -105,6 +107,8 @@ export abstract class LogGroupRef extends cdk.Construct {
105
107
filterPattern : FilterPattern . exists ( jsonField ) ,
106
108
metricValue : jsonField
107
109
} ) ;
110
+
111
+ return new cloudwatch . Metric ( { metricName, namespace : metricNamespace } ) ;
108
112
}
109
113
}
110
114
Original file line number Diff line number Diff line change 59
59
"pkglint" : " ^0.12.0"
60
60
},
61
61
"dependencies" : {
62
+ "@aws-cdk/aws-cloudwatch" : " ^0.12.0" ,
62
63
"@aws-cdk/aws-iam" : " ^0.12.0" ,
63
64
"@aws-cdk/cdk" : " ^0.12.0"
64
65
},
Original file line number Diff line number Diff line change @@ -100,7 +100,7 @@ export = {
100
100
const lg = new LogGroup ( stack , 'LogGroup' ) ;
101
101
102
102
// WHEN
103
- lg . extractMetric ( '$.myField' , 'MyService' , 'Field' ) ;
103
+ const metric = lg . extractMetric ( '$.myField' , 'MyService' , 'Field' ) ;
104
104
105
105
// THEN
106
106
expect ( stack ) . to ( haveResource ( 'AWS::Logs::MetricFilter' , {
@@ -114,6 +114,8 @@ export = {
114
114
}
115
115
]
116
116
} ) ) ;
117
+ test . equal ( metric . namespace , 'MyService' ) ;
118
+ test . equal ( metric . metricName , 'Field' ) ;
117
119
118
120
test . done ( ) ;
119
121
}
You can’t perform that action at this time.
0 commit comments