Skip to content

Add css obfuscation test [APMSP-2764]#6648

Draft
Eldolfin wants to merge 21 commits into
mainfrom
oscarld/add-css-obfuscation-test
Draft

Add css obfuscation test [APMSP-2764]#6648
Eldolfin wants to merge 21 commits into
mainfrom
oscarld/add-css-obfuscation-test

Conversation

@Eldolfin
Copy link
Copy Markdown
Contributor

@Eldolfin Eldolfin commented Mar 31, 2026

btw I don't get the fail in test_the_tests because the new scenario TRACE_STATS_COMPUTATION_OBFUSCATION_DISABLED has agent_env variables that the existing TRACE_STATS_COMPUTATION doesn't so they're not equivalent. fixed

TODO

Motivation

  • Test that libraries obfuscate spans before sending them to /stats

Changes

  • Add one testcase (is this considered a new feature ?)
  • Fix 2 small issues I found while looking at the repo

Workflow

  1. ⚠️ Create your PR as draft ⚠️
  2. Work on you PR until the CI passes
  3. Mark it as ready for review
    • Test logic is modified? -> Get a review from RFC owner.
    • Framework is modified, or non obvious usage of it -> get a review from R&P team

🚀 Once your PR is reviewed and the CI green, you can merge it!

🛟 #apm-shared-testing 🛟

Reviewer checklist

  • Anything but tests/ or manifests/ is modified ? I have the approval from R&P team
  • A docker base image is modified?
    • the relevant build-XXX-image label is present
  • A scenario is added, removed or renamed?

@Eldolfin Eldolfin changed the title Oscarld/add css obfuscation test [APMSP-2764] Add css obfuscation test [APMSP-2764] Mar 31, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Mar 31, 2026

CODEOWNERS have been resolved as:

.github/workflows/run-end-to-end.yml                                    @DataDog/system-tests-core
manifests/cpp.yml                                                       @DataDog/dd-trace-cpp
manifests/cpp_httpd.yml                                                 @DataDog/dd-trace-cpp
manifests/cpp_nginx.yml                                                 @DataDog/dd-trace-cpp
manifests/dotnet.yml                                                    @DataDog/apm-dotnet @DataDog/asm-dotnet
manifests/golang.yml                                                    @DataDog/dd-trace-go-guild
manifests/java.yml                                                      @DataDog/asm-java @DataDog/apm-java
manifests/java_otel.yml                                                 @DataDog/system-tests-core
manifests/nodejs_otel.yml                                               @DataDog/system-tests-core
manifests/php.yml                                                       @DataDog/apm-php @DataDog/asm-php
manifests/python.yml                                                    @DataDog/apm-python @DataDog/asm-python
manifests/python_lambda.yml                                             @DataDog/apm-python @DataDog/asm-python
manifests/python_otel.yml                                               @DataDog/apm-python @DataDog/asm-python
manifests/ruby.yml                                                      @DataDog/ruby-guild @DataDog/asm-ruby
tests/stats/test_stats.py                                               @DataDog/system-tests-core
utils/_context/_scenarios/__init__.py                                   @DataDog/system-tests-core
utils/_context/_scenarios/endtoend.py                                   @DataDog/system-tests-core
utils/_context/containers.py                                            @DataDog/system-tests-core
utils/proxy/mocked_response.py                                          @DataDog/system-tests-core

@Eldolfin Eldolfin force-pushed the oscarld/add-css-obfuscation-test branch from 4871555 to 0cf62ff Compare March 31, 2026 11:09
@datadog-datadog-prod-us1
Copy link
Copy Markdown

datadog-datadog-prod-us1 Bot commented Mar 31, 2026

Tests

🎉 All green!

🧪 All tests passed
❄️ No new flaky tests detected

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 45e38cc | Docs | Datadog PR Page | Give us feedback!

