mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-01 07:47:56 +00:00
Merge pull request #69895 from jpbetz/webhook-metrics-cardinality-fix
Reduce cardinality of admission webhook metrics
This commit is contained in:
commit
04d3949048
@ -112,17 +112,17 @@ func newAdmissionMetrics() *AdmissionMetrics {
|
|||||||
// Admission metrics for a step of the admission flow. The entire admission flow is broken down into a series of steps
|
// Admission metrics for a step of the admission flow. The entire admission flow is broken down into a series of steps
|
||||||
// Each step is identified by a distinct type label value.
|
// Each step is identified by a distinct type label value.
|
||||||
step := newMetricSet("step",
|
step := newMetricSet("step",
|
||||||
[]string{"type", "operation", "group", "version", "resource", "subresource", "rejected"},
|
[]string{"type", "operation", "rejected"},
|
||||||
"Admission sub-step %s, broken out for each operation and API resource and step type (validate or admit).", true)
|
"Admission sub-step %s, broken out for each operation and API resource and step type (validate or admit).", true)
|
||||||
|
|
||||||
// Built-in admission controller metrics. Each admission controller is identified by name.
|
// Built-in admission controller metrics. Each admission controller is identified by name.
|
||||||
controller := newMetricSet("controller",
|
controller := newMetricSet("controller",
|
||||||
[]string{"name", "type", "operation", "group", "version", "resource", "subresource", "rejected"},
|
[]string{"name", "type", "operation", "rejected"},
|
||||||
"Admission controller %s, identified by name and broken out for each operation and API resource and type (validate or admit).", false)
|
"Admission controller %s, identified by name and broken out for each operation and API resource and type (validate or admit).", false)
|
||||||
|
|
||||||
// Admission webhook metrics. Each webhook is identified by name.
|
// Admission webhook metrics. Each webhook is identified by name.
|
||||||
webhook := newMetricSet("webhook",
|
webhook := newMetricSet("webhook",
|
||||||
[]string{"name", "type", "operation", "group", "version", "resource", "subresource", "rejected"},
|
[]string{"name", "type", "operation", "rejected"},
|
||||||
"Admission webhook %s, identified by name and broken out for each operation and API resource and type (validate or admit).", false)
|
"Admission webhook %s, identified by name and broken out for each operation and API resource and type (validate or admit).", false)
|
||||||
|
|
||||||
step.mustRegister()
|
step.mustRegister()
|
||||||
@ -139,20 +139,17 @@ func (m *AdmissionMetrics) reset() {
|
|||||||
|
|
||||||
// ObserveAdmissionStep records admission related metrics for a admission step, identified by step type.
|
// ObserveAdmissionStep records admission related metrics for a admission step, identified by step type.
|
||||||
func (m *AdmissionMetrics) ObserveAdmissionStep(elapsed time.Duration, rejected bool, attr admission.Attributes, stepType string, extraLabels ...string) {
|
func (m *AdmissionMetrics) ObserveAdmissionStep(elapsed time.Duration, rejected bool, attr admission.Attributes, stepType string, extraLabels ...string) {
|
||||||
gvr := attr.GetResource()
|
m.step.observe(elapsed, append(extraLabels, stepType, string(attr.GetOperation()), strconv.FormatBool(rejected))...)
|
||||||
m.step.observe(elapsed, append(extraLabels, stepType, string(attr.GetOperation()), gvr.Group, gvr.Version, gvr.Resource, attr.GetSubresource(), strconv.FormatBool(rejected))...)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ObserveAdmissionController records admission related metrics for a built-in admission controller, identified by it's plugin handler name.
|
// ObserveAdmissionController records admission related metrics for a built-in admission controller, identified by it's plugin handler name.
|
||||||
func (m *AdmissionMetrics) ObserveAdmissionController(elapsed time.Duration, rejected bool, attr admission.Attributes, stepType string, extraLabels ...string) {
|
func (m *AdmissionMetrics) ObserveAdmissionController(elapsed time.Duration, rejected bool, attr admission.Attributes, stepType string, extraLabels ...string) {
|
||||||
gvr := attr.GetResource()
|
m.controller.observe(elapsed, append(extraLabels, stepType, string(attr.GetOperation()), strconv.FormatBool(rejected))...)
|
||||||
m.controller.observe(elapsed, append(extraLabels, stepType, string(attr.GetOperation()), gvr.Group, gvr.Version, gvr.Resource, attr.GetSubresource(), strconv.FormatBool(rejected))...)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ObserveWebhook records admission related metrics for a admission webhook.
|
// ObserveWebhook records admission related metrics for a admission webhook.
|
||||||
func (m *AdmissionMetrics) ObserveWebhook(elapsed time.Duration, rejected bool, attr admission.Attributes, stepType string, extraLabels ...string) {
|
func (m *AdmissionMetrics) ObserveWebhook(elapsed time.Duration, rejected bool, attr admission.Attributes, stepType string, extraLabels ...string) {
|
||||||
gvr := attr.GetResource()
|
m.webhook.observe(elapsed, append(extraLabels, stepType, string(attr.GetOperation()), strconv.FormatBool(rejected))...)
|
||||||
m.webhook.observe(elapsed, append(extraLabels, stepType, string(attr.GetOperation()), gvr.Group, gvr.Version, gvr.Resource, attr.GetSubresource(), strconv.FormatBool(rejected))...)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type metricSet struct {
|
type metricSet struct {
|
||||||
|
@ -38,10 +38,6 @@ func TestObserveAdmissionStep(t *testing.T) {
|
|||||||
handler.(admission.ValidationInterface).Validate(attr)
|
handler.(admission.ValidationInterface).Validate(attr)
|
||||||
wantLabels := map[string]string{
|
wantLabels := map[string]string{
|
||||||
"operation": string(admission.Create),
|
"operation": string(admission.Create),
|
||||||
"group": resource.Group,
|
|
||||||
"version": resource.Version,
|
|
||||||
"resource": resource.Resource,
|
|
||||||
"subresource": "subresource",
|
|
||||||
"type": "admit",
|
"type": "admit",
|
||||||
"rejected": "false",
|
"rejected": "false",
|
||||||
}
|
}
|
||||||
@ -61,10 +57,6 @@ func TestObserveAdmissionController(t *testing.T) {
|
|||||||
wantLabels := map[string]string{
|
wantLabels := map[string]string{
|
||||||
"name": "a",
|
"name": "a",
|
||||||
"operation": string(admission.Create),
|
"operation": string(admission.Create),
|
||||||
"group": resource.Group,
|
|
||||||
"version": resource.Version,
|
|
||||||
"resource": resource.Resource,
|
|
||||||
"subresource": "subresource",
|
|
||||||
"type": "admit",
|
"type": "admit",
|
||||||
"rejected": "false",
|
"rejected": "false",
|
||||||
}
|
}
|
||||||
@ -80,10 +72,6 @@ func TestObserveWebhook(t *testing.T) {
|
|||||||
wantLabels := map[string]string{
|
wantLabels := map[string]string{
|
||||||
"name": "x",
|
"name": "x",
|
||||||
"operation": string(admission.Create),
|
"operation": string(admission.Create),
|
||||||
"group": resource.Group,
|
|
||||||
"version": resource.Version,
|
|
||||||
"resource": resource.Resource,
|
|
||||||
"subresource": "subresource",
|
|
||||||
"type": "admit",
|
"type": "admit",
|
||||||
"rejected": "false",
|
"rejected": "false",
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user