INNER CODE UNIT · Python

_range_query_ui_params

pab1it0/prometheus-mcp-server · src/prometheus_mcp_server/server.py:333

def _range_query_ui_params(query: str, start: str, end: str, step: str) -> Optional[Dict[str, str]]:
    """Translate API timestamps and durations to Prometheus UI parameters."""
    def timestamp(value: str) -> float:
        try:
            return float(value)
        except ValueError:
            return datetime.fromisoformat(value.replace("Z", "+00:00")).timestamp()

    try:
        end_seconds = timestamp(end)
        window_ms = round((end_seconds - timestamp(start)) * 1000)
        if window_ms <= 0:
            return None
        end_input = datetime.fromtimestamp(end_seconds, timezone.utc).isoformat(timespec="milliseconds")
        try:
            step_seconds = float(step)
        except ValueError:
            units = {"y": 31536000, "w": 604800, "d": 86400, "h": 3600,

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…