test(tracing): add control plane sources attributes tests#923
Conversation
|
Note Reviews pausedIt 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 Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughAdds documentation for local Jaeger tracing setup, extends ChangesTracing sources support and tests
Estimated code review effort: 3 (Moderate) | ~25 minutes Possibly related PRs
Suggested labels: Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
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 inmake/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
📒 Files selected for processing (13)
CLAUDE.mdconfig/settings.local.yaml.tplmake/istio.mkmake/kuadrant.mkmake/local-setup.mkmake/tools.mkmake/vars.mktestsuite/config/__init__.pytestsuite/tests/singlecluster/tracing/control_plane/test_control_plane_lifecycle.pytestsuite/tests/singlecluster/tracing/control_plane/test_control_plane_sources.pytestsuite/tracing/__init__.pytestsuite/tracing/jaeger.pytestsuite/tracing/tempo.py
There was a problem hiding this comment.
Actionable comments posted: 3
🧹 Nitpick comments (1)
testsuite/tests/singlecluster/tracing/control_plane/test_control_plane_sources.py (1)
109-110: Considerautouse=Truefor policy setup fixtures to align with test fixture standard.Both policy-creation fixtures already use finalisers correctly; adding
autouse=Truewould align them with the repository fixture pattern and reduce per-test wiring.As per coding guidelines: "Use
autouse=Trueandrequest.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
📒 Files selected for processing (1)
testsuite/tests/singlecluster/tracing/control_plane/test_control_plane_sources.py
There was a problem hiding this comment.
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
📒 Files selected for processing (6)
CLAUDE.mdtestsuite/tests/singlecluster/tracing/control_plane/test_control_plane_lifecycle.pytestsuite/tests/singlecluster/tracing/control_plane/test_control_plane_sources.pytestsuite/tracing/__init__.pytestsuite/tracing/jaeger.pytestsuite/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
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>
Signed-off-by: Alexander Cristurean <acristur@redhat.com>
Description
Adds test coverage for control plane tracing
sourcesattributes (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 havesources,name, andnamespaceattributes with correct AuthPolicy referencestest_limitador_span_attributes: Validates limitador spans havesources,name, andnamespaceattributes with correct RateLimitPolicy referencestest_authconfig_span_is_child_of_reconciler: Validates authconfig spans are children ofreconciler.auth_configsspanstest_authconfig_sources_contains_multiple_policies: Creates a second AuthPolicy targeting the same route and verifies policy references appear in sourcestest_limitador_sources_contains_multiple_policies: Creates a second RateLimitPolicy targeting the same route and verifies policy references appear in sourcesTracing Client Improvements
start_timeparameter toTracingClient.get_traces(),JaegerClient.get_traces(), andRemoteTempoClient.get_traces()for timestamp-bounded trace queries (microseconds)Lifecycle Test Fixes (
test_control_plane_lifecycle.py)test_policy_update_generates_new_reconciliation_traceandtest_policy_target_change_tracedby capturing precise timestamps before mutations and usingstart_timeto scope trace queries, instead of relying on snapshot comparison aloneDocumentation
CLAUDE.mdVerification