Files
qdrant/tests/per_collection_metrics_test.sh
Excellencedev 77e2fe72f8 Implement Per collection metrics for Promethus (#8214)
* Implement Per-Collection Prometheus Metrics

* Update config/config.yaml

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* Update tests/per_collection_metrics_test.sh

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* Update tests/per_collection_metrics_test.sh

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* fix ci

* comment

* Update tests/per_collection_metrics_test.sh

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* adress revew

* fix: linter

* refactor: cardinality limit, anonymize fix, cleanup

- Add max_per_collection_metrics config (default 256) to bound
  per-collection label cardinality
- Fix anonymize: strip per_collection_responses entirely instead of
  leaking hashed collection names
- Move CollectionName into requests_telemetry, remove
  telemetry_context.rs
- Add unit tests for cardinality limits
- Add integration test assertions for default mode
- Regenerate OpenAPI spec
- Document why internal gRPC doesn't attach CollectionName

* avoid cloning

* fix: address pr reviews

* fix: linter

* fix: linter

* feat: enforce {name} in actix api

* chore: remove empty line

* feat: add actix pre-commit hook

* feat: potential enforce tonic collection name

* feat: use proc_macro instead

* feat: use collection_name instead of name

* feat: add tonic telemetry tests

* fix: linter

* fix: linter

* chore: remove unneccessary clone

* fix: use collection_name everywhere

* fix: python tests and openapi

* chore: simplify collection_name tests

* actix collection_name enforcign: use relative path in test + avoid grep

* fix: remove macro

* chore: add some comment to telemetry_wrapper

* fix: clippy

---------

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: Daniel Boros <dancixx@gmail.com>
Co-authored-by: generall <andrey@vasnetsov.com>
2026-03-26 18:39:05 +01:00

82 lines
2.4 KiB
Bash

#!/usr/bin/env bash
# This test checks that Qdrant exposes per-collection metrics when requested via query parameter.
set -e
QDRANT_HOST=${QDRANT_HOST:-'localhost:6333'}
COLLECTION_NAME="test_collection_metrics"
echo "Using Qdrant host: $QDRANT_HOST"
# 1. Cleanup & Create collection
echo "Creating collection $COLLECTION_NAME..."
# Attempt to delete collection if it exists, ignore output/errors
curl -X DELETE "http://$QDRANT_HOST/collections/$COLLECTION_NAME" -s > /dev/null || true
curl -X PUT "http://$QDRANT_HOST/collections/$COLLECTION_NAME" \
-H 'Content-Type: application/json' \
--fail -s \
--data-raw '{
"vectors": {
"size": 4,
"distance": "Dot"
}
}'
# 2. Insert points
echo "Inserting points..."
curl -X PUT "http://$QDRANT_HOST/collections/$COLLECTION_NAME/points?wait=true" \
-H 'Content-Type: application/json' \
--fail -s \
--data-raw '{
"points": [
{"id": 1, "vector": [0.05, 0.61, 0.76, 0.74]},
{"id": 2, "vector": [0.19, 0.81, 0.75, 0.11]}
]
}'
# 3. Search points (to generate read metrics)
echo "Searching points..."
curl -X POST "http://$QDRANT_HOST/collections/$COLLECTION_NAME/points/search" \
-H 'Content-Type: application/json' \
--fail -s \
--data-raw '{
"vector": [0.2,0.1,0.9,0.7],
"top": 3
}'
# 4. Fetch metrics with per_collection=true and verify
echo "Fetching per-collection metrics..."
METRICS=$(curl -s --fail "http://$QDRANT_HOST/metrics?per_collection=true")
echo "Verifying per-collection metrics..."
# Check for existence of collection label in rest responses
if echo "$METRICS" | grep -q "rest_responses_total{.*collection=\"$COLLECTION_NAME\".*}"; then
echo "Found per-collection rest_responses_total"
else
echo "Failed to find per-collection rest_responses_total"
exit 1
fi
# 5. Fetch default metrics (no per_collection) and verify global mode
echo "Fetching default metrics..."
DEFAULT_METRICS=$(curl -s --fail "http://$QDRANT_HOST/metrics")
# In default mode, rest_responses should NOT have collection label
if echo "$DEFAULT_METRICS" | grep -q 'rest_responses_total{.*collection='; then
echo "ERROR: Found per-collection label in default mode"
exit 1
else
echo "Default mode correctly shows global metrics (no collection label)"
fi
echo "All per-collection metrics verification passed!"
# Cleanup
echo "Cleaning up..."
curl -X DELETE "http://$QDRANT_HOST/collections/$COLLECTION_NAME" -s