-
Notifications
You must be signed in to change notification settings - Fork 15
test(ffe): add agentless serverless exposure contract #7477
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
Merged
leoromanovsky
merged 18 commits into
main
from
agent/nodejs-agentless-serverless-exposures
Aug 18, 2026
Merged
Changes from 3 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
4c36f02
test(ffe): add agentless serverless exposure contract
leoromanovsky f387372
test(ffe): separate serverless contract from SDK enablement
leoromanovsky 972b475
fix(ffe): use integer agentless poll interval
leoromanovsky ab7e4e5
test(ffe): use Datadog exposure route names
leoromanovsky 009373c
test(ffe): cover direct agentless exposure egress
leoromanovsky 6a43bea
test(ffe): account for capture key scrubbing
leoromanovsky 4c2aca8
test: register direct exposure scenario group exception
leoromanovsky be461a4
ci: run direct agentless exposure scenario
leoromanovsky 690a85b
test(ffe): identify Agent exposure tests
leoromanovsky fd59899
test: share exposure egress contract
leoromanovsky e230b5d
test: accept scrubbed sidecar API key
leoromanovsky 0ad24cf
Merge origin/main into agent/nodejs-agentless-serverless-exposures
leoromanovsky 4722018
test(ffe): address exposure review feedback
leoromanovsky d11223f
Merge remote-tracking branch 'origin/main' into agent/nodejs-agentles…
leoromanovsky a5674ac
test(ffe): harden sidecar topology checks
leoromanovsky 64740ce
test(php): mark OTel interoperability regressions as bugs
leoromanovsky 9e37350
test(php): re-enable OTel interoperability tests
leoromanovsky 437603f
Merge remote-tracking branch 'origin/main' into agent/nodejs-agentles…
leoromanovsky 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
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
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,53 @@ | ||
| """Test exposure delivery with agentless UFC and serverless-init.""" | ||
|
|
||
| from tests.ffe.utils.exposures import assert_exposure_side_effects_contract, exposure_events_from_data | ||
| from utils import features, interfaces, scenarios, weblog | ||
| from utils._context.component_version import Version | ||
| from utils.mocked_backend.ffe import EXPECTED_API_KEY | ||
|
|
||
|
|
||
| @scenarios.feature_flagging_and_experimentation_agentless_serverless | ||
| @features.feature_flags_exposures | ||
| class Test_FFE_Agentless_Serverless_Exposures: | ||
| flag_key = "empty-targeting-key-flag" | ||
| targeting_key = "agentless-serverless-exposure-user" | ||
|
|
||
| def setup_agentless_serverless_exposure(self) -> None: | ||
| self.responses = [ | ||
| weblog.post( | ||
| "/ffe", | ||
| json={ | ||
| "flag": self.flag_key, | ||
| "variationType": "STRING", | ||
| "defaultValue": "default", | ||
| "targetingKey": self.targeting_key, | ||
| "attributes": {}, | ||
| }, | ||
| ) | ||
| for _ in range(5) | ||
| ] | ||
|
|
||
| def test_agentless_serverless_exposure(self) -> None: | ||
| scenario = scenarios.feature_flagging_and_experimentation_agentless_serverless | ||
| assert scenario.components["serverless-init"] == Version("1.9.13") | ||
|
|
||
| matching_requests = assert_exposure_side_effects_contract( | ||
| interfaces.ffe_direct, | ||
| self.responses, | ||
| flag_key=self.flag_key, | ||
| targeting_key=self.targeting_key, | ||
| expected_value="on-value", | ||
| expected_variant="on", | ||
| ) | ||
| assert len(matching_requests) == 1 | ||
| request = matching_requests[0] | ||
| assert request["host"] == "event-platform-intake.datad0g.com" | ||
| assert request["response"]["status_code"] == 202 | ||
|
|
||
| headers = {name.lower(): value for name, value in request["request"]["headers"]} | ||
| assert headers["dd-api-key"] == EXPECTED_API_KEY | ||
|
|
||
| assert not any( | ||
| exposure_events_from_data(data, {self.flag_key}, self.targeting_key) | ||
| for data in interfaces.ffe_sidecar.get_data() | ||
| ) |
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,93 @@ | ||
| """Route-neutral Feature Flags exposure expectations.""" | ||
|
|
||
| from collections.abc import Iterable | ||
| import json | ||
|
|
||
| from utils._weblog import HttpResponse | ||
| from utils.interfaces._core import ProxyBasedInterfaceValidator | ||
|
|
||
| EXPOSURES_PATH = "/api/v2/exposures" | ||
| EXPOSURE_WAIT_TIMEOUT_SECONDS = 30 | ||
| EXPOSURE_CACHE_SETTLE_SECONDS = 3 | ||
|
|
||
|
|
||
| def exposure_events_from_data( | ||
| data: dict, flag_keys: set[str] | None = None, subject_id: str | None = None | ||
| ) -> list[dict]: | ||
| """Return matching exposure events from one captured request.""" | ||
| if data.get("path") != EXPOSURES_PATH: | ||
| return [] | ||
|
|
||
| exposure_data = data.get("request", {}).get("content") | ||
| if not isinstance(exposure_data, dict): | ||
| return [] | ||
|
|
||
| exposures = exposure_data.get("exposures") | ||
| if not isinstance(exposures, list): | ||
| return [] | ||
|
|
||
| events = [] | ||
| for event in exposures: | ||
| if not isinstance(event, dict): | ||
| continue | ||
|
|
||
| flag = event.get("flag") | ||
| subject = event.get("subject") | ||
| event_flag_key = flag.get("key") if isinstance(flag, dict) else None | ||
| event_subject_id = subject.get("id") if isinstance(subject, dict) else None | ||
|
|
||
| if flag_keys is not None and event_flag_key not in flag_keys: | ||
| continue | ||
| if subject_id is not None and event_subject_id != subject_id: | ||
| continue | ||
| events.append(event) | ||
| return events | ||
|
|
||
|
|
||
| def assert_exposure_side_effects_contract( | ||
| interface: ProxyBasedInterfaceValidator, | ||
| responses: Iterable[HttpResponse], | ||
| *, | ||
| flag_key: str, | ||
| targeting_key: str, | ||
| expected_value: str, | ||
| expected_variant: str, | ||
| expected_allocation: str = "default-allocation", | ||
| ) -> list[dict]: | ||
| """Assert one exposure contract through Agent, sidecar, or direct intake capture.""" | ||
| for index, response in enumerate(responses, start=1): | ||
| assert response.status_code == 200, f"Evaluation {index} failed: {response.text}" | ||
| value = json.loads(response.text)["value"] | ||
| assert value == expected_value, f"Evaluation {index} returned {value!r}" | ||
|
|
||
| def matches_exposure(data: dict) -> bool: | ||
| return bool(exposure_events_from_data(data, {flag_key}, targeting_key)) | ||
|
|
||
| assert interface.wait_for( | ||
| matches_exposure, | ||
| timeout=EXPOSURE_WAIT_TIMEOUT_SECONDS, | ||
| ), f"Timed out waiting for exposure event for {flag_key!r} and {targeting_key!r}" | ||
|
|
||
| if not interface.replay: | ||
| interface.wait(EXPOSURE_CACHE_SETTLE_SECONDS) | ||
|
|
||
| matching_requests = [data for data in interface.get_data() if matches_exposure(data)] | ||
| events = [ | ||
| event | ||
| for request in matching_requests | ||
| for event in exposure_events_from_data(request, {flag_key}, targeting_key) | ||
| ] | ||
| assert len(events) == 1, f"The exposure cache produced {len(events)} matching events instead of one" | ||
|
|
||
| for request in matching_requests: | ||
| context = request["request"]["content"]["context"] | ||
| assert context["service"] == "weblog" | ||
| assert context["version"] == "1.0.0" | ||
| assert context["env"] == "system-tests" | ||
|
|
||
| event = events[0] | ||
| assert event["flag"]["key"] == flag_key | ||
| assert event["variant"]["key"] == expected_variant | ||
| assert event["allocation"]["key"] == expected_allocation | ||
| assert event["subject"]["id"] == targeting_key | ||
| return matching_requests |
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
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.
Uh oh!
There was an error while loading. Please reload this page.