-
Notifications
You must be signed in to change notification settings - Fork 172
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Prometheus metrics to monitor the Agent Injector's performance. New metrics include a gauge of current requests being processed by the webhook, a summary of request processing times, and a count of successful and failed injections by Kubernetes namespace. Successful injections are broken down by injection type. The `injection_type` label can assume the value `init_only` for injections with only an initContainer (no sidecar) and `sidecar` for all other cases (sidecar only or sidecar + initContainer). Fixes AG-005161.
- Loading branch information
1 parent
c41ed32
commit f3f6b3a
Showing
3 changed files
with
102 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package agent_inject | ||
|
||
import ( | ||
"slices" | ||
|
||
"github.com/prometheus/client_golang/prometheus" | ||
admissionv1 "k8s.io/api/admission/v1" | ||
) | ||
|
||
const ( | ||
metricsNamespace = "vault" | ||
metricsSubsystem = "agent_injector" | ||
metricsLabelNamespace = "namespace" | ||
metricsLabelType = "injection_type" | ||
metricsLabelTypeDefault = "sidecar" | ||
metricsLabelTypeInitOnly = "init_only" | ||
) | ||
|
||
var ( | ||
requestQueue = prometheus.NewGauge(prometheus.GaugeOpts{ | ||
Namespace: metricsNamespace, | ||
Subsystem: metricsSubsystem, | ||
Name: "request_queue_total", | ||
Help: "Total count of webhook requests in the queue", | ||
}) | ||
|
||
requestProcessingTime = prometheus.NewHistogram(prometheus.HistogramOpts{ | ||
Namespace: metricsNamespace, | ||
Subsystem: metricsSubsystem, | ||
Name: "request_processing_duration_ms", | ||
Help: "Histogram of webhook request processing times in milliseconds", | ||
Buckets: []float64{5, 10, 25, 50, 75, 100, 250, 500, 1000, 2500, 5000, 7500, 10000}, | ||
}) | ||
|
||
injectionsByNamespace = prometheus.NewCounterVec(prometheus.CounterOpts{ | ||
Namespace: metricsNamespace, | ||
Subsystem: metricsSubsystem, | ||
Name: "injections_by_namespace_total", | ||
Help: "Total count of Agent Sidecar injections by namespace", | ||
}, []string{metricsLabelNamespace, metricsLabelType}) | ||
|
||
failedInjectionsByNamespace = prometheus.NewCounterVec(prometheus.CounterOpts{ | ||
Namespace: metricsNamespace, | ||
Subsystem: metricsSubsystem, | ||
Name: "failed_injections_by_namespace_total", | ||
Help: "Total count of failed Agent Sidecar injections by namespace", | ||
}, []string{metricsLabelNamespace}) | ||
) | ||
|
||
func incrementInjections(namespace string, res admissionv1.AdmissionResponse) { | ||
typeLabel := metricsLabelTypeDefault | ||
if slices.Contains(res.Warnings, warningInitOnlyInjection) { | ||
typeLabel = metricsLabelTypeInitOnly | ||
} | ||
|
||
injectionsByNamespace.With(prometheus.Labels{ | ||
metricsLabelNamespace: namespace, | ||
metricsLabelType: typeLabel, | ||
}).Inc() | ||
} | ||
|
||
func incrementInjectionFailures(namespace string) { | ||
failedInjectionsByNamespace.With(prometheus.Labels{metricsLabelNamespace: namespace}).Inc() | ||
} | ||
|
||
func MustRegisterInjectorMetrics(registry prometheus.Registerer) { | ||
registry.MustRegister( | ||
requestQueue, | ||
requestProcessingTime, | ||
injectionsByNamespace, | ||
failedInjectionsByNamespace, | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters