Skip to content

Commit 149b41e

Browse files
authored
fix(apigw2): respect humanReadableName specified by user (#263)
Fixes #258 --- _By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license_
1 parent 01ceb2a commit 149b41e

File tree

3 files changed

+20
-28
lines changed

3 files changed

+20
-28
lines changed

lib/monitoring/aws-apigatewayv2/ApiGatewayV2HttpApiMonitoring.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,8 @@ export class ApiGatewayV2HttpApiMonitoring extends Monitoring {
115115
readonly errorRateAnnotations: HorizontalAnnotation[];
116116

117117
readonly tpsMetric: MetricWithAlarmSupport;
118-
119118
readonly error4xxCountMetric: MetricWithAlarmSupport;
120119
readonly error4xxRateMetric: MetricWithAlarmSupport;
121-
122120
readonly error5xxCountMetric: MetricWithAlarmSupport;
123121
readonly error5xxRateMetric: MetricWithAlarmSupport;
124122

@@ -133,13 +131,23 @@ export class ApiGatewayV2HttpApiMonitoring extends Monitoring {
133131
) {
134132
super(scope, props);
135133

134+
// used when humanReadableName is not provided by user
135+
const fallbackNameArray = [props.api.apiId];
136+
fallbackNameArray.push(props.apiStage ?? "$default");
137+
if (props.apiMethod) {
138+
fallbackNameArray.push(props.apiMethod);
139+
}
140+
if (props.apiResource) {
141+
fallbackNameArray.push(props.apiResource);
142+
}
143+
136144
const namingStrategy = new MonitoringNamingStrategy({
137145
...props,
138146
namedConstruct: props.api,
139-
fallbackConstructName: props.api.apiId,
140-
humanReadableName: `${props.api.apiId} ${props.apiStage ?? "$default"} ${
141-
props.apiMethod ?? ""
142-
} ${props.apiResource ?? ""}`,
147+
fallbackConstructName: fallbackNameArray
148+
.join("-")
149+
.replace(/[^a-zA-Z0-9-_]/g, ""),
150+
humanReadableName: props.humanReadableName ?? fallbackNameArray.join(" "),
143151
});
144152

145153
this.title = namingStrategy.resolveHumanReadableName();

test/facade/__snapshots__/MonitoringAspect.test.ts.snap

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/monitoring/aws-apigatewayv2/__snapshots__/ApiGatewayV2HttpApiMonitoring.test.ts.snap

Lines changed: 4 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)