Query Grafana as mate
Authenticate with mate's cluster identity and search metrics or retained logs on either cluster through Grafana.
Mate uses its short-lived Kubernetes token to reach a query-only Grafana endpoint on each cluster. Operator, investigator and responder threads can use it.
Authenticate and discover data sources#
Choose
offsiteorfollyand set the service-proxy path.site=offsite endpoint=/api/v1/namespaces/monitoring/services/grafana-mate:8081/proxy kubectl --context "$site" get --raw "$endpoint/api/user"Result: Grafana identifies the caller as
mate-investigator, withisGrafanaAdmin: false. No password or separate Grafana token is needed.Discover the data source UIDs.
kubectl --context "$site" get --raw "$endpoint/api/datasources" | jq '.[] | {name, uid, type}'
Search metrics#
Put the Prometheus UID from discovery in
query.json.{ "from": "now-15m", "to": "now", "queries": [{ "refId": "A", "datasource": {"type": "prometheus", "uid": "REPLACE_WITH_UID"}, "expr": "up == 0", "range": true, "instant": false, "intervalMs": 60000, "maxDataPoints": 300 }] }Submit the query.
kubectl --context "$site" create --raw "$endpoint/api/ds/query" -f query.jsonResult: Grafana returns data frames under
results.A.frames. Checkresults.A.erroras well as the HTTP status.
Search retained logs#
Use the same command with this payload in query.json. Replace the expression with a LogsQL filter for the investigation.
{
"from": "now-15m",
"to": "now",
"queries": [{
"refId": "A",
"datasource": {"type": "victoriametrics-logs-datasource", "uid": "victorialogs"},
"expr": "error",
"queryType": "instant",
"maxLines": 100,
"intervalMs": 60000,
"maxDataPoints": 100
}]
}Grafana uses the tenant headers in each cluster's data source configuration. Keep the time range and line limit small; broaden them when the evidence needs it.
Access limits#
clusters/base/monitoring/grafana-mate/ defines the endpoint. The Kubernetes API authenticates the caller and checks service-proxy access. The sidecar supplies a fixed Grafana Viewer identity through loopback-only auth proxy.
Only GET /api/user, GET /api/datasources and POST /api/ds/query pass. Kubernetes calls the POST permission create; it does not grant resource creation. Dashboard writes, login sessions and arbitrary data-source proxy routes return 403. Direct VictoriaLogs access stays unavailable to read-only threads.
The network policy admits the API server and the Grafana node's host-network pods to the sidecar. Those nodes are trusted. Public Grafana requests cannot supply the trusted loopback identity.
If a query fails#
| Symptom | Check |
|---|---|
| Kubernetes returns Forbidden | The cluster's monitoring/mate-sandbox-reader.yaml binding and the base Role |
| The sidecar returns 403 | Use the exact method and path, without query arguments |
| Connection fails | Grafana's HelmRelease, the mate-query container and its network policy |
| Grafana returns a data-source error | The discovered UID, query type, expression and time range |
Related#
Linked from 2
- RowbuttA chat bot, code name mate, that answers the owner in Discord and Slack threads with a coding agent whose tools run in a sandbox on the offsite cluster.
- How Rowbutt worksHow mate runs Rowbutt's agent loop, leases a sandbox on the offsite cluster for its tools and keeps its sessions, and the credentials and network policy of each part.