Fix Tempo tracing field name and null data handling in API response#1337
Conversation
…ing' Signed-off-by: Sandeep20013 <sandeepm20013@gmail.com>
Signed-off-by: Sandeep20013 <sandeepm20013@gmail.com>
|
The following are automatically added/executed:
Available user actions:
Supported labels{'/lgtm', '/wip', '/build-push-pr-image', '/cherry-pick', '/verified', '/hold'} |
📝 WalkthroughWalkthroughTwo test files updated: Changes
Security notes (actionable):
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes 🚥 Pre-merge checks | ✅ 2✅ Passed checks (2 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.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
tests/model_explainability/guardrails/test_guardrails.py (1)
390-403:⚠️ Potential issue | 🟠 MajorAdd explicit HTTP timeouts (CWE-400) and handle transient request failures to allow retries.
Lines 392 and 399 call
requests.get()withouttimeout, risking indefinite hangs and resource exhaustion during polling. More critically, unhandledrequests.RequestExceptionand JSON decode errors will propagate immediately instead of triggering the@retrymechanism—the decorator only retries onFalsereturns, not exceptions. Without try-except blocks, any network or parsing failure breaks the retry loop entirely.Suggested fix
`@retry`(wait_timeout=Timeout.TIMEOUT_1MIN, sleep=5) def check_traces(): - services = requests.get(f"{tempo_traces_service_portforward}/api/services").json().get("data") or [] + try: + services_resp = requests.get( + f"{tempo_traces_service_portforward}/api/services", + timeout=10, + ) + services_resp.raise_for_status() + services = services_resp.json().get("data") or [] + except (requests.RequestException, ValueError): + return False guardrails_services = [s for s in services if "guardrails" in s] if not guardrails_services: return False svc = guardrails_services[0] - traces = requests.get(f"{tempo_traces_service_portforward}/api/traces?service={svc}").json() + try: + traces_resp = requests.get( + f"{tempo_traces_service_portforward}/api/traces?service={svc}", + timeout=10, + ) + traces_resp.raise_for_status() + traces = traces_resp.json() + except (requests.RequestException, ValueError): + return False if traces.get("data"): return traces🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@tests/model_explainability/guardrails/test_guardrails.py` around lines 390 - 403, The check_traces() helper currently calls requests.get(...) and .json() without timeouts or error handling; wrap each HTTP call in try/except catching requests.RequestException and ValueError/JSONDecodeError, pass a sensible timeout (e.g., timeout=10) to requests.get, check response.status_code before .json(), and on any exception or non-2xx status return False so the `@retry` decorator can retry; update references inside check_traces() where requests.get() is called (including the services and traces requests) to use this pattern.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Outside diff comments:
In `@tests/model_explainability/guardrails/test_guardrails.py`:
- Around line 390-403: The check_traces() helper currently calls
requests.get(...) and .json() without timeouts or error handling; wrap each HTTP
call in try/except catching requests.RequestException and
ValueError/JSONDecodeError, pass a sensible timeout (e.g., timeout=10) to
requests.get, check response.status_code before .json(), and on any exception or
non-2xx status return False so the `@retry` decorator can retry; update references
inside check_traces() where requests.get() is called (including the services and
traces requests) to use this pattern.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository YAML (base), Central YAML (inherited), Organization UI (inherited)
Review profile: CHILL
Plan: Pro
Run ID: 137690ea-37de-4e76-83ca-817b40385e5c
📒 Files selected for processing (2)
tests/fixtures/guardrails.pytests/model_explainability/guardrails/test_guardrails.py
dbasunag
left a comment
There was a problem hiding this comment.
Please fix the PR title.
kpunwatk
left a comment
There was a problem hiding this comment.
/lgtm, Thanks for the fix @Sandeep20013
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@tests/model_explainability/guardrails/test_guardrails.py`:
- Line 393: The requests.get() calls fetching Tempo data (e.g., the call that
assigns services =
requests.get(f"{tempo_traces_service_portforward}/api/services").json().get("data")
or []) must include an explicit timeout and an HTTP status check to avoid
hanging the retry loop (Timeout.TIMEOUT_1MIN); update those calls in
tests/model_explainability/guardrails/test_guardrails.py to pass a timeout
(e.g., timeout=5) to requests.get and call response.raise_for_status() or check
response.status_code before calling .json(), and handle/raise a clear exception
so the retry logic can proceed instead of blocking.
🪄 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: Repository YAML (base), Central YAML (inherited), Organization UI (inherited)
Review profile: CHILL
Plan: Pro
Run ID: ae9a5d7d-ca60-485a-9c6c-1ed80045fad0
📒 Files selected for processing (1)
tests/model_explainability/guardrails/test_guardrails.py
|
Status of building tag latest: success. |
…pendatahub-io#1337) * fix: use correct CRD field name 'enableTraces' instead of 'enableTracing' Signed-off-by: Sandeep20013 <sandeepm20013@gmail.com> * fix: handle null response from Tempo services API Signed-off-by: Sandeep20013 <sandeepm20013@gmail.com> --------- Signed-off-by: Sandeep20013 <sandeepm20013@gmail.com> Co-authored-by: Karishma Punwatkar <kpunwatk@redhat.com>
Pull Request
Summary
Fix two issues related to Tempo tracing and API handling:
.get("data", []). However, when the API returns"data": null, this caused runtime issues. Updated logic to useor []so it safely falls back to an empty list.Related Issues
Please review and indicate how it has been tested
Summary by CodeRabbit