Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(api-gatewayv2): use API name in fallback name when possible #572

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { HttpApi } from "aws-cdk-lib/aws-apigatewayv2";
import {
GraphWidget,
HorizontalAnnotation,
Expand Down Expand Up @@ -158,7 +159,11 @@ export class ApiGatewayV2HttpApiMonitoring extends Monitoring {
super(scope, props);

// used when humanReadableName is not provided by user
const fallbackNameArray = [props.api.apiId];
const fallbackNameArray = [
(props.api as HttpApi)?.httpApiName ??
(props.api as HttpApi)?.httpApiId ??
props.api.apiId,
];
fallbackNameArray.push(props.apiStage ?? "$default");
if (props.apiMethod) {
fallbackNameArray.push(props.apiMethod);
Expand Down
12 changes: 2 additions & 10 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.

Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,43 @@ import {
import { addMonitoringDashboardsToStack } from "../../utils/SnapshotUtil";
import { TestMonitoringScope } from "../TestMonitoringScope";

test("snapshot test: no alarms", () => {
test("snapshot test: no alarms with explicit API name", () => {
const stack = new Stack();

const scope = new TestMonitoringScope(stack, "Scope");

const testHttpApi = new HttpApi(stack, "testHttpApi", {
apiName: "testHttpApi",
const monitoring = new ApiGatewayV2HttpApiMonitoring(scope, {
api: new HttpApi(stack, "testHttpApi", {
apiName: "testHttpApiName",
}),
});

addMonitoringDashboardsToStack(stack, monitoring);
expect(Template.fromStack(stack)).toMatchSnapshot();
});

test("snapshot test: no alarms with no explicit API name", () => {
const stack = new Stack();

const scope = new TestMonitoringScope(stack, "Scope");

const monitoring = new ApiGatewayV2HttpApiMonitoring(scope, {
api: testHttpApi,
humanReadableName: "Dummy API Gateway for testing",
alarmFriendlyName: "DummyApi",
api: new HttpApi(stack, "testHttpApi"),
});

addMonitoringDashboardsToStack(stack, monitoring);
expect(Template.fromStack(stack)).toMatchSnapshot();
});

test("snapshot test: no alarms with imported IHttpApi", () => {
const stack = new Stack();

const scope = new TestMonitoringScope(stack, "Scope");

const monitoring = new ApiGatewayV2HttpApiMonitoring(scope, {
api: HttpApi.fromHttpApiAttributes(scope, "Imported", {
httpApiId: "imported-id",
}),
});

addMonitoringDashboardsToStack(stack, monitoring);
Expand Down
Loading