Remove is_system_ns from admission metrics

Kubernetes-commit: 375e2d03ab8c70c8c84676a7eee8b46646036bde
This commit is contained in:
Joe Betz 2017-11-13 12:34:36 -08:00 committed by Kubernetes Publisher
parent f3058e0b10
commit 3773a59cf0
4 changed files with 10 additions and 24 deletions

View File

@ -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",

View File

@ -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)

View File

@ -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 {

View File

@ -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)