/
utils.ts
67 lines (60 loc) · 1.96 KB
/
utils.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import * as cdk from '@aws-cdk/core';
import { CfnVirtualGateway, CfnVirtualNode } from '../appmesh.generated';
type AppMeshHealthCheck = CfnVirtualNode.HealthCheckProperty | CfnVirtualGateway.VirtualGatewayHealthCheckPolicyProperty
/**
* Validates health check properties, throws an error if they are misconfigured.
*
* @param healthCheck Healthcheck property from a Virtual Node or Virtual Gateway
*/
export function validateHealthChecks(healthCheck: AppMeshHealthCheck) {
(Object.keys(healthCheck) as Array<keyof AppMeshHealthCheck>)
.filter((key) =>
HEALTH_CHECK_PROPERTY_THRESHOLDS[key] &&
typeof healthCheck[key] === 'number' &&
!cdk.Token.isUnresolved(healthCheck[key]),
).map((key) => {
const [min, max] = HEALTH_CHECK_PROPERTY_THRESHOLDS[key]!;
const value = healthCheck[key]!;
if (value < min) {
throw new Error(`The value of '${key}' is below the minimum threshold (expected >=${min}, got ${value})`);
}
if (value > max) {
throw new Error(`The value of '${key}' is above the maximum threshold (expected <=${max}, got ${value})`);
}
});
}
/**
* Minimum and maximum thresholds for HeathCheck numeric properties
*
* @see https://docs.aws.amazon.com/app-mesh/latest/APIReference/API_HealthCheckPolicy.html
*/
const HEALTH_CHECK_PROPERTY_THRESHOLDS: {[key in (keyof AppMeshHealthCheck)]?: [number, number]} = {
healthyThreshold: [2, 10],
intervalMillis: [5000, 300000],
port: [1, 65535],
timeoutMillis: [2000, 60000],
unhealthyThreshold: [2, 10],
};
/**
* Generated Connection pool config
*/
export interface ConnectionPoolConfig {
/**
* The maximum connections in the pool
*
* @default - none
*/
readonly maxConnections?: number;
/**
* The maximum pending requests in the pool
*
* @default - none
*/
readonly maxPendingRequests?: number;
/**
* The maximum requests in the pool
*
* @default - none
*/
readonly maxRequests?: number;
}