@@ -37,16 +37,42 @@ import {
3737 ApiGatewayMetricFactoryProps ,
3838} from "./ApiGatewayMetricFactory" ;
3939
40+ const DefaultLatencyTypesToRender = [
41+ LatencyType . P50 ,
42+ LatencyType . P90 ,
43+ LatencyType . P99 ,
44+ ] ;
45+
4046export interface ApiGatewayMonitoringOptions extends BaseMonitoringProps {
4147 readonly addLatencyP50Alarm ?: Record < string , LatencyThreshold > ;
48+ readonly addLatencyP70Alarm ?: Record < string , LatencyThreshold > ;
4249 readonly addLatencyP90Alarm ?: Record < string , LatencyThreshold > ;
4350 readonly addLatencyP99Alarm ?: Record < string , LatencyThreshold > ;
51+ readonly addLatencyP999Alarm ?: Record < string , LatencyThreshold > ;
52+ readonly addLatencyP9999Alarm ?: Record < string , LatencyThreshold > ;
53+ readonly addLatencyP100Alarm ?: Record < string , LatencyThreshold > ;
54+ readonly addLatencyTM50Alarm ?: Record < string , LatencyThreshold > ;
55+ readonly addLatencyTM70Alarm ?: Record < string , LatencyThreshold > ;
56+ readonly addLatencyTM90Alarm ?: Record < string , LatencyThreshold > ;
57+ readonly addLatencyTM99Alarm ?: Record < string , LatencyThreshold > ;
58+ readonly addLatencyTM999Alarm ?: Record < string , LatencyThreshold > ;
59+ readonly addLatencyTM9999Alarm ?: Record < string , LatencyThreshold > ;
60+ readonly addLatencyAverageAlarm ?: Record < string , LatencyThreshold > ;
4461 readonly add4XXErrorCountAlarm ?: Record < string , ErrorCountThreshold > ;
4562 readonly add4XXErrorRateAlarm ?: Record < string , ErrorRateThreshold > ;
4663 readonly add5XXFaultCountAlarm ?: Record < string , ErrorCountThreshold > ;
4764 readonly add5XXFaultRateAlarm ?: Record < string , ErrorRateThreshold > ;
4865 readonly addLowTpsAlarm ?: Record < string , LowTpsThreshold > ;
4966 readonly addHighTpsAlarm ?: Record < string , HighTpsThreshold > ;
67+
68+ /**
69+ * You can specify what latency types you want to be rendered in the dashboards.
70+ * Note: any latency type with an alarm will be also added automatically.
71+ * If the list is undefined, default values will be shown.
72+ * If the list is empty, only the latency types with an alarm will be shown (if any).
73+ * @default p50, p90, p99 (@see DefaultLatencyTypesToRender)
74+ */
75+ readonly latencyTypesToRender ?: LatencyType [ ] ;
5076}
5177
5278export interface ApiGatewayMonitoringProps
@@ -67,14 +93,15 @@ export class ApiGatewayMonitoring extends Monitoring {
6793 protected readonly errorRateAnnotations : HorizontalAnnotation [ ] ;
6894
6995 protected readonly tpsMetric : MetricWithAlarmSupport ;
70- protected readonly p50LatencyMetric : MetricWithAlarmSupport ;
71- protected readonly p90LatencyMetric : MetricWithAlarmSupport ;
72- protected readonly p99LatencyMetric : MetricWithAlarmSupport ;
7396 protected readonly error4XXCountMetric : MetricWithAlarmSupport ;
7497 protected readonly error4XXRateMetric : MetricWithAlarmSupport ;
7598 protected readonly fault5XXCountMetric : MetricWithAlarmSupport ;
7699 protected readonly fault5XXRateMetric : MetricWithAlarmSupport ;
77100
101+ // keys are LatencyType, but JSII doesn't like non-string types
102+ protected readonly latencyMetrics : Record < string , MetricWithAlarmSupport > ;
103+ protected readonly latencyTypesToRender : string [ ] ;
104+
78105 constructor ( scope : MonitoringScope , props : ApiGatewayMonitoringProps ) {
79106 super ( scope , props ) ;
80107
@@ -115,48 +142,60 @@ export class ApiGatewayMonitoring extends Monitoring {
115142 scope . createMetricFactory ( ) ,
116143 props
117144 ) ;
145+
118146 this . tpsMetric = metricFactory . metricTps ( ) ;
119- this . p50LatencyMetric = metricFactory . metricLatencyP50InMillis ( ) ;
120- this . p90LatencyMetric = metricFactory . metricLatencyP90InMillis ( ) ;
121- this . p99LatencyMetric = metricFactory . metricLatencyP99InMillis ( ) ;
147+
148+ this . latencyMetrics = { } ;
149+ this . latencyTypesToRender = [
150+ ...( props . latencyTypesToRender ?? DefaultLatencyTypesToRender ) ,
151+ ] ;
152+
122153 this . error4XXCountMetric = metricFactory . metric4XXErrorCount ( ) ;
123154 this . error4XXRateMetric = metricFactory . metric4XXErrorRate ( ) ;
124155 this . fault5XXCountMetric = metricFactory . metric5XXFaultCount ( ) ;
125156 this . fault5XXRateMetric = metricFactory . metric5XXFaultRate ( ) ;
126157
127- for ( const disambiguator in props . addLatencyP50Alarm ) {
128- const alarmProps = props . addLatencyP50Alarm [ disambiguator ] ;
129- const createdAlarm = this . latencyAlarmFactory . addLatencyAlarm (
130- this . p50LatencyMetric ,
131- LatencyType . P50 ,
132- alarmProps ,
133- disambiguator
134- ) ;
135- this . latencyAnnotations . push ( createdAlarm . annotation ) ;
136- this . addAlarm ( createdAlarm ) ;
137- }
138- for ( const disambiguator in props . addLatencyP90Alarm ) {
139- const alarmProps = props . addLatencyP90Alarm [ disambiguator ] ;
140- const createdAlarm = this . latencyAlarmFactory . addLatencyAlarm (
141- this . p90LatencyMetric ,
142- LatencyType . P90 ,
143- alarmProps ,
144- disambiguator
145- ) ;
146- this . latencyAnnotations . push ( createdAlarm . annotation ) ;
147- this . addAlarm ( createdAlarm ) ;
148- }
149- for ( const disambiguator in props . addLatencyP99Alarm ) {
150- const alarmProps = props . addLatencyP99Alarm [ disambiguator ] ;
151- const createdAlarm = this . latencyAlarmFactory . addLatencyAlarm (
152- this . p99LatencyMetric ,
153- LatencyType . P99 ,
154- alarmProps ,
155- disambiguator
156- ) ;
157- this . latencyAnnotations . push ( createdAlarm . annotation ) ;
158- this . addAlarm ( createdAlarm ) ;
158+ const latencyAlarmDefinitions = {
159+ [ LatencyType . P50 ] : props . addLatencyP50Alarm ,
160+ [ LatencyType . P70 ] : props . addLatencyP70Alarm ,
161+ [ LatencyType . P90 ] : props . addLatencyP90Alarm ,
162+ [ LatencyType . P99 ] : props . addLatencyP99Alarm ,
163+ [ LatencyType . P999 ] : props . addLatencyP999Alarm ,
164+ [ LatencyType . P9999 ] : props . addLatencyP9999Alarm ,
165+ [ LatencyType . P100 ] : props . addLatencyP100Alarm ,
166+ [ LatencyType . TM50 ] : props . addLatencyTM50Alarm ,
167+ [ LatencyType . TM70 ] : props . addLatencyTM70Alarm ,
168+ [ LatencyType . TM90 ] : props . addLatencyTM90Alarm ,
169+ [ LatencyType . TM99 ] : props . addLatencyTM99Alarm ,
170+ [ LatencyType . TM999 ] : props . addLatencyTM999Alarm ,
171+ [ LatencyType . TM9999 ] : props . addLatencyTM9999Alarm ,
172+ [ LatencyType . AVERAGE ] : props . addLatencyAverageAlarm ,
173+ } ;
174+
175+ Object . values ( LatencyType ) . forEach ( ( latencyType ) => {
176+ this . latencyMetrics [ latencyType ] =
177+ metricFactory . metricLatencyInMillis ( latencyType ) ;
178+ } ) ;
179+
180+ for ( const [ latencyType , alarmDefinition ] of Object . entries (
181+ latencyAlarmDefinitions
182+ ) ) {
183+ for ( const disambiguator in alarmDefinition ) {
184+ const alarmProps = alarmDefinition [ disambiguator ] ;
185+ const latencyTypeEnum = latencyType as LatencyType ;
186+ const metric = this . latencyMetrics [ latencyTypeEnum ] ;
187+ const createdAlarm = this . latencyAlarmFactory . addLatencyAlarm (
188+ metric ,
189+ latencyTypeEnum ,
190+ alarmProps ,
191+ disambiguator
192+ ) ;
193+ this . latencyAnnotations . push ( createdAlarm . annotation ) ;
194+ this . latencyTypesToRender . push ( latencyTypeEnum ) ;
195+ this . addAlarm ( createdAlarm ) ;
196+ }
159197 }
198+
160199 for ( const disambiguator in props . add5XXFaultCountAlarm ) {
161200 const alarmProps = props . add5XXFaultCountAlarm [ disambiguator ] ;
162201 const createdAlarm = this . errorAlarmFactory . addErrorCountAlarm (
@@ -262,15 +301,15 @@ export class ApiGatewayMonitoring extends Monitoring {
262301 }
263302
264303 protected createLatencyWidget ( width : number , height : number ) {
304+ const left = Array . from ( new Set ( this . latencyTypesToRender ) )
305+ . sort ( )
306+ . map ( ( type ) => this . latencyMetrics [ type ] ) ;
307+
265308 return new GraphWidget ( {
266309 width,
267310 height,
268311 title : "Latency" ,
269- left : [
270- this . p50LatencyMetric ,
271- this . p90LatencyMetric ,
272- this . p99LatencyMetric ,
273- ] ,
312+ left,
274313 leftYAxis : TimeAxisMillisFromZero ,
275314 leftAnnotations : this . latencyAnnotations ,
276315 } ) ;
0 commit comments