Skip to content

Commit 9fb2879

Browse files
committed
update
1 parent d9a1c9f commit 9fb2879

4 files changed

Lines changed: 59 additions & 69 deletions

File tree

.gitlab/templates/pipeline.yaml.tpl

Lines changed: 57 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -414,25 +414,61 @@ integration-test:
414414
expire_in: 30 days
415415

416416
# Integration Tests - Cleanup stacks
417-
# integration-cleanup-stacks:
418-
# stage: integration-tests
419-
# tags: ["arch:amd64"]
420-
# image: ${CI_DOCKER_TARGET_IMAGE}:${CI_DOCKER_TARGET_VERSION}
421-
# when: always
422-
# rules:
423-
# - when: always
424-
# needs:
425-
# - integration-test
426-
# variables:
427-
# IDENTIFIER: integration
428-
# {{ with $environment := (ds "environments").environments.sandbox }}
429-
# before_script:
430-
# - EXTERNAL_ID_NAME={{ $environment.external_id }} ROLE_TO_ASSUME={{ $environment.role_to_assume }} AWS_ACCOUNT={{ $environment.account }} source .gitlab/scripts/get_secrets.sh
431-
# - curl -fsSL https://deb.nodesource.com/setup_20.x | bash -
432-
# - apt-get install -y nodejs
433-
# - cd integration-tests
434-
# {{ end }}
435-
# script:
436-
# - echo "Destroying CDK stacks with identifier ${IDENTIFIER}..."
437-
# - npx cdk destroy "IntegrationTests-$IDENTIFIER-*" --force || echo "Failed to destroy some stacks, but continuing..."
417+
integration-cleanup-stacks:
418+
stage: integration-tests
419+
tags: ["arch:amd64"]
420+
image: ${CI_DOCKER_TARGET_IMAGE}:${CI_DOCKER_TARGET_VERSION}
421+
when: always
422+
rules:
423+
- when: always
424+
needs:
425+
- integration-test
426+
variables:
427+
IDENTIFIER: ${CI_COMMIT_SHORT_SHA}
428+
{{ with $environment := (ds "environments").environments.sandbox }}
429+
before_script:
430+
- EXTERNAL_ID_NAME={{ $environment.external_id }} ROLE_TO_ASSUME={{ $environment.role_to_assume }} AWS_ACCOUNT={{ $environment.account }} source .gitlab/scripts/get_secrets.sh
431+
- curl -fsSL https://deb.nodesource.com/setup_20.x | bash -
432+
- apt-get install -y nodejs
433+
- cd integration-tests
434+
{{ end }}
435+
script:
436+
- echo "Destroying CDK stacks with identifier ${IDENTIFIER}..."
437+
- npx cdk destroy "integ-$IDENTIFIER-*" --force || echo "Failed to destroy some stacks, but continuing..."
438+
439+
# Integration Tests - Cleanup layer
440+
integration-cleanup-layer:
441+
stage: integration-tests
442+
tags: ["arch:amd64"]
443+
image: ${CI_DOCKER_TARGET_IMAGE}:${CI_DOCKER_TARGET_VERSION}
444+
when: always
445+
rules:
446+
- when: always
447+
needs:
448+
- integration-cleanup-stacks
449+
variables:
450+
IDENTIFIER: ${CI_COMMIT_SHORT_SHA}
451+
{{ with $environment := (ds "environments").environments.sandbox }}
452+
before_script:
453+
- EXTERNAL_ID_NAME={{ $environment.external_id }} ROLE_TO_ASSUME={{ $environment.role_to_assume }} AWS_ACCOUNT={{ $environment.account }} source .gitlab/scripts/get_secrets.sh
454+
{{ end }}
455+
script:
456+
- echo "Deleting integration test layer with identifier ${IDENTIFIER}..."
457+
- |
458+
LAYER_NAME="Datadog-Extension-${IDENTIFIER}"
459+
echo "Looking for layer: ${LAYER_NAME}"
460+
461+
# Get all versions of the layer
462+
VERSIONS=$(aws lambda list-layer-versions --layer-name "${LAYER_NAME}" --query 'LayerVersions[*].Version' --output text --region us-east-1 2>/dev/null || echo "")
463+
464+
if [ -z "$VERSIONS" ]; then
465+
echo "No versions found for layer ${LAYER_NAME}"
466+
else
467+
echo "Found versions: ${VERSIONS}"
468+
for VERSION in $VERSIONS; do
469+
echo "Deleting ${LAYER_NAME} version ${VERSION}..."
470+
aws lambda delete-layer-version --layer-name "${LAYER_NAME}" --version-number "${VERSION}" --region us-east-1 || echo "Failed to delete version ${VERSION}, continuing..."
471+
done
472+
echo "Successfully deleted all versions of ${LAYER_NAME}"
473+
fi
438474

