This PR implements per-collection metrics for Prometheus as requested in #3322.

Changes

Core Implementation

  1. Extended telemetry data structures (src/common/telemetry_ops/requests_telemetry.rs):

    • Added collection_responses field to WebApiTelemetry and GrpcTelemetry
    • Updated worker collectors to track both global and per-collection metrics
    • Implemented merge logic for per-collection metrics across workers
    • Updated anonymize implementations
  2. REST API collection extraction (src/actix/actix_telemetry.rs):

    • Added extract_collection_name() helper to parse URLs like /collections/{name}/points/search
    • Updated middleware to extract collection name from request path
    • Collection name is extracted for all collection-scoped endpoints
  3. gRPC support (src/tonic/tonic_telemetry.rs):

    • Updated to support per-collection metrics infrastructure
    • Note: gRPC collection name extraction requires request body parsing at middleware layer, which is architecturally complex. The infrastructure is in place for future enhancement.
  4. Metrics output (src/common/metrics.rs):

    • Updated WebApiTelemetry::add_metrics() to output per-collection metrics with collection label
    • Updated GrpcTelemetry::add_metrics() similarly
    • Both global (existing) and per-collection (new) metrics are generated

Example Output

# Global metrics (existing behavior preserved)
rest_responses_total{method="POST",endpoint="/collections/{name}/points",status="200"} 100
rest_responses_avg_duration_seconds{method="POST",endpoint="/collections/{name}/points",status="200"} 0.001
# Per-collection metrics (new)
rest_collection_responses_total{method="POST",endpoint="/collections/{name}/points",status="200",collection="my-collection"} 50
rest_collection_responses_avg_duration_seconds{method="POST",endpoint="/collections/{name}/points",status="200",collection="my-collection"} 0.0009

Verification

  • cargo check passes
  • cargo test metrics passes (test_endpoint_whitelists_sorted)
  • ✅ Code formatted with cargo +nightly fmt

Implementation Notes

  • Backward compatible: Global metrics continue to work exactly as before
  • REST API: Full per-collection metrics support
  • gRPC: Infrastructure ready, collection extraction requires additional architectural work
  • Performance: Minimal overhead - collection name extraction is O(n) on URL path segments

Fixes #3322

/claim #3322

Claim

Total prize pool $150
Total paid $0
Status Pending
Submitted March 15, 2026
Last updated March 15, 2026

Contributors

TI

tianlin-magi

@tele-he-gmail-com

100%

Sponsors

QD

Qdrant

@Qdrant

$150