refactor: replace magic numbers with named constants#980
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (26)
✅ Files skipped from review due to trivial changes (3)
🚧 Files skipped from review as they are similar to previous changes (20)
📝 WalkthroughWalkthroughThis pull request adds a centralized constants module ChangesConfiguration Constants Centralisation
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)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Tip 💬 Introducing Slack Agent: The best way for teams to turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. 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
🤖 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/utils/constants.py`:
- Line 72: Replace the ambiguous Unicode MULTIPLICATION SIGN in the comment
"SpiceDB relationship readiness retry (5s × 3)" with an ASCII character such as
lowercase 'x' or '*' so the comment reads e.g. "SpiceDB relationship readiness
retry (5s x 3)" to avoid non-ASCII punctuation; update that exact comment string
in testsuite/utils/constants.py.
🪄 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: 36495775-e0da-4fdc-9a7f-d73cc5faad80
📒 Files selected for processing (25)
testsuite/backend/__init__.pytestsuite/backend/httpbin.pytestsuite/backend/llm_sim.pytestsuite/backend/mockserver.pytestsuite/config/__init__.pytestsuite/gateway/envoy/__init__.pytestsuite/gateway/gateway_api/gateway.pytestsuite/gateway/gateway_api/grpc_route.pytestsuite/gateway/gateway_api/route.pytestsuite/grpc/__init__.pytestsuite/httpx/__init__.pytestsuite/kuadrant/extensions/oidc_policy.pytestsuite/kuadrant/policy/__init__.pytestsuite/kuadrant/policy/dns.pytestsuite/kuadrant/policy/rate_limit.pytestsuite/kuadrant/policy/tls.pytestsuite/kubernetes/__init__.pytestsuite/kubernetes/deployment.pytestsuite/kubernetes/service.pytestsuite/prometheus.pytestsuite/spicedb/spicedb.pytestsuite/tracing/jaeger.pytestsuite/tracing/tempo.pytestsuite/utils/__init__.pytestsuite/utils/constants.py
ceddf01 to
1881f2b
Compare
There was a problem hiding this comment.
Great progress on this issue!
I know this PR focused on infrastructure modules, but if you're interested in tackling test files as a follow-up (whether it be this or another PR) here are the remaining magic numbers:
Test files with time.sleep() calls:
testsuite/tests/singlecluster/gateway/scaling/test_manual_scale_gateway.pytestsuite/tests/singlecluster/gateway/scaling/test_auto_scale_gateway.pytestsuite/tests/singlecluster/grpc/test_grpcroute.pytestsuite/tests/singlecluster/gateway/reconciliation/change_targetref/test_update_tlspolicy_target_ref.pytestsuite/tests/singlecluster/gateway/reconciliation/change_targetref/conftest.pytestsuite/tests/singlecluster/authorino/identity/x509/gateway_validation/test_multi_ca_trust.pytestsuite/tests/singlecluster/authorino/identity/plain/test_jwt_user_story.py
Test files with direct sleep() calls:
testsuite/tests/singlecluster/identical_hostnames/rlp/test_rlp_on_routes.pytestsuite/tests/singlecluster/identical_hostnames/rlp/test_rlp_on_gw_and_route.pytestsuite/tests/singlecluster/limitador/test_multiple_iterations.pytestsuite/tests/singlecluster/limitador/tokens_rate_limit/basic/test_trlp_streaming.pytestsuite/tests/singlecluster/limitador/tokens_rate_limit/basic/test_trlp.pytestsuite/tests/singlecluster/limitador/tokens_rate_limit/multiple_iterations/test_multiple_trlp_iterations.pytestsuite/tests/singlecluster/limitador/tokens_rate_limit/multiple_iterations/test_multiple_trlp_stream_iterations.pytestsuite/tests/singlecluster/egress/test_egress.pytestsuite/tests/singlecluster/authorino/authorization/opa/external_registry/test_cache.pytestsuite/tests/multicluster/load_balanced/test_change_default_geo.pytestsuite/tests/multicluster/load_balanced/test_change_strategy.py
Test files with hardcoded timeout/timelimit values:
testsuite/tests/singlecluster/gateway/dnspolicy/health_check/test_remove_endpoint.pytestsuite/tests/singlecluster/gateway/reconciliation/change_targetref/conftest.pytestsuite/tests/singlecluster/gateway/reconciliation/test_gw_doesnt_exist.pytestsuite/tests/singlecluster/gateway/reconciliation/test_invalid_issuer_reference.pytestsuite/tests/singlecluster/gateway/reconciliation/test_same_target.pytestsuite/tests/singlecluster/tracing/control_plane/test_control_plane_errors.pytestsuite/tests/singlecluster/tracing/control_plane/test_control_plane_lifecycle.py
Test files with hardcoded backoff/retry configs:
testsuite/tests/singlecluster/observability/conftest.py
Test fixtures with hardcoded ports:
testsuite/tests/singlecluster/egress/credentials_injection/conftest.pytestsuite/tests/singlecluster/authorino/wristband/conftest.pytestsuite/tests/singlecluster/gateway/dnspolicy/health_check/test_additional_headers.py
Also left 2 nitpick comments.
|
Thanks for working on this! It would also be great if this PR included a short section in the contributing docs (e.g. |
Signed-off-by: Priyanshu-u07 <connect.priyanshu8271@gmail.com>
1881f2b to
73bb0ac
Compare
|
@emmaaroche, @silvi-t, I've addressed the nitpick comments and also added a "Using Constants" section to Thanks Emma for the review and for pointing out the test files. |
emmaaroche
left a comment
There was a problem hiding this comment.
Nice work, LGTM! Please wait for a 2nd reviewer to approve before merging as this PR touches shared infrastructure files 👍
Description
Replaces all hardcoded magic numbers across the infrastructure modules with named constants from a single centralized file.
Part of #930
Changes
New file
testsuite/utils/constants.py: Central module with multiples named constants organized by domain (Kubernetes, Policy, Prometheus, SpiceDB, Envoy, etc.)File Rename
testsuite/utils.pytotestsuite/utils/__init__.py: Converted to a package to support the newconstants.pysubmodule. No code changes and all existing imports unaffected.Fix
config/__init__.py: There were twoDefaultValueValidator("mockserver.url", ...)entries.Refactored Files(23)
Files
testsuite/backend/__init__.pytestsuite/backend/httpbin.pytestsuite/backend/llm_sim.pytestsuite/backend/mockserver.pytestsuite/config/__init__.pytestsuite/gateway/envoy/__init__.pytestsuite/gateway/gateway_api/gateway.pytestsuite/gateway/gateway_api/grpc_route.pytestsuite/gateway/gateway_api/route.pytestsuite/grpc/__init__.pytestsuite/httpx/__init__.pytestsuite/kuadrant/extensions/oidc_policy.pytestsuite/kuadrant/policy/__init__.pytestsuite/kuadrant/policy/dns.pytestsuite/kuadrant/policy/rate_limit.pytestsuite/kuadrant/policy/tls.pytestsuite/kubernetes/__init__.pytestsuite/kubernetes/deployment.pytestsuite/kubernetes/service.pytestsuite/prometheus.pytestsuite/spicedb/spicedb.pytestsuite/tracing/jaeger.pytestsuite/tracing/tempo.pyVerification
make reformat: Passedmake commit-acceptance: PassedSummary by CodeRabbit
Chores
Documentation