| 1 | # SPDX-License-Identifier: Apache-2.0 |
| 2 | # SPDX-FileCopyrightText: Copyright contributors to the vLLM project |
| 3 | """Tests for ObservabilityConfig validation.""" |
| 4 | |
| 5 | import pytest |
| 6 | from pydantic import ValidationError |
| 7 | |
| 8 | from vllm.config.observability import ObservabilityConfig |
| 9 | |
| 10 | |
| 11 | def test_custom_histogram_buckets_default_none(): |
| 12 | assert ObservabilityConfig().custom_histogram_buckets is None |
| 13 | |
| 14 | |
| 15 | def test_custom_histogram_buckets_valid(): |
| 16 | config = ObservabilityConfig( |
| 17 | custom_histogram_buckets={ |
| 18 | "request_latency": [0.01, 0.05, 0.1, 0.5], |
| 19 | "time_to_first_token": [1, 2, 5], |
| 20 | } |
| 21 | ) |
| 22 | assert config.custom_histogram_buckets == { |
| 23 | "request_latency": [0.01, 0.05, 0.1, 0.5], |
| 24 | "time_to_first_token": [1.0, 2.0, 5.0], |
| 25 | } |
| 26 | |
| 27 | |
| 28 | @pytest.mark.parametrize( |
| 29 | ("buckets", "match"), |
| 30 | [ |
| 31 | ({"bogus": [1.0, 2.0]}, "unknown bucket family 'bogus'"), |
| 32 | ({"request_latency": []}, "must not be empty"), |
| 33 | ({"request_latency": [0.0, 1.0]}, "must be finite and greater than 0"), |
| 34 | ({"request_latency": [-1.0, 1.0]}, "must be finite and greater than 0"), |
| 35 | ( |
| 36 | {"request_latency": [1.0, float("inf")]}, |
| 37 | "must be finite and greater than 0", |
| 38 | ), |
| 39 | ({"request_latency": [float("nan")]}, "must be finite and greater than 0"), |
| 40 | ({"request_latency": [1.0, 1.0]}, "must be strictly increasing"), |
| 41 | ({"request_latency": [2.0, 1.0]}, "must be strictly increasing"), |
| 42 | ({"request_latency": [True, 2.0]}, "must be a number, not a boolean"), |
| 43 | ({"request_latency": [False]}, "must be a number, not a boolean"), |
| 44 | ( |
| 45 | {"request_latency": [1.0, 2.0], "request_tokens": [16, 8]}, |
| 46 | r"request_tokens.*must be strictly increasing", |
| 47 | ), |
| 48 | ], |
| 49 | ) |
| 50 | def test_custom_histogram_buckets_rejects_invalid(buckets, match): |
| 51 | """Each validation rule must name the field, the value, and the rule.""" |
| 52 | with pytest.raises(ValidationError, match=match): |
| 53 | ObservabilityConfig(custom_histogram_buckets=buckets) |