-
Notifications
You must be signed in to change notification settings - Fork 173
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add agent injector telemetry (#703)
* feat: add agent injector telemetry 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. * refactor(metrics): add metadata to mutate response Update the `Mutate()` method to return a struct that extends the existing return data (AdmissionResponse) with metadata on the types of Vault Agent injections made. The metadata informs the count of injections by namespace, which are now further broken down by type of injection.
- Loading branch information
1 parent
f40afeb
commit b05b4ca
Showing
4 changed files
with
132 additions
and
15 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
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,77 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
package agent_inject | ||
|
||
import ( | ||
"github.com/prometheus/client_golang/prometheus" | ||
) | ||
|
||
const ( | ||
metricsNamespace = "vault" | ||
metricsSubsystem = "agent_injector" | ||
metricsLabelNamespace = "namespace" | ||
metricsLabelType = "injection_type" | ||
metricsLabelTypeBoth = "init_and_sidecar" | ||
metricsLabelTypeInitOnly = "init_only" | ||
metricsLabelTypeSidecarOnly = "sidecar_only" | ||
) | ||
|
||
var ( | ||
requestQueue = prometheus.NewGauge(prometheus.GaugeOpts{ | ||
Namespace: metricsNamespace, | ||
Subsystem: metricsSubsystem, | ||
Name: "request_queue_length", | ||
Help: "Count of webhook requests in the injector's queue", | ||
}) | ||
|
||
requestProcessingTime = prometheus.NewHistogram(prometheus.HistogramOpts{ | ||
Namespace: metricsNamespace, | ||
Subsystem: metricsSubsystem, | ||
Name: "request_processing_duration_ms", | ||
Help: "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 MutateResponse) { | ||
// Injection type can be one of: init_and_sidecar (default); init_only; or sidecar_only | ||
typeLabel := metricsLabelTypeBoth | ||
if res.InjectedInit && !res.InjectedSidecar { | ||
typeLabel = metricsLabelTypeInitOnly | ||
} else if res.InjectedSidecar && !res.InjectedInit { | ||
typeLabel = metricsLabelTypeSidecarOnly | ||
} | ||
|
||
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