Skip to content

Commit

Permalink
fix(apigw2): respect humanReadableName specified by user (#263)
Browse files Browse the repository at this point in the history
Fixes #258 

---

_By submitting this pull request, I confirm that my contribution is made
under the terms of the Apache-2.0 license_
  • Loading branch information
voho committed Oct 24, 2022
1 parent 01ceb2a commit 149b41e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 28 deletions.
20 changes: 14 additions & 6 deletions lib/monitoring/aws-apigatewayv2/ApiGatewayV2HttpApiMonitoring.ts
Expand Up @@ -115,10 +115,8 @@ export class ApiGatewayV2HttpApiMonitoring extends Monitoring {
readonly errorRateAnnotations: HorizontalAnnotation[];

readonly tpsMetric: MetricWithAlarmSupport;

readonly error4xxCountMetric: MetricWithAlarmSupport;
readonly error4xxRateMetric: MetricWithAlarmSupport;

readonly error5xxCountMetric: MetricWithAlarmSupport;
readonly error5xxRateMetric: MetricWithAlarmSupport;

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

// used when humanReadableName is not provided by user
const fallbackNameArray = [props.api.apiId];
fallbackNameArray.push(props.apiStage ?? "$default");
if (props.apiMethod) {
fallbackNameArray.push(props.apiMethod);
}
if (props.apiResource) {
fallbackNameArray.push(props.apiResource);
}

const namingStrategy = new MonitoringNamingStrategy({
...props,
namedConstruct: props.api,
fallbackConstructName: props.api.apiId,
humanReadableName: `${props.api.apiId} ${props.apiStage ?? "$default"} ${
props.apiMethod ?? ""
} ${props.apiResource ?? ""}`,
fallbackConstructName: fallbackNameArray
.join("-")
.replace(/[^a-zA-Z0-9-_]/g, ""),
humanReadableName: props.humanReadableName ?? fallbackNameArray.join(" "),
});

this.title = namingStrategy.resolveHumanReadableName();
Expand Down
4 changes: 2 additions & 2 deletions test/facade/__snapshots__/MonitoringAspect.test.ts.snap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 149b41e

Please sign in to comment.