Skip to content

Commit a61576f

Browse files
authoredDec 14, 2021
fix(appmesh): adding support with gateway route priority (#17694)
Adding the Gateway Route `Priority` support. This is not a new feature but it was missed from the implementation. The implementation method is mimicking how Route's `Priority` is implemented: - [route-spec.ts](https://github.com/aws/aws-cdk/blob/master/packages/%40aws-cdk/aws-appmesh/lib/route-spec.ts) - [route.ts](https://github.com/aws/aws-cdk/blob/master/packages/%40aws-cdk/aws-appmesh/lib/route.ts) Fixes #16821 ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent c21320d commit a61576f

File tree

4 files changed

+114
-6
lines changed

4 files changed

+114
-6
lines changed
 

‎packages/@aws-cdk/aws-appmesh/lib/gateway-route-spec.ts

+31-2
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,24 @@ export interface GrpcGatewayRouteMatch {
148148
readonly rewriteRequestHostname?: boolean;
149149
}
150150

151+
/**
152+
* Base options for all gateway route specs.
153+
*/
154+
export interface CommonGatewayRouteSpecOptions {
155+
/**
156+
* The priority for the gateway route. When a Virtual Gateway has multiple gateway routes, gateway route match
157+
* is performed in the order of specified value, where 0 is the highest priority,
158+
* and first matched gateway route is selected.
159+
*
160+
* @default - no particular priority
161+
*/
162+
readonly priority?: number;
163+
}
164+
151165
/**
152166
* Properties specific for HTTP Based GatewayRoutes
153167
*/
154-
export interface HttpGatewayRouteSpecOptions {
168+
export interface HttpGatewayRouteSpecOptions extends CommonGatewayRouteSpecOptions {
155169
/**
156170
* The criterion for determining a request match for this GatewayRoute.
157171
* When path match is defined, this may optionally determine the path rewrite configuration.
@@ -169,7 +183,7 @@ export interface HttpGatewayRouteSpecOptions {
169183
/**
170184
* Properties specific for a gRPC GatewayRoute
171185
*/
172-
export interface GrpcGatewayRouteSpecOptions {
186+
export interface GrpcGatewayRouteSpecOptions extends CommonGatewayRouteSpecOptions {
173187
/**
174188
* The criterion for determining a request match for this GatewayRoute
175189
*/
@@ -205,6 +219,15 @@ export interface GatewayRouteSpecConfig {
205219
* @default - no grpc spec
206220
*/
207221
readonly grpcSpecConfig?: CfnGatewayRoute.GrpcGatewayRouteProperty;
222+
223+
/**
224+
* The priority for the gateway route. When a Virtual Gateway has multiple gateway routes, gateway route match
225+
* is performed in the order of specified value, where 0 is the highest priority,
226+
* and first matched gateway route is selected.
227+
*
228+
* @default - no particular priority
229+
*/
230+
readonly priority?: number;
208231
}
209232

210233
/**
@@ -257,12 +280,14 @@ class HttpGatewayRouteSpec extends GatewayRouteSpec {
257280
* Type of route you are creating
258281
*/
259282
readonly routeType: Protocol;
283+
readonly priority?: number;
260284

261285
constructor(options: HttpGatewayRouteSpecOptions, protocol: Protocol.HTTP | Protocol.HTTP2) {
262286
super();
263287
this.routeTarget = options.routeTarget;
264288
this.routeType = protocol;
265289
this.match = options.match;
290+
this.priority = options.priority;
266291
}
267292

268293
public bind(scope: Construct): GatewayRouteSpecConfig {
@@ -301,6 +326,7 @@ class HttpGatewayRouteSpec extends GatewayRouteSpec {
301326
},
302327
};
303328
return {
329+
priority: this.priority,
304330
httpSpecConfig: this.routeType === Protocol.HTTP ? httpConfig : undefined,
305331
http2SpecConfig: this.routeType === Protocol.HTTP2 ? httpConfig : undefined,
306332
};
@@ -314,11 +340,13 @@ class GrpcGatewayRouteSpec extends GatewayRouteSpec {
314340
* The VirtualService this GatewayRoute directs traffic to
315341
*/
316342
readonly routeTarget: IVirtualService;
343+
readonly priority?: number;
317344

318345
constructor(options: GrpcGatewayRouteSpecOptions) {
319346
super();
320347
this.match = options.match;
321348
this.routeTarget = options.routeTarget;
349+
this.priority = options.priority;
322350
}
323351

324352
public bind(scope: Construct): GatewayRouteSpecConfig {
@@ -349,6 +377,7 @@ class GrpcGatewayRouteSpec extends GatewayRouteSpec {
349377
},
350378
},
351379
},
380+
priority: this.priority,
352381
};
353382
}
354383
}

‎packages/@aws-cdk/aws-appmesh/lib/gateway-route.ts

+1
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ export class GatewayRoute extends cdk.Resource implements IGatewayRoute {
119119
httpRoute: routeSpecConfig.httpSpecConfig,
120120
http2Route: routeSpecConfig.http2SpecConfig,
121121
grpcRoute: routeSpecConfig.grpcSpecConfig,
122+
priority: routeSpecConfig.priority,
122123
},
123124
virtualGatewayName: this.virtualGateway.virtualGatewayName,
124125
});

