4b6817381b
CI (OpenClaw E2E) / openclaw test (push) Has been cancelled
CI / coverage-report (push) Has been cancelled
CI / test-kubernetes (push) Has been cancelled
CI / should-run-thorough (push) Has been cancelled
CI / test-thorough (cloudwatch-demo) (push) Has been cancelled
CI / test-thorough (flink-ecs) (push) Has been cancelled
CI / test-thorough (upstream-lambda) (push) Has been cancelled
CI / test-thorough (prefect-ecs-fargate) (push) Has been cancelled
Release / build-binaries (zip, opensre.exe, onefile, windows-latest, windows-x64) (push) Has been cancelled
Benchmark image — build + push to ECR (any adapter) / build + push (push) Has been cancelled
CI / quality (ubuntu-latest) (push) Has been cancelled
CI / test (tools-runtime) (push) Has been cancelled
CI / test (e2e-general) (push) Has been cancelled
CI / test (cli-runtime) (push) Has been cancelled
CI / test (e2e-provider-and-openclaw) (push) Has been cancelled
CI / test (integrations-and-misc) (push) Has been cancelled
Release / verify (push) Has been cancelled
Release / build-python-dist (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, macos-15-intel, darwin-x64) (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, macos-latest, darwin-arm64) (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, ubuntu-22.04, linux-x64) (push) Has been cancelled
Release / publish-release (push) Has been cancelled
Release / publish-main-release (push) Has been cancelled
Interactive Shell Live (PR + post-merge) / turn-checks (no-LLM) (push) Has been cancelled
CodeQL / Analyze (python) (push) Has been cancelled
Interactive Shell Live (PR + post-merge) / turn-live shard ${{ matrix.shard_index }} (push) Has been cancelled
Release / prepare (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, ubuntu-22.04-arm, linux-arm64) (push) Has been cancelled
Synthetic Deterministic Tests / Synthetic offline (deterministic) (push) Has been cancelled
79 lines
2.3 KiB
Python
79 lines
2.3 KiB
Python
"""Mimir metrics query mixin for Grafana Cloud client."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import TYPE_CHECKING, Any
|
|
|
|
if TYPE_CHECKING:
|
|
from integrations.grafana.base import GrafanaClientBase
|
|
|
|
|
|
class MimirMixin:
|
|
"""Mixin providing Mimir metrics query capabilities."""
|
|
|
|
def query_mimir( # type: ignore[misc]
|
|
self: GrafanaClientBase,
|
|
metric_name: str,
|
|
service_name: str | None = None,
|
|
) -> dict[str, Any]:
|
|
"""Query Grafana Cloud Mimir for metrics.
|
|
|
|
Args:
|
|
metric_name: Prometheus metric name (e.g., pipeline_runs_total)
|
|
service_name: Optional service name filter
|
|
|
|
Returns:
|
|
Dictionary with metric series and values
|
|
"""
|
|
if not self.is_configured:
|
|
return {
|
|
"success": False,
|
|
"error": f"Grafana client not configured for account '{self.account_id}'",
|
|
"metrics": [],
|
|
}
|
|
|
|
url = self._build_datasource_url(
|
|
self.mimir_datasource_uid,
|
|
"/api/v1/query",
|
|
)
|
|
|
|
query = metric_name
|
|
if service_name:
|
|
query = f'{metric_name}{{service_name="{service_name}"}}'
|
|
|
|
params = {"query": query}
|
|
|
|
try:
|
|
data = self._make_request(url, params=params)
|
|
result = data.get("data", {}).get("result", [])
|
|
|
|
metrics = []
|
|
for series in result:
|
|
metrics.append(
|
|
{
|
|
"metric": series.get("metric", {}),
|
|
"value": series.get("value", []),
|
|
}
|
|
)
|
|
|
|
return {
|
|
"success": True,
|
|
"metrics": metrics,
|
|
"total_series": len(result),
|
|
"query": query,
|
|
"account_id": self.account_id,
|
|
}
|
|
except Exception as e:
|
|
error_msg = str(e)
|
|
response_text = ""
|
|
if hasattr(e, "response") and e.response is not None:
|
|
response_text = e.response.text[:300]
|
|
error_msg = f"Mimir query failed: {e.response.status_code}"
|
|
|
|
return {
|
|
"success": False,
|
|
"error": error_msg,
|
|
"response": response_text,
|
|
"metrics": [],
|
|
}
|