mirror of
https://git.datalinker.icu/vllm-project/vllm.git
synced 2025-12-21 05:25:02 +08:00
[Feature]: Use pydantic validation in observability.py config (#26637)
Signed-off-by: Samuel Wu <cernunnos1710@gmail.com> Signed-off-by: Sam/Samuel <57896620+cern1710@users.noreply.github.com> Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com> Co-authored-by: Harry Mellor <19981378+hmellor@users.noreply.github.com>
This commit is contained in:
parent
4794c2bd92
commit
14f8456344
@ -5,6 +5,8 @@ import hashlib
|
|||||||
from functools import cached_property
|
from functools import cached_property
|
||||||
from typing import Any, Literal, cast
|
from typing import Any, Literal, cast
|
||||||
|
|
||||||
|
from packaging.version import parse
|
||||||
|
from pydantic import field_validator, model_validator
|
||||||
from pydantic.dataclasses import dataclass
|
from pydantic.dataclasses import dataclass
|
||||||
|
|
||||||
from vllm import version
|
from vllm import version
|
||||||
@ -79,25 +81,43 @@ class ObservabilityConfig:
|
|||||||
hash_str = hashlib.md5(str(factors).encode(), usedforsecurity=False).hexdigest()
|
hash_str = hashlib.md5(str(factors).encode(), usedforsecurity=False).hexdigest()
|
||||||
return hash_str
|
return hash_str
|
||||||
|
|
||||||
def __post_init__(self):
|
@field_validator("show_hidden_metrics_for_version")
|
||||||
if (
|
@classmethod
|
||||||
self.collect_detailed_traces is not None
|
def _validate_show_hidden_metrics_for_version(cls, value: str | None) -> str | None:
|
||||||
and len(self.collect_detailed_traces) == 1
|
if value is not None:
|
||||||
and "," in self.collect_detailed_traces[0]
|
# Raises an exception if the string is not a valid version.
|
||||||
):
|
parse(value)
|
||||||
self._parse_collect_detailed_traces()
|
return value
|
||||||
|
|
||||||
|
@field_validator("otlp_traces_endpoint")
|
||||||
|
@classmethod
|
||||||
|
def _validate_otlp_traces_endpoint(cls, value: str | None) -> str | None:
|
||||||
|
if value is not None:
|
||||||
from vllm.tracing import is_otel_available, otel_import_error_traceback
|
from vllm.tracing import is_otel_available, otel_import_error_traceback
|
||||||
|
|
||||||
if not is_otel_available() and self.otlp_traces_endpoint is not None:
|
if not is_otel_available():
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
"OpenTelemetry is not available. Unable to configure "
|
"OpenTelemetry is not available. Unable to configure "
|
||||||
"'otlp_traces_endpoint'. Ensure OpenTelemetry packages are "
|
"'otlp_traces_endpoint'. Ensure OpenTelemetry packages are "
|
||||||
f"installed. Original error:\n{otel_import_error_traceback}"
|
f"installed. Original error:\n{otel_import_error_traceback}"
|
||||||
)
|
)
|
||||||
|
return value
|
||||||
|
|
||||||
def _parse_collect_detailed_traces(self):
|
@field_validator("collect_detailed_traces")
|
||||||
assert isinstance(self.collect_detailed_traces, list)
|
@classmethod
|
||||||
self.collect_detailed_traces = cast(
|
def _validate_collect_detailed_traces(
|
||||||
list[DetailedTraceModules], self.collect_detailed_traces[0].split(",")
|
cls, value: list[DetailedTraceModules] | None
|
||||||
|
) -> list[DetailedTraceModules] | None:
|
||||||
|
"""Handle the legacy case where users might provide a comma-separated
|
||||||
|
string instead of a list of strings."""
|
||||||
|
if value is not None and len(value) == 1 and "," in value[0]:
|
||||||
|
value = cast(list[DetailedTraceModules], value[0].split(","))
|
||||||
|
return value
|
||||||
|
|
||||||
|
@model_validator(mode="after")
|
||||||
|
def _validate_tracing_config(self):
|
||||||
|
if self.collect_detailed_traces and not self.otlp_traces_endpoint:
|
||||||
|
raise ValueError(
|
||||||
|
"collect_detailed_traces requires `--otlp-traces-endpoint` to be set."
|
||||||
)
|
)
|
||||||
|
return self
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user