‎packages/@aws-cdk/aws-appmesh/lib/route-spec.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ export interface GrpcRouteMatch {
120120
*/
121121
export interface RouteSpecOptionsBase {
122122
/**
123-
* The priority for the route. Routes are matched based on the specified
124-
* value, where 0 is the highest priority.
123+
* The priority for the route. When a Virtual Router has multiple routes, route match is performed in the
124+
* order of specified value, where 0 is the highest priority, and first matched route is selected.
125125
*
126126
* @default - no particular priority
127127
*/
@@ -357,8 +357,8 @@ export interface RouteSpecConfig {
357357
readonly tcpRouteSpec?: CfnRoute.TcpRouteProperty;
358358

359359
/**
360-
* The priority for the route. Routes are matched based on the specified
361-
* value, where 0 is the highest priority.
360+
* The priority for the route. When a Virtual Router has multiple routes, route match is performed in the
361+
* order of specified value, where 0 is the highest priority, and first matched route is selected.
362362
*
363363
* @default - no particular priority
364364
*/

‎packages/@aws-cdk/aws-appmesh/test/gateway-route.test.ts

+78
Original file line numberDiff line numberDiff line change
@@ -1122,8 +1122,86 @@ describe('gateway route', () => {
11221122
},
11231123
},
11241124
});
1125+
});
1126+
});
1127+
1128+
describe('with priority', () => {
1129+
test('should set the priority for http gateway route', () => {
1130+
// GIVEN
1131+
const stack = new cdk.Stack();
1132+
1133+
// WHEN
1134+
const mesh = new appmesh.Mesh(stack, 'mesh', {
1135+
meshName: 'test-mesh',
1136+
});
1137+
1138+
const virtualGateway = new appmesh.VirtualGateway(stack, 'gateway-1', {
1139+
listeners: [appmesh.VirtualGatewayListener.http()],
1140+
mesh: mesh,
1141+
});
1142+
1143+
const virtualService = new appmesh.VirtualService(stack, 'vs-1', {
1144+
virtualServiceProvider: appmesh.VirtualServiceProvider.none(mesh),
1145+
virtualServiceName: 'target.local',
1146+
});
1147+
1148+
// Add an HTTP Route
1149+
virtualGateway.addGatewayRoute('gateway-http-route', {
1150+
routeSpec: appmesh.GatewayRouteSpec.http({
1151+
routeTarget: virtualService,
1152+
match: {
1153+
},
1154+
priority: 100,
1155+
}),
1156+
gatewayRouteName: 'gateway-http-route',
1157+
});
1158+
1159+
// THEN
1160+
expect(stack).toHaveResourceLike('AWS::AppMesh::GatewayRoute', {
1161+
Spec: {
1162+
Priority: 100,
1163+
},
1164+
});
1165+
});
11251166

1167+
test('should set the priority for grpc gateway route', () => {
1168+
// GIVEN
1169+
const stack = new cdk.Stack();
11261170

1171+
// WHEN
1172+
const mesh = new appmesh.Mesh(stack, 'mesh', {
1173+
meshName: 'test-mesh',
1174+
});
1175+
1176+
const virtualGateway = new appmesh.VirtualGateway(stack, 'gateway-1', {
1177+
listeners: [appmesh.VirtualGatewayListener.grpc()],
1178+
mesh: mesh,
1179+
});
1180+
1181+
const virtualService = new appmesh.VirtualService(stack, 'vs-1', {
1182+
virtualServiceProvider: appmesh.VirtualServiceProvider.none(mesh),
1183+
virtualServiceName: 'target.local',
1184+
});
1185+
1186+
// Add an Grpc Route
1187+
new appmesh.GatewayRoute(stack, 'test-node', {
1188+
routeSpec: appmesh.GatewayRouteSpec.grpc({
1189+
match: {
1190+
serviceName: virtualService.virtualServiceName,
1191+
},
1192+
routeTarget: virtualService,
1193+
priority: 500,
1194+
}),
1195+
virtualGateway: virtualGateway,
1196+
gatewayRouteName: 'routeWithPriority',
1197+
});
1198+
1199+
// THEN
1200+
expect(stack).toHaveResourceLike('AWS::AppMesh::GatewayRoute', {
1201+
Spec: {
1202+
Priority: 500,
1203+
},
1204+
});
11271205
});
11281206
});
11291207

0 commit comments

Comments
 (0)
Please sign in to comment.