integration-tests/lib/util.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export const datadogEnvVariables = {
2121
DD_VERSION: '1.0.0',
2222
DD_SERVERLESS_FLUSH_STRATEGY: 'end',
2323
DD_SERVERLESS_LOGS_ENABLED: 'true',
24-
DD_LOG_LEVEL: 'debug',
24+
DD_LOG_LEVEL: 'info',
2525
};
2626

2727
export const secretPolicy = new iam.PolicyStatement({

integration-tests/tests/base.test.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,17 @@ describe('Example Lambda Integration Test', () => {
1515

1616
// Step 3: Verify logs were sent to Datadog and contain the expected content
1717
const logs = result.logs;
18-
console.log('Logs:', JSON.stringify(logs, null, 2));
19-
2018
expect(logs?.length).toBeGreaterThanOrEqual(1);
2119
expect(logs?.some((log: any) => log.attributes.message.includes('Hello world!'))).toBe(true);
2220

2321
// Step 4: Verify traces were sent to Datadog and contain the expected content
2422
const traces = result.traces;
25-
26-
// Assertions for traces
2723
expect(traces?.length).toBe(1);
2824

2925
const trace = traces![0];
3026
const spanNames = trace.spans.map((span: any) => span.name);
3127
console.log('Span names:', spanNames);
3228

33-
// Should contain 'aws.lambda.cold_start' and 'aws.lambda' spans
3429
expect(spanNames).toContain('aws.lambda.cold_start');
3530
expect(spanNames).toContain('aws.lambda.load');
3631
expect(spanNames).toContain('aws.lambda');

integration-tests/tests/utils/datadog.ts

Lines changed: 1 addition & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,6 @@ export async function getLogs(
186186
const fromTime = now - (2 * 60 * 60 * 1000); // 2 hours ago
187187
const toTime = now;
188188
try {
189-
// NOTE: Logs use the original service name casing, unlike traces which use lowercase
190-
// Build query with service name and optional request ID
191189
let query = `service:${serviceName}`;
192190
if (requestId) {
193191
query += ` ${requestId}`;
@@ -247,43 +245,4 @@ export async function queryMetrics(
247245
console.error('Error querying metrics:', error.response?.data || error.message);
248246
throw error;
249247
}
250-
}
251-
252-
/**
253-
* Wait for data to appear in Datadog with retries
254-
*/
255-
export async function waitForData<T>(
256-
fetchFn: () => Promise<T[]>,
257-
options: {
258-
timeout?: number;
259-
interval?: number;
260-
minCount?: number;
261-
} = {}
262-
): Promise<T[]> {
263-
const timeout = options.timeout || 180000; // 3 minutes default
264-
const interval = options.interval || 10000; // 10 seconds default
265-
const minCount = options.minCount || 1;
266-
267-
const startTime = Date.now();
268-
let attempts = 0;
269-
270-
while (Date.now() - startTime < timeout) {
271-
attempts++;
272-
console.log(`Attempt ${attempts}: Checking for data in Datadog...`);
273-
274-
try {
275-
const data = await fetchFn();
276-
if (data.length >= minCount) {
277-
console.log(`Found ${data.length} items in Datadog`);
278-
return data;
279-
}
280-
console.log(`Found ${data.length} items, waiting for at least ${minCount}...`);
281-
} catch (error) {
282-
console.log(`Error fetching data (attempt ${attempts}):`, error);
283-
}
284-
285-
await new Promise(resolve => setTimeout(resolve, interval));
286-
}
287-
288-
throw new Error(`Timeout waiting for data in Datadog after ${timeout}ms`);
289-
}
248+
}

0 commit comments

Comments
 (0)