diff --git a/pkg/admission/BUILD b/pkg/admission/BUILD index c6279ba77..0102e5b38 100644 --- a/pkg/admission/BUILD +++ b/pkg/admission/BUILD @@ -51,7 +51,6 @@ go_library( "//vendor/k8s.io/apimachinery/pkg/api/meta:go_default_library", "//vendor/k8s.io/apimachinery/pkg/apimachinery/announced:go_default_library", "//vendor/k8s.io/apimachinery/pkg/apimachinery/registered:go_default_library", - "//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library", "//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library", "//vendor/k8s.io/apimachinery/pkg/runtime/schema:go_default_library", "//vendor/k8s.io/apimachinery/pkg/runtime/serializer:go_default_library", diff --git a/pkg/admission/chain_test.go b/pkg/admission/chain_test.go index 868d7dcb0..09a1bbdf0 100644 --- a/pkg/admission/chain_test.go +++ b/pkg/admission/chain_test.go @@ -17,7 +17,6 @@ limitations under the License. package admission import ( - "strconv" "testing" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -109,8 +108,7 @@ func TestAdmitAndValidate(t *testing.T) { } labelFilter := map[string]string{ - "is_system_ns": strconv.FormatBool(test.ns == sysns), - "type": "mutating", + "type": "mutating", } checkAdmitAndValidateMetrics(t, labelFilter, test.accept, test.calls) @@ -136,8 +134,7 @@ func TestAdmitAndValidate(t *testing.T) { } labelFilter = map[string]string{ - "is_system_ns": strconv.FormatBool(test.ns == sysns), - "type": "validating", + "type": "validating", } checkAdmitAndValidateMetrics(t, labelFilter, test.accept, test.calls) diff --git a/pkg/admission/metrics.go b/pkg/admission/metrics.go index 0f3bea661..877ea660d 100644 --- a/pkg/admission/metrics.go +++ b/pkg/admission/metrics.go @@ -24,8 +24,6 @@ import ( "k8s.io/api/admissionregistration/v1alpha1" "github.com/prometheus/client_golang/prometheus" - - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) const ( @@ -59,17 +57,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 // Each step is identified by a distinct type label value. step := newMetricSet("step", - []string{"type", "operation", "group", "version", "resource", "subresource", "is_system_ns", "rejected"}, + []string{"type", "operation", "group", "version", "resource", "subresource", "rejected"}, "Admission sub-step %s, broken out for each operation and API resource and step type (validating or mutating).") // Built-in admission controller metrics. Each admission controller is identified by name. controller := newMetricSet("controller", - []string{"name", "type", "operation", "group", "version", "resource", "subresource", "is_system_ns", "rejected"}, + []string{"name", "type", "operation", "group", "version", "resource", "subresource", "rejected"}, "Admission controller %s, identified by name and broken out for each operation and API resource and type (validating or mutating).") // External admission webhook metrics. Each webhook is identified by name. externalWebhook := newMetricSet("external_webhook", - []string{"name", "type", "operation", "group", "version", "resource", "subresource", "is_system_ns", "rejected"}, + []string{"name", "type", "operation", "group", "version", "resource", "subresource", "rejected"}, "External admission webhook %s, identified by name and broken out for each operation and API resource and type (validating or mutating).") step.mustRegister() @@ -87,25 +85,20 @@ func (m *AdmissionMetrics) reset() { // ObserveAdmissionStep records admission related metrics for a admission step, identified by step type. func (m *AdmissionMetrics) ObserveAdmissionStep(elapsed time.Duration, rejected bool, attr Attributes, stepType string) { gvr := attr.GetResource() - m.step.observe(elapsed, stepType, string(attr.GetOperation()), gvr.Group, gvr.Version, gvr.Resource, attr.GetSubresource(), isSystemNsLabel(attr), strconv.FormatBool(rejected)) + m.step.observe(elapsed, 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. func (m *AdmissionMetrics) ObserveAdmissionController(elapsed time.Duration, rejected bool, handler NamedHandler, attr Attributes, stepType string) { gvr := attr.GetResource() - m.controller.observe(elapsed, handler.Name(), stepType, string(attr.GetOperation()), gvr.Group, gvr.Version, gvr.Resource, attr.GetSubresource(), isSystemNsLabel(attr), strconv.FormatBool(rejected)) + m.controller.observe(elapsed, handler.Name(), stepType, string(attr.GetOperation()), gvr.Group, gvr.Version, gvr.Resource, attr.GetSubresource(), strconv.FormatBool(rejected)) } // ObserveExternalWebhook records admission related metrics for a external admission webhook. -func (m *AdmissionMetrics) ObserveExternalWebhook(elapsed time.Duration, rejected bool, hook *v1alpha1.ExternalAdmissionHook, attr Attributes) { +func (m *AdmissionMetrics) ObserveExternalWebhook(elapsed time.Duration, rejected bool, hook *v1alpha1.Webhook, attr Attributes) { t := "validating" // TODO: pass in type (validating|mutating) once mutating webhook functionality has been implemented gvr := attr.GetResource() - m.externalWebhook.observe(elapsed, hook.Name, t, string(attr.GetOperation()), gvr.Group, gvr.Version, gvr.Resource, attr.GetSubresource(), isSystemNsLabel(attr), strconv.FormatBool(rejected)) -} - -// isSystemNsLabel returns the value to use for the `is_system_ns` metric label. -func isSystemNsLabel(a Attributes) string { - return strconv.FormatBool(a.GetNamespace() == metav1.NamespaceSystem) + m.externalWebhook.observe(elapsed, hook.Name, t, string(attr.GetOperation()), gvr.Group, gvr.Version, gvr.Resource, attr.GetSubresource(), strconv.FormatBool(rejected)) } type metricSet struct { diff --git a/pkg/admission/metrics_test.go b/pkg/admission/metrics_test.go index 202f7f84d..c1402e50a 100644 --- a/pkg/admission/metrics_test.go +++ b/pkg/admission/metrics_test.go @@ -41,7 +41,6 @@ func TestObserveAdmissionStep(t *testing.T) { "resource": resource.Resource, "subresource": "subresource", "type": "mutating", - "isSystemNs": "false", "rejected": "false", } expectHistogramCountTotal(t, "apiserver_admission_step_latencies", wantLabels, 1) @@ -60,7 +59,6 @@ func TestObserveAdmissionController(t *testing.T) { "resource": resource.Resource, "subresource": "subresource", "type": "validating", - "isSystemNs": "false", "rejected": "false", } expectHistogramCountTotal(t, "apiserver_admission_controller_latencies", wantLabels, 1) @@ -69,7 +67,7 @@ func TestObserveAdmissionController(t *testing.T) { func TestObserveExternalWebhook(t *testing.T) { Metrics.reset() - hook := &v1alpha1.ExternalAdmissionHook{Name: "x"} + hook := &v1alpha1.Webhook{Name: "x"} Metrics.ObserveExternalWebhook(2*time.Second, false, hook, attr) wantLabels := map[string]string{ "name": "x", @@ -79,7 +77,6 @@ func TestObserveExternalWebhook(t *testing.T) { "resource": resource.Resource, "subresource": "subresource", "type": "validating", - "isSystemNs": "false", "rejected": "false", } expectHistogramCountTotal(t, "apiserver_admission_external_webhook_latencies", wantLabels, 1)