refactor(test): update data plane tracing tests#1008
Conversation
📝 WalkthroughWalkthroughThe tracing tests now validate policy-source spans with action-aware filtering, add ratelimit tag checks for limited and limit-name values, and assert a more detailed span hierarchy using a new direct-child helper. ChangesTracing span assertions
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related issues
Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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: 1
🧹 Nitpick comments (2)
testsuite/tests/singlecluster/tracing/data_plane_tracing/test_kuadrant_tracing.py (2)
206-213: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick winMake
assert_childdeterministic for duplicate matches.
assert_childcurrently returns the first match, which can hide ambiguous span structures; assert a single match to avoid order-dependent flakiness.Proposed refactor
def assert_child(trace, parent_span, child_op, **tags): """Assert that parent_span has a direct child with the given operation name and tags. Returns the child span.""" children = trace.get_children(parent_span.span_id) matches = [c for c in children if c.operation_name == child_op] for key, value in tags.items(): matches = [c for c in matches if c.has_tag(key, value)] - assert matches, f"No '{child_op}' child of '{parent_span.operation_name}' found (tags={tags})" + assert matches, f"No '{child_op}' child of '{parent_span.operation_name}' found (tags={tags})" + assert len(matches) == 1, ( + f"Expected exactly one '{child_op}' child of '{parent_span.operation_name}' " + f"(tags={tags}), found {len(matches)}" + ) return matches[0]🤖 Prompt for 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. In `@testsuite/tests/singlecluster/tracing/data_plane_tracing/test_kuadrant_tracing.py` around lines 206 - 213, assert_child currently returns the first matching child span, which can be order-dependent when multiple spans match the same operation and tags. Update assert_child in test_kuadrant_tracing.py to verify there is exactly one matching child after filtering by child_op and tags, and fail if there are zero or multiple matches. Keep the existing helper signature and locate the logic in assert_child using trace.get_children and the matches filtering.
195-203: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAvoid hard-coding the expected
ratelimit.limit_name.At Line 201,
"testuser"is brittle; derive it from the policy fixture/config so this test stays aligned with fixture changes.🤖 Prompt for 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. In `@testsuite/tests/singlecluster/tracing/data_plane_tracing/test_kuadrant_tracing.py` around lines 195 - 203, The test in test_ratelimit_limit_name_tag is hard-coding the expected ratelimit.limit_name value, which makes it brittle. Update the assertion in test_ratelimit_limit_name_tag to derive the expected limit name from the existing policy fixture/config used by trace_429 rather than comparing against the literal "testuser". Keep the span filter on should_rate_limit, but reference the configured limit name from the same source that defines the RateLimitPolicy so the test stays in sync with fixture changes.
🤖 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/tests/singlecluster/tracing/data_plane_tracing/test_kuadrant_tracing.py`:
- Line 224: The kuadrant_filter span lookup is indexing the filtered list
directly, which can raise an IndexError when no matching span exists. Update the
test around trace_200.filter_spans and kuadrant_filter to first assert that the
filtered result is non-empty, then assign the first span so failures are
explicit and easier to diagnose.
---
Nitpick comments:
In
`@testsuite/tests/singlecluster/tracing/data_plane_tracing/test_kuadrant_tracing.py`:
- Around line 206-213: assert_child currently returns the first matching child
span, which can be order-dependent when multiple spans match the same operation
and tags. Update assert_child in test_kuadrant_tracing.py to verify there is
exactly one matching child after filtering by child_op and tags, and fail if
there are zero or multiple matches. Keep the existing helper signature and
locate the logic in assert_child using trace.get_children and the matches
filtering.
- Around line 195-203: The test in test_ratelimit_limit_name_tag is hard-coding
the expected ratelimit.limit_name value, which makes it brittle. Update the
assertion in test_ratelimit_limit_name_tag to derive the expected limit name
from the existing policy fixture/config used by trace_429 rather than comparing
against the literal "testuser". Keep the span filter on should_rate_limit, but
reference the configured limit name from the same source that defines the
RateLimitPolicy so the test stays in sync with fixture changes.
🪄 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: 7892b217-5916-4c68-89fc-438429ad8217
📒 Files selected for processing (1)
testsuite/tests/singlecluster/tracing/data_plane_tracing/test_kuadrant_tracing.py
cf62150 to
155bf37
Compare
Signed-off-by: Silvia Tarabova <starabov@redhat.com>
155bf37 to
4cbcdc4
Compare
PR description:
Description
grpc/grpc_request/grpc_responsenaming scheme, usingactionandgrpc_servicetags to disambiguateratelimit.limitedandratelimit.limit_namespan tagsChanges
Refactoring
test_spans_have_correct_policy_source_references: filter byoperation_name == "grpc"withactiontag instead of old unique operation names (auth/ratelimit)test_span_hierarchy: rewrite from flat dict-based hierarchy to tree-walking withassert_childhelper, usingactionandgrpc_servicetags to distinguishgrpcspansassert_parent_childhelper withassert_childthat walks the tree viaTrace.get_children()and supports tag filteringheadersspan underkuadrant_filterNew Tests
test_ratelimit_limited_tag: verifyratelimit.limitedisFalseon 200 andTrueon 429test_ratelimit_limit_name_tag: verifyratelimit.limit_namematches the configured limit name on 429Verification steps
Requires a cluster with the new wasm-shim (from Kuadrant/wasm-shim#375) deployed and tracing enabled.
Closes #1007
Summary by CodeRabbit