-
Notifications
You must be signed in to change notification settings - Fork 0
feat: implement prometheus metrics for reconcile duration and quota u… #15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
f478e28
c17bdf8
d5e554b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,137 @@ | ||
| apiVersion: v1 | ||
| kind: ConfigMap | ||
| metadata: | ||
| name: agentrax-grafana-dashboard | ||
| namespace: agentrax-system | ||
| labels: | ||
| app.kubernetes.io/name: agentrax | ||
| app.kubernetes.io/component: grafana-dashboard | ||
| # kube-prometheus-stack's Grafana sidecar watches for this label and | ||
| # auto-imports the JSON payload below as a Grafana dashboard. | ||
| grafana_dashboard: "1" | ||
| data: | ||
| agentrax-dashboard.json: | | ||
| { | ||
| "title": "Agentrax Operator — RED Dashboard", | ||
| "uid": "agentrax-red", | ||
| "tags": ["agentrax", "operator", "kubernetes"], | ||
| "timezone": "browser", | ||
| "schemaVersion": 38, | ||
| "refresh": "30s", | ||
| "templating": { | ||
| "list": [ | ||
| { | ||
| "name": "tenant", | ||
| "label": "Tenant", | ||
| "type": "query", | ||
| "datasource": "Prometheus", | ||
| "query": "label_values(agentrax_tenant_quota_usage_ratio, tenant)", | ||
| "includeAll": true, | ||
| "allValue": ".*", | ||
| "refresh": 1, | ||
| "multi": true, | ||
| "current": { "text": "All", "value": "$__all" } | ||
| } | ||
| ] | ||
| }, | ||
| "panels": [ | ||
| { | ||
| "id": 1, | ||
| "title": "Rate — Reconcile Operations / sec", | ||
| "type": "timeseries", | ||
| "gridPos": { "x": 0, "y": 0, "w": 12, "h": 8 }, | ||
| "datasource": "Prometheus", | ||
| "targets": [ | ||
| { | ||
| "expr": "sum(rate(agentrax_reconcile_duration_seconds_count{tenant=~\"$tenant\"}[5m])) by (tenant)", | ||
| "legendFormat": "{{ tenant }}" | ||
| } | ||
| ], | ||
| "fieldConfig": { | ||
| "defaults": { | ||
| "unit": "reqps", | ||
| "custom": { "lineWidth": 2 } | ||
| } | ||
| } | ||
| }, | ||
| { | ||
| "id": 2, | ||
| "title": "Errors — Reconcile Error Rate / sec", | ||
| "type": "timeseries", | ||
| "gridPos": { "x": 12, "y": 0, "w": 12, "h": 8 }, | ||
| "datasource": "Prometheus", | ||
| "targets": [ | ||
| { | ||
| "expr": "sum(rate(controller_runtime_reconcile_errors_total{controller=\"agentdeployment\"}[5m]))", | ||
| "legendFormat": "errors/s" | ||
| } | ||
| ], | ||
| "fieldConfig": { | ||
| "defaults": { | ||
| "unit": "reqps", | ||
| "color": { "fixedColor": "red", "mode": "fixed" }, | ||
| "custom": { "lineWidth": 2 } | ||
| } | ||
| } | ||
| }, | ||
| { | ||
| "id": 3, | ||
| "title": "Duration — Reconcile P99 Latency (seconds)", | ||
| "type": "timeseries", | ||
| "gridPos": { "x": 0, "y": 8, "w": 12, "h": 8 }, | ||
| "datasource": "Prometheus", | ||
| "targets": [ | ||
| { | ||
| "expr": "histogram_quantile(0.99, sum(rate(agentrax_reconcile_duration_seconds_bucket{tenant=~\"$tenant\"}[5m])) by (le, tenant))", | ||
| "legendFormat": "P99 {{ tenant }}" | ||
| }, | ||
| { | ||
| "expr": "histogram_quantile(0.50, sum(rate(agentrax_reconcile_duration_seconds_bucket{tenant=~\"$tenant\"}[5m])) by (le, tenant))", | ||
| "legendFormat": "P50 {{ tenant }}" | ||
| } | ||
| ], | ||
| "fieldConfig": { | ||
| "defaults": { | ||
| "unit": "s", | ||
| "custom": { "lineWidth": 2 }, | ||
| "thresholds": { | ||
| "mode": "absolute", | ||
| "steps": [ | ||
| { "color": "green", "value": null }, | ||
| { "color": "yellow", "value": 1 }, | ||
| { "color": "red", "value": 2 } | ||
| ] | ||
| } | ||
| } | ||
| } | ||
| }, | ||
| { | ||
| "id": 4, | ||
| "title": "Quota — Tenant Replica Usage Ratio", | ||
| "type": "gauge", | ||
| "gridPos": { "x": 12, "y": 8, "w": 12, "h": 8 }, | ||
| "datasource": "Prometheus", | ||
| "targets": [ | ||
| { | ||
| "expr": "agentrax_tenant_quota_usage_ratio{tenant=~\"$tenant\"}", | ||
| "legendFormat": "{{ tenant }}" | ||
| } | ||
| ], | ||
| "fieldConfig": { | ||
| "defaults": { | ||
| "unit": "percentunit", | ||
| "min": 0, | ||
| "max": 1, | ||
| "thresholds": { | ||
| "mode": "absolute", | ||
| "steps": [ | ||
| { "color": "green", "value": null }, | ||
| { "color": "yellow", "value": 0.7 }, | ||
| { "color": "red", "value": 0.9 } | ||
| ] | ||
| } | ||
| } | ||
| } | ||
| } | ||
| ] | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| apiVersion: monitoring.coreos.com/v1 | ||
| kind: PrometheusRule | ||
| metadata: | ||
| name: agentrax-alerts | ||
| namespace: agentrax-system | ||
| labels: | ||
| app.kubernetes.io/name: agentrax | ||
| app.kubernetes.io/component: alerting | ||
| # kube-prometheus-stack discovers PrometheusRule resources by this label. | ||
| release: kube-prometheus-stack | ||
| spec: | ||
| groups: | ||
|
|
||
| # ------------------------------------------------------------------------- | ||
| # Reconcile latency — fires when the P99 reconcile time sustained > 2s. | ||
| # This indicates the operator is struggling to converge: slow API server, | ||
| # contention on the TenantQuota lock, or an unhealthy admission webhook. | ||
| # ------------------------------------------------------------------------- | ||
| - name: agentrax.reconcile | ||
| rules: | ||
| - alert: AgentraxReconcileLatencyHigh | ||
| expr: | | ||
| histogram_quantile(0.99, | ||
| sum(rate(agentrax_reconcile_duration_seconds_bucket[5m])) | ||
| by (le, controller, tenant) | ||
| ) > 2 | ||
| for: 5m | ||
| labels: | ||
| severity: critical | ||
| annotations: | ||
| summary: >- | ||
| Reconcile P99 > 2s for controller={{ $labels.controller }} | ||
| tenant={{ $labels.tenant }} | ||
| description: >- | ||
| The AgentDeployment reconciler P99 latency has exceeded 2 seconds | ||
| for 5 minutes. Check kube-apiserver latency, webhook response times, | ||
| and operator logs for slow database or registry calls. | ||
| runbook_url: "https://github.com/gitcommitankit/agentrax/docs/ARCHITECTURE.md" | ||
|
|
||
| # ------------------------------------------------------------------------- | ||
| # Quota saturation — fires when a tenant's replica usage ratio exceeds 90%. | ||
| # Early warning before the hard cap blocks new AgentDeployment creates. | ||
| # ------------------------------------------------------------------------- | ||
| - name: agentrax.quota | ||
| rules: | ||
| - alert: AgentraxTenantQuotaHigh | ||
| expr: agentrax_tenant_quota_usage_ratio > 0.9 | ||
| for: 2m | ||
| labels: | ||
| severity: warning | ||
| annotations: | ||
| summary: >- | ||
| Tenant {{ $labels.tenant }} replica quota usage > 90% | ||
| description: >- | ||
| Tenant {{ $labels.tenant }} is using more than 90% of its | ||
| maxTotalReplicas quota. New AgentDeployment creates will be | ||
| rejected by the admission webhook when the limit is reached. | ||
| Consider raising maxTotalReplicas in the TenantQuota spec. | ||
| runbook_url: "https://github.com/gitcommitankit/agentrax/docs/ARCHITECTURE.md" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,3 @@ | ||
| resources: | ||
| - monitor.yaml | ||
| - alerting-rules.yaml |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,7 @@ metadata: | |
| control-plane: controller-manager | ||
| app.kubernetes.io/name: agentrax | ||
| app.kubernetes.io/managed-by: kustomize | ||
| release: kube-prometheus-stack | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔒 Security & Privacy | 🟠 Major | 🏗️ Heavy lift 🧩 Analysis chain🏁 Script executed: sed -n '1,160p' config/prometheus/monitor.yaml
printf '\n--- related Prometheus configuration references ---\n'
rg -n --glob '*.yaml' --glob '*.yml' 'insecureSkipVerify|bearerTokenFile|ServiceMonitor|kube-prometheus-stack|release:' configRepository: gitcommitankit/agentrax Length of output: 3344 🤖 get_repo_knowledge executed:
Length of output: 23008 🏁 Script executed: printf '%s\n' '--- direct references to the ServiceMonitor and controller metrics Service ---'
rg -n 'controller-manager-metrics-monitor|metrics-service|controller-manager|serviceMonitorSelector|serviceMonitorNamespaceSelector|serviceAccountName|automountServiceAccountToken' config charts infra --glob '*.yaml' --glob '*.yml' --glob '*.tpl' --glob '*.tf' 2>/dev/null
printf '%s\n' '--- monitoring and manager manifests ---'
fd -i '.*(prometheus|manager|service).*' config charts infra --type f 2>/dev/null | head -80Repository: gitcommitankit/agentrax Length of output: 3927 🏁 Script executed: printf '%s\n' '--- metrics Service ---'
cat -n config/default/metrics_service.yaml
printf '%s\n' '--- controller-manager metrics/authentication configuration ---'
sed -n '1,150p' config/manager/manager.yaml
cat -n config/rbac/metrics_auth_role_binding.yaml
cat -n config/rbac/role.yaml 2>/dev/null | sed -n '1,180p'
printf '%s\n' '--- monitoring composition and Prometheus resources ---'
rg -n 'config/prometheus|monitor.yaml|kube-prometheus-stack|kind: Prometheus|serviceMonitorSelector|serviceMonitorNamespaceSelector' . --glob '!vendor/**' --glob '!*.md' --glob '!go.sum' 2>/dev/nullRepository: gitcommitankit/agentrax Length of output: 8812 🏁 Script executed: printf '%s\n' '--- default composition ---'
cat -n config/default/kustomization.yaml
cat -n config/default/manager_metrics_patch.yaml
printf '%s\n' '--- metrics authentication resources ---'
fd -i '.*metrics.*' config --type f --exec sh -c 'echo "--- $1"; cat -n "$1"' sh {}
printf '%s\n' '--- relevant infrastructure values ---'
sed -n '35,75p' infra/modules/agentrax_stack/main.tf
sed -n '1,130p' infra/modules/agentrax_stack/variables.tfRepository: gitcommitankit/agentrax Length of output: 14775 🏁 Script executed: printf '%s\n' '--- chart monitoring templates and values ---'
fd -i '.*(monitor|prometheus|metrics).*' charts/agentrax --type f --exec sh -c 'echo "--- $1"; sed -n "1,180p" "$1"' sh {} 2>/dev/null
printf '%s\n' '--- RBAC composition ---'
cat -n config/rbac/kustomization.yaml
rg -n 'metrics-reader|metrics-auth-role|ClusterRoleBinding|serviceAccount' charts/agentrax config/rbac --glob '*.yaml' --glob '*.yml' --glob '*.tpl'Repository: gitcommitankit/agentrax Length of output: 4815 🌐 Web query:
💡 Result: In the kube-prometheus-stack Helm chart, the serviceMonitorSelectorNilUsesHelmValues setting controls how Prometheus selects ServiceMonitors when no explicit selector is defined [1][2]. By default (with this value set to true), the Helm chart automatically configures Prometheus to select only ServiceMonitors that carry a label matching the current Helm release name (release: ) [1][3][4]. If you set serviceMonitorSelectorNilUsesHelmValues to false, the chart removes this default label-based restriction [2][5][4]. This allows Prometheus to discover all ServiceMonitors within its namespace, regardless of their labels [6][5][4]. This is commonly used when you need to scrape custom targets or third-party applications that do not include the Helm release label [2][5]. The underlying template logic is as follows: - If a custom serviceMonitorSelector is provided in values, it is used [1]. - If not, but serviceMonitorSelectorNilUsesHelmValues is true (default), the selector is set to match the release label [1][3]. - If serviceMonitorSelectorNilUsesHelmValues is false, the selector is set to an empty object {}, which effectively selects all ServiceMonitors in the namespace [1][2][6]. Note that some users have reported confusion regarding this behavior, specifically that setting this to false might effectively disable label-based filtering, allowing discovery of all ServiceMonitors in the target namespace [6][5]. Citations:
Security Misconfiguration (CWE-295): Improper Certificate Validation Exploitability: Difficult Disable When applied, kube-prometheus-stack selects this ServiceMonitor through 🤖 Prompt for AI Agents |
||
| name: controller-manager-metrics-monitor | ||
| namespace: system | ||
| spec: | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Add the dashboard ConfigMap to the deployed kustomization graph.
make deployandbuild-installerbuildconfig/default, which does not referenceconfig/grafana/dashboard-configmap.yaml. The ConfigMap therefore is absent from applied manifests, so Grafana cannot auto-import the dashboard.🤖 Prompt for AI Agents