Comment thread utils/build/docker/python/flask/app.py
Comment thread tests/stats/test_stats.py Outdated
@Eldolfin Eldolfin force-pushed the oscarld/add-css-obfuscation-test branch from 0cf62ff to 714e99a Compare April 2, 2026 11:32
Comment thread tests/stats/test_stats.py Outdated
Comment thread tests/stats/test_stats.py Outdated
"DD_TRACE_TRACER_METRICS_ENABLED": "true", # java
},
agent_env={
"DD_APM_SQL_OBFUSCATION_MODE": "normalize_only",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see anything about disabling the obfuscation in the spec is it done by setting the obfuscation version to 0 (if not maybe we need a scenario for the missing/version 0 case)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not a setting from the CSS spec but to avoid breaking changes in the obfuscation behavior when switching from agent obfuscation to client obfuscation I decided that following as much of the config as possible would be preferable.

https://github.com/DataDog/datadog-agent/blob/main/pkg/config/config_template.yaml#L1633

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I wasn't really clear what I meant was:

  1. Agent obfuscation config doesn't seem to be covered in the current spec, maybe it should be updated (CC @ichinaski)
  2. Does this scenario implies Agent version 0 or missing if not maybe we want to run a scenario for this case.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Yes, I think this is a shortcoming of the spec currently, because with CSS disabled the agent would have followed the obfuscation config.
  2. No it's exactly like TRACE_STATS_COMPUTATION but with config such as obfuscation makes the 4 spans different so that they end up in different buckets so it's visible. I'll add a similar test with a missing version 👍🏽

Copy link
Copy Markdown
Contributor

@VianneyRuhlmann VianneyRuhlmann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, the idea for a version 0 scenario can be addressed in a follow-up PR if needed

@Eldolfin Eldolfin force-pushed the oscarld/add-css-obfuscation-test branch from 1c3b465 to 38567bc Compare June 2, 2026 16:25
@Eldolfin Eldolfin changed the base branch from main to oscarld/fix-test-minimal-number-of-scenarios-check-agent-env June 4, 2026 11:25
Base automatically changed from oscarld/fix-test-minimal-number-of-scenarios-check-agent-env to main June 4, 2026 12:52
@Eldolfin Eldolfin force-pushed the oscarld/add-css-obfuscation-test branch from 9d3f272 to 1fcdc3a Compare June 4, 2026 13:03
Eldolfin added 4 commits June 4, 2026 17:37
…ternal queries

SQLite internally executes SELECT QUOTE(?) which naturally contains '?'
as a parameter placeholder. Narrowing the resource filter from
startswith('SELECT') to startswith('SELECT * FROM users') excludes
these internal queries from the no-obfuscation assertions.
…ries

Django ORM generates queries like 'SELECT ? FROM app_customuser...' that
don't match the test's expected resource pattern. Filter to
startswith('SELECT * FROM users') to only capture queries from the
/rasp/sqli endpoint used in setup.
Comment thread tests/stats/test_stats.py
Comment on lines 71 to 81
def test_obfuscation(self):
stats_count = 0
hits = 0
top_hits = 0
resource = "SELECT * FROM users WHERE id = ?"
# wait for 10 seconds to be sure all the buckets are flushed (better than be flaky)
for s in interfaces.agent.get_stats(resource):
stats_count += 1
for s in interfaces.agent.get_stats():
if s["Type"] != "sql" or "?" not in s["Resource"]:
continue
logger.debug(f"asserting on {s}")
hits += s["Hits"]
top_hits += s["TopLevelHits"]
assert s["Type"] == "sql", "expect 'sql' type"
assert stats_count <= 4, (
"expect <= 4 stats"
) # Normally this is exactly 2 but in certain high load this can flake and result in additional payloads where hits are split across two payloads
assert hits == top_hits >= 4, "expect at least 4 'OK' hits and top level hits across all payloads"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be restored

@Eldolfin
Copy link
Copy Markdown
Contributor Author

Eldolfin commented Jun 5, 2026

@codex review

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 45e38cceca

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread tests/stats/test_stats.py


@features.client_side_stats_supported
@scenarios.trace_stats_computation_future_obfuscation_version
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Regenerate the scenario map for new stats tests

For future PRs that touch only tests/stats/test_stats.py, CI selects impacted end-to-end scenarios from tests/test_the_test/scenarios.json via utils/scripts/compute_libraries_and_scenarios.py; I checked this commit's map with rg "Obfuscation|OBFUSCATION" and none of the new Test_Client_Stats_*Obfuscation* nodeids are present. As a result, these new TRACE_STATS_COMPUTATION_* scenarios are not added to inputs.scenarios, so the workflow steps added for them will not run on test-file-only changes. Please regenerate/update the scenario map with the new nodeids.

Useful? React with 👍 / 👎.

if: steps.build.outcome == 'success' && !cancelled() && contains(inputs.scenarios, '"TRACE_STATS_COMPUTATION"')
run: ./run.sh TRACE_STATS_COMPUTATION
- name: Run TRACE_STATS_COMPUTATION_OBFUSCATION_DISABLED scenario
if: always() && steps.build.outcome == 'success' && contains(inputs.scenarios, '"TRACE_STATS_COMPUTATION_OBFUSCATION_DISABLED"')
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve failure gating for obfuscation scenario steps

In this workflow section, the existing scenario steps use the default successful-previous-steps gating plus !cancelled(), but these new steps add always() and omit !cancelled(). GitHub Actions treats always() as a status override, so when an earlier scenario in this job fails or a run is cancelled, these obfuscation scenarios can still start instead of skipping like the surrounding scenario steps, wasting CI time and making cancellations less responsive. Use the same steps.build.outcome == 'success' && !cancelled() && ... pattern unless these are intentionally post-failure cleanup steps.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants