Skip to content

test(tracing): add control plane sources attributes tests#923

Merged
crstrn13 merged 17 commits into
mainfrom
issues/919
Jul 7, 2026
Merged

test(tracing): add control plane sources attributes tests#923
crstrn13 merged 17 commits into
mainfrom
issues/919

Conversation

@crstrn13

@crstrn13 crstrn13 commented Apr 7, 2026

Copy link
Copy Markdown
Contributor

Description

Adds test coverage for control plane tracing sources attributes (issue #919). These attributes link policy reconciliation spans to the policies that triggered them. Also fixes timing-related flakiness in existing lifecycle tracing tests when running in fast environments like kind.

Closes #919

Changes

New Tests (test_control_plane_sources.py)

  • test_authconfig_span_attributes: Validates authconfig spans have sources, name, and namespace attributes with correct AuthPolicy references
  • test_limitador_span_attributes: Validates limitador spans have sources, name, and namespace attributes with correct RateLimitPolicy references
  • test_authconfig_span_is_child_of_reconciler: Validates authconfig spans are children of reconciler.auth_configs spans
  • test_authconfig_sources_contains_multiple_policies: Creates a second AuthPolicy targeting the same route and verifies policy references appear in sources
  • test_limitador_sources_contains_multiple_policies: Creates a second RateLimitPolicy targeting the same route and verifies policy references appear in sources

Tracing Client Improvements

  • Added start_time parameter to TracingClient.get_traces(), JaegerClient.get_traces(), and RemoteTempoClient.get_traces() for timestamp-bounded trace queries (microseconds)

Lifecycle Test Fixes (test_control_plane_lifecycle.py)

  • Fixed race conditions in test_policy_update_generates_new_reconciliation_trace and test_policy_target_change_traced by capturing precise timestamps before mutations and using start_time to scope trace queries, instead of relying on snapshot comparison alone

Documentation

  • Added Jaeger tracing access instructions to CLAUDE.md

Verification

poetry run pytest -vv -n4 testsuite/tests/singlecluster/tracing/control_plane/

@coderabbitai

coderabbitai Bot commented Apr 7, 2026

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds documentation for local Jaeger tracing setup, extends get_traces across tracing client implementations (abstract, Jaeger, Tempo) with an optional start_time parameter for microsecond-based filtering, updates existing control-plane lifecycle tracing tests to use timestamp-bounded queries, and introduces a new test module validating sources attribute correctness on authconfig and limitador spans, including multi-policy scenarios.

Changes

Tracing sources support and tests

Layer / File(s) Summary
Local Jaeger tracing setup docs
CLAUDE.md
Documents accessing local Jaeger tracing for control plane and data plane, including endpoint config, UI access, test commands, and how to disable tracing.
get_traces start_time parameter
testsuite/tracing/__init__.py, testsuite/tracing/jaeger.py, testsuite/tracing/tempo.py
Extends get_traces with an optional start_time parameter that adds a start query parameter for microsecond-based trace filtering across the abstract contract, Jaeger client, and Tempo client.
Timestamp-bounded lifecycle tracing tests
testsuite/tests/singlecluster/tracing/control_plane/test_control_plane_lifecycle.py
Updates fixtures to capture microsecond timestamps and return them with the authorization object, and updates tests to query traces with start_time and reference the returned authorization object.
New sources attribute tests
testsuite/tests/singlecluster/tracing/control_plane/test_control_plane_sources.py
Adds a new test module with fixtures locating authconfig and limitador spans with sources tags, verifies span content and parent linkage, and includes multi-policy fixtures/tests asserting sources attribution across two policies.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Possibly related PRs

  • Kuadrant/testsuite#870: Both PRs modify the tracing infrastructure around testsuite.tracing.*.get_traces(...) and related control-plane tracing tests, with this PR building on that earlier refactor by adding start_time filtering.

Suggested labels: infrastructure, documentation

Suggested reviewers: averevki, azgabur

Poem

A rabbit hops through spans and traces,
Timestamps set in all the right places,
Sources now tell which policy led,
Authconfig and limits, clearly read,
Hop, hop, hooray — the tests are laid! 🐇✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Title check ⚠️ Warning The title is relevant and concise, but uses the non-allowed tracing scope instead of an approved Conventional Commit scope. Use an allowed scope or omit it, e.g. test: add control plane sources attribute tests.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The new tests cover authconfig and limitador sources, multiple policies, and span linking, matching #919's acceptance criteria.
Out of Scope Changes check ✅ Passed The documented changes stay focused on tracing test coverage and supporting trace-query timing/documentation.
Docstring Coverage ✅ Passed Docstring coverage is 95.00% which is sufficient. The required threshold is 80.00%.
Description check ✅ Passed The description follows the required template and covers the purpose, main changes, and verification command.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch issues/919

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@crstrn13 crstrn13 self-assigned this Apr 7, 2026
@crstrn13 crstrn13 added this to Kuadrant Apr 7, 2026
@crstrn13 crstrn13 moved this to Ready For Review in Kuadrant Apr 7, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 4

🧹 Nitpick comments (2)
CLAUDE.md (1)

94-101: Consider removing specific test counts to avoid staleness.

The comments mentioning "40 tests" and "10 tests" will become outdated as tests are added or removed. Consider removing these counts or making them more generic.

♻️ Suggested change
 4. **Run tracing tests:**
    ```bash
-   # Control plane tracing tests (40 tests)
+   # Control plane tracing tests
    make testsuite/tests/singlecluster/tracing/control_plane/
    
-   # Data plane tracing tests (10 tests)
+   # Data plane tracing tests
    make testsuite/tests/singlecluster/tracing/data_plane_tracing/
    ```
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@CLAUDE.md` around lines 94 - 101, The documentation comments include
hard-coded test counts ("40 tests" and "10 tests") that can become stale; remove
the numeric counts from the two comment lines above the make commands (the lines
commenting "Control plane tracing tests (40 tests)" and "Data plane tracing
tests (10 tests)") so they read generically as "Control plane tracing tests" and
"Data plane tracing tests" next to the make commands `make
testsuite/tests/singlecluster/tracing/control_plane/` and `make
testsuite/tests/singlecluster/tracing/data_plane_tracing/`.
make/istio.mk (1)

36-36: Consider extracting the long JSON patch for improved maintainability.

This single-line JSON patch is difficult to read and maintain. Additionally, the service name and port (4318) are hardcoded here rather than being derived from $(JAEGER_COLLECTOR_ENDPOINT) defined in make/vars.mk, which could lead to inconsistencies if the endpoint changes.

♻️ Suggested approach: use a heredoc or external file

Consider extracting the patch to a heredoc similar to the Telemetry resource below, or parsing the port from $(JAEGER_COLLECTOR_ENDPOINT):

# Alternative: Store patch in a variable or external file for readability
# The port should ideally match JAEGER_COLLECTOR_ENDPOINT (currently 4318)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@make/istio.mk` at line 36, The kubectl patch command on istio.mk currently
inlines a long JSON and hardcodes jaeger-collector port 4318; extract that JSON
into a heredoc or separate file and reference it from the make target to improve
readability, and derive the Jaeger endpoint/port from the existing
JAEGER_COLLECTOR_ENDPOINT variable (or parse it into host and port) instead of
hardcoding 4318 so the opentelemetry.service value uses the canonical
$(JAEGER_COLLECTOR_ENDPOINT) (and keep $(TOOLS_NAMESPACE) for the service FQDN);
update the istio patch invocation (the kubectl patch line) to read the payload
from the heredoc/file and replace the inline JSON with a reference to that
payload.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In
`@testsuite/tests/singlecluster/tracing/control_plane/test_control_plane_sources.py`:
- Around line 19-28: The fixtures (e.g., authconfig_trace, limitador_trace,
authconfig_trace_multiple_policies, limitador_trace_multiple_policies) sometimes
call skip_or_fail(...) which raises but pylint can't see that, causing
inconsistent-return-statements; after each skip_or_fail(...) call add an
explicit "return None" so every control path returns a value and the pylint
warning is silenced.
- Around line 246-249: The file ends without a trailing newline which breaks the
CI formatter; add a final newline to the end of the file (after the assert
block) so the file ends with a newline character, then run the formatter (make
reformat or poetry run black) to ensure consistent styling; locate the assert
that references found, first_policy_ref, second_policy_ref and
spans_with_sources and append the missing newline to that file.

In `@testsuite/tracing/jaeger.py`:
- Around line 62-63: The params dict in testsuite/tracing/jaeger.py expects
string values but start_time is an int, so before assigning to params["start"]
convert start_time to a string using Python's str() and then assign; update the
assignment near the conditional that checks start_time to set params["start"] to
the stringified start_time.

In `@testsuite/tracing/tempo.py`:
- Around line 30-31: The params dict in testsuite/tracing/tempo.py is getting an
int start_time assigned (params["start"] = start_time) which causes a type
mismatch; convert start_time to a string before assigning (e.g.,
str(start_time)) so params holds string values like in JaegerClient, updating
the assignment where params["start"] is set and ensuring any related uses expect
a string.

---

Nitpick comments:
In `@CLAUDE.md`:
- Around line 94-101: The documentation comments include hard-coded test counts
("40 tests" and "10 tests") that can become stale; remove the numeric counts
from the two comment lines above the make commands (the lines commenting
"Control plane tracing tests (40 tests)" and "Data plane tracing tests (10
tests)") so they read generically as "Control plane tracing tests" and "Data
plane tracing tests" next to the make commands `make
testsuite/tests/singlecluster/tracing/control_plane/` and `make
testsuite/tests/singlecluster/tracing/data_plane_tracing/`.

In `@make/istio.mk`:
- Line 36: The kubectl patch command on istio.mk currently inlines a long JSON
and hardcodes jaeger-collector port 4318; extract that JSON into a heredoc or
separate file and reference it from the make target to improve readability, and
derive the Jaeger endpoint/port from the existing JAEGER_COLLECTOR_ENDPOINT
variable (or parse it into host and port) instead of hardcoding 4318 so the
opentelemetry.service value uses the canonical $(JAEGER_COLLECTOR_ENDPOINT) (and
keep $(TOOLS_NAMESPACE) for the service FQDN); update the istio patch invocation
(the kubectl patch line) to read the payload from the heredoc/file and replace
the inline JSON with a reference to that payload.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 2d1b4c2e-e087-4989-831e-6ab5163efd47

📥 Commits

Reviewing files that changed from the base of the PR and between d6450a3 and cef128b.

📒 Files selected for processing (13)
  • CLAUDE.md
  • config/settings.local.yaml.tpl
  • make/istio.mk
  • make/kuadrant.mk
  • make/local-setup.mk
  • make/tools.mk
  • make/vars.mk
  • testsuite/config/__init__.py
  • testsuite/tests/singlecluster/tracing/control_plane/test_control_plane_lifecycle.py
  • testsuite/tests/singlecluster/tracing/control_plane/test_control_plane_sources.py
  • testsuite/tracing/__init__.py
  • testsuite/tracing/jaeger.py
  • testsuite/tracing/tempo.py

Comment thread testsuite/tests/singlecluster/tracing/control_plane/test_control_plane_sources.py Outdated
Comment thread testsuite/tracing/jaeger.py Outdated
Comment thread testsuite/tracing/tempo.py Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Nitpick comments (1)
testsuite/tests/singlecluster/tracing/control_plane/test_control_plane_sources.py (1)

109-110: Consider autouse=True for policy setup fixtures to align with test fixture standard.

Both policy-creation fixtures already use finalisers correctly; adding autouse=True would align them with the repository fixture pattern and reduce per-test wiring.

As per coding guidelines: "Use autouse=True and request.addfinalizer() in fixture setup to automatically commit policies before tests and ensure cleanup after tests complete".

Also applies to: 183-184

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

In
`@testsuite/tests/singlecluster/tracing/control_plane/test_control_plane_sources.py`
around lines 109 - 110, The fixture second_auth_policy (and other
policy-creation fixtures) should be made autouse to follow repo conventions:
change the `@pytest.fixture`(...) decorator to include autouse=True, ensure the
setup still commits the policy during fixture setup, and keep the existing
cleanup registered via request.addfinalizer so the policy is removed after each
test; apply the same change to the other policy-creation fixture(s) referenced
in the review.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In
`@testsuite/tests/singlecluster/tracing/control_plane/test_control_plane_sources.py`:
- Around line 214-219: The test currently accepts a trace when either
first_policy_ref or second_policy_ref is present; change the conditional that
checks sources (the one using first_policy_ref and second_policy_ref) to require
both references (use logical AND instead of OR) so it only returns trace when
both first_policy_ref and second_policy_ref are in sources, and apply the same
change to the second occurrence of the same check (the other block that
currently uses OR before calling skip_or_fail).
- Around line 140-146: The test currently accepts a trace if either policy ref
appears in the trace's sources; change that to require both policies so the test
validates multiple-policy propagation: in the block that checks "if sources and
(first_policy_ref in sources or second_policy_ref in sources)" replace the
logical OR with AND (or equivalently assert both first_policy_ref and
second_policy_ref are in sources) so the function returns the trace only when
both are present; make the same change in the second occurrence that mirrors
lines ~173-180 so both checks require both refs, keeping the surrounding use of
variables first_policy_ref, second_policy_ref, sources, trace and the
skip_or_fail behavior unchanged.
- Line 73: The filter on limitador_trace currently picks any span with the
"sources" tag and may match unrelated spans; update the lambda used in
limitador_trace.filter_spans(...) so it only returns spans that both
have_tag("sources") and whose operation_name == "limits" (e.g., change lambda s:
s.has_tag("sources") to lambda s: s.has_tag("sources") and s.operation_name ==
"limits") where limitador_span is selected (also apply the same change to the
other two occurrences that assert on limitador spans).

---

Nitpick comments:
In
`@testsuite/tests/singlecluster/tracing/control_plane/test_control_plane_sources.py`:
- Around line 109-110: The fixture second_auth_policy (and other policy-creation
fixtures) should be made autouse to follow repo conventions: change the
`@pytest.fixture`(...) decorator to include autouse=True, ensure the setup still
commits the policy during fixture setup, and keep the existing cleanup
registered via request.addfinalizer so the policy is removed after each test;
apply the same change to the other policy-creation fixture(s) referenced in the
review.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 8052dbb5-42c2-49d2-b5ff-474d0298205b

📥 Commits

Reviewing files that changed from the base of the PR and between cef128b and e25f033.

📒 Files selected for processing (1)
  • testsuite/tests/singlecluster/tracing/control_plane/test_control_plane_sources.py

Comment thread testsuite/tests/singlecluster/tracing/control_plane/test_control_plane_sources.py Outdated
Comment thread testsuite/tests/singlecluster/tracing/control_plane/test_control_plane_sources.py Outdated
Comment thread testsuite/tests/singlecluster/tracing/control_plane/test_control_plane_sources.py Outdated
@crstrn13 crstrn13 marked this pull request as draft April 23, 2026 08:31
@crstrn13 crstrn13 added the test case New test case label Apr 24, 2026
@crstrn13 crstrn13 marked this pull request as ready for review July 2, 2026 09:12

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@testsuite/tracing/jaeger.py`:
- Around line 54-55: The Jaeger trace query builder is dropping an explicit zero
timestamp because `start_time` is checked with a truthy condition. Update the
`get_traces`/query-parameter construction in `testsuite/tracing/jaeger.py` to
use an explicit `start_time is not None` check before setting `params["start"]`,
so `0` is preserved as a valid `start` value.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: a0415ee1-97d0-4b46-afe5-87ce8cc21310

📥 Commits

Reviewing files that changed from the base of the PR and between bb94042 and a8bd064.

📒 Files selected for processing (6)
  • CLAUDE.md
  • testsuite/tests/singlecluster/tracing/control_plane/test_control_plane_lifecycle.py
  • testsuite/tests/singlecluster/tracing/control_plane/test_control_plane_sources.py
  • testsuite/tracing/__init__.py
  • testsuite/tracing/jaeger.py
  • testsuite/tracing/tempo.py
✅ Files skipped from review due to trivial changes (1)
  • testsuite/tracing/tempo.py
🚧 Files skipped from review as they are similar to previous changes (3)
  • testsuite/tracing/init.py
  • testsuite/tests/singlecluster/tracing/control_plane/test_control_plane_lifecycle.py
  • testsuite/tests/singlecluster/tracing/control_plane/test_control_plane_sources.py

Comment thread testsuite/tracing/jaeger.py Outdated
Comment thread CLAUDE.md Outdated
Comment thread testsuite/tests/singlecluster/tracing/control_plane/test_control_plane_sources.py Outdated
Comment thread testsuite/tests/singlecluster/tracing/control_plane/test_control_plane_sources.py Outdated
Comment thread testsuite/tests/singlecluster/tracing/control_plane/test_control_plane_sources.py Outdated
Comment thread testsuite/tests/singlecluster/tracing/control_plane/test_control_plane_sources.py Outdated
crstrn13 added 16 commits July 3, 2026 16:00
Signed-off-by: Alexander Cristurean <acristur@redhat.com>

# Conflicts:
#	config/settings.local.yaml.tpl
#	make/istio.mk
#	make/local-setup.mk
#	make/vars.mk
Signed-off-by: Alexander Cristurean <acristur@redhat.com>
Signed-off-by: Alexander Cristurean <acristur@redhat.com>
Signed-off-by: Alexander Cristurean <acristur@redhat.com>
Signed-off-by: Alexander Cristurean <acristur@redhat.com>
Signed-off-by: Alexander Cristurean <acristur@redhat.com>
Signed-off-by: Alexander Cristurean <acristur@redhat.com>
Signed-off-by: Alexander Cristurean <acristur@redhat.com>
Signed-off-by: Alexander Cristurean <acristur@redhat.com>
Signed-off-by: Alexander Cristurean <acristur@redhat.com>
Signed-off-by: Alexander Cristurean <acristur@redhat.com>
Signed-off-by: Alexander Cristurean <acristur@redhat.com>
Signed-off-by: Alexander Cristurean <acristur@redhat.com>
Signed-off-by: Alexander Cristurean <acristur@redhat.com>
Signed-off-by: Alexander Cristurean <acristur@redhat.com>
…tions

The second policy's trace may not be indexed yet when get_traces() returns
(backoff only retries on empty results, not on missing specific spans).
Split into unscoped query for first policy and time-scoped query for second
policy so the backoff retry kicks in until the second trace appears.

Signed-off-by: Alexander Cristurean <acristur@redhat.com>
@crstrn13 crstrn13 requested review from a team and silvi-t July 3, 2026 14:01
Signed-off-by: Alexander Cristurean <acristur@redhat.com>

@silvi-t silvi-t left a comment

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.

LGTM

@crstrn13 crstrn13 merged commit ccce99e into main Jul 7, 2026
6 checks passed
@github-project-automation github-project-automation Bot moved this from Ready For Review to Done in Kuadrant Jul 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

test case New test case

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Add tests for control plane tracing: source policies attributes

2 participants