From c7cf46d81513b93b5f990829dd5b1508641e5325 Mon Sep 17 00:00:00 2001 From: Shan Kiyani Date: Tue, 8 Dec 2020 16:16:14 -0600 Subject: [PATCH 01/12] Support route timeouts --- .../@aws-cdk/aws-appmesh/lib/route-spec.ts | 72 ++++++++++++++++++- .../aws-appmesh/lib/shared-interfaces.ts | 50 +++++++++++++ .../aws-appmesh/lib/virtual-node-listener.ts | 52 +------------- packages/@aws-cdk/aws-appmesh/package.json | 5 +- .../aws-appmesh/test/integ.mesh.expected.json | 26 +++++++ .../@aws-cdk/aws-appmesh/test/integ.mesh.ts | 11 +++ .../@aws-cdk/aws-appmesh/test/test.route.ts | 19 +++++ .../aws-appmesh/test/test.virtual-router.ts | 19 +++++ 8 files changed, 201 insertions(+), 53 deletions(-) diff --git a/packages/@aws-cdk/aws-appmesh/lib/route-spec.ts b/packages/@aws-cdk/aws-appmesh/lib/route-spec.ts index b015bd4580171..386b2d42596ce 100644 --- a/packages/@aws-cdk/aws-appmesh/lib/route-spec.ts +++ b/packages/@aws-cdk/aws-appmesh/lib/route-spec.ts @@ -1,6 +1,6 @@ import * as cdk from '@aws-cdk/core'; import { CfnRoute } from './appmesh.generated'; -import { Protocol } from './shared-interfaces'; +import { Protocol, HttpTimeout, GrpcTimeout, TcpTimeout } from './shared-interfaces'; import { IVirtualNode } from './virtual-node'; /** @@ -58,6 +58,12 @@ export interface HttpRouteSpecOptions { * List of targets that traffic is routed to when a request matches the route */ readonly weightedTargets: WeightedTarget[]; + + /** + * An object that represents a http timeout + * @default - None + */ + readonly timeout?: HttpTimeout; } /** @@ -68,6 +74,12 @@ export interface TcpRouteSpecOptions { * List of targets that traffic is routed to when a request matches the route */ readonly weightedTargets: WeightedTarget[]; + + /** + * An object that represents a tcp timeout + * @default - None + */ + readonly timeout?: TcpTimeout; } /** @@ -79,6 +91,12 @@ export interface GrpcRouteSpecOptions { */ readonly match: GrpcRouteMatch; + /** + * An object that represents a grpc timeout + * @default - None + */ + readonly timeout?: GrpcTimeout; + /** * List of targets that traffic is routed to when a request matches the route */ @@ -169,6 +187,11 @@ class HttpRouteSpec extends RouteSpec { */ public readonly match?: HttpRouteMatch; + /** + * The criteria for determining a timeout configuration + */ + public readonly timeout?: HttpTimeout; + /** * List of targets that traffic is routed to when a request matches the route */ @@ -179,6 +202,7 @@ class HttpRouteSpec extends RouteSpec { this.protocol = protocol; this.match = props.match; this.weightedTargets = props.weightedTargets; + this.timeout = props.timeout; } public bind(_scope: cdk.Construct): RouteSpecConfig { @@ -193,12 +217,26 @@ class HttpRouteSpec extends RouteSpec { match: { prefix: prefixPath, }, + timeout: this.timeout ? this.renderTimeout(this.timeout): undefined, }; return { httpRouteSpec: this.protocol === Protocol.HTTP ? httpConfig : undefined, http2RouteSpec: this.protocol === Protocol.HTTP2 ? httpConfig : undefined, }; } + + private renderTimeout(timeout: HttpTimeout): CfnRoute.HttpTimeoutProperty { + return ({ + idle: timeout?.idle !== undefined ? { + unit: 'ms', + value: timeout?.idle.toMilliseconds(), + } : undefined, + perRequest: timeout?.perRequest !== undefined ? { + unit: 'ms', + value: timeout?.perRequest.toMilliseconds(), + } : undefined, + }); + } } class TcpRouteSpec extends RouteSpec { @@ -207,9 +245,15 @@ class TcpRouteSpec extends RouteSpec { */ public readonly weightedTargets: WeightedTarget[]; + /** + * The criteria for determining a timeout configuration + */ + public readonly timeout?: TcpTimeout; + constructor(props: TcpRouteSpecOptions) { super(); this.weightedTargets = props.weightedTargets; + this.timeout = props.timeout; } public bind(_scope: cdk.Construct): RouteSpecConfig { @@ -218,19 +262,31 @@ class TcpRouteSpec extends RouteSpec { action: { weightedTargets: renderWeightedTargets(this.weightedTargets), }, + timeout: this.timeout ? this.renderTimeout(this.timeout): undefined, }, }; } + + private renderTimeout(timeout: TcpTimeout): CfnRoute.TcpTimeoutProperty { + return ({ + idle: timeout?.idle !== undefined ? { + unit: 'ms', + value: timeout?.idle.toMilliseconds(), + } : undefined, + }); + } } class GrpcRouteSpec extends RouteSpec { public readonly weightedTargets: WeightedTarget[]; public readonly match: GrpcRouteMatch; + public readonly timeout?: GrpcTimeout; constructor(props: GrpcRouteSpecOptions) { super(); this.weightedTargets = props.weightedTargets; this.match = props.match; + this.timeout = props.timeout; } public bind(_scope: cdk.Construct): RouteSpecConfig { @@ -242,9 +298,23 @@ class GrpcRouteSpec extends RouteSpec { match: { serviceName: this.match.serviceName, }, + timeout: this.timeout ? this.renderTimeout(this.timeout): undefined, }, }; } + + private renderTimeout(timeout: GrpcTimeout): CfnRoute.GrpcTimeoutProperty { + return ({ + idle: timeout?.idle !== undefined ? { + unit: 'ms', + value: timeout?.idle.toMilliseconds(), + } : undefined, + perRequest: timeout?.perRequest !== undefined ? { + unit: 'ms', + value: timeout?.perRequest.toMilliseconds(), + } : undefined, + }); + } } /** diff --git a/packages/@aws-cdk/aws-appmesh/lib/shared-interfaces.ts b/packages/@aws-cdk/aws-appmesh/lib/shared-interfaces.ts index c8b3ba88f6378..cbd574489f9c4 100644 --- a/packages/@aws-cdk/aws-appmesh/lib/shared-interfaces.ts +++ b/packages/@aws-cdk/aws-appmesh/lib/shared-interfaces.ts @@ -1,6 +1,56 @@ import * as cdk from '@aws-cdk/core'; import { CfnVirtualGateway, CfnVirtualNode } from './appmesh.generated'; +/** + * Represents timeouts for HTTP protocols. + */ +export interface HttpTimeout { + /** + * Represents an idle timeout. The amount of time that a connection may be idle. + * + * @default - none + */ + readonly idle?: cdk.Duration; + + /** + * Represents per request timeout. + * + * @default - 15 s + */ + readonly perRequest?: cdk.Duration; +} + +/** + * Represents timeouts for GRPC protocols. + */ +export interface GrpcTimeout { + /** + * Represents an idle timeout. The amount of time that a connection may be idle. + * + * @default - none + */ + readonly idle?: cdk.Duration; + + /** + * Represents per request timeout. + * + * @default - 15 s + */ + readonly perRequest?: cdk.Duration; +} + +/** + * Represents timeouts for TCP protocols. + */ +export interface TcpTimeout { + /** + * Represents an idle timeout. The amount of time that a connection may be idle. + * + * @default - none + */ + readonly idle?: cdk.Duration; +} + /** * Enum of supported AppMesh protocols */ diff --git a/packages/@aws-cdk/aws-appmesh/lib/virtual-node-listener.ts b/packages/@aws-cdk/aws-appmesh/lib/virtual-node-listener.ts index e3e433d8e25d8..5793a746ee968 100644 --- a/packages/@aws-cdk/aws-appmesh/lib/virtual-node-listener.ts +++ b/packages/@aws-cdk/aws-appmesh/lib/virtual-node-listener.ts @@ -1,7 +1,7 @@ import * as cdk from '@aws-cdk/core'; import { CfnVirtualNode } from './appmesh.generated'; import { validateHealthChecks } from './private/utils'; -import { HealthCheck, Protocol } from './shared-interfaces'; +import { HealthCheck, Protocol, HttpTimeout, GrpcTimeout, TcpTimeout } from './shared-interfaces'; /** * Properties for a VirtualNode listener @@ -68,56 +68,6 @@ export interface TcpVirtualNodeListenerOptions extends VirtualNodeListenerCommon readonly timeout?: TcpTimeout; } -/** - * Represents timeouts for HTTP protocols. - */ -export interface HttpTimeout { - /** - * Represents an idle timeout. The amount of time that a connection may be idle. - * - * @default - none - */ - readonly idle?: cdk.Duration; - - /** - * Represents per request timeout. - * - * @default - 15 s - */ - readonly perRequest?: cdk.Duration; -} - -/** - * Represents timeouts for GRPC protocols. - */ -export interface GrpcTimeout { - /** - * Represents an idle timeout. The amount of time that a connection may be idle. - * - * @default - none - */ - readonly idle?: cdk.Duration; - - /** - * Represents per request timeout. - * - * @default - 15 s - */ - readonly perRequest?: cdk.Duration; -} - -/** - * Represents timeouts for TCP protocols. - */ -export interface TcpTimeout { - /** - * Represents an idle timeout. The amount of time that a connection may be idle. - * - * @default - none - */ - readonly idle?: cdk.Duration; -} - /** * Defines listener for a VirtualNode */ diff --git a/packages/@aws-cdk/aws-appmesh/package.json b/packages/@aws-cdk/aws-appmesh/package.json index c956c2e77c844..fad86447a4fe3 100644 --- a/packages/@aws-cdk/aws-appmesh/package.json +++ b/packages/@aws-cdk/aws-appmesh/package.json @@ -180,7 +180,10 @@ "duration-prop-type:@aws-cdk/aws-appmesh.GrpcVirtualNodeListenerOptions.timeout", "duration-prop-type:@aws-cdk/aws-appmesh.HttpVirtualNodeListenerOptions.timeout", "duration-prop-type:@aws-cdk/aws-appmesh.Http2VirtualNodeListenerOptions.timeout", - "duration-prop-type:@aws-cdk/aws-appmesh.TcpVirtualNodeListenerOptions.timeout" + "duration-prop-type:@aws-cdk/aws-appmesh.TcpVirtualNodeListenerOptions.timeout", + "duration-prop-type:@aws-cdk/aws-appmesh.GrpcRouteSpecOptions.timeout", + "duration-prop-type:@aws-cdk/aws-appmesh.HttpRouteSpecOptions.timeout", + "duration-prop-type:@aws-cdk/aws-appmesh.TcpRouteSpecOptions.timeout" ] }, "stability": "experimental", diff --git a/packages/@aws-cdk/aws-appmesh/test/integ.mesh.expected.json b/packages/@aws-cdk/aws-appmesh/test/integ.mesh.expected.json index e3a9f98c5a016..e642633387206 100644 --- a/packages/@aws-cdk/aws-appmesh/test/integ.mesh.expected.json +++ b/packages/@aws-cdk/aws-appmesh/test/integ.mesh.expected.json @@ -515,6 +515,16 @@ }, "Match": { "Prefix": "/" + }, + "Timeout": { + "Idle": { + "Unit": "ms", + "Value": 10000 + }, + "PerRequest": { + "Unit": "ms", + "Value": 10000 + } } } }, @@ -553,6 +563,16 @@ }, "Match": { "Prefix": "/path2" + }, + "Timeout": { + "Idle": { + "Unit": "ms", + "Value": 11000 + }, + "PerRequest": { + "Unit": "ms", + "Value": 11000 + } } } }, @@ -588,6 +608,12 @@ "Weight": 20 } ] + }, + "Timeout": { + "Idle": { + "Unit": "ms", + "Value": 12000 + } } } }, diff --git a/packages/@aws-cdk/aws-appmesh/test/integ.mesh.ts b/packages/@aws-cdk/aws-appmesh/test/integ.mesh.ts index 63e027b8ef0e5..881a36af82a47 100644 --- a/packages/@aws-cdk/aws-appmesh/test/integ.mesh.ts +++ b/packages/@aws-cdk/aws-appmesh/test/integ.mesh.ts @@ -59,6 +59,10 @@ router.addRoute('route-1', { match: { prefixPath: '/', }, + timeout: { + idle: cdk.Duration.seconds(10), + perRequest: cdk.Duration.seconds(10), + }, }), }); @@ -118,6 +122,10 @@ router.addRoute('route-2', { match: { prefixPath: '/path2', }, + timeout: { + idle: cdk.Duration.seconds(11), + perRequest: cdk.Duration.seconds(11), + }, }), }); @@ -129,6 +137,9 @@ router.addRoute('route-3', { weight: 20, }, ], + timeout: { + idle: cdk.Duration.seconds(12), + }, }), }); diff --git a/packages/@aws-cdk/aws-appmesh/test/test.route.ts b/packages/@aws-cdk/aws-appmesh/test/test.route.ts index c3b6bab0357cb..d3df5cc1ab33d 100644 --- a/packages/@aws-cdk/aws-appmesh/test/test.route.ts +++ b/packages/@aws-cdk/aws-appmesh/test/test.route.ts @@ -29,6 +29,10 @@ export = { virtualNode: node, }, ], + timeout: { + idle: cdk.Duration.seconds(10), + perRequest: cdk.Duration.seconds(10), + }, }), }); @@ -39,6 +43,10 @@ export = { virtualNode: node, }, ], + timeout: { + idle: cdk.Duration.seconds(10), + perRequest: cdk.Duration.seconds(10), + }, }), }); @@ -49,6 +57,9 @@ export = { virtualNode: node, }, ], + timeout: { + idle: cdk.Duration.seconds(10), + }, }), }); @@ -62,6 +73,10 @@ export = { match: { serviceName: 'test.svc.local', }, + timeout: { + idle: cdk.Duration.seconds(10), + perRequest: cdk.Duration.seconds(10), + }, }), }); @@ -188,6 +203,10 @@ export = { match: { prefixPath: '/node', }, + timeout: { + idle: cdk.Duration.seconds(10), + perRequest: cdk.Duration.seconds(10), + }, }), }); diff --git a/packages/@aws-cdk/aws-appmesh/test/test.virtual-router.ts b/packages/@aws-cdk/aws-appmesh/test/test.virtual-router.ts index 671ffb8aa61ae..6c5797e70fdc6 100644 --- a/packages/@aws-cdk/aws-appmesh/test/test.virtual-router.ts +++ b/packages/@aws-cdk/aws-appmesh/test/test.virtual-router.ts @@ -123,6 +123,10 @@ export = { match: { prefixPath: '/', }, + timeout: { + idle: cdk.Duration.seconds(8), + perRequest: cdk.Duration.seconds(8), + }, }), }); @@ -216,6 +220,10 @@ export = { match: { prefixPath: '/', }, + timeout: { + idle: cdk.Duration.seconds(9), + perRequest: cdk.Duration.seconds(9), + }, }), }); @@ -230,6 +238,10 @@ export = { match: { prefixPath: '/path2', }, + timeout: { + idle: cdk.Duration.seconds(10), + perRequest: cdk.Duration.seconds(10), + }, }), }); @@ -244,6 +256,10 @@ export = { match: { prefixPath: '/path3', }, + timeout: { + idle: cdk.Duration.seconds(11), + perRequest: cdk.Duration.seconds(11), + }, }), }); @@ -353,6 +369,9 @@ export = { weight: 50, }, ], + timeout: { + idle: cdk.Duration.seconds(10), + }, }), }); From c1f319314043f3b5ddeb2e8d335efdff17a5dcb8 Mon Sep 17 00:00:00 2001 From: Shan Kiyani Date: Wed, 9 Dec 2020 18:05:37 -0600 Subject: [PATCH 02/12] assert in tests --- .../@aws-cdk/aws-appmesh/lib/route-spec.ts | 8 +++- .../@aws-cdk/aws-appmesh/test/test.route.ts | 42 +++++++++++++++++-- 2 files changed, 45 insertions(+), 5 deletions(-) diff --git a/packages/@aws-cdk/aws-appmesh/lib/route-spec.ts b/packages/@aws-cdk/aws-appmesh/lib/route-spec.ts index 386b2d42596ce..a01345b619638 100644 --- a/packages/@aws-cdk/aws-appmesh/lib/route-spec.ts +++ b/packages/@aws-cdk/aws-appmesh/lib/route-spec.ts @@ -61,6 +61,7 @@ export interface HttpRouteSpecOptions { /** * An object that represents a http timeout + * * @default - None */ readonly timeout?: HttpTimeout; @@ -77,6 +78,7 @@ export interface TcpRouteSpecOptions { /** * An object that represents a tcp timeout + * * @default - None */ readonly timeout?: TcpTimeout; @@ -93,6 +95,7 @@ export interface GrpcRouteSpecOptions { /** * An object that represents a grpc timeout + * * @default - None */ readonly timeout?: GrpcTimeout; @@ -184,6 +187,7 @@ class HttpRouteSpec extends RouteSpec { /** * The criteria for determining a request match + * */ public readonly match?: HttpRouteMatch; @@ -226,7 +230,7 @@ class HttpRouteSpec extends RouteSpec { } private renderTimeout(timeout: HttpTimeout): CfnRoute.HttpTimeoutProperty { - return ({ + return { idle: timeout?.idle !== undefined ? { unit: 'ms', value: timeout?.idle.toMilliseconds(), @@ -235,7 +239,7 @@ class HttpRouteSpec extends RouteSpec { unit: 'ms', value: timeout?.perRequest.toMilliseconds(), } : undefined, - }); + }; } } diff --git a/packages/@aws-cdk/aws-appmesh/test/test.route.ts b/packages/@aws-cdk/aws-appmesh/test/test.route.ts index d3df5cc1ab33d..c90e1cf38c96a 100644 --- a/packages/@aws-cdk/aws-appmesh/test/test.route.ts +++ b/packages/@aws-cdk/aws-appmesh/test/test.route.ts @@ -31,7 +31,7 @@ export = { ], timeout: { idle: cdk.Duration.seconds(10), - perRequest: cdk.Duration.seconds(10), + perRequest: cdk.Duration.seconds(11), }, }), }); @@ -45,7 +45,7 @@ export = { ], timeout: { idle: cdk.Duration.seconds(10), - perRequest: cdk.Duration.seconds(10), + perRequest: cdk.Duration.seconds(11), }, }), }); @@ -75,7 +75,7 @@ export = { }, timeout: { idle: cdk.Duration.seconds(10), - perRequest: cdk.Duration.seconds(10), + perRequest: cdk.Duration.seconds(11), }, }), }); @@ -100,6 +100,16 @@ export = { Match: { Prefix: '/', }, + Timeout: { + Idle: { + Value: 10000, + Unit: 'ms', + }, + PerRequest: { + Value: 11000, + Unit: 'ms', + }, + }, }, }, RouteName: 'test-http-route', @@ -124,6 +134,16 @@ export = { Match: { Prefix: '/', }, + Timeout: { + Idle: { + Value: 10000, + Unit: 'ms', + }, + PerRequest: { + Value: 11000, + Unit: 'ms', + }, + }, }, }, RouteName: 'test-http2-route', @@ -145,6 +165,12 @@ export = { }, ], }, + Timeout: { + Idle: { + Value: 10000, + Unit: 'ms', + }, + }, }, }, RouteName: 'test-tcp-route', @@ -169,6 +195,16 @@ export = { Match: { ServiceName: 'test.svc.local', }, + Timeout: { + Idle: { + Value: 10000, + Unit: 'ms', + }, + PerRequest: { + Value: 11000, + Unit: 'ms', + }, + }, }, }, RouteName: 'test-grpc-route', From 38cc77dd36745d00566b05d6c440dabaa8635018 Mon Sep 17 00:00:00 2001 From: Shan Kiyani Date: Wed, 9 Dec 2020 18:21:55 -0600 Subject: [PATCH 03/12] update readme for timeouts --- packages/@aws-cdk/aws-appmesh/README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/@aws-cdk/aws-appmesh/README.md b/packages/@aws-cdk/aws-appmesh/README.md index 4b38e150a042e..0635a695669ce 100644 --- a/packages/@aws-cdk/aws-appmesh/README.md +++ b/packages/@aws-cdk/aws-appmesh/README.md @@ -282,7 +282,7 @@ The _RouteSpec_ class provides an easy interface for defining new protocol speci The `tcp()`, `http()` and `http2()` methods provide the spec necessary to define a protocol specific spec. For HTTP based routes, the match field can be used to match on a route prefix. -By default, an HTTP based route will match on `/`. All matches must start with a leading `/`. +By default, an HTTP based route will match on `/`. All matches must start with a leading `/`. The timeout field can also be specified for `idle` and `perRequest` timeouts. ```ts router.addRoute('route-http', { @@ -295,6 +295,10 @@ router.addRoute('route-http', { match: { serviceName: 'my-service.default.svc.cluster.local', }, + timeout: { + idle : Duration.seconds(2), + perRequest: Duration.seconds(1), + }, }), }); ``` From adbbdb23f9d6d371910ff0763d96684e49fa68ee Mon Sep 17 00:00:00 2001 From: Shan Kiyani Date: Tue, 8 Dec 2020 16:16:14 -0600 Subject: [PATCH 04/12] Support route timeouts --- .../@aws-cdk/aws-appmesh/lib/route-spec.ts | 72 ++++++++++++++++++- .../aws-appmesh/lib/shared-interfaces.ts | 50 +++++++++++++ .../aws-appmesh/lib/virtual-node-listener.ts | 52 +------------- packages/@aws-cdk/aws-appmesh/package.json | 5 +- .../aws-appmesh/test/integ.mesh.expected.json | 26 +++++++ .../@aws-cdk/aws-appmesh/test/integ.mesh.ts | 11 +++ .../@aws-cdk/aws-appmesh/test/test.route.ts | 19 +++++ .../aws-appmesh/test/test.virtual-router.ts | 19 +++++ 8 files changed, 201 insertions(+), 53 deletions(-) diff --git a/packages/@aws-cdk/aws-appmesh/lib/route-spec.ts b/packages/@aws-cdk/aws-appmesh/lib/route-spec.ts index b015bd4580171..386b2d42596ce 100644 --- a/packages/@aws-cdk/aws-appmesh/lib/route-spec.ts +++ b/packages/@aws-cdk/aws-appmesh/lib/route-spec.ts @@ -1,6 +1,6 @@ import * as cdk from '@aws-cdk/core'; import { CfnRoute } from './appmesh.generated'; -import { Protocol } from './shared-interfaces'; +import { Protocol, HttpTimeout, GrpcTimeout, TcpTimeout } from './shared-interfaces'; import { IVirtualNode } from './virtual-node'; /** @@ -58,6 +58,12 @@ export interface HttpRouteSpecOptions { * List of targets that traffic is routed to when a request matches the route */ readonly weightedTargets: WeightedTarget[]; + + /** + * An object that represents a http timeout + * @default - None + */ + readonly timeout?: HttpTimeout; } /** @@ -68,6 +74,12 @@ export interface TcpRouteSpecOptions { * List of targets that traffic is routed to when a request matches the route */ readonly weightedTargets: WeightedTarget[]; + + /** + * An object that represents a tcp timeout + * @default - None + */ + readonly timeout?: TcpTimeout; } /** @@ -79,6 +91,12 @@ export interface GrpcRouteSpecOptions { */ readonly match: GrpcRouteMatch; + /** + * An object that represents a grpc timeout + * @default - None + */ + readonly timeout?: GrpcTimeout; + /** * List of targets that traffic is routed to when a request matches the route */ @@ -169,6 +187,11 @@ class HttpRouteSpec extends RouteSpec { */ public readonly match?: HttpRouteMatch; + /** + * The criteria for determining a timeout configuration + */ + public readonly timeout?: HttpTimeout; + /** * List of targets that traffic is routed to when a request matches the route */ @@ -179,6 +202,7 @@ class HttpRouteSpec extends RouteSpec { this.protocol = protocol; this.match = props.match; this.weightedTargets = props.weightedTargets; + this.timeout = props.timeout; } public bind(_scope: cdk.Construct): RouteSpecConfig { @@ -193,12 +217,26 @@ class HttpRouteSpec extends RouteSpec { match: { prefix: prefixPath, }, + timeout: this.timeout ? this.renderTimeout(this.timeout): undefined, }; return { httpRouteSpec: this.protocol === Protocol.HTTP ? httpConfig : undefined, http2RouteSpec: this.protocol === Protocol.HTTP2 ? httpConfig : undefined, }; } + + private renderTimeout(timeout: HttpTimeout): CfnRoute.HttpTimeoutProperty { + return ({ + idle: timeout?.idle !== undefined ? { + unit: 'ms', + value: timeout?.idle.toMilliseconds(), + } : undefined, + perRequest: timeout?.perRequest !== undefined ? { + unit: 'ms', + value: timeout?.perRequest.toMilliseconds(), + } : undefined, + }); + } } class TcpRouteSpec extends RouteSpec { @@ -207,9 +245,15 @@ class TcpRouteSpec extends RouteSpec { */ public readonly weightedTargets: WeightedTarget[]; + /** + * The criteria for determining a timeout configuration + */ + public readonly timeout?: TcpTimeout; + constructor(props: TcpRouteSpecOptions) { super(); this.weightedTargets = props.weightedTargets; + this.timeout = props.timeout; } public bind(_scope: cdk.Construct): RouteSpecConfig { @@ -218,19 +262,31 @@ class TcpRouteSpec extends RouteSpec { action: { weightedTargets: renderWeightedTargets(this.weightedTargets), }, + timeout: this.timeout ? this.renderTimeout(this.timeout): undefined, }, }; } + + private renderTimeout(timeout: TcpTimeout): CfnRoute.TcpTimeoutProperty { + return ({ + idle: timeout?.idle !== undefined ? { + unit: 'ms', + value: timeout?.idle.toMilliseconds(), + } : undefined, + }); + } } class GrpcRouteSpec extends RouteSpec { public readonly weightedTargets: WeightedTarget[]; public readonly match: GrpcRouteMatch; + public readonly timeout?: GrpcTimeout; constructor(props: GrpcRouteSpecOptions) { super(); this.weightedTargets = props.weightedTargets; this.match = props.match; + this.timeout = props.timeout; } public bind(_scope: cdk.Construct): RouteSpecConfig { @@ -242,9 +298,23 @@ class GrpcRouteSpec extends RouteSpec { match: { serviceName: this.match.serviceName, }, + timeout: this.timeout ? this.renderTimeout(this.timeout): undefined, }, }; } + + private renderTimeout(timeout: GrpcTimeout): CfnRoute.GrpcTimeoutProperty { + return ({ + idle: timeout?.idle !== undefined ? { + unit: 'ms', + value: timeout?.idle.toMilliseconds(), + } : undefined, + perRequest: timeout?.perRequest !== undefined ? { + unit: 'ms', + value: timeout?.perRequest.toMilliseconds(), + } : undefined, + }); + } } /** diff --git a/packages/@aws-cdk/aws-appmesh/lib/shared-interfaces.ts b/packages/@aws-cdk/aws-appmesh/lib/shared-interfaces.ts index c8b3ba88f6378..cbd574489f9c4 100644 --- a/packages/@aws-cdk/aws-appmesh/lib/shared-interfaces.ts +++ b/packages/@aws-cdk/aws-appmesh/lib/shared-interfaces.ts @@ -1,6 +1,56 @@ import * as cdk from '@aws-cdk/core'; import { CfnVirtualGateway, CfnVirtualNode } from './appmesh.generated'; +/** + * Represents timeouts for HTTP protocols. + */ +export interface HttpTimeout { + /** + * Represents an idle timeout. The amount of time that a connection may be idle. + * + * @default - none + */ + readonly idle?: cdk.Duration; + + /** + * Represents per request timeout. + * + * @default - 15 s + */ + readonly perRequest?: cdk.Duration; +} + +/** + * Represents timeouts for GRPC protocols. + */ +export interface GrpcTimeout { + /** + * Represents an idle timeout. The amount of time that a connection may be idle. + * + * @default - none + */ + readonly idle?: cdk.Duration; + + /** + * Represents per request timeout. + * + * @default - 15 s + */ + readonly perRequest?: cdk.Duration; +} + +/** + * Represents timeouts for TCP protocols. + */ +export interface TcpTimeout { + /** + * Represents an idle timeout. The amount of time that a connection may be idle. + * + * @default - none + */ + readonly idle?: cdk.Duration; +} + /** * Enum of supported AppMesh protocols */ diff --git a/packages/@aws-cdk/aws-appmesh/lib/virtual-node-listener.ts b/packages/@aws-cdk/aws-appmesh/lib/virtual-node-listener.ts index e3e433d8e25d8..5793a746ee968 100644 --- a/packages/@aws-cdk/aws-appmesh/lib/virtual-node-listener.ts +++ b/packages/@aws-cdk/aws-appmesh/lib/virtual-node-listener.ts @@ -1,7 +1,7 @@ import * as cdk from '@aws-cdk/core'; import { CfnVirtualNode } from './appmesh.generated'; import { validateHealthChecks } from './private/utils'; -import { HealthCheck, Protocol } from './shared-interfaces'; +import { HealthCheck, Protocol, HttpTimeout, GrpcTimeout, TcpTimeout } from './shared-interfaces'; /** * Properties for a VirtualNode listener @@ -68,56 +68,6 @@ export interface TcpVirtualNodeListenerOptions extends VirtualNodeListenerCommon readonly timeout?: TcpTimeout; } -/** - * Represents timeouts for HTTP protocols. - */ -export interface HttpTimeout { - /** - * Represents an idle timeout. The amount of time that a connection may be idle. - * - * @default - none - */ - readonly idle?: cdk.Duration; - - /** - * Represents per request timeout. - * - * @default - 15 s - */ - readonly perRequest?: cdk.Duration; -} - -/** - * Represents timeouts for GRPC protocols. - */ -export interface GrpcTimeout { - /** - * Represents an idle timeout. The amount of time that a connection may be idle. - * - * @default - none - */ - readonly idle?: cdk.Duration; - - /** - * Represents per request timeout. - * - * @default - 15 s - */ - readonly perRequest?: cdk.Duration; -} - -/** - * Represents timeouts for TCP protocols. - */ -export interface TcpTimeout { - /** - * Represents an idle timeout. The amount of time that a connection may be idle. - * - * @default - none - */ - readonly idle?: cdk.Duration; -} - /** * Defines listener for a VirtualNode */ diff --git a/packages/@aws-cdk/aws-appmesh/package.json b/packages/@aws-cdk/aws-appmesh/package.json index c956c2e77c844..fad86447a4fe3 100644 --- a/packages/@aws-cdk/aws-appmesh/package.json +++ b/packages/@aws-cdk/aws-appmesh/package.json @@ -180,7 +180,10 @@ "duration-prop-type:@aws-cdk/aws-appmesh.GrpcVirtualNodeListenerOptions.timeout", "duration-prop-type:@aws-cdk/aws-appmesh.HttpVirtualNodeListenerOptions.timeout", "duration-prop-type:@aws-cdk/aws-appmesh.Http2VirtualNodeListenerOptions.timeout", - "duration-prop-type:@aws-cdk/aws-appmesh.TcpVirtualNodeListenerOptions.timeout" + "duration-prop-type:@aws-cdk/aws-appmesh.TcpVirtualNodeListenerOptions.timeout", + "duration-prop-type:@aws-cdk/aws-appmesh.GrpcRouteSpecOptions.timeout", + "duration-prop-type:@aws-cdk/aws-appmesh.HttpRouteSpecOptions.timeout", + "duration-prop-type:@aws-cdk/aws-appmesh.TcpRouteSpecOptions.timeout" ] }, "stability": "experimental", diff --git a/packages/@aws-cdk/aws-appmesh/test/integ.mesh.expected.json b/packages/@aws-cdk/aws-appmesh/test/integ.mesh.expected.json index e3a9f98c5a016..e642633387206 100644 --- a/packages/@aws-cdk/aws-appmesh/test/integ.mesh.expected.json +++ b/packages/@aws-cdk/aws-appmesh/test/integ.mesh.expected.json @@ -515,6 +515,16 @@ }, "Match": { "Prefix": "/" + }, + "Timeout": { + "Idle": { + "Unit": "ms", + "Value": 10000 + }, + "PerRequest": { + "Unit": "ms", + "Value": 10000 + } } } }, @@ -553,6 +563,16 @@ }, "Match": { "Prefix": "/path2" + }, + "Timeout": { + "Idle": { + "Unit": "ms", + "Value": 11000 + }, + "PerRequest": { + "Unit": "ms", + "Value": 11000 + } } } }, @@ -588,6 +608,12 @@ "Weight": 20 } ] + }, + "Timeout": { + "Idle": { + "Unit": "ms", + "Value": 12000 + } } } }, diff --git a/packages/@aws-cdk/aws-appmesh/test/integ.mesh.ts b/packages/@aws-cdk/aws-appmesh/test/integ.mesh.ts index 6790f4c749316..2f1884b3f7e63 100644 --- a/packages/@aws-cdk/aws-appmesh/test/integ.mesh.ts +++ b/packages/@aws-cdk/aws-appmesh/test/integ.mesh.ts @@ -59,6 +59,10 @@ router.addRoute('route-1', { match: { prefixPath: '/', }, + timeout: { + idle: cdk.Duration.seconds(10), + perRequest: cdk.Duration.seconds(10), + }, }), }); @@ -118,6 +122,10 @@ router.addRoute('route-2', { match: { prefixPath: '/path2', }, + timeout: { + idle: cdk.Duration.seconds(11), + perRequest: cdk.Duration.seconds(11), + }, }), }); @@ -129,6 +137,9 @@ router.addRoute('route-3', { weight: 20, }, ], + timeout: { + idle: cdk.Duration.seconds(12), + }, }), }); diff --git a/packages/@aws-cdk/aws-appmesh/test/test.route.ts b/packages/@aws-cdk/aws-appmesh/test/test.route.ts index 2fd03f907f236..d5ebaa89ae0fb 100644 --- a/packages/@aws-cdk/aws-appmesh/test/test.route.ts +++ b/packages/@aws-cdk/aws-appmesh/test/test.route.ts @@ -29,6 +29,10 @@ export = { virtualNode: node, }, ], + timeout: { + idle: cdk.Duration.seconds(10), + perRequest: cdk.Duration.seconds(10), + }, }), }); @@ -39,6 +43,10 @@ export = { virtualNode: node, }, ], + timeout: { + idle: cdk.Duration.seconds(10), + perRequest: cdk.Duration.seconds(10), + }, }), }); @@ -49,6 +57,9 @@ export = { virtualNode: node, }, ], + timeout: { + idle: cdk.Duration.seconds(10), + }, }), }); @@ -62,6 +73,10 @@ export = { match: { serviceName: 'test.svc.local', }, + timeout: { + idle: cdk.Duration.seconds(10), + perRequest: cdk.Duration.seconds(10), + }, }), }); @@ -188,6 +203,10 @@ export = { match: { prefixPath: '/node', }, + timeout: { + idle: cdk.Duration.seconds(10), + perRequest: cdk.Duration.seconds(10), + }, }), }); diff --git a/packages/@aws-cdk/aws-appmesh/test/test.virtual-router.ts b/packages/@aws-cdk/aws-appmesh/test/test.virtual-router.ts index aafe3dff8ce7f..24f16e0b4a059 100644 --- a/packages/@aws-cdk/aws-appmesh/test/test.virtual-router.ts +++ b/packages/@aws-cdk/aws-appmesh/test/test.virtual-router.ts @@ -123,6 +123,10 @@ export = { match: { prefixPath: '/', }, + timeout: { + idle: cdk.Duration.seconds(8), + perRequest: cdk.Duration.seconds(8), + }, }), }); @@ -216,6 +220,10 @@ export = { match: { prefixPath: '/', }, + timeout: { + idle: cdk.Duration.seconds(9), + perRequest: cdk.Duration.seconds(9), + }, }), }); @@ -230,6 +238,10 @@ export = { match: { prefixPath: '/path2', }, + timeout: { + idle: cdk.Duration.seconds(10), + perRequest: cdk.Duration.seconds(10), + }, }), }); @@ -244,6 +256,10 @@ export = { match: { prefixPath: '/path3', }, + timeout: { + idle: cdk.Duration.seconds(11), + perRequest: cdk.Duration.seconds(11), + }, }), }); @@ -353,6 +369,9 @@ export = { weight: 50, }, ], + timeout: { + idle: cdk.Duration.seconds(10), + }, }), }); From 31a711e18ab26181ee9ab3cceec11a7f61081909 Mon Sep 17 00:00:00 2001 From: Shan Kiyani Date: Wed, 9 Dec 2020 18:05:37 -0600 Subject: [PATCH 05/12] assert in tests --- .../@aws-cdk/aws-appmesh/lib/route-spec.ts | 8 +++- .../@aws-cdk/aws-appmesh/test/test.route.ts | 42 +++++++++++++++++-- 2 files changed, 45 insertions(+), 5 deletions(-) diff --git a/packages/@aws-cdk/aws-appmesh/lib/route-spec.ts b/packages/@aws-cdk/aws-appmesh/lib/route-spec.ts index 386b2d42596ce..a01345b619638 100644 --- a/packages/@aws-cdk/aws-appmesh/lib/route-spec.ts +++ b/packages/@aws-cdk/aws-appmesh/lib/route-spec.ts @@ -61,6 +61,7 @@ export interface HttpRouteSpecOptions { /** * An object that represents a http timeout + * * @default - None */ readonly timeout?: HttpTimeout; @@ -77,6 +78,7 @@ export interface TcpRouteSpecOptions { /** * An object that represents a tcp timeout + * * @default - None */ readonly timeout?: TcpTimeout; @@ -93,6 +95,7 @@ export interface GrpcRouteSpecOptions { /** * An object that represents a grpc timeout + * * @default - None */ readonly timeout?: GrpcTimeout; @@ -184,6 +187,7 @@ class HttpRouteSpec extends RouteSpec { /** * The criteria for determining a request match + * */ public readonly match?: HttpRouteMatch; @@ -226,7 +230,7 @@ class HttpRouteSpec extends RouteSpec { } private renderTimeout(timeout: HttpTimeout): CfnRoute.HttpTimeoutProperty { - return ({ + return { idle: timeout?.idle !== undefined ? { unit: 'ms', value: timeout?.idle.toMilliseconds(), @@ -235,7 +239,7 @@ class HttpRouteSpec extends RouteSpec { unit: 'ms', value: timeout?.perRequest.toMilliseconds(), } : undefined, - }); + }; } } diff --git a/packages/@aws-cdk/aws-appmesh/test/test.route.ts b/packages/@aws-cdk/aws-appmesh/test/test.route.ts index d5ebaa89ae0fb..01164ae89402f 100644 --- a/packages/@aws-cdk/aws-appmesh/test/test.route.ts +++ b/packages/@aws-cdk/aws-appmesh/test/test.route.ts @@ -31,7 +31,7 @@ export = { ], timeout: { idle: cdk.Duration.seconds(10), - perRequest: cdk.Duration.seconds(10), + perRequest: cdk.Duration.seconds(11), }, }), }); @@ -45,7 +45,7 @@ export = { ], timeout: { idle: cdk.Duration.seconds(10), - perRequest: cdk.Duration.seconds(10), + perRequest: cdk.Duration.seconds(11), }, }), }); @@ -75,7 +75,7 @@ export = { }, timeout: { idle: cdk.Duration.seconds(10), - perRequest: cdk.Duration.seconds(10), + perRequest: cdk.Duration.seconds(11), }, }), }); @@ -100,6 +100,16 @@ export = { Match: { Prefix: '/', }, + Timeout: { + Idle: { + Value: 10000, + Unit: 'ms', + }, + PerRequest: { + Value: 11000, + Unit: 'ms', + }, + }, }, }, RouteName: 'test-http-route', @@ -124,6 +134,16 @@ export = { Match: { Prefix: '/', }, + Timeout: { + Idle: { + Value: 10000, + Unit: 'ms', + }, + PerRequest: { + Value: 11000, + Unit: 'ms', + }, + }, }, }, RouteName: 'test-http2-route', @@ -145,6 +165,12 @@ export = { }, ], }, + Timeout: { + Idle: { + Value: 10000, + Unit: 'ms', + }, + }, }, }, RouteName: 'test-tcp-route', @@ -169,6 +195,16 @@ export = { Match: { ServiceName: 'test.svc.local', }, + Timeout: { + Idle: { + Value: 10000, + Unit: 'ms', + }, + PerRequest: { + Value: 11000, + Unit: 'ms', + }, + }, }, }, RouteName: 'test-grpc-route', From 7f13ceba4eb0a2018ede91e536cc65b9764f634b Mon Sep 17 00:00:00 2001 From: Shan Kiyani Date: Wed, 9 Dec 2020 18:21:55 -0600 Subject: [PATCH 06/12] update readme for timeouts --- packages/@aws-cdk/aws-appmesh/README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/@aws-cdk/aws-appmesh/README.md b/packages/@aws-cdk/aws-appmesh/README.md index 0b736380de817..1484db17200a8 100644 --- a/packages/@aws-cdk/aws-appmesh/README.md +++ b/packages/@aws-cdk/aws-appmesh/README.md @@ -288,7 +288,7 @@ The _RouteSpec_ class provides an easy interface for defining new protocol speci The `tcp()`, `http()` and `http2()` methods provide the spec necessary to define a protocol specific spec. For HTTP based routes, the match field can be used to match on a route prefix. -By default, an HTTP based route will match on `/`. All matches must start with a leading `/`. +By default, an HTTP based route will match on `/`. All matches must start with a leading `/`. The timeout field can also be specified for `idle` and `perRequest` timeouts. ```ts router.addRoute('route-http', { @@ -301,6 +301,10 @@ router.addRoute('route-http', { match: { serviceName: 'my-service.default.svc.cluster.local', }, + timeout: { + idle : Duration.seconds(2), + perRequest: Duration.seconds(1), + }, }), }); ``` From 0c54d9009edcc1e63e9535028ac61ab3ff98291f Mon Sep 17 00:00:00 2001 From: Shan Kiyani Date: Thu, 10 Dec 2020 12:21:34 -0600 Subject: [PATCH 07/12] assert more in tests, remove redundant helper method --- .../@aws-cdk/aws-appmesh/lib/route-spec.ts | 58 ++++++------------- .../@aws-cdk/aws-appmesh/test/test.route.ts | 12 +++- .../aws-appmesh/test/test.virtual-router.ts | 6 ++ 3 files changed, 36 insertions(+), 40 deletions(-) diff --git a/packages/@aws-cdk/aws-appmesh/lib/route-spec.ts b/packages/@aws-cdk/aws-appmesh/lib/route-spec.ts index a01345b619638..e575cf47c727e 100644 --- a/packages/@aws-cdk/aws-appmesh/lib/route-spec.ts +++ b/packages/@aws-cdk/aws-appmesh/lib/route-spec.ts @@ -187,7 +187,6 @@ class HttpRouteSpec extends RouteSpec { /** * The criteria for determining a request match - * */ public readonly match?: HttpRouteMatch; @@ -221,26 +220,13 @@ class HttpRouteSpec extends RouteSpec { match: { prefix: prefixPath, }, - timeout: this.timeout ? this.renderTimeout(this.timeout): undefined, + timeout: this.timeout ? renderTimeout(this.timeout): undefined, }; return { httpRouteSpec: this.protocol === Protocol.HTTP ? httpConfig : undefined, http2RouteSpec: this.protocol === Protocol.HTTP2 ? httpConfig : undefined, }; } - - private renderTimeout(timeout: HttpTimeout): CfnRoute.HttpTimeoutProperty { - return { - idle: timeout?.idle !== undefined ? { - unit: 'ms', - value: timeout?.idle.toMilliseconds(), - } : undefined, - perRequest: timeout?.perRequest !== undefined ? { - unit: 'ms', - value: timeout?.perRequest.toMilliseconds(), - } : undefined, - }; - } } class TcpRouteSpec extends RouteSpec { @@ -266,19 +252,10 @@ class TcpRouteSpec extends RouteSpec { action: { weightedTargets: renderWeightedTargets(this.weightedTargets), }, - timeout: this.timeout ? this.renderTimeout(this.timeout): undefined, + timeout: this.timeout ? renderTimeout(this.timeout): undefined, }, }; } - - private renderTimeout(timeout: TcpTimeout): CfnRoute.TcpTimeoutProperty { - return ({ - idle: timeout?.idle !== undefined ? { - unit: 'ms', - value: timeout?.idle.toMilliseconds(), - } : undefined, - }); - } } class GrpcRouteSpec extends RouteSpec { @@ -302,23 +279,10 @@ class GrpcRouteSpec extends RouteSpec { match: { serviceName: this.match.serviceName, }, - timeout: this.timeout ? this.renderTimeout(this.timeout): undefined, + timeout: this.timeout ? renderTimeout(this.timeout): undefined, }, }; } - - private renderTimeout(timeout: GrpcTimeout): CfnRoute.GrpcTimeoutProperty { - return ({ - idle: timeout?.idle !== undefined ? { - unit: 'ms', - value: timeout?.idle.toMilliseconds(), - } : undefined, - perRequest: timeout?.perRequest !== undefined ? { - unit: 'ms', - value: timeout?.perRequest.toMilliseconds(), - } : undefined, - }); - } } /** @@ -334,3 +298,19 @@ function renderWeightedTargets(weightedTargets: WeightedTarget[]): CfnRoute.Weig } return renderedTargets; } + +/** + * Utility method to construct a route timeout object + */ +function renderTimeout(timeout: HttpTimeout): CfnRoute.HttpTimeoutProperty { + return { + idle: timeout?.idle !== undefined ? { + unit: 'ms', + value: timeout?.idle.toMilliseconds(), + } : undefined, + perRequest: timeout?.perRequest !== undefined ? { + unit: 'ms', + value: timeout?.perRequest.toMilliseconds(), + } : undefined, + }; +} diff --git a/packages/@aws-cdk/aws-appmesh/test/test.route.ts b/packages/@aws-cdk/aws-appmesh/test/test.route.ts index 01164ae89402f..cea5eed33e5a1 100644 --- a/packages/@aws-cdk/aws-appmesh/test/test.route.ts +++ b/packages/@aws-cdk/aws-appmesh/test/test.route.ts @@ -241,7 +241,7 @@ export = { }, timeout: { idle: cdk.Duration.seconds(10), - perRequest: cdk.Duration.seconds(10), + perRequest: cdk.Duration.seconds(11), }, }), }); @@ -266,6 +266,16 @@ export = { Match: { Prefix: '/node', }, + Timeout: { + Idle: { + Value: 10000, + Unit: 'ms', + }, + PerRequest: { + Value: 11000, + Unit: 'ms', + }, + }, }, }, RouteName: 'test-http-route', diff --git a/packages/@aws-cdk/aws-appmesh/test/test.virtual-router.ts b/packages/@aws-cdk/aws-appmesh/test/test.virtual-router.ts index 24f16e0b4a059..d707db57792c9 100644 --- a/packages/@aws-cdk/aws-appmesh/test/test.virtual-router.ts +++ b/packages/@aws-cdk/aws-appmesh/test/test.virtual-router.ts @@ -391,6 +391,12 @@ export = { }, ], }, + Timeout: { + Idle: { + Value: 10000, + Unit: 'ms', + }, + }, }, }, VirtualRouterName: { From 2f88b124fb36867e254ae8f17040843c3effb2e7 Mon Sep 17 00:00:00 2001 From: Shan Kiyani Date: Thu, 10 Dec 2020 12:56:45 -0600 Subject: [PATCH 08/12] remove conflict issues --- .../@aws-cdk/aws-appmesh/lib/route-spec.ts | 43 ------------------- 1 file changed, 43 deletions(-) diff --git a/packages/@aws-cdk/aws-appmesh/lib/route-spec.ts b/packages/@aws-cdk/aws-appmesh/lib/route-spec.ts index e422b620eeadc..9b223da6c946f 100644 --- a/packages/@aws-cdk/aws-appmesh/lib/route-spec.ts +++ b/packages/@aws-cdk/aws-appmesh/lib/route-spec.ts @@ -228,19 +228,6 @@ class HttpRouteSpec extends RouteSpec { http2RouteSpec: this.protocol === Protocol.HTTP2 ? httpConfig : undefined, }; } - - private renderTimeout(timeout: HttpTimeout): CfnRoute.HttpTimeoutProperty { - return { - idle: timeout?.idle !== undefined ? { - unit: 'ms', - value: timeout?.idle.toMilliseconds(), - } : undefined, - perRequest: timeout?.perRequest !== undefined ? { - unit: 'ms', - value: timeout?.perRequest.toMilliseconds(), - } : undefined, - }; - } } class TcpRouteSpec extends RouteSpec { @@ -266,23 +253,10 @@ class TcpRouteSpec extends RouteSpec { action: { weightedTargets: renderWeightedTargets(this.weightedTargets), }, -<<<<<<< HEAD timeout: this.timeout ? renderTimeout(this.timeout): undefined, -======= - timeout: this.timeout ? this.renderTimeout(this.timeout): undefined, ->>>>>>> 65ca4ed162f7e5ad3c7eb7811761edbd11d7b870 }, }; } - - private renderTimeout(timeout: TcpTimeout): CfnRoute.TcpTimeoutProperty { - return ({ - idle: timeout?.idle !== undefined ? { - unit: 'ms', - value: timeout?.idle.toMilliseconds(), - } : undefined, - }); - } } class GrpcRouteSpec extends RouteSpec { @@ -306,27 +280,10 @@ class GrpcRouteSpec extends RouteSpec { match: { serviceName: this.match.serviceName, }, -<<<<<<< HEAD timeout: this.timeout ? renderTimeout(this.timeout): undefined, -======= - timeout: this.timeout ? this.renderTimeout(this.timeout): undefined, ->>>>>>> 65ca4ed162f7e5ad3c7eb7811761edbd11d7b870 }, }; } - - private renderTimeout(timeout: GrpcTimeout): CfnRoute.GrpcTimeoutProperty { - return ({ - idle: timeout?.idle !== undefined ? { - unit: 'ms', - value: timeout?.idle.toMilliseconds(), - } : undefined, - perRequest: timeout?.perRequest !== undefined ? { - unit: 'ms', - value: timeout?.perRequest.toMilliseconds(), - } : undefined, - }); - } } /** From ceab66d1d2ae8ee5db03cf79efad80293c611983 Mon Sep 17 00:00:00 2001 From: Shan Kiyani Date: Fri, 11 Dec 2020 17:49:35 -0600 Subject: [PATCH 09/12] remove timeout from VR tests, change timeout values in route tests --- .../@aws-cdk/aws-appmesh/lib/route-spec.ts | 21 +++++++++++-------- .../@aws-cdk/aws-appmesh/test/test.route.ts | 20 +++++++++--------- .../aws-appmesh/test/test.virtual-router.ts | 16 -------------- 3 files changed, 22 insertions(+), 35 deletions(-) diff --git a/packages/@aws-cdk/aws-appmesh/lib/route-spec.ts b/packages/@aws-cdk/aws-appmesh/lib/route-spec.ts index 9b223da6c946f..32bdf694e626a 100644 --- a/packages/@aws-cdk/aws-appmesh/lib/route-spec.ts +++ b/packages/@aws-cdk/aws-appmesh/lib/route-spec.ts @@ -187,7 +187,6 @@ class HttpRouteSpec extends RouteSpec { /** * The criteria for determining a request match - * */ public readonly match?: HttpRouteMatch; @@ -305,13 +304,17 @@ function renderWeightedTargets(weightedTargets: WeightedTarget[]): CfnRoute.Weig */ function renderTimeout(timeout: HttpTimeout): CfnRoute.HttpTimeoutProperty { return { - idle: timeout?.idle !== undefined ? { - unit: 'ms', - value: timeout?.idle.toMilliseconds(), - } : undefined, - perRequest: timeout?.perRequest !== undefined ? { - unit: 'ms', - value: timeout?.perRequest.toMilliseconds(), - } : undefined, + idle: timeout?.idle !== undefined + ? { + unit: 'ms', + value: timeout?.idle.toMilliseconds(), + } + : undefined, + perRequest: timeout?.perRequest !== undefined + ? { + unit: 'ms', + value: timeout?.perRequest.toMilliseconds(), + } + : undefined, }; } diff --git a/packages/@aws-cdk/aws-appmesh/test/test.route.ts b/packages/@aws-cdk/aws-appmesh/test/test.route.ts index cea5eed33e5a1..cb5c92e6464cf 100644 --- a/packages/@aws-cdk/aws-appmesh/test/test.route.ts +++ b/packages/@aws-cdk/aws-appmesh/test/test.route.ts @@ -44,8 +44,8 @@ export = { }, ], timeout: { - idle: cdk.Duration.seconds(10), - perRequest: cdk.Duration.seconds(11), + idle: cdk.Duration.seconds(12), + perRequest: cdk.Duration.seconds(13), }, }), }); @@ -58,7 +58,7 @@ export = { }, ], timeout: { - idle: cdk.Duration.seconds(10), + idle: cdk.Duration.seconds(14), }, }), }); @@ -74,8 +74,8 @@ export = { serviceName: 'test.svc.local', }, timeout: { - idle: cdk.Duration.seconds(10), - perRequest: cdk.Duration.seconds(11), + idle: cdk.Duration.seconds(15), + perRequest: cdk.Duration.seconds(16), }, }), }); @@ -136,11 +136,11 @@ export = { }, Timeout: { Idle: { - Value: 10000, + Value: 12000, Unit: 'ms', }, PerRequest: { - Value: 11000, + Value: 13000, Unit: 'ms', }, }, @@ -167,7 +167,7 @@ export = { }, Timeout: { Idle: { - Value: 10000, + Value: 14000, Unit: 'ms', }, }, @@ -197,11 +197,11 @@ export = { }, Timeout: { Idle: { - Value: 10000, + Value: 15000, Unit: 'ms', }, PerRequest: { - Value: 11000, + Value: 16000, Unit: 'ms', }, }, diff --git a/packages/@aws-cdk/aws-appmesh/test/test.virtual-router.ts b/packages/@aws-cdk/aws-appmesh/test/test.virtual-router.ts index d707db57792c9..b40f66457b668 100644 --- a/packages/@aws-cdk/aws-appmesh/test/test.virtual-router.ts +++ b/packages/@aws-cdk/aws-appmesh/test/test.virtual-router.ts @@ -123,10 +123,6 @@ export = { match: { prefixPath: '/', }, - timeout: { - idle: cdk.Duration.seconds(8), - perRequest: cdk.Duration.seconds(8), - }, }), }); @@ -220,10 +216,6 @@ export = { match: { prefixPath: '/', }, - timeout: { - idle: cdk.Duration.seconds(9), - perRequest: cdk.Duration.seconds(9), - }, }), }); @@ -238,10 +230,6 @@ export = { match: { prefixPath: '/path2', }, - timeout: { - idle: cdk.Duration.seconds(10), - perRequest: cdk.Duration.seconds(10), - }, }), }); @@ -256,10 +244,6 @@ export = { match: { prefixPath: '/path3', }, - timeout: { - idle: cdk.Duration.seconds(11), - perRequest: cdk.Duration.seconds(11), - }, }), }); From b3d657b592dda32ea5c0a6b62b374e54c463b07b Mon Sep 17 00:00:00 2001 From: Shan Kiyani Date: Fri, 11 Dec 2020 17:55:44 -0600 Subject: [PATCH 10/12] remove another timeout assertion on VR --- .../@aws-cdk/aws-appmesh/test/test.virtual-router.ts | 9 --------- 1 file changed, 9 deletions(-) diff --git a/packages/@aws-cdk/aws-appmesh/test/test.virtual-router.ts b/packages/@aws-cdk/aws-appmesh/test/test.virtual-router.ts index b40f66457b668..aafe3dff8ce7f 100644 --- a/packages/@aws-cdk/aws-appmesh/test/test.virtual-router.ts +++ b/packages/@aws-cdk/aws-appmesh/test/test.virtual-router.ts @@ -353,9 +353,6 @@ export = { weight: 50, }, ], - timeout: { - idle: cdk.Duration.seconds(10), - }, }), }); @@ -375,12 +372,6 @@ export = { }, ], }, - Timeout: { - Idle: { - Value: 10000, - Unit: 'ms', - }, - }, }, }, VirtualRouterName: { From 647837556cd23c9a2e61e6cb282526030c4b0f1c Mon Sep 17 00:00:00 2001 From: Shan Kiyani Date: Mon, 14 Dec 2020 16:49:19 -0600 Subject: [PATCH 11/12] fix helper method routeTimeout, fix trailing whitespace --- .../@aws-cdk/aws-appmesh/lib/route-spec.ts | 38 ++++++++++--------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/packages/@aws-cdk/aws-appmesh/lib/route-spec.ts b/packages/@aws-cdk/aws-appmesh/lib/route-spec.ts index 32bdf694e626a..b3ce09f0c0031 100644 --- a/packages/@aws-cdk/aws-appmesh/lib/route-spec.ts +++ b/packages/@aws-cdk/aws-appmesh/lib/route-spec.ts @@ -220,7 +220,7 @@ class HttpRouteSpec extends RouteSpec { match: { prefix: prefixPath, }, - timeout: this.timeout ? renderTimeout(this.timeout): undefined, + timeout: renderTimeout(this.timeout), }; return { httpRouteSpec: this.protocol === Protocol.HTTP ? httpConfig : undefined, @@ -252,7 +252,7 @@ class TcpRouteSpec extends RouteSpec { action: { weightedTargets: renderWeightedTargets(this.weightedTargets), }, - timeout: this.timeout ? renderTimeout(this.timeout): undefined, + timeout: renderTimeout(this.timeout), }, }; } @@ -279,7 +279,7 @@ class GrpcRouteSpec extends RouteSpec { match: { serviceName: this.match.serviceName, }, - timeout: this.timeout ? renderTimeout(this.timeout): undefined, + timeout: renderTimeout(this.timeout), }, }; } @@ -302,19 +302,21 @@ function renderWeightedTargets(weightedTargets: WeightedTarget[]): CfnRoute.Weig /** * Utility method to construct a route timeout object */ -function renderTimeout(timeout: HttpTimeout): CfnRoute.HttpTimeoutProperty { - return { - idle: timeout?.idle !== undefined - ? { - unit: 'ms', - value: timeout?.idle.toMilliseconds(), - } - : undefined, - perRequest: timeout?.perRequest !== undefined - ? { - unit: 'ms', - value: timeout?.perRequest.toMilliseconds(), - } - : undefined, - }; +function renderTimeout(timeout?: HttpTimeout): CfnRoute.HttpTimeoutProperty | undefined { + return timeout + ? { + idle: timeout?.idle !== undefined + ? { + unit: 'ms', + value: timeout?.idle.toMilliseconds(), + } + : undefined, + perRequest: timeout?.perRequest !== undefined + ? { + unit: 'ms', + value: timeout?.perRequest.toMilliseconds(), + } + : undefined, + } + : undefined; } From 19240514730a2f73f93902659af107d347a59884 Mon Sep 17 00:00:00 2001 From: Adam Ruka Date: Mon, 14 Dec 2020 17:12:22 -0800 Subject: [PATCH 12/12] Break on line in the ReadMe on sentence boundaries --- packages/@aws-cdk/aws-appmesh/README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/@aws-cdk/aws-appmesh/README.md b/packages/@aws-cdk/aws-appmesh/README.md index 1484db17200a8..9a4fcddf386cc 100644 --- a/packages/@aws-cdk/aws-appmesh/README.md +++ b/packages/@aws-cdk/aws-appmesh/README.md @@ -288,7 +288,8 @@ The _RouteSpec_ class provides an easy interface for defining new protocol speci The `tcp()`, `http()` and `http2()` methods provide the spec necessary to define a protocol specific spec. For HTTP based routes, the match field can be used to match on a route prefix. -By default, an HTTP based route will match on `/`. All matches must start with a leading `/`. The timeout field can also be specified for `idle` and `perRequest` timeouts. +By default, an HTTP based route will match on `/`. All matches must start with a leading `/`. +The timeout field can also be specified for `idle` and `perRequest` timeouts. ```ts router.addRoute('route-http', {