Repository navigation
Restructuring integration tests #899
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
rithikanarayan
wants to merge
13
commits into
main
Choose a base branch
from
rithika.narayan/APMSVLS-728
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+9,525
−1
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
0452d0d
Restructuring integration tests
rithikanarayan faef304
cleaning
rithikanarayan 1b9463d
change permissions used
rithikanarayan b9e3e75
reduce perms for extension
rithikanarayan 9f1f57f
adjust test expectations
rithikanarayan 2245f0f
regenerate snapshots
rithikanarayan 2f2a29d
all snapshots
rithikanarayan 06c04cb
dedup
rithikanarayan 0b761c8
fix extension version
rithikanarayan 240ee89
reducing volume
rithikanarayan 66d4398
nits
rithikanarayan 253c7a4
linting
rithikanarayan 9d8983b
update snapshots
rithikanarayan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| #!/bin/bash | ||
|
|
||
| # Unless explicitly stated otherwise all files in this repository are licensed | ||
| # under the Apache License Version 2.0. | ||
| # This product includes software developed at Datadog (https://www.datadoghq.com/). | ||
| # Copyright 2026 Datadog, Inc. | ||
|
|
||
| # Runs the pytest integration suite in tests/integration (SAM-deployed stack). | ||
| # | ||
| # Usage, from the repo root: | ||
| # ARCH=amd64 DD_API_KEY=XXXX \ | ||
| # aws-vault exec sso-serverless-sandbox-account-admin -- ./scripts/run_integration_pytest.sh | ||
| # | ||
| # DD_API_KEY_SECRET_ARN can stand in for DD_API_KEY. The deployed functions read | ||
| # the key from Secrets Manager themselves, so the role they run as must be | ||
| # allowed to read that secret. | ||
| # | ||
| # Runs every Python version in python_versions.yaml, one after another (each | ||
| # deploys its own stack), unless PYTHON_VERSION is set. | ||
| # | ||
| # Optional: | ||
| # PYTHON_VERSION=3.13 run one version only (shorthand like 13 works too) | ||
| # BUILD_LAYERS=true build the layer(s) first | ||
| # DD_EXTENSION_LAYER_VERSION=N Datadog Extension layer version (default: the pin in | ||
| # tests/integration/harness/settings.py; | ||
| # "none" skips the extension / mock intake tests) | ||
| # INTEGRATION_STACK_NAME=... reuse a deployed stack (kept afterwards); needs PYTHON_VERSION | ||
| # KEEP_STACK=true keep the stack(s) for debugging | ||
| # UPDATE_EXPECTED=true write snapshots instead of comparing (see CONTRIBUTING.md) | ||
| # Extra arguments are passed to pytest, e.g. -k sqs. With several versions, | ||
| # --junitxml=<file>.xml writes one <file>-<version>.xml per version. | ||
|
|
||
| set -e | ||
|
|
||
| scripts_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) | ||
| repo_dir=$(dirname "$scripts_dir") | ||
| source "$scripts_dir/python_versions.sh" | ||
|
|
||
| if [ -z "$ARCH" ]; then | ||
| echo "ARCH must be set" | ||
| exit 1 | ||
| fi | ||
|
|
||
| if [ -z "$DD_API_KEY" ] && [ -z "$DD_API_KEY_SECRET_ARN" ]; then | ||
| echo "DD_API_KEY or DD_API_KEY_SECRET_ARN must be set" | ||
| exit 1 | ||
| fi | ||
|
|
||
| if [ -n "$PYTHON_VERSION" ]; then | ||
| if [[ "$PYTHON_VERSION" =~ ^[0-9]+$ ]]; then | ||
| PYTHON_VERSION="3.${PYTHON_VERSION}" | ||
| fi | ||
| if [[ ! " ${SUPPORTED_PYTHON_VERSIONS[*]} " =~ " ${PYTHON_VERSION} " ]]; then | ||
| echo "Python version $PYTHON_VERSION is not supported. Choose from: ${SUPPORTED_PYTHON_VERSIONS[*]}" | ||
| exit 1 | ||
| fi | ||
| versions=("$PYTHON_VERSION") | ||
| else | ||
| if [ -n "$INTEGRATION_STACK_NAME" ]; then | ||
| echo "INTEGRATION_STACK_NAME reuses one runtime's stack; set PYTHON_VERSION too" | ||
| exit 1 | ||
| fi | ||
| versions=("${SUPPORTED_PYTHON_VERSIONS[@]}") | ||
| echo "PYTHON_VERSION not set, running all versions: ${versions[*]}" | ||
| fi | ||
|
|
||
| marker_args=() | ||
| if [ "$DD_EXTENSION_LAYER_VERSION" = "none" ]; then | ||
| echo "DD_EXTENSION_LAYER_VERSION=none, skipping extension tests" | ||
| marker_args=(-m "not extension") | ||
| fi | ||
|
|
||
| failed=() | ||
| for version in "${versions[@]}"; do | ||
| echo "=== Python $version ($ARCH) ===" | ||
|
|
||
| # One JUnit file per version, so runs don't overwrite each other. | ||
| pytest_args=() | ||
| for arg in "$@"; do | ||
| if [ ${#versions[@]} -gt 1 ] && [[ "$arg" == --junitxml=*.xml ]]; then | ||
| arg="${arg%.xml}-${version}.xml" | ||
| fi | ||
| pytest_args+=("$arg") | ||
| done | ||
|
|
||
| # Keep going after a failure, so one run covers every version. | ||
| set +e | ||
| ( | ||
| set -e | ||
| if [ -n "$BUILD_LAYERS" ]; then | ||
| PYTHON_VERSION=$version ARCH=$ARCH "$scripts_dir/build_layers.sh" | ||
| fi | ||
| cd "$repo_dir/tests/integration" | ||
| PYTHON_VERSION=$version python -m pytest "${marker_args[@]}" "${pytest_args[@]}" | ||
| ) | ||
| status=$? | ||
| set -e | ||
| if [ $status -ne 0 ]; then | ||
| failed+=("$version") | ||
| fi | ||
| done | ||
|
|
||
| if [ ${#versions[@]} -gt 1 ]; then | ||
| echo "=== Ran ${#versions[@]} versions on $ARCH; failed: ${failed[*]:-none} ===" | ||
| fi | ||
| [ ${#failed[@]} -eq 0 ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| """Session fixtures: deploy the stack once, run the baseline invocations once. | ||
|
|
||
| Environment: | ||
| PYTHON_VERSION, ARCH, and one of DD_API_KEY or DD_API_KEY_SECRET_ARN required | ||
| DD_EXTENSION_LAYER_VERSION Datadog Extension layer version number (default: | ||
| the pinned version in harness/settings.py) or "none" | ||
| (no extension tests) | ||
| INTEGRATION_STACK_NAME reuse a deployed stack (it is kept afterwards) | ||
| KEEP_STACK=true don't delete the stack at the end | ||
| INTEGRATION_REGION default eu-west-1 | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import json | ||
| import secrets | ||
| from typing import Dict, Tuple | ||
|
|
||
| import pytest | ||
|
|
||
| from .harness import aws | ||
| from .harness import settings as settings_mod | ||
|
|
||
| from .harness.settings import BASELINE_FUNCTIONS, EVENT_NAMES, INPUT_EVENTS_DIR | ||
|
|
||
| CASES = [(fn, ev) for fn in BASELINE_FUNCTIONS for ev in EVENT_NAMES] | ||
|
|
||
|
|
||
| def load_event(name: str): | ||
| return json.loads((INPUT_EVENTS_DIR / (name + ".json")).read_text()) | ||
|
|
||
|
|
||
| @pytest.fixture(scope="session") | ||
| def run_settings() -> settings_mod.Settings: | ||
| return settings_mod.load() | ||
|
|
||
|
|
||
| @pytest.fixture(scope="session") | ||
| def stack(request, run_settings) -> Dict[str, str]: | ||
| """Deploy the stack and return its outputs.""" | ||
| s = run_settings | ||
| if not s.existing_stack: | ||
| # Stream deploy output (pip, sam) live instead of capturing it. | ||
| capture = request.config.pluginmanager.getplugin("capturemanager") | ||
| with capture.global_and_fixture_disabled(): | ||
| print("\nIntegration test stack: %s" % s.stack_name, flush=True) | ||
| try: | ||
| aws.deploy(s, mock_intake_api_key=secrets.token_hex(16)) | ||
| except Exception as e: | ||
| # Report the deploy error first: a failing cleanup must not hide it. | ||
| print("Deploying %s failed: %s" % (s.stack_name, e), flush=True) | ||
| if not s.keep_stack: | ||
| try: | ||
| aws.delete(s) | ||
| except Exception as cleanup_error: | ||
| print( | ||
| "Deleting %s also failed, delete it manually: %s" | ||
| % (s.stack_name, cleanup_error), | ||
| flush=True, | ||
| ) | ||
| # Every test needs the stack; stop with one error, not one per test. | ||
| pytest.exit("Deploying %s failed: %s" % (s.stack_name, e), returncode=1) | ||
| try: | ||
| yield aws.stack_outputs(s) | ||
| finally: | ||
| if not s.keep_stack: | ||
| aws.delete(s) | ||
|
|
||
|
|
||
| @pytest.fixture(scope="session") | ||
| def baseline_invocations(run_settings, stack) -> Dict[Tuple[str, str], aws.Invocation]: | ||
| """Invoke each baseline function once per input event, in sorted order, | ||
| and attach the parsed logs. Keyed by (function key, event name).""" | ||
| results: Dict[Tuple[str, str], aws.Invocation] = {} | ||
| for key, output in BASELINE_FUNCTIONS.items(): | ||
| function_name = stack[output] | ||
| if run_settings.existing_stack: | ||
| # A reused stack may be warm; the first invocation must be a cold start. | ||
| aws.force_cold_start(run_settings.region, function_name) | ||
| invocations = [ | ||
| aws.invoke(run_settings.region, function_name, load_event(name)) | ||
| for name in EVENT_NAMES | ||
| ] | ||
| logs = aws.wait_for_logs( | ||
| run_settings.region, function_name, [i.request_id for i in invocations] | ||
| ) | ||
| for name, inv in zip(EVENT_NAMES, invocations): | ||
| inv.logs = logs[inv.request_id] | ||
| results[(key, name)] = inv | ||
| return results | ||
|
|
||
|
|
||
| @pytest.fixture(params=CASES, ids=["%s-%s" % c for c in CASES]) | ||
| def case(request, baseline_invocations): | ||
| """(function key, event name, Invocation), once per baseline function and event.""" | ||
| fn, event_name = request.param | ||
| return fn, event_name, baseline_invocations[(fn, event_name)] | ||
|
|
||
|
|
||
| @pytest.fixture(scope="session") | ||
| def extension_function(run_settings, stack) -> str: | ||
| if "ExtensionFunctionName" not in stack: | ||
| pytest.fail( | ||
| "Stack has no extension function (DD_EXTENSION_LAYER_VERSION=none); " | ||
| 'deselect these tests with -m "not extension"' | ||
| ) | ||
| return stack["ExtensionFunctionName"] |
35 changes: 35 additions & 0 deletions
35
tests/integration/expected/metrics/default/async-metrics.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| [ | ||
| { | ||
| "m": "aws.lambda.enhanced.invocations", | ||
| "t": [ | ||
| "account_id:<account_id>", | ||
| "cold_start:<bool>", | ||
| "datadog_lambda:<version>", | ||
| "dd_lambda_layer:datadog-<runtime_key>_<version>", | ||
| "functionname:<function_name>", | ||
| "memorysize:1024", | ||
| "region:eu-west-1", | ||
| "resource:<function_name>", | ||
| "runtime:<runtime>" | ||
| ], | ||
| "v": 1 | ||
| }, | ||
| { | ||
| "m": "hello.dog", | ||
| "t": [ | ||
| "dd_lambda_layer:datadog-<runtime_key>_<version>", | ||
| "role:hello", | ||
| "team:serverless" | ||
| ], | ||
| "v": 1 | ||
| }, | ||
| { | ||
| "m": "tests.integration.count", | ||
| "t": [ | ||
| "dd_lambda_layer:datadog-<runtime_key>_<version>", | ||
| "role:hello", | ||
| "test:integration" | ||
| ], | ||
| "v": 21 | ||
| } | ||
| ] |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Without an explicit pipeline override, this enables two new integration jobs for each of eight Python runtimes and two architectures: 32 additional AWS stack deployments alongside the existing suite. That adds deployment costs and CI work despite the stated plan to keep the replacement suite disabled. Default this variable to false so the jobs remain opt-in.
React: 👍 useful · 👎 wrong · 😕 unclear · 👀 right, but not acting on it
What each reaction means
🤖 Bits Code Review · Open Bits AI session