Merge pull request #2114 from dgrisonnet/webhook-services
feat: Add webhooks client config service metrics
This commit is contained in:
commit
61c9de04cd
|
|
@ -5,3 +5,4 @@
|
||||||
| kube_mutatingwebhookconfiguration_info | Gauge | `mutatingwebhookconfiguration`=<mutatingwebhookconfiguration-name> <br> `namespace`=<mutatingwebhookconfiguration-namespace> | EXPERIMENTAL |
|
| kube_mutatingwebhookconfiguration_info | Gauge | `mutatingwebhookconfiguration`=<mutatingwebhookconfiguration-name> <br> `namespace`=<mutatingwebhookconfiguration-namespace> | EXPERIMENTAL |
|
||||||
| kube_mutatingwebhookconfiguration_created | Gauge | `mutatingwebhookconfiguration`=<mutatingwebhookconfiguration-name> <br> `namespace`=<mutatingwebhookconfiguration-namespace> | EXPERIMENTAL |
|
| kube_mutatingwebhookconfiguration_created | Gauge | `mutatingwebhookconfiguration`=<mutatingwebhookconfiguration-name> <br> `namespace`=<mutatingwebhookconfiguration-namespace> | EXPERIMENTAL |
|
||||||
| kube_mutatingwebhookconfiguration_metadata_resource_version | Gauge | `mutatingwebhookconfiguration`=<mutatingwebhookconfiguration-name> <br> `namespace`=<mutatingwebhookconfiguration-namespace> | EXPERIMENTAL |
|
| kube_mutatingwebhookconfiguration_metadata_resource_version | Gauge | `mutatingwebhookconfiguration`=<mutatingwebhookconfiguration-name> <br> `namespace`=<mutatingwebhookconfiguration-namespace> | EXPERIMENTAL |
|
||||||
|
| kube_mutatingwebhookconfiguration_webhook_clientconfig_service | Gauge | `mutatingwebhookconfiguration`=<mutatingwebhookconfiguration-name> <br> `namespace`=<mutatingwebhookconfiguration-namespace> <br> `webhook_name`=<webhook-name> <br> `service_name`=<webhook-service-name> <br> `service_namespace`=<webhook-service-namespace>| EXPERIMENTAL |
|
||||||
|
|
|
||||||
|
|
@ -5,3 +5,4 @@
|
||||||
| kube_validatingwebhookconfiguration_info | Gauge | `validatingwebhookconfiguration`=<validatingwebhookconfiguration-name> <br> `namespace`=<validatingwebhookconfiguration-namespace> | EXPERIMENTAL |
|
| kube_validatingwebhookconfiguration_info | Gauge | `validatingwebhookconfiguration`=<validatingwebhookconfiguration-name> <br> `namespace`=<validatingwebhookconfiguration-namespace> | EXPERIMENTAL |
|
||||||
| kube_validatingwebhookconfiguration_created | Gauge | `validatingwebhookconfiguration`=<validatingwebhookconfiguration-name> <br> `namespace`=<validatingwebhookconfiguration-namespace> | EXPERIMENTAL |
|
| kube_validatingwebhookconfiguration_created | Gauge | `validatingwebhookconfiguration`=<validatingwebhookconfiguration-name> <br> `namespace`=<validatingwebhookconfiguration-namespace> | EXPERIMENTAL |
|
||||||
| kube_validatingwebhookconfiguration_metadata_resource_version | Gauge | `validatingwebhookconfiguration`=<validatingwebhookconfiguration-name> <br> `namespace`=<validatingwebhookconfiguration-namespace> | EXPERIMENTAL |
|
| kube_validatingwebhookconfiguration_metadata_resource_version | Gauge | `validatingwebhookconfiguration`=<validatingwebhookconfiguration-name> <br> `namespace`=<validatingwebhookconfiguration-namespace> | EXPERIMENTAL |
|
||||||
|
| kube_validatingwebhookconfiguration_webhook_clientconfig_service | Gauge | `validatingwebhookconfiguration`=<validatingwebhookconfiguration-name> <br> `namespace`=<validatingwebhookconfiguration-namespace> <br> `webhook_name`=<webhook-name> <br> `service_name`=<webhook-service-name> <br> `service_namespace`=<webhook-service-namespace>| EXPERIMENTAL |
|
||||||
|
|
|
||||||
|
|
@ -82,6 +82,32 @@ var (
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
|
*generator.NewFamilyGeneratorWithStability(
|
||||||
|
"kube_mutatingwebhookconfiguration_webhook_clientconfig_service",
|
||||||
|
"Service used by the apiserver to connect to a mutating webhook.",
|
||||||
|
metric.Gauge,
|
||||||
|
basemetrics.ALPHA,
|
||||||
|
"",
|
||||||
|
wrapMutatingWebhookConfigurationFunc(func(mwc *admissionregistrationv1.MutatingWebhookConfiguration) *metric.Family {
|
||||||
|
ms := []*metric.Metric{}
|
||||||
|
for _, webhook := range mwc.Webhooks {
|
||||||
|
var serviceName, serviceNamespace string
|
||||||
|
if webhook.ClientConfig.Service != nil {
|
||||||
|
serviceName = webhook.ClientConfig.Service.Name
|
||||||
|
serviceNamespace = webhook.ClientConfig.Service.Namespace
|
||||||
|
}
|
||||||
|
|
||||||
|
ms = append(ms, &metric.Metric{
|
||||||
|
LabelKeys: []string{"webhook_name", "service_name", "service_namespace"},
|
||||||
|
LabelValues: []string{webhook.Name, serviceName, serviceNamespace},
|
||||||
|
Value: 1,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return &metric.Family{
|
||||||
|
Metrics: ms,
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
),
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,7 @@ import (
|
||||||
func TestMutatingWebhookConfigurationStore(t *testing.T) {
|
func TestMutatingWebhookConfigurationStore(t *testing.T) {
|
||||||
startTime := 1501569018
|
startTime := 1501569018
|
||||||
metav1StartTime := metav1.Unix(int64(startTime), 0)
|
metav1StartTime := metav1.Unix(int64(startTime), 0)
|
||||||
|
externalURL := "example.com"
|
||||||
|
|
||||||
cases := []generateMetricsTestCase{
|
cases := []generateMetricsTestCase{
|
||||||
{
|
{
|
||||||
|
|
@ -69,6 +70,37 @@ func TestMutatingWebhookConfigurationStore(t *testing.T) {
|
||||||
`,
|
`,
|
||||||
MetricNames: []string{"kube_mutatingwebhookconfiguration_created", "kube_mutatingwebhookconfiguration_info", "kube_mutatingwebhookconfiguration_metadata_resource_version"},
|
MetricNames: []string{"kube_mutatingwebhookconfiguration_created", "kube_mutatingwebhookconfiguration_info", "kube_mutatingwebhookconfiguration_metadata_resource_version"},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Obj: &admissionregistrationv1.MutatingWebhookConfiguration{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Name: "mutatingwebhookconfiguration3",
|
||||||
|
Namespace: "ns3",
|
||||||
|
CreationTimestamp: metav1StartTime,
|
||||||
|
ResourceVersion: "abcdef",
|
||||||
|
},
|
||||||
|
Webhooks: []admissionregistrationv1.MutatingWebhook{
|
||||||
|
{
|
||||||
|
Name: "webhook_with_service",
|
||||||
|
ClientConfig: admissionregistrationv1.WebhookClientConfig{
|
||||||
|
Service: &admissionregistrationv1.ServiceReference{Name: "svc", Namespace: "ns"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "webhook_with_external_url",
|
||||||
|
ClientConfig: admissionregistrationv1.WebhookClientConfig{
|
||||||
|
URL: &externalURL,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Want: `
|
||||||
|
# HELP kube_mutatingwebhookconfiguration_webhook_clientconfig_service Service used by the apiserver to connect to a mutating webhook.
|
||||||
|
# TYPE kube_mutatingwebhookconfiguration_webhook_clientconfig_service gauge
|
||||||
|
kube_mutatingwebhookconfiguration_webhook_clientconfig_service{webhook_name="webhook_with_external_url",namespace="ns3",service_name="",service_namespace="",mutatingwebhookconfiguration="mutatingwebhookconfiguration3"} 1
|
||||||
|
kube_mutatingwebhookconfiguration_webhook_clientconfig_service{webhook_name="webhook_with_service",namespace="ns3",service_name="svc",service_namespace="ns",mutatingwebhookconfiguration="mutatingwebhookconfiguration3"} 1
|
||||||
|
`,
|
||||||
|
MetricNames: []string{"kube_mutatingwebhookconfiguration_webhook_clientconfig_service"},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
for i, c := range cases {
|
for i, c := range cases {
|
||||||
c.Func = generator.ComposeMetricGenFuncs(mutatingWebhookConfigurationMetricFamilies)
|
c.Func = generator.ComposeMetricGenFuncs(mutatingWebhookConfigurationMetricFamilies)
|
||||||
|
|
|
||||||
|
|
@ -82,6 +82,32 @@ var (
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
|
*generator.NewFamilyGeneratorWithStability(
|
||||||
|
"kube_validatingwebhookconfiguration_webhook_clientconfig_service",
|
||||||
|
"Service used by the apiserver to connect to a validating webhook.",
|
||||||
|
metric.Gauge,
|
||||||
|
basemetrics.ALPHA,
|
||||||
|
"",
|
||||||
|
wrapValidatingWebhookConfigurationFunc(func(vwc *admissionregistrationv1.ValidatingWebhookConfiguration) *metric.Family {
|
||||||
|
ms := []*metric.Metric{}
|
||||||
|
for _, webhook := range vwc.Webhooks {
|
||||||
|
var serviceName, serviceNamespace string
|
||||||
|
if webhook.ClientConfig.Service != nil {
|
||||||
|
serviceName = webhook.ClientConfig.Service.Name
|
||||||
|
serviceNamespace = webhook.ClientConfig.Service.Namespace
|
||||||
|
}
|
||||||
|
|
||||||
|
ms = append(ms, &metric.Metric{
|
||||||
|
LabelKeys: []string{"webhook_name", "service_name", "service_namespace"},
|
||||||
|
LabelValues: []string{webhook.Name, serviceName, serviceNamespace},
|
||||||
|
Value: 1,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return &metric.Family{
|
||||||
|
Metrics: ms,
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
),
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,7 @@ import (
|
||||||
func TestValidatingWebhookConfigurationStore(t *testing.T) {
|
func TestValidatingWebhookConfigurationStore(t *testing.T) {
|
||||||
startTime := 1501569018
|
startTime := 1501569018
|
||||||
metav1StartTime := metav1.Unix(int64(startTime), 0)
|
metav1StartTime := metav1.Unix(int64(startTime), 0)
|
||||||
|
externalURL := "example.com"
|
||||||
|
|
||||||
cases := []generateMetricsTestCase{
|
cases := []generateMetricsTestCase{
|
||||||
{
|
{
|
||||||
|
|
@ -69,6 +70,37 @@ func TestValidatingWebhookConfigurationStore(t *testing.T) {
|
||||||
`,
|
`,
|
||||||
MetricNames: []string{"kube_validatingwebhookconfiguration_created", "kube_validatingwebhookconfiguration_info", "kube_validatingwebhookconfiguration_metadata_resource_version"},
|
MetricNames: []string{"kube_validatingwebhookconfiguration_created", "kube_validatingwebhookconfiguration_info", "kube_validatingwebhookconfiguration_metadata_resource_version"},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Obj: &admissionregistrationv1.ValidatingWebhookConfiguration{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Name: "validatingwebhookconfiguration3",
|
||||||
|
Namespace: "ns3",
|
||||||
|
CreationTimestamp: metav1StartTime,
|
||||||
|
ResourceVersion: "abcdef",
|
||||||
|
},
|
||||||
|
Webhooks: []admissionregistrationv1.ValidatingWebhook{
|
||||||
|
{
|
||||||
|
Name: "webhook_with_service",
|
||||||
|
ClientConfig: admissionregistrationv1.WebhookClientConfig{
|
||||||
|
Service: &admissionregistrationv1.ServiceReference{Name: "svc", Namespace: "ns"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "webhook_with_external_url",
|
||||||
|
ClientConfig: admissionregistrationv1.WebhookClientConfig{
|
||||||
|
URL: &externalURL,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Want: `
|
||||||
|
# HELP kube_validatingwebhookconfiguration_webhook_clientconfig_service Service used by the apiserver to connect to a validating webhook.
|
||||||
|
# TYPE kube_validatingwebhookconfiguration_webhook_clientconfig_service gauge
|
||||||
|
kube_validatingwebhookconfiguration_webhook_clientconfig_service{webhook_name="webhook_with_external_url",namespace="ns3",service_name="",service_namespace="",validatingwebhookconfiguration="validatingwebhookconfiguration3"} 1
|
||||||
|
kube_validatingwebhookconfiguration_webhook_clientconfig_service{webhook_name="webhook_with_service",namespace="ns3",service_name="svc",service_namespace="ns",validatingwebhookconfiguration="validatingwebhookconfiguration3"} 1
|
||||||
|
`,
|
||||||
|
MetricNames: []string{"kube_validatingwebhookconfiguration_webhook_clientconfig_service"},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
for i, c := range cases {
|
for i, c := range cases {
|
||||||
c.Func = generator.ComposeMetricGenFuncs(validatingWebhookConfigurationMetricFamilies)
|
c.Func = generator.ComposeMetricGenFuncs(validatingWebhookConfigurationMetricFamilies)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue