Add integration and unit tests for monitoring JSON API endpoints#373
Add integration and unit tests for monitoring JSON API endpoints#373gimballock wants to merge 3 commits intostratum-mining:mainfrom
Conversation
85a3f7e to
f7f95d2
Compare
f7f95d2 to
f3c2e96
Compare
Shourya742
left a comment
There was a problem hiding this comment.
Shouldn't monitoring module have abstractions for most of these?
f3c2e96 to
1f12145
Compare
|
I think the test failure here is the target of PR #338, once we rebase off of that this failure should go away i think. |
Shourya742
left a comment
There was a problem hiding this comment.
I still dont see any changes requested. Now, we have some random files in the PR
d7dfb76 to
65dd528
Compare
My bad, all those extra files are removed now. |
1f5ce90 to
6ecedf7
Compare
|
Rebased onto main and addressed all review feedback. Summary of changes in the current commit: All review feedback addressed:
Additional cleanup done during rebase:
@Shourya742 if you could take a look when you have a chance |
|
Note:when running the monitoring integration tests sequentially ( |
6ecedf7 to
cf90755
Compare
|
Thanks for investigating. I believe this is pre-existing and unrelated to this PR — opened #430 to track it. Looking at the code, This PR's tests use isolated ports via |
- Add typed response structs for JSON API parsing (minimal fields only) - Add typed polling functions to replace stringly-typed JSON access - Add prometheus_metrics_assertions module with polling helpers - Add #[track_caller] to assert helpers for better debugging - Add shutdown calls to all integration tests - Use POLL_TIMEOUT constant instead of magic numbers - Add unit tests for http_server.rs endpoints
…ename lib types Quality refactors of the new monitoring API integration tests, scoped strictly to the test infrastructure (no production API changes): * **Consolidate API tests.** The 15 narrow per-endpoint API tests collapse to 4 broader topology-shaped tests (`pool_api_endpoints_static`, `pool_api_endpoints_with_miner`, `tproxy_api_endpoints_static`, `tproxy_api_endpoints_with_miner`), each spinning up its topology once and exercising every relevant endpoint. Roughly halves CI time for these tests with no loss of coverage. * **Cross-validate JSON API and Prometheus.** The two with-miner tests now also assert on the matching Prometheus counters using the `Metric::with_labels` selector, catching drift between the two surfaces. * **Rename lib typed structs with an `Api*` prefix** (`ApiGlobalResponse`, `ApiServerSummary`, `ApiClientMetadata`, etc.) to remove the silent collision with the production response types of the same names defined inside `stratum_apps::monitoring::http_server`. * **Unify polling timeout.** Drop `POLL_TIMEOUT` from the lib; all polling callers use the test-file-local `METRIC_POLL_TIMEOUT` (5 s). * **Drop dead comment** in the SV1-client lookup test. A separate follow-up will consider exposing the production response types (currently private to `http_server`) as a public API for downstream consumers; this PR keeps the test-only mirror types.
Coverage expansion on top of the consolidation refactor:
* **JDC API endpoints test.** Adds `jdc_api_endpoints_with_miner`,
parallel to the existing Pool and tProxy with-miner tests. JDC sits
between pool and tProxy: it is an SV2 client to the pool (so
`server` is populated on /api/v1/global) and an SV2 server to the
tProxy (so `sv2_clients` is populated). JDC has no SV1 surface, so
/api/v1/sv1/clients must 404. Exercises root, /api/v1/global,
/api/v1/server, /api/v1/server/channels, /api/v1/clients,
/api/v1/clients/{id}, /api/v1/clients/{id}/channels and the SV1 404.
* **shares_rejected field-shape regression guard.** Adds inline JSON
asserts to the tProxy and JDC with-miner tests verifying that the
upstream-channel detail under /api/v1/server/channels exposes both
`shares_rejected` (number) and `shares_rejected_by_reason` (object).
This guards against rename or type regressions of the kind PR stratum-mining#468
surfaced. The guard intentionally lives only on roles whose channels
use the server-side `ServerExtendedChannelInfo` struct (tProxy and
JDC); the pool's downstream-client channels use `ExtendedChannelInfo`/
`StandardChannelInfo`, which by design do not carry these fields.
cf90755 to
d71e1a3
Compare
|
I rebased and tried to account for all the changes since last update now that #338 is merged |
Closes #329
Exercise every JSON REST API endpoint against live SV2 topologies and strengthen unit-test coverage for edge cases.
Integration tests (monitoring_integration.rs):
Assertion helpers (prometheus_metrics_assertions.rs):
HTTP helper (utils.rs):
Unit tests (http_server.rs):
Dependencies: