eebc86a52b
Add a shared ServiceBaseUrl type (BeforeValidator + Field description) in integrations/base.py and apply it to base_url across all six service configs (grafana, prometheus, alertmanager, jellyfin, jellyseerr, nextcloud). Missing http:// or https:// schema now fails fast with a clear 422 instead of breaking HTTP clients silently. Tests cover reject/accept cases; REQUIREMENTS updated.
47 lines
1.1 KiB
Python
47 lines
1.1 KiB
Python
"""Prometheus service definition."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from media_library_viewer_api.integrations.base import (
|
|
SecretField,
|
|
ServiceBaseUrl,
|
|
ServiceConfigBase,
|
|
ServiceDefinition,
|
|
WidgetConfigBase,
|
|
widget_kind,
|
|
)
|
|
|
|
|
|
class PrometheusConfig(ServiceConfigBase):
|
|
"""Non-secret Prometheus connection config."""
|
|
|
|
base_url: ServiceBaseUrl
|
|
timeout_seconds: int = 10
|
|
|
|
|
|
class PrometheusMetricWidgetConfig(WidgetConfigBase):
|
|
"""A PromQL instant query rendered as a metric."""
|
|
|
|
promql: str
|
|
|
|
|
|
DEFINITION = ServiceDefinition(
|
|
service_type="prometheus",
|
|
name="Prometheus",
|
|
description="Metrics storage and PromQL queries.",
|
|
config_model=PrometheusConfig,
|
|
secret_fields=[
|
|
SecretField(key="api_key", label="API key", helper="Optional bearer token"),
|
|
],
|
|
widget_kinds=[
|
|
widget_kind(
|
|
kind="metric",
|
|
name="Metric",
|
|
description="Instant query result rendered as a metric.",
|
|
model_cls=PrometheusMetricWidgetConfig,
|
|
default_config={"promql": ""},
|
|
refresh_interval_ms=30_000,
|
|
),
|
|
],
|
|
)
|