@digitraffic/common 2022.11.10-1 → 2022.11.11-1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/aws/infra/canaries/database-checker.d.ts +4 -6
- package/dist/aws/infra/canaries/database-checker.js +4 -3
- package/dist/aws/infra/canaries/database-checker.js.map +1 -1
- package/dist/aws/infra/stack/lambda-configs.d.ts +0 -8
- package/dist/aws/infra/stack/lambda-configs.js +7 -7
- package/package.json +1 -1
- package/src/aws/infra/canaries/database-checker.ts +11 -13
- package/src/aws/infra/stack/lambda-configs.ts +7 -16
@@ -1,3 +1,4 @@
|
|
1
|
+
import { Countable } from "../../../database/models";
|
1
2
|
declare abstract class DatabaseCheck<T> {
|
2
3
|
readonly name: string;
|
3
4
|
readonly sql: string;
|
@@ -5,16 +6,13 @@ declare abstract class DatabaseCheck<T> {
|
|
5
6
|
protected constructor(name: string, sql: string);
|
6
7
|
abstract check(value: T): void;
|
7
8
|
}
|
8
|
-
interface CountResponse {
|
9
|
-
count: number;
|
10
|
-
}
|
11
9
|
/**
|
12
10
|
* Checker for sql that checks the count. Meaning that the
|
13
|
-
* sql must be structured as select(*) from table where something.
|
11
|
+
* sql must be structured as "select count(*) from <table> where <something>".
|
14
12
|
*/
|
15
13
|
export declare class DatabaseCountChecker {
|
16
|
-
credentialsFunction: () => Promise<void>;
|
17
|
-
checks: DatabaseCheck<
|
14
|
+
readonly credentialsFunction: () => Promise<void>;
|
15
|
+
readonly checks: DatabaseCheck<Countable>[];
|
18
16
|
private constructor();
|
19
17
|
static createForProxy(): DatabaseCountChecker;
|
20
18
|
static createForRds(): DatabaseCountChecker;
|
@@ -17,7 +17,8 @@ class DatabaseCheck {
|
|
17
17
|
class CountDatabaseCheck extends DatabaseCheck {
|
18
18
|
constructor(name, sql, minCount, maxCount) {
|
19
19
|
super(name, sql);
|
20
|
-
if (!sql.toLowerCase().includes("select
|
20
|
+
if (!sql.toLowerCase().includes("select") ||
|
21
|
+
!sql.toLowerCase().includes("count")) {
|
21
22
|
throw new Error("sql must contain select count(*)");
|
22
23
|
}
|
23
24
|
if (minCount == null && maxCount == null) {
|
@@ -51,12 +52,12 @@ const stepConfig = {
|
|
51
52
|
};
|
52
53
|
/**
|
53
54
|
* Checker for sql that checks the count. Meaning that the
|
54
|
-
* sql must be structured as select(*) from table where something.
|
55
|
+
* sql must be structured as "select count(*) from <table> where <something>".
|
55
56
|
*/
|
56
57
|
class DatabaseCountChecker {
|
57
58
|
constructor(credentialsFunction) {
|
58
|
-
this.credentialsFunction = credentialsFunction;
|
59
59
|
this.checks = [];
|
60
|
+
this.credentialsFunction = credentialsFunction;
|
60
61
|
synthetics.getConfiguration().disableRequestMetrics();
|
61
62
|
synthetics.getConfiguration().withFailedCanaryMetric(true);
|
62
63
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"database-checker.js","sourceRoot":"","sources":["../../../../src/aws/infra/canaries/database-checker.ts"],"names":[],"mappings":";;;AAAA,yDAA4E;AAC5E,qEAAiE;AACjE,iEAA6D;AAC7D,gDAAsD;
|
1
|
+
{"version":3,"file":"database-checker.js","sourceRoot":"","sources":["../../../../src/aws/infra/canaries/database-checker.ts"],"names":[],"mappings":";;;AAAA,yDAA4E;AAC5E,qEAAiE;AACjE,iEAA6D;AAC7D,gDAAsD;AAGtD,8DAA8D;AAC9D,MAAM,UAAU,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;AAEzC,MAAe,aAAa;IAKxB,YAAsB,IAAY,EAAE,GAAW;QAC3C,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;IACxB,CAAC;CAGJ;AAED,MAAM,kBAAmB,SAAQ,aAAwB;IAIrD,YACI,IAAY,EACZ,GAAW,EACX,QAAuB,EACvB,QAAuB;QAEvB,KAAK,CAAC,IAAI,EAAE,GAAG,CAAC,CA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B,CAAC;IAED,KAAK,CAAC,MAAM;QACR,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE;YACrB,MAAM,IAAI,KAAK,CAAC,WAAW,CAAC,CAAC;SAChC;QAED,MAAM,IAAI,CAAC,mBAAmB,EAAE,CAAC;QACjC,MAAM,IAAA,6BAAkB,EAAC,KAAK,EAAE,EAAc,EAAE,EAAE;YAC9C,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,MAAM,EAAE;gBAC7B,OAAO,CAAC,IAAI,CAAC,sBAAsB,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC;gBAEjD,MAAM,KAAK,GAAG,MAAM,EAAE,CAAC,GAAG,CAAY,KAAK,CAAC,GAAG,CAAC,CAAC;gBACjD,MAAM,aAAa,GAAG,GAAG,EAAE;oBACvB,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;gBACvB,CAAC,CAAC;gBAEF,UAAU,CAAC,WAAW,CAAC,KAAK,CAAC,IAAI,EAAE,aAAa,EAAE,UAAU,CAAC,CAAC;aACjE;QACL,CAAC,CAAC,CAAC;QAEH,IAAI,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE;YAC3C,MAAM,IAAI,KAAK,CAAC,QAAQ,CAAC,CAAC;SAC7B;QAED,OAAO,IAAI,CAAC;IAChB,CAAC;CACJ;AA3ED,oDA2EC"}
|
@@ -56,14 +56,6 @@ export interface FunctionParameters {
|
|
56
56
|
singleLambda?: boolean;
|
57
57
|
}
|
58
58
|
export declare type MonitoredFunctionParameters = FunctionParameters & {
|
59
|
-
readonly memorySize?: number;
|
60
|
-
readonly timeout?: number;
|
61
|
-
readonly functionName?: string;
|
62
|
-
readonly reservedConcurrentExecutions?: number;
|
63
|
-
readonly role?: Role;
|
64
|
-
readonly runtime?: Runtime;
|
65
|
-
readonly architecture?: Architecture;
|
66
|
-
readonly singleLambda?: boolean;
|
67
59
|
readonly durationAlarmProps?: MonitoredFunctionAlarmProps;
|
68
60
|
readonly durationWarningProps?: MonitoredFunctionAlarmProps;
|
69
61
|
readonly errorAlarmProps?: MonitoredFunctionAlarmProps;
|
@@ -22,7 +22,7 @@ function databaseFunctionProps(stack, environment, lambdaName, simpleLambdaName,
|
|
22
22
|
exports.databaseFunctionProps = databaseFunctionProps;
|
23
23
|
function lambdaFunctionProps(stack, environment, lambdaName, simpleLambdaName, config) {
|
24
24
|
return {
|
25
|
-
runtime: config?.runtime ?? aws_lambda_1.Runtime.
|
25
|
+
runtime: config?.runtime ?? aws_lambda_1.Runtime.NODEJS_16_X,
|
26
26
|
architecture: config?.architecture ?? aws_lambda_1.Architecture.ARM_64,
|
27
27
|
memorySize: config?.memorySize ?? 128,
|
28
28
|
functionName: lambdaName,
|
@@ -51,14 +51,14 @@ function getAssetCode(simpleLambdaName, isSingleLambda) {
|
|
51
51
|
*/
|
52
52
|
function dbLambdaConfiguration(vpc, lambdaDbSg, props, config) {
|
53
53
|
return {
|
54
|
-
runtime: props.runtime
|
55
|
-
memorySize: props.memorySize
|
54
|
+
runtime: props.runtime ?? aws_lambda_1.Runtime.NODEJS_16_X,
|
55
|
+
memorySize: props.memorySize ?? config.memorySize ?? 1024,
|
56
56
|
functionName: config.functionName,
|
57
57
|
code: config.code,
|
58
58
|
role: config.role,
|
59
59
|
handler: config.handler,
|
60
|
-
timeout: aws_cdk_lib_1.Duration.seconds(config.timeout
|
61
|
-
environment: config.environment
|
60
|
+
timeout: aws_cdk_lib_1.Duration.seconds(config.timeout ?? props.defaultLambdaDurationSeconds ?? 60),
|
61
|
+
environment: config.environment ?? {
|
62
62
|
DB_USER: props.dbProps?.username ?? "",
|
63
63
|
DB_PASS: props.dbProps?.password ?? "",
|
64
64
|
DB_URI: (config.readOnly
|
@@ -71,13 +71,13 @@ function dbLambdaConfiguration(vpc, lambdaDbSg, props, config) {
|
|
71
71
|
subnets: vpc.privateSubnets,
|
72
72
|
},
|
73
73
|
securityGroups: [lambdaDbSg],
|
74
|
-
reservedConcurrentExecutions: config.reservedConcurrentExecutions
|
74
|
+
reservedConcurrentExecutions: config.reservedConcurrentExecutions ?? 3,
|
75
75
|
};
|
76
76
|
}
|
77
77
|
exports.dbLambdaConfiguration = dbLambdaConfiguration;
|
78
78
|
function defaultLambdaConfiguration(config) {
|
79
79
|
const props = {
|
80
|
-
runtime: aws_lambda_1.Runtime.
|
80
|
+
runtime: aws_lambda_1.Runtime.NODEJS_16_X,
|
81
81
|
memorySize: config.memorySize ?? 128,
|
82
82
|
functionName: config.functionName,
|
83
83
|
handler: config.handler,
|
package/package.json
CHANGED
@@ -2,6 +2,7 @@ import { DTDatabase, inDatabaseReadonly } from "../../../database/database";
|
|
2
2
|
import { ProxyHolder } from "../../runtime/secrets/proxy-holder";
|
3
3
|
import { RdsHolder } from "../../runtime/secrets/rds-holder";
|
4
4
|
import { getEnvVariable } from "../../../utils/utils";
|
5
|
+
import { Countable } from "../../../database/models";
|
5
6
|
|
6
7
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
7
8
|
const synthetics = require("Synthetics");
|
@@ -20,11 +21,7 @@ abstract class DatabaseCheck<T> {
|
|
20
21
|
abstract check(value: T): void;
|
21
22
|
}
|
22
23
|
|
23
|
-
|
24
|
-
count: number;
|
25
|
-
}
|
26
|
-
|
27
|
-
class CountDatabaseCheck extends DatabaseCheck<CountResponse> {
|
24
|
+
class CountDatabaseCheck extends DatabaseCheck<Countable> {
|
28
25
|
readonly minCount: number | null;
|
29
26
|
readonly maxCount: number | null;
|
30
27
|
|
@@ -36,7 +33,10 @@ class CountDatabaseCheck extends DatabaseCheck<CountResponse> {
|
|
36
33
|
) {
|
37
34
|
super(name, sql);
|
38
35
|
|
39
|
-
if (
|
36
|
+
if (
|
37
|
+
!sql.toLowerCase().includes("select") ||
|
38
|
+
!sql.toLowerCase().includes("count")
|
39
|
+
) {
|
40
40
|
throw new Error("sql must contain select count(*)");
|
41
41
|
}
|
42
42
|
|
@@ -48,7 +48,7 @@ class CountDatabaseCheck extends DatabaseCheck<CountResponse> {
|
|
48
48
|
this.maxCount = maxCount;
|
49
49
|
}
|
50
50
|
|
51
|
-
check(value:
|
51
|
+
check(value: Countable) {
|
52
52
|
if ("count" in value) {
|
53
53
|
if (this.minCount && value.count < this.minCount) {
|
54
54
|
this.failed = true;
|
@@ -79,18 +79,16 @@ const stepConfig = {
|
|
79
79
|
|
80
80
|
/**
|
81
81
|
* Checker for sql that checks the count. Meaning that the
|
82
|
-
* sql must be structured as select(*) from table where something.
|
82
|
+
* sql must be structured as "select count(*) from <table> where <something>".
|
83
83
|
*/
|
84
84
|
export class DatabaseCountChecker {
|
85
|
-
credentialsFunction: () => Promise<void>;
|
86
|
-
checks: DatabaseCheck<
|
85
|
+
readonly credentialsFunction: () => Promise<void>;
|
86
|
+
readonly checks: DatabaseCheck<Countable>[] = [];
|
87
87
|
|
88
88
|
private constructor(credentialsFunction: () => Promise<void>) {
|
89
89
|
this.credentialsFunction = credentialsFunction;
|
90
|
-
this.checks = [];
|
91
90
|
|
92
91
|
synthetics.getConfiguration().disableRequestMetrics();
|
93
|
-
|
94
92
|
synthetics.getConfiguration().withFailedCanaryMetric(true);
|
95
93
|
}
|
96
94
|
|
@@ -143,7 +141,7 @@ export class DatabaseCountChecker {
|
|
143
141
|
for (const check of this.checks) {
|
144
142
|
console.info("canary checking sql " + check.sql);
|
145
143
|
|
146
|
-
const value = await db.one<
|
144
|
+
const value = await db.one<Countable>(check.sql);
|
147
145
|
const checkFunction = () => {
|
148
146
|
check.check(value);
|
149
147
|
};
|
@@ -76,7 +76,7 @@ export function lambdaFunctionProps(
|
|
76
76
|
config?: Partial<FunctionParameters>
|
77
77
|
): FunctionProps {
|
78
78
|
return {
|
79
|
-
runtime: config?.runtime ?? Runtime.
|
79
|
+
runtime: config?.runtime ?? Runtime.NODEJS_16_X,
|
80
80
|
architecture: config?.architecture ?? Architecture.ARM_64,
|
81
81
|
memorySize: config?.memorySize ?? 128,
|
82
82
|
functionName: lambdaName,
|
@@ -115,16 +115,16 @@ export function dbLambdaConfiguration(
|
|
115
115
|
config: FunctionParameters
|
116
116
|
): FunctionProps {
|
117
117
|
return {
|
118
|
-
runtime: props.runtime
|
119
|
-
memorySize: props.memorySize
|
118
|
+
runtime: props.runtime ?? Runtime.NODEJS_16_X,
|
119
|
+
memorySize: props.memorySize ?? config.memorySize ?? 1024,
|
120
120
|
functionName: config.functionName,
|
121
121
|
code: config.code,
|
122
122
|
role: config.role,
|
123
123
|
handler: config.handler,
|
124
124
|
timeout: Duration.seconds(
|
125
|
-
config.timeout
|
125
|
+
config.timeout ?? props.defaultLambdaDurationSeconds ?? 60
|
126
126
|
),
|
127
|
-
environment: config.environment
|
127
|
+
environment: config.environment ?? {
|
128
128
|
DB_USER: props.dbProps?.username ?? "",
|
129
129
|
DB_PASS: props.dbProps?.password ?? "",
|
130
130
|
DB_URI:
|
@@ -138,7 +138,7 @@ export function dbLambdaConfiguration(
|
|
138
138
|
subnets: vpc.privateSubnets,
|
139
139
|
},
|
140
140
|
securityGroups: [lambdaDbSg],
|
141
|
-
reservedConcurrentExecutions: config.reservedConcurrentExecutions
|
141
|
+
reservedConcurrentExecutions: config.reservedConcurrentExecutions ?? 3,
|
142
142
|
};
|
143
143
|
}
|
144
144
|
|
@@ -146,7 +146,7 @@ export function defaultLambdaConfiguration(
|
|
146
146
|
config: FunctionParameters
|
147
147
|
): FunctionProps {
|
148
148
|
const props: FunctionProps = {
|
149
|
-
runtime: Runtime.
|
149
|
+
runtime: Runtime.NODEJS_16_X,
|
150
150
|
memorySize: config.memorySize ?? 128,
|
151
151
|
functionName: config.functionName,
|
152
152
|
handler: config.handler,
|
@@ -191,15 +191,6 @@ export interface FunctionParameters {
|
|
191
191
|
}
|
192
192
|
|
193
193
|
export type MonitoredFunctionParameters = FunctionParameters & {
|
194
|
-
readonly memorySize?: number;
|
195
|
-
readonly timeout?: number;
|
196
|
-
readonly functionName?: string;
|
197
|
-
readonly reservedConcurrentExecutions?: number;
|
198
|
-
readonly role?: Role;
|
199
|
-
readonly runtime?: Runtime;
|
200
|
-
readonly architecture?: Architecture;
|
201
|
-
readonly singleLambda?: boolean;
|
202
|
-
|
203
194
|
readonly durationAlarmProps?: MonitoredFunctionAlarmProps;
|
204
195
|
readonly durationWarningProps?: MonitoredFunctionAlarmProps;
|
205
196
|
readonly errorAlarmProps?: MonitoredFunctionAlarmProps;
|