@digitraffic/common 2023.9.14-1 → 2023.10.18-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.
Files changed (33) hide show
  1. package/README.md +7 -0
  2. package/dist/aws/infra/api/integration.d.ts +6 -6
  3. package/dist/aws/infra/canaries/canary-alarm.d.ts +1 -1
  4. package/dist/aws/infra/canaries/canary-parameters.d.ts +1 -1
  5. package/dist/aws/infra/canaries/canary.d.ts +1 -1
  6. package/dist/aws/infra/canaries/canary.js +6 -6
  7. package/dist/aws/infra/canaries/database-checker.js +5 -1
  8. package/dist/aws/infra/canaries/url-checker.js +7 -2
  9. package/dist/aws/infra/sqs-queue.js +1 -1
  10. package/dist/aws/infra/stack/stack-checking-aspect.js +1 -1
  11. package/dist/aws/runtime/dt-logger-default.d.ts +4 -0
  12. package/dist/aws/runtime/dt-logger.d.ts +2 -1
  13. package/dist/aws/runtime/secrets/secret-holder.js +5 -1
  14. package/dist/database/database.js +3 -1
  15. package/dist/utils/geometry.js +5 -1
  16. package/dist/utils/retry.js +2 -0
  17. package/dist/utils/slack.js +7 -2
  18. package/package.json +18 -20
  19. package/src/aws/infra/api/integration.ts +6 -6
  20. package/src/aws/infra/canaries/canary-alarm.ts +1 -1
  21. package/src/aws/infra/canaries/canary-parameters.ts +1 -1
  22. package/src/aws/infra/canaries/canary.ts +1 -1
  23. package/src/aws/infra/canaries/database-checker.ts +5 -1
  24. package/src/aws/infra/canaries/url-checker.ts +7 -2
  25. package/src/aws/infra/sqs-queue.ts +1 -1
  26. package/src/aws/infra/stack/stack-checking-aspect.ts +1 -1
  27. package/src/aws/runtime/dt-logger-default.ts +5 -0
  28. package/src/aws/runtime/dt-logger.ts +2 -1
  29. package/src/aws/runtime/secrets/secret-holder.ts +5 -1
  30. package/src/database/database.ts +4 -1
  31. package/src/utils/geometry.ts +6 -1
  32. package/src/utils/retry.ts +2 -0
  33. package/src/utils/slack.ts +9 -5
package/README.md CHANGED
@@ -2,6 +2,13 @@
2
2
 
3
3
  This is a place for common utilities and classes that can be used in other cdk-projects.
4
4
 
5
+ ## How to build
6
+
7
+ Use `npm` to build the code i.e.
8
+
9
+ npm run build
10
+ npm run test
11
+
5
12
  ## How to use
6
13
 
7
14
  In package.json dependencies:
@@ -6,28 +6,28 @@ interface ApiParameter {
6
6
  type: ParameterType;
7
7
  name: string;
8
8
  }
9
- export declare class DigitrafficIntegration {
9
+ export declare class DigitrafficIntegration<T extends string> {
10
10
  readonly lambda: IFunction;
11
11
  readonly mediaType: MediaType;
12
12
  readonly parameters: ApiParameter[];
13
13
  readonly sunset?: string;
14
14
  constructor(lambda: IFunction, mediaType?: MediaType, sunset?: string);
15
- addPathParameter(...names: string[]): this;
16
- addQueryParameter(...names: string[]): this;
17
- addMultiValueQueryParameter(...names: string[]): this;
15
+ addPathParameter(...names: T[]): this;
16
+ addQueryParameter(...names: T[]): this;
17
+ addMultiValueQueryParameter(...names: T[]): this;
18
18
  /**
19
19
  * Note that context parameter values needs to be in json format as they will be parsed in template as json.
20
20
  * See createRequestTemplates below.
21
21
  * @param names for the parameters
22
22
  * @returns
23
23
  */
24
- addContextParameter(...names: string[]): this;
24
+ addContextParameter(...names: T[]): this;
25
25
  /**
26
26
  * Do not use Authorization header as that will be consumed by ApiGW.
27
27
  * If Authorization header is needed, use lambda authorizers.
28
28
  * @param names for the headers
29
29
  */
30
- addHeaderParameter(...names: string[]): this;
30
+ addHeaderParameter(...names: T[]): this;
31
31
  build(): LambdaIntegration;
32
32
  createRequestParameters(): Record<string, string>;
33
33
  createRequestTemplates(): Record<string, string>;
@@ -1,6 +1,6 @@
1
1
  import { Construct } from "constructs";
2
2
  import { CanaryParameters } from "./canary-parameters";
3
- import { Canary } from "@aws-cdk/aws-synthetics-alpha";
3
+ import { Canary } from "aws-cdk-lib/aws-synthetics";
4
4
  export declare class CanaryAlarm {
5
5
  constructor(stack: Construct, canary: Canary, params: CanaryParameters);
6
6
  }
@@ -1,4 +1,4 @@
1
- import { Schedule } from "@aws-cdk/aws-synthetics-alpha";
1
+ import { Schedule } from "aws-cdk-lib/aws-synthetics";
2
2
  /** Optional env parameters for canary */
3
3
  type CanaryEnv = Record<string, string>;
4
4
  export interface CanaryParameters {
@@ -1,4 +1,4 @@
1
- import { Canary } from "@aws-cdk/aws-synthetics-alpha";
1
+ import { Canary } from "aws-cdk-lib/aws-synthetics";
2
2
  import { Role } from "aws-cdk-lib/aws-iam";
3
3
  import { CanaryParameters } from "./canary-parameters";
4
4
  import { Construct } from "constructs";
@@ -2,15 +2,15 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DigitrafficCanary = void 0;
4
4
  const aws_cdk_lib_1 = require("aws-cdk-lib");
5
- const aws_synthetics_alpha_1 = require("@aws-cdk/aws-synthetics-alpha");
5
+ const aws_synthetics_1 = require("aws-cdk-lib/aws-synthetics");
6
6
  const canary_alarm_1 = require("./canary-alarm");
7
- class DigitrafficCanary extends aws_synthetics_alpha_1.Canary {
7
+ class DigitrafficCanary extends aws_synthetics_1.Canary {
8
8
  constructor(scope, canaryName, role, params, environmentVariables) {
9
9
  super(scope, canaryName, {
10
- runtime: aws_synthetics_alpha_1.Runtime.SYNTHETICS_NODEJS_PUPPETEER_4_0,
10
+ runtime: aws_synthetics_1.Runtime.SYNTHETICS_NODEJS_PUPPETEER_4_0,
11
11
  role,
12
- test: aws_synthetics_alpha_1.Test.custom({
13
- code: new aws_synthetics_alpha_1.AssetCode("dist", {
12
+ test: aws_synthetics_1.Test.custom({
13
+ code: new aws_synthetics_1.AssetCode("dist", {
14
14
  exclude: ["lambda", "out", "canaries"],
15
15
  }),
16
16
  handler: params.handler,
@@ -20,7 +20,7 @@ class DigitrafficCanary extends aws_synthetics_alpha_1.Canary {
20
20
  ...params.canaryEnv,
21
21
  },
22
22
  canaryName,
23
- schedule: params.schedule ?? aws_synthetics_alpha_1.Schedule.rate(aws_cdk_lib_1.Duration.minutes(15)),
23
+ schedule: params.schedule ?? aws_synthetics_1.Schedule.rate(aws_cdk_lib_1.Duration.minutes(15)),
24
24
  });
25
25
  this.artifactsBucket.grantWrite(role);
26
26
  new canary_alarm_1.CanaryAlarm(scope, this, params);
@@ -5,6 +5,7 @@ const database_1 = require("../../../database/database");
5
5
  const proxy_holder_1 = require("../../runtime/secrets/proxy-holder");
6
6
  const rds_holder_1 = require("../../runtime/secrets/rds-holder");
7
7
  const utils_1 = require("../../../utils/utils");
8
+ const dt_logger_default_1 = require("../../runtime/dt-logger-default");
8
9
  // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-var-requires
9
10
  const synthetics = require("Synthetics");
10
11
  class DatabaseCheck {
@@ -97,7 +98,10 @@ class DatabaseCountChecker {
97
98
  await this.credentialsFunction();
98
99
  await (0, database_1.inDatabaseReadonly)(async (db) => {
99
100
  for (const check of this.checks) {
100
- console.info("canary checking sql " + check.sql);
101
+ dt_logger_default_1.logger.info({
102
+ method: "DatabaseCountChecker.expect",
103
+ message: "Running sql: " + check.sql,
104
+ });
101
105
  const value = await db.one(check.sql);
102
106
  const checkFunction = () => {
103
107
  check.check(value);
@@ -10,6 +10,8 @@ const apikey_1 = require("../../runtime/apikey");
10
10
  const geometry_1 = require("../../../utils/geometry");
11
11
  const utils_1 = require("../../../utils/utils");
12
12
  const canary_keys_1 = require("./canary-keys");
13
+ const dt_logger_default_1 = require("../../runtime/dt-logger-default");
14
+ const logging_1 = require("../../../utils/logging");
13
15
  exports.API_KEY_HEADER = "x-api-key";
14
16
  const baseHeaders = {
15
17
  "Digitraffic-User": "internal-digitraffic-canary",
@@ -88,7 +90,10 @@ class UrlChecker {
88
90
  // eslint-disable-next-line @typescript-eslint/prefer-optional-chain
89
91
  !this.requestOptions.headers ||
90
92
  !this.requestOptions.headers[exports.API_KEY_HEADER]) {
91
- console.error("No api key defined");
93
+ dt_logger_default_1.logger.error({
94
+ method: "UrlChecker.expect403WithoutApiKey",
95
+ message: "No Api-key defined",
96
+ });
92
97
  }
93
98
  const requestOptions = {
94
99
  ...this.requestOptions,
@@ -112,7 +117,7 @@ async function getResponseBody(response) {
112
117
  return zlib.gunzipSync(body).toString();
113
118
  }
114
119
  catch (e) {
115
- console.info("error " + JSON.stringify(e));
120
+ (0, logging_1.logException)(dt_logger_default_1.logger, e);
116
121
  }
117
122
  }
118
123
  return body.toString();
@@ -48,7 +48,7 @@ class DigitrafficDLQueue {
48
48
  });
49
49
  const dlqFunctionName = `${dlqName}-Function`;
50
50
  const lambda = monitoredfunction_1.MonitoredFunction.create(stack, dlqFunctionName, {
51
- runtime: aws_lambda_1.Runtime.NODEJS_14_X,
51
+ runtime: aws_lambda_1.Runtime.NODEJS_16_X,
52
52
  logRetention: aws_logs_1.RetentionDays.ONE_YEAR,
53
53
  functionName: dlqFunctionName,
54
54
  code: getDlqCode(dlqBucket.bucketName),
@@ -10,7 +10,7 @@ const change_case_1 = require("change-case");
10
10
  const aws_sqs_1 = require("aws-cdk-lib/aws-sqs");
11
11
  const aws_logs_1 = require("aws-cdk-lib/aws-logs");
12
12
  const MAX_CONCURRENCY_LIMIT = 100;
13
- const NODE_RUNTIMES = [aws_lambda_1.Runtime.NODEJS_14_X.name, aws_lambda_1.Runtime.NODEJS_16_X.name];
13
+ const NODE_RUNTIMES = [aws_lambda_1.Runtime.NODEJS_16_X.name, aws_lambda_1.Runtime.NODEJS_18_X.name];
14
14
  var ResourceType;
15
15
  (function (ResourceType) {
16
16
  ResourceType["stackName"] = "STACK_NAME";
@@ -1,4 +1,8 @@
1
1
  import { DtLogger } from "./dt-logger";
2
+ /**
3
+ * You can use this for method name definition to match DtLogger LoggableType.method parameter.
4
+ */
5
+ export type { LoggerMethodType } from "./dt-logger";
2
6
  /**
3
7
  * You can use this for your logging needs or create one locally and configure it as you wish.
4
8
  */
@@ -2,6 +2,7 @@
2
2
  import { Writable } from "stream";
3
3
  /** Logging level */
4
4
  export type LOG_LEVEL = "DEBUG" | "INFO" | "WARN" | "ERROR";
5
+ export type LoggerMethodType = `${string}.${string}`;
5
6
  /**
6
7
  * Configuration object for configuring the Digitraffic logging utility
7
8
  * @see {@link DtLogger}
@@ -39,7 +40,7 @@ export interface CustomParams {
39
40
  */
40
41
  export interface LoggableType extends CustomParams {
41
42
  /** Name of the method logging the message */
42
- method: `${string}.${string}`;
43
+ method: LoggerMethodType;
43
44
  /** Message to log, optional */
44
45
  message?: string;
45
46
  /** Type of message, optional */
@@ -4,6 +4,7 @@ exports.SecretHolder = void 0;
4
4
  const secret_1 = require("./secret");
5
5
  const dbsecret_1 = require("./dbsecret");
6
6
  const utils_1 = require("../../../utils/utils");
7
+ const dt_logger_default_1 = require("../dt-logger-default");
7
8
  // eslint-disable-next-line @typescript-eslint/no-var-requires, @typescript-eslint/no-unsafe-assignment
8
9
  const NodeTtl = require("node-ttl");
9
10
  const DEFAULT_PREFIX = "";
@@ -33,7 +34,10 @@ class SecretHolder {
33
34
  }
34
35
  async initSecret() {
35
36
  const secretValue = await (0, secret_1.getSecret)(this.secretId);
36
- console.info("refreshing secret " + this.secretId);
37
+ dt_logger_default_1.logger.info({
38
+ method: "SecretHolder.initSecret",
39
+ message: "Refreshing secret " + this.secretId,
40
+ });
37
41
  // eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
38
42
  this.secretCache.push(DEFAULT_SECRET_KEY, secretValue);
39
43
  }
@@ -2,6 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.inDatabaseReadonly = exports.inDatabase = exports.inTransaction = exports.initDbConnection = exports.DatabaseEnvironmentKeys = void 0;
4
4
  const utils_1 = require("../utils/utils");
5
+ const dt_logger_default_1 = require("../aws/runtime/dt-logger-default");
6
+ const logging_1 = require("../utils/logging");
5
7
  var DatabaseEnvironmentKeys;
6
8
  (function (DatabaseEnvironmentKeys) {
7
9
  DatabaseEnvironmentKeys["DB_USER"] = "DB_USER";
@@ -68,7 +70,7 @@ async function doInDatabase(readonly, fn) {
68
70
  return await fn(db);
69
71
  }
70
72
  catch (e) {
71
- console.error("Error in db:", e);
73
+ (0, logging_1.logException)(dt_logger_default_1.logger, e);
72
74
  throw e;
73
75
  }
74
76
  finally {
@@ -25,6 +25,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.positionToList = exports.createGmlLineString = exports.distanceBetweenPositionsInM = exports.areDistinctPositions = exports.distanceBetweenPositionsInKm = exports.isFeatureCollection = exports.isValidGeoJson = exports.createFeatureCollection = exports.createGeometry = exports.SRID_WGS84 = void 0;
27
27
  const geoJsonValidator = __importStar(require("geojson-validation"));
28
+ const dt_logger_default_1 = require("../aws/runtime/dt-logger-default");
28
29
  exports.SRID_WGS84 = 4326;
29
30
  /**
30
31
  * Creates WKT geometry from GeoJSON geometry
@@ -47,7 +48,10 @@ function createGeometry(geometry) {
47
48
  const coordinates = multiPolygon(geometry.coordinates);
48
49
  return `MULTIPOLYGON(${coordinates})`;
49
50
  }
50
- console.error("unsupported locationType=%s", geometry.type);
51
+ dt_logger_default_1.logger.error({
52
+ method: "Geometry.createGeometry",
53
+ message: "Unsupported locationType " + geometry.type,
54
+ });
51
55
  return "POLYGON EMPTY";
52
56
  }
53
57
  exports.createGeometry = createGeometry;
@@ -15,6 +15,7 @@ var RetryLogError;
15
15
  */
16
16
  exports.timeoutFunctions = (function () {
17
17
  return {
18
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
18
19
  noTimeout: (retryCount) => {
19
20
  return 0;
20
21
  },
@@ -40,6 +41,7 @@ exports.retryPredicates = (function () {
40
41
  }
41
42
  return false;
42
43
  },
44
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
43
45
  alwaysRetry: (error) => {
44
46
  return true;
45
47
  },
@@ -5,19 +5,24 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.SlackApi = void 0;
7
7
  const axios_1 = __importDefault(require("axios"));
8
+ const dt_logger_default_1 = require("../aws/runtime/dt-logger-default");
9
+ const logging_1 = require("./logging");
8
10
  class SlackApi {
9
11
  constructor(url) {
10
12
  this.url = url;
11
13
  }
12
14
  async notify(text) {
13
15
  try {
14
- console.info('method=notify Notifying Slack');
16
+ dt_logger_default_1.logger.info({
17
+ method: "SlackApi.notify",
18
+ message: "Sending slack notification",
19
+ });
15
20
  await axios_1.default.post(this.url, {
16
21
  text,
17
22
  });
18
23
  }
19
24
  catch (error) {
20
- console.error('method=notify Slack notify failed!');
25
+ (0, logging_1.logException)(dt_logger_default_1.logger, error);
21
26
  }
22
27
  }
23
28
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@digitraffic/common",
3
- "version": "2023.9.14-1",
3
+ "version": "2023.10.18-1",
4
4
  "description": "",
5
5
  "repository": {
6
6
  "type": "git",
@@ -17,13 +17,12 @@
17
17
  "src/**/*.ts"
18
18
  ],
19
19
  "peerDependencies": {
20
- "@aws-cdk/aws-synthetics-alpha": "^2.85.0-alpha.0",
21
- "@types/geojson": "^7946.0.10",
22
- "aws-cdk-lib": "^2.85.0",
23
- "aws-sdk": "^2.1405.0",
24
- "axios": "^1.2.6",
20
+ "@types/geojson": "^7946.0.11",
21
+ "aws-cdk-lib": "^2.101.1",
22
+ "aws-sdk": "^2.1474.0",
23
+ "axios": "^1.5.1",
25
24
  "change-case": "^4.1.2",
26
- "constructs": "^10.2.17",
25
+ "constructs": "^10.3.0",
27
26
  "date-fns-tz": "~2.0.0",
28
27
  "date-fns": "~2.30.0",
29
28
  "etag": "^1.8.1",
@@ -33,27 +32,26 @@
33
32
  "pg-promise": "^11.5.0"
34
33
  },
35
34
  "devDependencies": {
36
- "@aws-cdk/aws-synthetics-alpha": "2.85.0-alpha.0",
37
35
  "@types/aws-lambda": "~8.10.119",
38
- "@types/geojson": "^7946.0.10",
36
+ "@types/geojson": "^7946.0.11",
39
37
  "@types/etag": "^1.8.1",
40
- "@types/jest": "^29.5.2",
41
- "@types/lodash": "^4.14.195",
42
- "@types/node": "18.15.13",
38
+ "@types/jest": "^29.5.5",
39
+ "@types/lodash": "^4.14.199",
40
+ "@types/node": "20.8.4",
43
41
  "@types/ramda": "~0.29.1",
44
42
  "@types/sinon": "10.0.15",
45
- "@typescript-eslint/eslint-plugin": "~5.60.1",
46
- "@typescript-eslint/parser": "^5.60.1",
47
- "aws-cdk-lib": "~2.85.0",
48
- "aws-sdk": "~2.1405.0",
49
- "axios": "^1.3.6",
43
+ "@typescript-eslint/eslint-plugin": "~6.7.5",
44
+ "@typescript-eslint/parser": "^6.0.0",
45
+ "aws-cdk-lib": "~2.101.1",
46
+ "aws-sdk": "~2.1474.0",
47
+ "axios": "^1.5.1",
50
48
  "change-case": "^4.1.2",
51
- "constructs": "10.2.61",
49
+ "constructs": "10.3.0",
52
50
  "date-fns-tz": "~2.0.0",
53
51
  "date-fns": "~2.30.0",
54
- "eslint": "~8.43.0",
52
+ "eslint": "~8.51.0",
55
53
  "eslint-config-prettier": "^8.8.0",
56
- "eslint-plugin-deprecation": "~1.4.1",
54
+ "eslint-plugin-deprecation": "~2.0.0",
57
55
  "etag": "^1.8.1",
58
56
  "geojson-validation": "^1.0.2",
59
57
  "husky": "^8.0.3",
@@ -19,7 +19,7 @@ interface ApiParameter {
19
19
  name: string;
20
20
  }
21
21
 
22
- export class DigitrafficIntegration {
22
+ export class DigitrafficIntegration<T extends string> {
23
23
  readonly lambda: IFunction;
24
24
  readonly mediaType: MediaType;
25
25
  readonly parameters: ApiParameter[] = [];
@@ -35,20 +35,20 @@ export class DigitrafficIntegration {
35
35
  this.sunset = sunset;
36
36
  }
37
37
 
38
- addPathParameter(...names: string[]): this {
38
+ addPathParameter(...names: T[]): this {
39
39
  names.forEach((name) => this.parameters.push({ type: "path", name }));
40
40
 
41
41
  return this;
42
42
  }
43
43
 
44
- addQueryParameter(...names: string[]): this {
44
+ addQueryParameter(...names: T[]): this {
45
45
  names.forEach((name) =>
46
46
  this.parameters.push({ type: "querystring", name })
47
47
  );
48
48
  return this;
49
49
  }
50
50
 
51
- addMultiValueQueryParameter(...names: string[]): this {
51
+ addMultiValueQueryParameter(...names: T[]): this {
52
52
  names.forEach((name) =>
53
53
  this.parameters.push({ type: "multivaluequerystring", name })
54
54
  );
@@ -61,7 +61,7 @@ export class DigitrafficIntegration {
61
61
  * @param names for the parameters
62
62
  * @returns
63
63
  */
64
- addContextParameter(...names: string[]): this {
64
+ addContextParameter(...names: T[]): this {
65
65
  names.forEach((name) =>
66
66
  this.parameters.push({ type: "context", name })
67
67
  );
@@ -74,7 +74,7 @@ export class DigitrafficIntegration {
74
74
  * If Authorization header is needed, use lambda authorizers.
75
75
  * @param names for the headers
76
76
  */
77
- addHeaderParameter(...names: string[]): this {
77
+ addHeaderParameter(...names: T[]): this {
78
78
  names.forEach((name) => this.parameters.push({ type: "header", name }));
79
79
 
80
80
  return this;
@@ -1,7 +1,7 @@
1
1
  import { Construct } from "constructs";
2
2
  import { CanaryParameters } from "./canary-parameters";
3
3
  import { Alarm, ComparisonOperator } from "aws-cdk-lib/aws-cloudwatch";
4
- import { Canary } from "@aws-cdk/aws-synthetics-alpha";
4
+ import { Canary } from "aws-cdk-lib/aws-synthetics";
5
5
  import { SnsAction } from "aws-cdk-lib/aws-cloudwatch-actions";
6
6
  import { Topic } from "aws-cdk-lib/aws-sns";
7
7
 
@@ -1,4 +1,4 @@
1
- import { Schedule } from "@aws-cdk/aws-synthetics-alpha";
1
+ import { Schedule } from "aws-cdk-lib/aws-synthetics";
2
2
 
3
3
  /** Optional env parameters for canary */
4
4
  type CanaryEnv = Record<string, string>;
@@ -5,7 +5,7 @@ import {
5
5
  Runtime,
6
6
  Schedule,
7
7
  Test,
8
- } from "@aws-cdk/aws-synthetics-alpha";
8
+ } from "aws-cdk-lib/aws-synthetics";
9
9
  import { Role } from "aws-cdk-lib/aws-iam";
10
10
  import { CanaryAlarm } from "./canary-alarm";
11
11
  import { CanaryParameters } from "./canary-parameters";
@@ -3,6 +3,7 @@ import { ProxyHolder } from "../../runtime/secrets/proxy-holder";
3
3
  import { RdsHolder } from "../../runtime/secrets/rds-holder";
4
4
  import { getEnvVariable } from "../../../utils/utils";
5
5
  import { Countable } from "../../../database/models";
6
+ import { logger } from "../../runtime/dt-logger-default";
6
7
 
7
8
  // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-var-requires
8
9
  const synthetics = require("Synthetics");
@@ -141,7 +142,10 @@ export class DatabaseCountChecker {
141
142
  await this.credentialsFunction();
142
143
  await inDatabaseReadonly(async (db: DTDatabase) => {
143
144
  for (const check of this.checks) {
144
- console.info("canary checking sql " + check.sql);
145
+ logger.info({
146
+ method: "DatabaseCountChecker.expect",
147
+ message: "Running sql: " + check.sql,
148
+ });
145
149
 
146
150
  const value = await db.one<Countable>(check.sql);
147
151
  const checkFunction = () => {
@@ -10,6 +10,8 @@ import { FeatureCollection } from "geojson";
10
10
  import { isValidGeoJson } from "../../../utils/geometry";
11
11
  import { getEnvVariable } from "../../../utils/utils";
12
12
  import { ENV_API_KEY, ENV_HOSTNAME } from "./canary-keys";
13
+ import { logger } from "../../runtime/dt-logger-default";
14
+ import { logException } from "../../../utils/logging";
13
15
 
14
16
  export const API_KEY_HEADER = "x-api-key";
15
17
 
@@ -142,7 +144,10 @@ export class UrlChecker {
142
144
  !this.requestOptions.headers ||
143
145
  !this.requestOptions.headers[API_KEY_HEADER]
144
146
  ) {
145
- console.error("No api key defined");
147
+ logger.error({
148
+ method: "UrlChecker.expect403WithoutApiKey",
149
+ message: "No Api-key defined",
150
+ });
146
151
  }
147
152
 
148
153
  const requestOptions = {
@@ -176,7 +181,7 @@ async function getResponseBody(response: IncomingMessage): Promise<string> {
176
181
  try {
177
182
  return zlib.gunzipSync(body).toString();
178
183
  } catch (e) {
179
- console.info("error " + JSON.stringify(e));
184
+ logException(logger, e);
180
185
  }
181
186
  }
182
187
 
@@ -61,7 +61,7 @@ export class DigitrafficDLQueue {
61
61
 
62
62
  const dlqFunctionName = `${dlqName}-Function`;
63
63
  const lambda = MonitoredFunction.create(stack, dlqFunctionName, {
64
- runtime: Runtime.NODEJS_14_X,
64
+ runtime: Runtime.NODEJS_16_X,
65
65
  logRetention: RetentionDays.ONE_YEAR,
66
66
  functionName: dlqFunctionName,
67
67
  code: getDlqCode(dlqBucket.bucketName),
@@ -10,7 +10,7 @@ import { LogRetention } from "aws-cdk-lib/aws-logs";
10
10
  import IntegrationProperty = CfnMethod.IntegrationProperty;
11
11
 
12
12
  const MAX_CONCURRENCY_LIMIT = 100;
13
- const NODE_RUNTIMES = [Runtime.NODEJS_14_X.name, Runtime.NODEJS_16_X.name];
13
+ const NODE_RUNTIMES = [Runtime.NODEJS_16_X.name, Runtime.NODEJS_18_X.name];
14
14
 
15
15
  enum ResourceType {
16
16
  stackName = "STACK_NAME",
@@ -1,5 +1,10 @@
1
1
  import { DtLogger } from "./dt-logger";
2
2
 
3
+ /**
4
+ * You can use this for method name definition to match DtLogger LoggableType.method parameter.
5
+ */
6
+ export type { LoggerMethodType } from "./dt-logger";
7
+
3
8
  /**
4
9
  * You can use this for your logging needs or create one locally and configure it as you wish.
5
10
  */
@@ -3,6 +3,7 @@ import _ from "lodash";
3
3
 
4
4
  /** Logging level */
5
5
  export type LOG_LEVEL = "DEBUG" | "INFO" | "WARN" | "ERROR";
6
+ export type LoggerMethodType = `${string}.${string}`;
6
7
 
7
8
  /**
8
9
  * Configuration object for configuring the Digitraffic logging utility
@@ -55,7 +56,7 @@ export interface CustomParams {
55
56
  */
56
57
  export interface LoggableType extends CustomParams {
57
58
  /** Name of the method logging the message */
58
- method: `${string}.${string}`;
59
+ method: LoggerMethodType;
59
60
  /** Message to log, optional */
60
61
  message?: string;
61
62
  /** Type of message, optional */
@@ -1,6 +1,7 @@
1
1
  import { GenericSecret, getSecret } from "./secret";
2
2
  import { checkExpectedSecretKeys } from "./dbsecret";
3
3
  import { getEnvVariable } from "../../../utils/utils";
4
+ import { logger } from "../dt-logger-default";
4
5
 
5
6
  // eslint-disable-next-line @typescript-eslint/no-var-requires, @typescript-eslint/no-unsafe-assignment
6
7
  const NodeTtl = require("node-ttl");
@@ -47,7 +48,10 @@ export class SecretHolder<Secret extends GenericSecret> {
47
48
  private async initSecret() {
48
49
  const secretValue = await getSecret<Secret>(this.secretId);
49
50
 
50
- console.info("refreshing secret " + this.secretId);
51
+ logger.info({
52
+ method: "SecretHolder.initSecret",
53
+ message: "Refreshing secret " + this.secretId,
54
+ });
51
55
 
52
56
  // eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
53
57
  this.secretCache.push(DEFAULT_SECRET_KEY, secretValue);
@@ -1,5 +1,7 @@
1
1
  import { IDatabase, ITask } from "pg-promise";
2
2
  import { getEnvVariable, getEnvVariableOrElse } from "../utils/utils";
3
+ import { logger } from "../aws/runtime/dt-logger-default";
4
+ import { logException } from "../utils/logging";
3
5
 
4
6
  export enum DatabaseEnvironmentKeys {
5
7
  DB_USER = "DB_USER",
@@ -97,7 +99,8 @@ async function doInDatabase<T>(
97
99
  await db.none("DISCARD ALL");
98
100
  return await fn(db);
99
101
  } catch (e) {
100
- console.error("Error in db:", e);
102
+ logException(logger, e);
103
+
101
104
  throw e;
102
105
  } finally {
103
106
  await db.$pool.end();
@@ -3,6 +3,7 @@
3
3
  */
4
4
  import { Feature, FeatureCollection, Geometry, Position } from "geojson";
5
5
  import * as geoJsonValidator from "geojson-validation";
6
+ import { logger } from "../aws/runtime/dt-logger-default";
6
7
 
7
8
  export const SRID_WGS84 = 4326;
8
9
 
@@ -29,7 +30,11 @@ export function createGeometry(geometry: Geometry): string {
29
30
  return `MULTIPOLYGON(${coordinates})`;
30
31
  }
31
32
 
32
- console.error("unsupported locationType=%s", geometry.type);
33
+ logger.error({
34
+ method: "Geometry.createGeometry",
35
+ message: "Unsupported locationType " + geometry.type,
36
+ });
37
+
33
38
  return "POLYGON EMPTY";
34
39
  }
35
40
 
@@ -16,6 +16,7 @@ export type RetryPredicate = (error: unknown) => boolean;
16
16
  */
17
17
  export const timeoutFunctions = (function () {
18
18
  return {
19
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
19
20
  noTimeout: (retryCount: number): number => {
20
21
  return 0;
21
22
  },
@@ -42,6 +43,7 @@ export const retryPredicates = (function () {
42
43
  }
43
44
  return false;
44
45
  },
46
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
45
47
  alwaysRetry: (error: unknown): boolean => {
46
48
  return true;
47
49
  },
@@ -1,22 +1,26 @@
1
1
  import axios from "axios";
2
+ import { logger } from "../aws/runtime/dt-logger-default";
3
+ import { logException } from "./logging";
2
4
 
3
5
  export class SlackApi {
4
-
5
6
  private readonly url: string;
6
7
 
7
- constructor(url :string) {
8
+ constructor(url: string) {
8
9
  this.url = url;
9
10
  }
10
11
 
11
12
  async notify(text: string) {
12
13
  try {
13
- console.info('method=notify Notifying Slack');
14
+ logger.info({
15
+ method: "SlackApi.notify",
16
+ message: "Sending slack notification",
17
+ });
18
+
14
19
  await axios.post(this.url, {
15
20
  text,
16
21
  });
17
22
  } catch (error) {
18
- console.error('method=notify Slack notify failed!');
23
+ logException(logger, error);
19
24
  }
20
25
  }
21
-
22
26
  }