Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit c634a79

Browse filesBrowse files
authored
feat(integ-tests-alpha): add option to set the provider log level (#38005)
### Issue # (if applicable) Closes #<issue number here>. ### Reason for this change Adds a providerLogLevel prop to the integ-tests assertions framework that controls the ApplicationLogLevel of the provider Lambda functions. Defaults to FATAL to suppress verbose logging, with the ability to increase it for debugging. This mirrors the change made to the custom-resources Provider framework. ### Description of changes - Added ProviderOptions interface as a shared contract for provider configuration - Set LoggingConfig.ApplicationLogLevel to FATAL by default on the provider Lambda - All interfaces extend ProviderOptions so future provider-level config only needs one addition point - Updated README with usage example - Added unit tests for default behavior and override Usage ``` import * as lambda from 'aws-cdk-lib/aws-lambda'; const integ = new IntegTest(app, 'MyTest', { testCases: [stack], providerLogLevel: lambda.ApplicationLogLevel.INFO, }); ``` ### Description of how you validated changes Added unit tests, deployed tests with `INFO` log level and `FATAL`. ### Checklist - [X] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent a7cc53c commit c634a79
Copy full SHA for c634a79

10 files changed

+154-18Lines changed: 154 additions & 18 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎packages/@aws-cdk/integ-tests-alpha/README.md‎

Copy file name to clipboardExpand all lines: packages/@aws-cdk/integ-tests-alpha/README.md
+16Lines changed: 16 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,22 @@ const invoke = integ.assertions.invokeFunction({
478478
});
479479
```
480480

481+
#### Provider Log Level
482+
483+
By default, the assertion provider lambda function has its log level set to `FATAL`.
484+
If you need to debug assertion failures, you can increase the log level by setting
485+
`providerLogLevel` on the `IntegTest` construct:
486+
487+
```ts
488+
declare const app: App;
489+
declare const stack: Stack;
490+
491+
const integ = new IntegTest(app, 'IntegTest', {
492+
testCases: [stack],
493+
providerLogLevel: lambda.ApplicationLogLevel.INFO,
494+
});
495+
```
496+
481497
#### Make an AWS API Call
482498

483499
In this example there is a StepFunctions state machine that is executed
Collapse file

‎packages/@aws-cdk/integ-tests-alpha/lib/assertions/assertions.ts‎

Copy file name to clipboardExpand all lines: packages/@aws-cdk/integ-tests-alpha/lib/assertions/assertions.ts
+5-3Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ import { CustomResource, CfnOutput } from 'aws-cdk-lib/core';
22
import { Construct } from 'constructs';
33
import type { ExpectedResult, ActualResult } from './common';
44
import { md5hash } from './private/hash';
5-
import type { AssertionRequest } from './providers';
5+
import type { AssertionRequest, ProviderOptions } from './providers';
66
import { AssertionsProvider, ASSERT_RESOURCE_TYPE } from './providers';
77

88
/**
99
* Options for an EqualsAssertion
1010
*/
11-
export interface EqualsAssertionProps {
11+
export interface EqualsAssertionProps extends ProviderOptions {
1212
/**
1313
* The actual results to compare
1414
*/
@@ -44,7 +44,9 @@ export class EqualsAssertion extends Construct {
4444
constructor(scope: Construct, id: string, props: EqualsAssertionProps) {
4545
super(scope, id);
4646

47-
const assertionProvider = new AssertionsProvider(this, 'AssertionProvider');
47+
const assertionProvider = new AssertionsProvider(this, 'AssertionProvider', {
48+
providerLogLevel: props.providerLogLevel,
49+
});
4850
const properties: AssertionRequest = {
4951
actual: props.actual.result,
5052
expected: props.expected.result,
Collapse file

‎packages/@aws-cdk/integ-tests-alpha/lib/assertions/http-call.ts‎

Copy file name to clipboardExpand all lines: packages/@aws-cdk/integ-tests-alpha/lib/assertions/http-call.ts
+10-3Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,40 @@
11
import { AspectPriority, Aspects, CfnOutput, CustomResource, Lazy, Token } from 'aws-cdk-lib';
2+
import type { ApplicationLogLevel } from 'aws-cdk-lib/aws-lambda';
23
import type { Construct, IConstruct } from 'constructs';
34
import type { IApiCall } from './api-call-base';
45
import { ApiCallBase } from './api-call-base';
56
import type { ExpectedResult } from './common';
6-
import type { HttpRequestParameters } from './providers';
7+
import type { HttpRequestParameters, ProviderOptions } from './providers';
78
import { AssertionsProvider, HTTP_RESOURCE_TYPE } from './providers';
89
import type { WaiterStateMachineOptions } from './waiter-state-machine';
910
import { WaiterStateMachine } from './waiter-state-machine';
1011

1112
/**
1213
* Options for creating an HttpApiCall provider
1314
*/
14-
export interface HttpCallProps extends HttpRequestParameters { }
15+
export interface HttpCallProps extends HttpRequestParameters, ProviderOptions {}
1516
/**
1617
* Construct that creates a custom resource that will perform
1718
* an HTTP API Call
1819
*/
1920
export class HttpApiCall extends ApiCallBase {
2021
protected readonly apiCallResource: CustomResource;
2122
public readonly provider: AssertionsProvider;
23+
private readonly providerLogLevel?: ApplicationLogLevel;
2224

2325
constructor(scope: Construct, id: string, props: HttpCallProps) {
2426
super(scope, id);
2527

28+
this.providerLogLevel = props.providerLogLevel;
29+
2630
let name = '';
2731
if (!Token.isUnresolved(props.url)) {
2832
const url = new URL(props.url);
2933
name = `${url.hostname}${url.pathname}`.replace(/\/|\.|:/g, '');
3034
}
31-
this.provider = new AssertionsProvider(this, 'HttpProvider');
35+
this.provider = new AssertionsProvider(this, 'HttpProvider', {
36+
providerLogLevel: props.providerLogLevel,
37+
});
3238
this.apiCallResource = new CustomResource(this, 'Default', {
3339
serviceToken: this.provider.serviceToken,
3440
properties: {
@@ -64,6 +70,7 @@ export class HttpApiCall extends ApiCallBase {
6470
public waitForAssertions(options?: WaiterStateMachineOptions | undefined): IApiCall {
6571
const waiter = new WaiterStateMachine(this, 'WaitFor', {
6672
...options,
73+
providerLogLevel: this.providerLogLevel,
6774
});
6875
this.stateMachineArn = waiter.stateMachineArn;
6976
this.provider.addPolicyStatementFromSdkCall('states', 'StartExecution');
Collapse file

‎packages/@aws-cdk/integ-tests-alpha/lib/assertions/private/deploy-assert.ts‎

Copy file name to clipboardExpand all lines: packages/@aws-cdk/integ-tests-alpha/lib/assertions/private/deploy-assert.ts
+8-2Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { ApplicationLogLevel } from 'aws-cdk-lib/aws-lambda';
12
import { Stack, Token, UnscopedValidationError } from 'aws-cdk-lib/core';
23
import { lit } from 'aws-cdk-lib/core/lib/helpers-internal';
34
import type { IConstruct } from 'constructs';
@@ -7,7 +8,7 @@ import { EqualsAssertion } from '../assertions';
78
import type { ActualResult, ExpectedResult } from '../common';
89
import { HttpApiCall as HttpApiCall } from '../http-call';
910
import { md5hash } from '../private/hash';
10-
import type { FetchOptions } from '../providers';
11+
import type { FetchOptions, ProviderOptions } from '../providers';
1112
import type { LambdaInvokeFunctionProps } from '../sdk';
1213
import { AwsApiCall, LambdaInvokeFunction } from '../sdk';
1314
import type { IDeployAssert } from '../types';
@@ -17,7 +18,7 @@ const DEPLOY_ASSERT_SYMBOL = Symbol.for('@aws-cdk/integ-tests.DeployAssert');
1718
/**
1819
* Options for DeployAssert
1920
*/
20-
export interface DeployAssertProps {
21+
export interface DeployAssertProps extends ProviderOptions {
2122

2223
/**
2324
* A stack to use for assertions
@@ -53,11 +54,13 @@ export class DeployAssert extends Construct implements IDeployAssert {
5354

5455
public scope: Stack;
5556
private assertionIdCounts = new Map<string, number>();
57+
private readonly _providerLogLevel?: ApplicationLogLevel;
5658

5759
constructor(scope: Construct, props?: DeployAssertProps) {
5860
super(scope, 'Default');
5961

6062
this.scope = props?.stack ?? new Stack(scope, 'DeployAssert');
63+
this._providerLogLevel = props?.providerLogLevel;
6164

6265
Object.defineProperty(this, DEPLOY_ASSERT_SYMBOL, { value: true });
6366
}
@@ -73,6 +76,7 @@ export class DeployAssert extends Construct implements IDeployAssert {
7376
service,
7477
parameters,
7578
outputPaths,
79+
providerLogLevel: this._providerLogLevel,
7680
});
7781
}
7882

@@ -93,6 +97,7 @@ export class DeployAssert extends Construct implements IDeployAssert {
9397
return new HttpApiCall(this.scope, this.uniqueAssertionId(`HttpApiCall${append}${hash}`), {
9498
url,
9599
fetchOptions: options,
100+
providerLogLevel: this._providerLogLevel,
96101
});
97102
}
98103

@@ -105,6 +110,7 @@ export class DeployAssert extends Construct implements IDeployAssert {
105110
new EqualsAssertion(this.scope, `EqualsAssertion${id}`, {
106111
expected,
107112
actual,
113+
providerLogLevel: this._providerLogLevel,
108114
});
109115
}
110116

Collapse file

‎packages/@aws-cdk/integ-tests-alpha/lib/assertions/providers/provider.ts‎

Copy file name to clipboardExpand all lines: packages/@aws-cdk/integ-tests-alpha/lib/assertions/providers/provider.ts
+21-4Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as path from 'path';
2+
import type { ApplicationLogLevel } from 'aws-cdk-lib/aws-lambda';
23
import type { RetentionDays } from 'aws-cdk-lib/aws-logs';
34
import type { Reference } from 'aws-cdk-lib/core';
45
import {
@@ -15,10 +16,22 @@ import { memoizedGetter } from 'aws-cdk-lib/core/lib/helpers-internal';
1516
import { awsSdkToIamAction } from 'aws-cdk-lib/custom-resources/lib/helpers-internal';
1617
import { Construct } from 'constructs';
1718

19+
/**
20+
* Shared options for configuring the assertion provider lambda function.
21+
*/
22+
export interface ProviderOptions {
23+
/**
24+
* The log level of the provider lambda function.
25+
*
26+
* @default ApplicationLogLevel.FATAL
27+
*/
28+
readonly providerLogLevel?: ApplicationLogLevel;
29+
}
30+
1831
/**
1932
* Properties for a lambda function provider
2033
*/
21-
export interface LambdaFunctionProviderProps {
34+
export interface LambdaFunctionProviderProps extends ProviderOptions {
2235
/**
2336
* The handler to use for the lambda function
2437
*
@@ -99,6 +112,10 @@ class LambdaFunctionProvider extends Construct {
99112
Timeout: Duration.minutes(2).toSeconds(),
100113
Handler: props?.handler ?? 'index.handler',
101114
Role: role.getAtt('Arn'),
115+
LoggingConfig: {
116+
LogFormat: 'JSON',
117+
ApplicationLogLevel: props?.providerLogLevel ?? 'FATAL',
118+
},
102119
};
103120

104121
if (props?.logRetention) {
@@ -110,9 +127,7 @@ class LambdaFunctionProvider extends Construct {
110127
},
111128
});
112129

113-
functionProperties.LoggingConfig = {
114-
LogGroup: logGroup.ref,
115-
};
130+
functionProperties.LoggingConfig.LogGroup = logGroup.ref;
116131
}
117132

118133
this.handler = new CfnResource(this, 'Handler', {
@@ -170,6 +185,7 @@ class SingletonFunction extends Construct {
170185
return new LambdaFunctionProvider(Stack.of(this), constructName, {
171186
handler: props.handler,
172187
logRetention: props.logRetention,
188+
providerLogLevel: props.providerLogLevel,
173189
});
174190
}
175191

@@ -245,6 +261,7 @@ export class AssertionsProvider extends Construct {
245261
handler: props?.handler,
246262
uuid: props?.uuid ?? '1488541a-7b23-4664-81b6-9b4408076b81',
247263
logRetention: props?.logRetention,
264+
providerLogLevel: props?.providerLogLevel,
248265
});
249266

250267
this.handlerRoleArn = this.handler.lambdaFunction.roleArn;
Collapse file

‎packages/@aws-cdk/integ-tests-alpha/lib/assertions/sdk.ts‎

Copy file name to clipboardExpand all lines: packages/@aws-cdk/integ-tests-alpha/lib/assertions/sdk.ts
+8-1Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
1+
import type { ApplicationLogLevel } from 'aws-cdk-lib/aws-lambda';
12
import type { RetentionDays } from 'aws-cdk-lib/aws-logs';
23
import { ArnFormat, CfnResource, CustomResource, Lazy, Stack, Aspects, CfnOutput, AspectPriority } from 'aws-cdk-lib/core';
34
import type { Construct, IConstruct } from 'constructs';
45
import type { IApiCall } from './api-call-base';
56
import { ApiCallBase } from './api-call-base';
67
import type { ExpectedResult } from './common';
78
import { AssertionsProvider, SDK_RESOURCE_TYPE_PREFIX } from './providers';
9+
import type { ProviderOptions } from './providers';
810
import type { WaiterStateMachineOptions } from './waiter-state-machine';
911
import { WaiterStateMachine } from './waiter-state-machine';
1012

1113
/**
1214
* Options to perform an AWS JavaScript V2 API call
1315
*/
14-
export interface AwsApiCallOptions {
16+
export interface AwsApiCallOptions extends ProviderOptions {
1517
/**
1618
* The AWS service, i.e. S3
1719
*/
@@ -74,12 +76,16 @@ export class AwsApiCall extends ApiCallBase {
7476
private _assertAtPath?: string;
7577
private readonly api: string;
7678
private readonly service: string;
79+
private readonly providerLogLevel?: ApplicationLogLevel;
7780

7881
constructor(scope: Construct, id: string, props: AwsApiCallProps) {
7982
super(scope, id);
8083

84+
this.providerLogLevel = props.providerLogLevel;
85+
8186
this.provider = new AssertionsProvider(this, 'SdkProvider', {
8287
logRetention: props.parameters?.RetentionDays,
88+
providerLogLevel: props.providerLogLevel,
8389
});
8490
this.provider.addPolicyStatementFromSdkCall(props.service, props.api);
8591
this.name = `${props.service}${props.api}`;
@@ -141,6 +147,7 @@ export class AwsApiCall extends ApiCallBase {
141147
public waitForAssertions(options?: WaiterStateMachineOptions): IApiCall {
142148
const waiter = new WaiterStateMachine(this, 'WaitFor', {
143149
...options,
150+
providerLogLevel: this.providerLogLevel,
144151
});
145152
this.stateMachineArn = waiter.stateMachineArn;
146153
this.provider.addPolicyStatementFromSdkCall('states', 'StartExecution');
Collapse file

‎packages/@aws-cdk/integ-tests-alpha/lib/assertions/waiter-state-machine.ts‎

Copy file name to clipboardExpand all lines: packages/@aws-cdk/integ-tests-alpha/lib/assertions/waiter-state-machine.ts
+4-1Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22
import { CfnResource, Duration, Stack } from 'aws-cdk-lib/core';
33
import { Construct } from 'constructs';
44
import { AssertionsProvider } from './providers';
5+
import type { ProviderOptions } from './providers';
56

67
/**
78
* Options for creating a WaiterStateMachine
89
*/
9-
export interface WaiterStateMachineOptions {
10+
export interface WaiterStateMachineOptions extends ProviderOptions {
1011
/**
1112
* The total time that the state machine will wait
1213
* for a successful response
@@ -91,11 +92,13 @@ export class WaiterStateMachine extends Construct {
9192
this.isCompleteProvider = new AssertionsProvider(this, 'IsCompleteProvider', {
9293
handler: 'index.isComplete',
9394
uuid: '76b3e830-a873-425f-8453-eddd85c86925',
95+
providerLogLevel: props.providerLogLevel,
9496
});
9597

9698
const timeoutProvider = new AssertionsProvider(this, 'TimeoutProvider', {
9799
handler: 'index.onTimeout',
98100
uuid: '5c1898e0-96fb-4e3e-95d5-f6c67f3ce41a',
101+
providerLogLevel: props.providerLogLevel,
99102
});
100103

101104
const role = new CfnResource(this, 'Role', {
Collapse file

‎packages/@aws-cdk/integ-tests-alpha/lib/test-case.ts‎

Copy file name to clipboardExpand all lines: packages/@aws-cdk/integ-tests-alpha/lib/test-case.ts
+5-4Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Manifest } from 'aws-cdk-lib/cloud-assembly-schema';
33
import type { ISynthesisSession, StackProps } from 'aws-cdk-lib/core';
44
import { attachCustomSynthesis, Stack } from 'aws-cdk-lib/core';
55
import { Construct } from 'constructs';
6-
import type { IDeployAssert } from './assertions';
6+
import type { IDeployAssert, ProviderOptions } from './assertions';
77
import { DeployAssert } from './assertions/private/deploy-assert';
88
import { IntegManifestSynthesizer } from './manifest-synthesizer';
99

@@ -12,7 +12,7 @@ const TEST_CASE_STACK_SYMBOL = Symbol.for('@aws-cdk/integ-tests.IntegTestCaseSta
1212
/**
1313
* Properties of an integration test case
1414
*/
15-
export interface IntegTestCaseProps extends TestOptions {
15+
export interface IntegTestCaseProps extends TestOptions, ProviderOptions {
1616
/**
1717
* Stacks to be deployed during the test
1818
*/
@@ -44,7 +44,7 @@ export class IntegTestCase extends Construct {
4444
constructor(scope: Construct, id: string, private readonly props: IntegTestCaseProps) {
4545
super(scope, id);
4646

47-
this._assert = new DeployAssert(this, { stack: props.assertionStack });
47+
this._assert = new DeployAssert(this, { stack: props.assertionStack, providerLogLevel: props.providerLogLevel });
4848
this.assertions = this._assert;
4949
}
5050

@@ -118,7 +118,7 @@ export class IntegTestCaseStack extends Stack {
118118
/**
119119
* Integration test properties
120120
*/
121-
export interface IntegTestProps extends TestOptions {
121+
export interface IntegTestProps extends TestOptions, ProviderOptions {
122122
/**
123123
* List of test cases that make up this test
124124
*/
@@ -166,6 +166,7 @@ export class IntegTest extends Construct {
166166
cdkCommandOptions: props.cdkCommandOptions,
167167
stackUpdateWorkflow: props.stackUpdateWorkflow,
168168
assertionStack: props.assertionStack,
169+
providerLogLevel: props.providerLogLevel,
169170
});
170171
this.assertions = defaultTestCase.assertions;
171172

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.