|
| 1 | +import type { HorizontalAnnotation, IWidget } from "aws-cdk-lib/aws-cloudwatch"; |
| 2 | +import { GraphWidget, Row } from "aws-cdk-lib/aws-cloudwatch"; |
| 3 | + |
| 4 | +import type { OpenSearchIngestionPipelineMetricFactoryProps } from "./OpenSearchIngestionPipelineMetricFactory"; |
| 5 | +import { OpenSearchIngestionPipelineMetricFactory } from "./OpenSearchIngestionPipelineMetricFactory"; |
| 6 | +import { |
| 7 | + BaseMonitoringProps, |
| 8 | + MaxUsageCountThreshold, |
| 9 | + MetricWithAlarmSupport, |
| 10 | + Monitoring, |
| 11 | + AlarmFactory, |
| 12 | + UsageAlarmFactory, |
| 13 | + MonitoringScope, |
| 14 | + ThirdWidth, |
| 15 | + DefaultGraphWidgetHeight, |
| 16 | + TimeAxisMillisFromZero, |
| 17 | + CountAxisFromZero, |
| 18 | +} from "../../common"; |
| 19 | +import { |
| 20 | + MonitoringNamingStrategy, |
| 21 | + MonitoringHeaderWidget, |
| 22 | +} from "../../dashboard"; |
| 23 | + |
| 24 | +export interface OpenSearchIngestionPipelineMonitoringOptions |
| 25 | + extends BaseMonitoringProps { |
| 26 | + readonly addMaxDlqS3CountAlarm?: Record<string, MaxUsageCountThreshold>; |
| 27 | +} |
| 28 | + |
| 29 | +export interface OpenSearchIngestionPipelineMonitoringProps |
| 30 | + extends OpenSearchIngestionPipelineMetricFactoryProps, |
| 31 | + OpenSearchIngestionPipelineMonitoringOptions {} |
| 32 | + |
| 33 | +/** |
| 34 | + * @experimental This is subject to change if an L2 construct becomes available. |
| 35 | + */ |
| 36 | +export class OpenSearchIngestionPipelineMonitoring extends Monitoring { |
| 37 | + readonly title: string; |
| 38 | + readonly pipelineUrl?: string; |
| 39 | + |
| 40 | + readonly metricSinkRecordsInCount: MetricWithAlarmSupport; |
| 41 | + readonly metricSourceBytesReceivedSum: MetricWithAlarmSupport; |
| 42 | + readonly metricSinkBulkRequestLatencyMax: MetricWithAlarmSupport; |
| 43 | + readonly metricSinkBulkPipelineLatencyMax: MetricWithAlarmSupport; |
| 44 | + readonly metricDlqS3RecordsCount: MetricWithAlarmSupport; |
| 45 | + |
| 46 | + readonly alarmFactory: AlarmFactory; |
| 47 | + readonly usageAlarmFactory: UsageAlarmFactory; |
| 48 | + |
| 49 | + readonly usageAnnotations: HorizontalAnnotation[]; |
| 50 | + |
| 51 | + constructor( |
| 52 | + scope: MonitoringScope, |
| 53 | + props: OpenSearchIngestionPipelineMonitoringProps, |
| 54 | + ) { |
| 55 | + super(scope, props); |
| 56 | + |
| 57 | + const namingStrategy = new MonitoringNamingStrategy({ |
| 58 | + ...props, |
| 59 | + fallbackConstructName: props.pipelineName, |
| 60 | + }); |
| 61 | + this.title = namingStrategy.resolveHumanReadableName(); |
| 62 | + this.pipelineUrl = scope |
| 63 | + .createAwsConsoleUrlFactory() |
| 64 | + .getOsisPipelineUrl(props.pipelineName); |
| 65 | + |
| 66 | + this.alarmFactory = this.createAlarmFactory( |
| 67 | + namingStrategy.resolveAlarmFriendlyName(), |
| 68 | + ); |
| 69 | + this.usageAlarmFactory = new UsageAlarmFactory(this.alarmFactory); |
| 70 | + |
| 71 | + this.usageAnnotations = []; |
| 72 | + |
| 73 | + const metricFactory = new OpenSearchIngestionPipelineMetricFactory( |
| 74 | + scope.createMetricFactory(), |
| 75 | + props, |
| 76 | + ); |
| 77 | + |
| 78 | + this.metricSinkRecordsInCount = metricFactory.metricSinkRecordsInCount(); |
| 79 | + this.metricSourceBytesReceivedSum = |
| 80 | + metricFactory.metricSourceBytesReceivedSum(); |
| 81 | + this.metricSinkBulkRequestLatencyMax = |
| 82 | + metricFactory.metricSinkBulkRequestLatencyMax(); |
| 83 | + this.metricSinkBulkPipelineLatencyMax = |
| 84 | + metricFactory.metricSinkBulkPipelineLatencyMax(); |
| 85 | + this.metricDlqS3RecordsCount = metricFactory.metricDlqS3RecordsCount(); |
| 86 | + |
| 87 | + for (const disambiguator in props.addMaxDlqS3CountAlarm) { |
| 88 | + const alarmProps = props.addMaxDlqS3CountAlarm[disambiguator]; |
| 89 | + const createdAlarm = this.usageAlarmFactory.addMaxCountAlarm( |
| 90 | + this.metricDlqS3RecordsCount, |
| 91 | + alarmProps, |
| 92 | + disambiguator, |
| 93 | + ); |
| 94 | + this.usageAnnotations.push(createdAlarm.annotation); |
| 95 | + this.addAlarm(createdAlarm); |
| 96 | + } |
| 97 | + |
| 98 | + props.useCreatedAlarms?.consume(this.createdAlarms()); |
| 99 | + } |
| 100 | + |
| 101 | + summaryWidgets(): IWidget[] { |
| 102 | + return this.widgets(); |
| 103 | + } |
| 104 | + |
| 105 | + widgets(): IWidget[] { |
| 106 | + return [ |
| 107 | + this.createTitleWidget(), |
| 108 | + new Row( |
| 109 | + this.createLatencyWidget(ThirdWidth, DefaultGraphWidgetHeight), |
| 110 | + this.createIncomingDataWidget(ThirdWidth, DefaultGraphWidgetHeight), |
| 111 | + this.createDlqS3Widget(ThirdWidth, DefaultGraphWidgetHeight), |
| 112 | + ), |
| 113 | + ]; |
| 114 | + } |
| 115 | + |
| 116 | + protected createTitleWidget(): IWidget { |
| 117 | + return new MonitoringHeaderWidget({ |
| 118 | + family: "OpenSearch Ingestion", |
| 119 | + title: this.title, |
| 120 | + goToLinkUrl: this.pipelineUrl, |
| 121 | + }); |
| 122 | + } |
| 123 | + |
| 124 | + protected createLatencyWidget(width: number, height: number): IWidget { |
| 125 | + return new GraphWidget({ |
| 126 | + width, |
| 127 | + height, |
| 128 | + title: "Latency", |
| 129 | + left: [ |
| 130 | + this.metricSinkBulkRequestLatencyMax, |
| 131 | + this.metricSinkBulkPipelineLatencyMax, |
| 132 | + ], |
| 133 | + leftYAxis: TimeAxisMillisFromZero, |
| 134 | + }); |
| 135 | + } |
| 136 | + |
| 137 | + protected createIncomingDataWidget(width: number, height: number): IWidget { |
| 138 | + return new GraphWidget({ |
| 139 | + width, |
| 140 | + height, |
| 141 | + title: "Incoming data", |
| 142 | + left: [this.metricSinkRecordsInCount], |
| 143 | + leftYAxis: CountAxisFromZero, |
| 144 | + right: [this.metricSourceBytesReceivedSum], |
| 145 | + rightYAxis: CountAxisFromZero, |
| 146 | + }); |
| 147 | + } |
| 148 | + |
| 149 | + protected createDlqS3Widget(width: number, height: number): IWidget { |
| 150 | + return new GraphWidget({ |
| 151 | + width, |
| 152 | + height, |
| 153 | + title: "DLQ", |
| 154 | + left: [this.metricDlqS3RecordsCount], |
| 155 | + leftYAxis: CountAxisFromZero, |
| 156 | + leftAnnotations: this.usageAnnotations, |
| 157 | + }); |
| 158 | + } |
| 159 | +} |
0 commit comments