API Response Test: direct unit tests for app/services/datadog/client.py#1104
Conversation
Greptile SummaryThis PR adds dedicated service-layer unit tests for Confidence Score: 5/5Safe to merge — all findings are P2 style and completeness suggestions with no blocking correctness issues. The mock wiring is technically correct for both sync and async clients, tests cover success/error/empty paths and is_configured edge cases, and no production code is changed. All feedback is P2 (missing raise_for_status assertions, incomplete error leg coverage in one async test, leftover debug comments). No files require special attention; improvements are optional polish. Important Files Changed
Sequence DiagramsequenceDiagram
participant Test
participant DatadogClient
participant _get_client
participant httpx_Client_mock
Note over Test,httpx_Client_mock: Synchronous client tests
Test->>DatadogClient: search_logs("error")
DatadogClient->>_get_client: _get_client()
_get_client->>httpx_Client_mock: httpx.Client(base_url, headers, timeout)
httpx_Client_mock-->>_get_client: mock_instance (cached)
_get_client-->>DatadogClient: mock_instance
DatadogClient->>httpx_Client_mock: mock_instance.post("/api/v2/logs/events/search")
httpx_Client_mock-->>DatadogClient: mock_response
DatadogClient->>DatadogClient: resp.raise_for_status()
DatadogClient->>DatadogClient: data = resp.json()
DatadogClient-->>Test: {success: True, logs: [...], total: N}
Note over Test,httpx_Client_mock: Async client tests (fetch_all)
Test->>DatadogAsyncClient: fetch_all(logs_query, monitor_query, events_query)
DatadogAsyncClient->>httpx_Client_mock: async with httpx.AsyncClient(...) as client
par asyncio.gather
DatadogAsyncClient->>httpx_Client_mock: client.post("/api/v2/logs/events/search")
DatadogAsyncClient->>httpx_Client_mock: client.get("/api/v1/monitor")
DatadogAsyncClient->>httpx_Client_mock: client.post("/api/v2/events/search")
end
DatadogAsyncClient-->>Test: {logs: {...}, monitors: {...}, events: {...}}
Reviews (1): Last reviewed commit: "api test" | Re-trigger Greptile |
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
…/SB2318/opensre into client_service_api_response_test
|
@yashksaini-coder please review |
|
🏄 Some PRs rot in review for six weeks. @SB2318's said "not today" and merged like it owned the place. 🌊 👋 Join us on Discord - OpenSRE : hang out, contribute, or hunt for features and issues. Everyone's welcome. |

Fixes #878
Describe the changes you have made in this PR -
Added a dedicated service-layer test suite for the
DatadogClientintegration to ensure direct coverage of core Datadog API interactions without relying on tool-layer tests.Key changes:
tests/services/test_datadog_client.pysearch_logs()(success, HTTP failure, empty response)list_monitors()(success, HTTP failure, empty response)get_events()(success, HTTP failure, empty response)is_configuredvalidationhttpx.Clientto ensure no real Datadog API calls are madeDemo/Screenshot for feature changes and bug fixes -
Code Understanding and AI Usage
Did you use AI assistance (ChatGPT, Claude, Copilot, etc.) to write any part of this code?
If you used AI assistance:
Explain your implementation approach:
This PR introduces service-level testing for the Datadog integration to improve test isolation, reliability, and maintainability.
Previously, Datadog client behavior was only indirectly validated through tool-layer tests. This created tight coupling between layers and made failures harder to trace and debug.
What this solves:
Implementation approach:
httpx.Clientmocking to simulate Datadog API responses without making real network callssearch_logs)list_monitors)get_events)is_configuredKey design choice:
I chose service-layer mocking instead of integration testing to ensure:
This approach ensures that the Datadog client is independently verifiable and does not rely on higher-level tool tests for correctness.
This helps reviewers understand your thought process and ensures you understand the code.
-->
Checklist before requesting a review
Note: Please check Allow edits from maintainers if you would like us to assist in the PR.