Skip to content

Add env/stage filter for DDog and collapse more API URLs into single templates#4924

Merged
lukaszgryglicki merged 4 commits intodevfrom
unicron-add-stage-filter-to-ddog-scan-tools
Mar 5, 2026
Merged

Add env/stage filter for DDog and collapse more API URLs into single templates#4924
lukaszgryglicki merged 4 commits intodevfrom
unicron-add-stage-filter-to-ddog-scan-tools

Conversation

@lukaszgryglicki
Copy link
Member

cc @mlehotskylf

Signed-off-by: Lukasz Gryglicki lgryglicki@cncf.io

Assisted by OpenAI

Assisted by GitHub Copilot

…templates

Signed-off-by: Lukasz Gryglicki <lgryglicki@cncf.io>

Assisted by [OpenAI](https://platform.openai.com/)

Assisted by [GitHub Copilot](https://github.com/features/copilot)
@lukaszgryglicki lukaszgryglicki self-assigned this Mar 5, 2026
Copilot AI review requested due to automatic review settings March 5, 2026 08:50
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds Datadog “env/stage” filtering support to the local span-querying utilities and continues unifying API route templating so span routes group consistently.

Changes:

  • check_spans_in_ddog.sh: adds strict bash settings, argument parsing for env/service, and builds the Datadog search payload via jq.
  • api_usage_stats_ddog.py: introduces --env/--stage and appends env:<value> to the query unless already present.
  • Backend path sanitizers: updates route-templating logic in both Python and Go (but introduces a duplicate replacement call in each).

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

File Description
utils/otel_dd/check_spans_in_ddog.sh Adds env/service CLI args and safer JSON payload construction for Datadog span search.
utils/otel_dd/api_usage_stats_ddog.py Adds env/stage option and auto-appends env: to the Datadog query when missing.
cla-backend/cla/routes.py Adjusts API path sanitization (currently includes a duplicated numeric-id substitution).
cla-backend-go/telemetry/datadog_otlp.go Adjusts Go-side path sanitization to match templating (currently includes a duplicated numeric-id replacement).

@coderabbitai
Copy link

coderabbitai bot commented Mar 5, 2026

Walkthrough

Adds duplicate numeric ID-masking calls in two backend files (redundant replacements) and enhances Datadog utilities with environment-filter detection, new CLI/environment options, and safer jq-based payload construction for Datadog queries.

Changes

Cohort / File(s) Summary
ID Masking Duplicates
cla-backend-go/telemetry/datadog_otlp.go, cla-backend/cla/routes.py
Inserts an additional, identical numeric-ID regex replacement/substitution immediately after an existing one, causing the same ID-masking operation to be applied twice.
Environment Filter Detection & CLI
utils/otel_dd/api_usage_stats_ddog.py
Adds _ENV_RE regex and has_env_filter(query: str) -> bool; introduces --env/--environment/--stage CLI options and logic to append env:<value> to queries when absent.
Bash Script: Datadog Query Construction
utils/otel_dd/check_spans_in_ddog.sh
Enables strict shell options, improves arg parsing (--skip-e2e, --env/--environment/--stage, --service), provides defaults, and constructs the Datadog request payload using jq with a dynamically built query including service and env.
Test Header Addition
cla-backend/cla/tests/unit/test_jwt_auth.py
Prepends license/header lines to the test file; no functional changes to tests.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main changes: adding env/stage filter for Datadog and collapsing API URLs into templates, which aligns with the modifications across multiple files.
Description check ✅ Passed The description is minimal but related to the changeset, providing context about the PR author and acknowledgments without being off-topic.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch unicron-add-stage-filter-to-ddog-scan-tools

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
cla-backend/cla/routes.py (1)

111-111: Drop the duplicate numeric-ID substitution.

Line 111 duplicates Line 110 with the same pattern/replacement, so this second pass has no effect.

Proposed cleanup
     p = _RE_UUID_VALID.sub("{uuid}", p)
     p = _RE_UUID_LIKE.sub(r"/{invalid-uuid}\1", p)
     p = _RE_UUID_HEXDASH_36.sub(r"/{invalid-uuid}\1", p)
     p = _RE_NUMERIC_ID.sub(r"/{id}\1", p)
-    p = _RE_NUMERIC_ID.sub(r"/{id}\1", p)
     p = _RE_SFID_VALID.sub(r"/{sfid}\1", p)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@cla-backend/cla/routes.py` at line 111, Remove the redundant second
substitution call that applies the numeric-ID regex to p; the line invoking
_RE_NUMERIC_ID.sub(r"/{id}\1", p) is a duplicate of the previous line and should
be deleted so only the first substitution on variable p remains (search for the
two consecutive calls to _RE_NUMERIC_ID.sub in the function/class that builds p
and remove the latter).
cla-backend-go/telemetry/datadog_otlp.go (1)

194-194: Remove the redundant numeric-ID replacement pass.

Line 194 repeats the exact same substitution from Line 193; it is a no-op and adds maintenance noise.

Proposed cleanup
 		p = reUUIDLike.ReplaceAllString(p, "/{invalid-uuid}$1")
 		p = reUUIDHexDash36.ReplaceAllString(p, "/{invalid-uuid}$1")
 		p = reNumericID.ReplaceAllString(p, "/{id}$1")
-		p = reNumericID.ReplaceAllString(p, "/{id}$1")
 		// Salesforce IDs: valid vs invalid
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@cla-backend-go/telemetry/datadog_otlp.go` at line 194, The code calls
reNumericID.ReplaceAllString twice in a row on variable p (the second call
repeating the exact substitution), so remove the redundant second invocation —
keep only a single p = reNumericID.ReplaceAllString(p, "/{id}$1") call (where p
and reNumericID are used) to eliminate the no-op duplicate and reduce
maintenance noise.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@utils/otel_dd/api_usage_stats_ddog.py`:
- Around line 36-39: The env-filter regex (_ENV_RE) and its usage in
has_env_filter incorrectly miss common forms like "(env:prod)" and "-env:prod";
update _ENV_RE so it matches "env:" when preceded by start-of-string,
whitespace, a parenthesis, or a negative sign (e.g., account for "(" and "-"
before "env"), then keep has_env_filter(query: str) returning
bool(_ENV_RE.search(query)) so Line 209–210 won't append a duplicate env:
filter.

---

Nitpick comments:
In `@cla-backend-go/telemetry/datadog_otlp.go`:
- Line 194: The code calls reNumericID.ReplaceAllString twice in a row on
variable p (the second call repeating the exact substitution), so remove the
redundant second invocation — keep only a single p =
reNumericID.ReplaceAllString(p, "/{id}$1") call (where p and reNumericID are
used) to eliminate the no-op duplicate and reduce maintenance noise.

In `@cla-backend/cla/routes.py`:
- Line 111: Remove the redundant second substitution call that applies the
numeric-ID regex to p; the line invoking _RE_NUMERIC_ID.sub(r"/{id}\1", p) is a
duplicate of the previous line and should be deleted so only the first
substitution on variable p remains (search for the two consecutive calls to
_RE_NUMERIC_ID.sub in the function/class that builds p and remove the latter).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 831c09ce-3d8a-4023-b1ad-2fa7f8e6df39

📥 Commits

Reviewing files that changed from the base of the PR and between f34a386 and fceb9db.

📒 Files selected for processing (4)
  • cla-backend-go/telemetry/datadog_otlp.go
  • cla-backend/cla/routes.py
  • utils/otel_dd/api_usage_stats_ddog.py
  • utils/otel_dd/check_spans_in_ddog.sh

Signed-off-by: Lukasz Gryglicki <lgryglicki@cncf.io>

Assisted by [OpenAI](https://platform.openai.com/)

Assisted by [GitHub Copilot](https://github.com/features/copilot)
Signed-off-by: Lukasz Gryglicki <lgryglicki@cncf.io>

Assisted by [OpenAI](https://platform.openai.com/)

Assisted by [GitHub Copilot](https://github.com/features/copilot)
Signed-off-by: Lukasz Gryglicki <lgryglicki@cncf.io>

Assisted by [OpenAI](https://platform.openai.com/)

Assisted by [GitHub Copilot](https://github.com/features/copilot)
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

♻️ Duplicate comments (1)
utils/otel_dd/api_usage_stats_ddog.py (1)

39-42: ⚠️ Potential issue | 🟠 Major

Env-filter detection misses common Datadog query forms.

The regex r"(^|\s)env\s*:" only matches env: at string start or after whitespace. Common query patterns like (env:prod) or -env:prod won't be detected, causing the code at Lines 212-213 to append a duplicate env: filter unexpectedly.

🐛 Proposed fix to broaden the pattern
-_ENV_RE = re.compile(r"(^|\s)env\s*:")
+_ENV_RE = re.compile(r"(?:^|[\s(\-])env\s*:", re.IGNORECASE)

This matches env: when preceded by start-of-string, whitespace, opening parenthesis, or hyphen (negation).

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@utils/otel_dd/api_usage_stats_ddog.py` around lines 39 - 42, The current
env-detection regex `_ENV_RE = re.compile(r"(^|\s)env\s*:")` in function
`has_env_filter` misses forms like `(env:prod)` or `-env:prod`; update the
pattern to treat start-of-string OR any of whitespace, opening parenthesis, or
hyphen as valid preceders (e.g. use a character class like
`(^|[\s\(\-])env\s*:`) so `has_env_filter(query: str)` correctly detects `env:`
when preceded by `(` or `-` as well as whitespace/start.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Duplicate comments:
In `@utils/otel_dd/api_usage_stats_ddog.py`:
- Around line 39-42: The current env-detection regex `_ENV_RE =
re.compile(r"(^|\s)env\s*:")` in function `has_env_filter` misses forms like
`(env:prod)` or `-env:prod`; update the pattern to treat start-of-string OR any
of whitespace, opening parenthesis, or hyphen as valid preceders (e.g. use a
character class like `(^|[\s\(\-])env\s*:`) so `has_env_filter(query: str)`
correctly detects `env:` when preceded by `(` or `-` as well as
whitespace/start.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 0308d40c-fc0f-43df-b10d-48cd4c6b0356

📥 Commits

Reviewing files that changed from the base of the PR and between fceb9db and f7730ba.

📒 Files selected for processing (2)
  • cla-backend/cla/tests/unit/test_jwt_auth.py
  • utils/otel_dd/api_usage_stats_ddog.py
✅ Files skipped from review due to trivial changes (1)
  • cla-backend/cla/tests/unit/test_jwt_auth.py

@lukaszgryglicki lukaszgryglicki merged commit d2a1611 into dev Mar 5, 2026
4 checks passed
@lukaszgryglicki lukaszgryglicki deleted the unicron-add-stage-filter-to-ddog-scan-tools branch March 5, 2026 10:34
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.

3 participants