Skip to content

Commit d600213

Browse files
authored
feat(endpoint): log endpoint decisions at debug level (#4106)
1 parent 6bfdb02 commit d600213

File tree

7 files changed

+44
-0
lines changed

7 files changed

+44
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const debugId = "endpoints";
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from "./debugId";
2+
export * from "./toDebugString";
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { EndpointParameters, EndpointV2 } from "@aws-sdk/types";
2+
3+
import { GetAttrValue } from "../lib";
4+
import { EndpointObject, FunctionObject, FunctionReturn } from "../types";
5+
6+
export function toDebugString(input: EndpointParameters): string;
7+
export function toDebugString(input: EndpointV2): string;
8+
export function toDebugString(input: GetAttrValue): string;
9+
export function toDebugString(input: FunctionObject): string;
10+
export function toDebugString(input: FunctionReturn): string;
11+
export function toDebugString(input: EndpointObject): string;
12+
export function toDebugString(input: any): string {
13+
if (typeof input !== 'object' || input == null) {
14+
return input;
15+
}
16+
17+
if ('ref' in input) {
18+
return `$${toDebugString(input.ref)}`
19+
}
20+
21+
if ('fn' in input) {
22+
return `${input.fn}(${(input.argv || []).map(toDebugString)})`;
23+
}
24+
25+
return JSON.stringify(input, null, 2);
26+
}

packages/util-endpoints/src/resolveEndpoint.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { EndpointV2 } from "@aws-sdk/types";
22

3+
import { debugId, toDebugString } from "./debug";
34
import { EndpointError, EndpointResolverOptions, RuleSetObject } from "./types";
45
import { evaluateRules } from "./utils";
56

@@ -10,6 +11,8 @@ export const resolveEndpoint = (ruleSetObject: RuleSetObject, options: EndpointR
1011
const { endpointParams, logger } = options;
1112
const { parameters, rules } = ruleSetObject;
1213

14+
options.logger?.debug(debugId, `Initial EndpointParams: ${toDebugString(endpointParams)}`);
15+
1316
// @ts-ignore Type 'undefined' is not assignable to type 'string | boolean' (2322)
1417
const paramsWithDefault: [string, string | boolean][] = Object.entries(parameters)
1518
.filter(([, v]) => v.default != null)
@@ -45,5 +48,7 @@ export const resolveEndpoint = (ruleSetObject: RuleSetObject, options: EndpointR
4548
}
4649
}
4750

51+
options.logger?.debug(debugId, `Resolved endpoint: ${toDebugString(endpoint)}`);
52+
4853
return endpoint;
4954
};

packages/util-endpoints/src/utils/evaluateCondition.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { debugId, toDebugString } from "../debug";
12
import { ConditionObject, EndpointError, EvaluateOptions } from "../types";
23
import { callFunction } from "./callFunction";
34

@@ -6,6 +7,9 @@ export const evaluateCondition = ({ assign, ...fnArgs }: ConditionObject, option
67
throw new EndpointError(`'${assign}' is already defined in Reference Record.`);
78
}
89
const value = callFunction(fnArgs, options);
10+
11+
options.logger?.debug(debugId, `evaluateCondition: ${toDebugString(fnArgs)} = ${toDebugString(value)}`);
12+
913
return {
1014
result: value === "" ? true : !!value,
1115
...(assign != null && { toAssign: { name: assign, value } }),

packages/util-endpoints/src/utils/evaluateConditions.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { debugId, toDebugString } from "../debug";
12
import { ConditionObject, EvaluateOptions, FunctionReturn } from "../types";
23
import { evaluateCondition } from "./evaluateCondition";
34

@@ -19,6 +20,7 @@ export const evaluateConditions = (conditions: ConditionObject[] = [], options:
1920

2021
if (toAssign) {
2122
conditionsReferenceRecord[toAssign.name] = toAssign.value;
23+
options.logger?.debug(debugId, `assign: ${toAssign.name} := ${toDebugString(toAssign.value)}`);
2224
}
2325
}
2426

packages/util-endpoints/src/utils/evaluateEndpointRule.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { EndpointV2 } from "@aws-sdk/types";
22

3+
import { debugId, toDebugString } from "../debug";
34
import { EndpointRuleObject, EvaluateOptions } from "../types";
45
import { evaluateConditions } from "./evaluateConditions";
56
import { getEndpointHeaders } from "./getEndpointHeaders";
@@ -23,6 +24,9 @@ export const evaluateEndpointRule = (
2324
};
2425

2526
const { url, properties, headers } = endpoint;
27+
28+
options.logger?.debug(debugId, `Resolving endpoint from template: ${toDebugString(endpoint)}`);
29+
2630
return {
2731
...(headers != undefined && {
2832
headers: getEndpointHeaders(headers, endpointRuleOptions),

0 commit comments

Comments
 (0)