-
Notifications
You must be signed in to change notification settings - Fork 0
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
feat(appmesh): add timeout support to Routes #3
base: master
Are you sure you want to change the base?
Conversation
This looks fine. Just one observation, I feel we could have designed |
Can you be more specific, it looks to follow the same pattern to me. |
I was suggesting something along these line, so that we are not repeating the export abstract class RouteSpec {
/**
* Creates an HTTP Based RouteSpec
*/
public static http(options: HttpRouteSpecOptions): RouteSpec {
return new RouteSpecImpl(Protocol.HTTP, options.match, undefined, options.timeout, options.weightedTargets);
}
/**
* Creates an HTTP2 Based RouteSpec
*
*/
public static http2(options: HttpRouteSpecOptions): RouteSpec {
return new RouteSpecImpl(Protocol.HTTP2, options.match, undefined, options.timeout, options.weightedTargets);
}
/**
* Creates a TCP Based RouteSpec
*/
public static tcp(options: TcpRouteSpecOptions): RouteSpec {
return new RouteSpecImpl(Protocol.TCP, undefined, undefined, options.timeout, options.weightedTargets);
}
/**
* Creates a GRPC Based RouteSpec
*/
public static grpc(options: GrpcRouteSpecOptions): RouteSpec {
return new RouteSpecImpl(Protocol.HTTP, undefined, options.match, options.timeout, options.weightedTargets);
}
/**
* Called when the GatewayRouteSpec type is initialized. Can be used to enforce
* mutual exclusivity with future properties
*/
public abstract bind(scope: cdk.Construct): RouteSpecConfig;
}
class RouteSpecImpl extends RouteSpec {
constructor(private readonly protocol: Protocol,
private readonly httpMatch: HttpRouteMatch,
private readonly grpcMatch: GrpcRouteMatch,
private readonly timeout: HttpTimeout,
public readonly weightedTargets: WeightedTarget[]) {
super();
}
public bind(_scope: cdk.Construct): RouteSpecConfig {
const prefixPath = this.httpMatch ? this.httpMatch.prefixPath : '/';
if (prefixPath[0] != '/') {
throw new Error(`Prefix Path must start with \'/\', got: ${prefixPath}`);
}
const httpConfig: CfnRoute.HttpRouteProperty = {
action: {
weightedTargets: renderWeightedTargets(this.weightedTargets),
},
match: {
prefix: prefixPath,
},
timeout: this.timeout ? this.renderTimeout(this.timeout): undefined,
};
const tcpConfig: CfnRoute.TcpRouteProperty = {
action: {
weightedTargets: renderWeightedTargets(this.weightedTargets),
},
timeout: this.timeout ? this.renderTimeout(this.timeout): undefined,
};
const grpcConfig: CfnRoute.GrpcRouteProperty = {
action: {
weightedTargets: renderWeightedTargets(this.weightedTargets),
},
match: {
serviceName: this.grpcMatch.serviceName,
},
timeout: this.timeout ? this.renderTimeout(this.timeout): undefined,
};
return {
httpRouteSpec: this.protocol === Protocol.HTTP ? httpConfig : undefined,
http2RouteSpec: this.protocol === Protocol.HTTP2 ? httpConfig : undefined,
tcpRouteSpec: this.protocol === Protocol.TCP ? tcpConfig : undefined,
grpcRouteSpec: this.protocol === Protocol.GRPC ? grpcConfig: 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,
});
}
} |
I like this suggestion, but let's make it a separate PR. No need to do a refactor in a feature commit |
@sshver feel free to pick it up or create an issue for it |
Add support to http/http2/grpc/tpc route timeouts.
Reference links for HttpTimeout, GrpcTimeout, and TcpTimeout. (Http2 uses the HttpTimeout object).
closes aws#11643
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license