From 5968a5ec41b299d361235830ea52bf8183cfc3e1 Mon Sep 17 00:00:00 2001 From: Mark Robinson Date: Mon, 5 Jun 2023 09:12:16 -0700 Subject: [PATCH 01/13] Add support for endpoint topology routing hints Fix goimports Fix gocritic issue --- docs/endpointslice-metrics.md | 2 +- internal/store/endpointslice.go | 32 +++++++++++++++++++++---- internal/store/endpointslice_test.go | 36 ++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+), 6 deletions(-) diff --git a/docs/endpointslice-metrics.md b/docs/endpointslice-metrics.md index f2327a5265..e230fa30ff 100644 --- a/docs/endpointslice-metrics.md +++ b/docs/endpointslice-metrics.md @@ -5,6 +5,6 @@ | kube_endpointslice_annotations | Gauge | `endpointslice`=<endpointslice-name>
`namespace`=<endpointslice-namespace>
`annotation_ENDPOINTSLICE_ANNOTATION`=<ENDPOINTSLICE_ANNOTATION> | EXPERIMENTAL | | kube_endpointslice_info | Gauge | `endpointslice`=<endpointslice-name>
`namespace`=<endpointslice-namespace> | EXPERIMENTAL | | kube_endpointslice_ports | Gauge | `endpointslice`=<endpointslice-name>
`namespace`=<endpointslice-namespace>
`port_name`=<endpointslice-port-name>
`port_protocol`=<endpointslice-port-protocol>
`port_number`=<endpointslice-port-number> | EXPERIMENTAL | -| kube_endpointslice_endpoints | Gauge | `endpointslice`=<endpointslice-name>
`namespace`=<endpointslice-namespace>
`ready`=<endpointslice-ready>
`serving`=<endpointslice-serving>
`terminating`=<endpointslice-terminating>
`hostname`=<endpointslice-hostname>
`targetref_kind`=<endpointslice-targetref-kind>
`targetref_name`=<endpointslice-targetref-name>
`targetref_namespace`=<endpointslice-targetref-namespace>
`nodename`=<endpointslice-nodename>
`endpoint_zone`=<endpointslice-zone> | EXPERIMENTAL | +| kube_endpointslice_endpoints | Gauge | `endpointslice`=<endpointslice-name>
`namespace`=<endpointslice-namespace>
`ready`=<endpointslice-ready>
`serving`=<endpointslice-serving>
`terminating`=<endpointslice-terminating>
`hostname`=<endpointslice-hostname>
`targetref_kind`=<endpointslice-targetref-kind>
`targetref_name`=<endpointslice-targetref-name>
`targetref_namespace`=<endpointslice-targetref-namespace>
`nodename`=<endpointslice-nodename>
`endpoint_zone`=<endpointslice-zone>
`hint`=<topology-aware-routing-hint> | EXPERIMENTAL | | kube_endpointslice_labels | Gauge | `endpointslice`=<endpointslice-name>
`namespace`=<endpointslice-namespace>
`label_ENDPOINTSLICE_LABEL`=<ENDPOINTSLICE_LABEL> | EXPERIMENTAL | | kube_endpointslice_created | Gauge | `endpointslice`=<endpointslice-name>
`namespace`=<endpointslice-namespace> | EXPERIMENTAL | diff --git a/internal/store/endpointslice.go b/internal/store/endpointslice.go index 0b01284468..f732d75a1e 100644 --- a/internal/store/endpointslice.go +++ b/internal/store/endpointslice.go @@ -134,11 +134,33 @@ func endpointSliceMetricFamilies(allowAnnotationsList, allowLabelsList []string) for _, address := range ep.Addresses { newlabelValues := make([]string, len(labelValues)) copy(newlabelValues, labelValues) - m = append(m, &metric.Metric{ - LabelKeys: labelKeys, - LabelValues: append(newlabelValues, address), - Value: 1, - }) + newlabelValues = append(newlabelValues, address) + + // Hint is populated when the endpoint is configured to be zone aware and preferentially route requests to its local zone. + if ep.Hints != nil && len(ep.Hints.ForZones) > 0 { + + // Because each endpoint can have multiple zones, we need to create a metric for each zone. + // and we need to make sure we aren't adding the hint label repeatedly, we need to copy the array + zoneLabelKeys := make([]string, len(labelKeys)) + copy(zoneLabelKeys, labelKeys) + zoneLabelKeys = append(zoneLabelKeys, "hint") + for _, zone := range ep.Hints.ForZones { + zoneLabelValues := make([]string, len(newlabelValues)) + copy(zoneLabelValues, newlabelValues) + zoneLabelValues = append(zoneLabelValues, zone.Name) + m = append(m, &metric.Metric{ + LabelKeys: zoneLabelKeys, + LabelValues: zoneLabelValues, + Value: 1, + }) + } + } else { + m = append(m, &metric.Metric{ + LabelKeys: labelKeys, + LabelValues: newlabelValues, + Value: 1, + }) + } } } return &metric.Family{ diff --git a/internal/store/endpointslice_test.go b/internal/store/endpointslice_test.go index cca8638cd9..bd95123e41 100644 --- a/internal/store/endpointslice_test.go +++ b/internal/store/endpointslice_test.go @@ -17,6 +17,7 @@ import ( "testing" corev1 "k8s.io/api/core/v1" + discoveryv1 "k8s.io/api/discovery/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -122,6 +123,41 @@ func TestEndpointSliceStore(t *testing.T) { "kube_endpointslice_endpoints", }, }, + { + Obj: &discoveryv1.EndpointSlice{ + ObjectMeta: metav1.ObjectMeta{ + Name: "test_endpointslice-endpoints", + }, + AddressType: "IPv4", + Endpoints: []discoveryv1.Endpoint{ + { + NodeName: &nodename, + Conditions: discoveryv1.EndpointConditions{ + Ready: &ready, + Terminating: &terminating, + }, + Hostname: &hostname, + Zone: &zone, + Addresses: addresses, + Hints: &discoveryv1.EndpointHints{ + ForZones: []discoveryv1.ForZone{ + {Name: "zone1"}, + }, + }, + }, + }, + }, + Want: ` + # HELP kube_endpointslice_endpoints Endpoints attached to the endpointslice. + # TYPE kube_endpointslice_endpoints gauge + kube_endpointslice_endpoints{address="10.0.0.1",endpoint_nodename="node",endpoint_zone="west",endpointslice="test_endpointslice-endpoints",hostname="host",ready="true",terminating="false",hint="zone1"} 1 + kube_endpointslice_endpoints{address="192.168.1.10",endpoint_nodename="node",endpoint_zone="west",endpointslice="test_endpointslice-endpoints",hostname="host",ready="true",terminating="false",hint="zone1"} 1 + `, + + MetricNames: []string{ + "kube_endpointslice_endpoints", + }, + }, { AllowAnnotationsList: []string{ "foo", From b4247ac3d07c0fb91010737b06554d58ef1eba78 Mon Sep 17 00:00:00 2001 From: Mark Robinson Date: Mon, 17 Jul 2023 09:40:12 -0700 Subject: [PATCH 02/13] Update docs/endpointslice-metrics.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Manuel Rüger --- docs/endpointslice-metrics.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/endpointslice-metrics.md b/docs/endpointslice-metrics.md index e230fa30ff..2da40e4f45 100644 --- a/docs/endpointslice-metrics.md +++ b/docs/endpointslice-metrics.md @@ -5,6 +5,6 @@ | kube_endpointslice_annotations | Gauge | `endpointslice`=<endpointslice-name>
`namespace`=<endpointslice-namespace>
`annotation_ENDPOINTSLICE_ANNOTATION`=<ENDPOINTSLICE_ANNOTATION> | EXPERIMENTAL | | kube_endpointslice_info | Gauge | `endpointslice`=<endpointslice-name>
`namespace`=<endpointslice-namespace> | EXPERIMENTAL | | kube_endpointslice_ports | Gauge | `endpointslice`=<endpointslice-name>
`namespace`=<endpointslice-namespace>
`port_name`=<endpointslice-port-name>
`port_protocol`=<endpointslice-port-protocol>
`port_number`=<endpointslice-port-number> | EXPERIMENTAL | -| kube_endpointslice_endpoints | Gauge | `endpointslice`=<endpointslice-name>
`namespace`=<endpointslice-namespace>
`ready`=<endpointslice-ready>
`serving`=<endpointslice-serving>
`terminating`=<endpointslice-terminating>
`hostname`=<endpointslice-hostname>
`targetref_kind`=<endpointslice-targetref-kind>
`targetref_name`=<endpointslice-targetref-name>
`targetref_namespace`=<endpointslice-targetref-namespace>
`nodename`=<endpointslice-nodename>
`endpoint_zone`=<endpointslice-zone>
`hint`=<topology-aware-routing-hint> | EXPERIMENTAL | +| kube_endpointslice_endpoints | Gauge | `endpointslice`=<endpointslice-name>
`namespace`=<endpointslice-namespace>
`ready`=<endpointslice-ready>
`serving`=<endpointslice-serving>
`terminating`=<endpointslice-terminating>
`hostname`=<endpointslice-hostname>
`targetref_kind`=<endpointslice-targetref-kind>
`targetref_name`=<endpointslice-targetref-name>
`targetref_namespace`=<endpointslice-targetref-namespace>
`nodename`=<endpointslice-nodename>
`endpoint_zone`=<endpointslice-zone>
`hint`=<topology-aware-routing-hint> | EXPERIMENTAL | | kube_endpointslice_labels | Gauge | `endpointslice`=<endpointslice-name>
`namespace`=<endpointslice-namespace>
`label_ENDPOINTSLICE_LABEL`=<ENDPOINTSLICE_LABEL> | EXPERIMENTAL | | kube_endpointslice_created | Gauge | `endpointslice`=<endpointslice-name>
`namespace`=<endpointslice-namespace> | EXPERIMENTAL | From 6cb9af14e5d335a0995345e6c777b83d23ad2fc9 Mon Sep 17 00:00:00 2001 From: Mark Robinson Date: Mon, 17 Jul 2023 09:42:31 -0700 Subject: [PATCH 03/13] Update internal/store/endpointslice.go MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Manuel Rüger --- internal/store/endpointslice.go | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/internal/store/endpointslice.go b/internal/store/endpointslice.go index f732d75a1e..c74ab748fe 100644 --- a/internal/store/endpointslice.go +++ b/internal/store/endpointslice.go @@ -141,15 +141,12 @@ func endpointSliceMetricFamilies(allowAnnotationsList, allowLabelsList []string) // Because each endpoint can have multiple zones, we need to create a metric for each zone. // and we need to make sure we aren't adding the hint label repeatedly, we need to copy the array - zoneLabelKeys := make([]string, len(labelKeys)) - copy(zoneLabelKeys, labelKeys) - zoneLabelKeys = append(zoneLabelKeys, "hint") for _, zone := range ep.Hints.ForZones { zoneLabelValues := make([]string, len(newlabelValues)) copy(zoneLabelValues, newlabelValues) zoneLabelValues = append(zoneLabelValues, zone.Name) m = append(m, &metric.Metric{ - LabelKeys: zoneLabelKeys, + LabelKeys: append(labelKeys, "hint"), LabelValues: zoneLabelValues, Value: 1, }) From 7cdf165fb04713572d8a2a909c2e33a1499871ee Mon Sep 17 00:00:00 2001 From: Mark Robinson Date: Fri, 21 Jul 2023 11:46:35 -0700 Subject: [PATCH 04/13] Update Dockerfile --- Dockerfile | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index c02e3a5bc9..2e5b5d2a6e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,14 +1,13 @@ ARG GOVERSION=1.20 ARG GOARCH FROM golang:${GOVERSION} as builder -ARG GOARCH -ENV GOARCH=${GOARCH} +ENV GOARCH=${TARGETARCH} WORKDIR /go/src/k8s.io/kube-state-metrics/ COPY . /go/src/k8s.io/kube-state-metrics/ RUN make build-local -FROM gcr.io/distroless/static:latest-${GOARCH} +FROM gcr.io/distroless/static:latest-${TARGETARCH} COPY --from=builder /go/src/k8s.io/kube-state-metrics/kube-state-metrics / USER nobody From 699725b0ae11916d952d6422cfcfdc391dec29ec Mon Sep 17 00:00:00 2001 From: Mark Robinson Date: Fri, 11 Aug 2023 10:15:58 -0700 Subject: [PATCH 05/13] Update Dockerfile --- Dockerfile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 2e5b5d2a6e..c02e3a5bc9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,13 +1,14 @@ ARG GOVERSION=1.20 ARG GOARCH FROM golang:${GOVERSION} as builder -ENV GOARCH=${TARGETARCH} +ARG GOARCH +ENV GOARCH=${GOARCH} WORKDIR /go/src/k8s.io/kube-state-metrics/ COPY . /go/src/k8s.io/kube-state-metrics/ RUN make build-local -FROM gcr.io/distroless/static:latest-${TARGETARCH} +FROM gcr.io/distroless/static:latest-${GOARCH} COPY --from=builder /go/src/k8s.io/kube-state-metrics/kube-state-metrics / USER nobody From 2cf37cc4bd83c6f1ec948c5963446733fa20f0b0 Mon Sep 17 00:00:00 2001 From: Mark Robinson Date: Fri, 11 Aug 2023 10:16:34 -0700 Subject: [PATCH 06/13] Update endpointslice_test.go --- internal/store/endpointslice_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/internal/store/endpointslice_test.go b/internal/store/endpointslice_test.go index bd95123e41..6655996d29 100644 --- a/internal/store/endpointslice_test.go +++ b/internal/store/endpointslice_test.go @@ -17,7 +17,6 @@ import ( "testing" corev1 "k8s.io/api/core/v1" - discoveryv1 "k8s.io/api/discovery/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" From 3ae8a286857cd6f03a37a4dc65a4c56e854d9aac Mon Sep 17 00:00:00 2001 From: Mark Robinson Date: Tue, 29 Aug 2023 10:36:31 -0700 Subject: [PATCH 07/13] Redesign metric --- docs/endpointslice-metrics.md | 1 + internal/store/endpointslice.go | 77 ++++++++++++++++++++-------- internal/store/endpointslice_test.go | 9 +++- 3 files changed, 63 insertions(+), 24 deletions(-) diff --git a/docs/endpointslice-metrics.md b/docs/endpointslice-metrics.md index 59af50bda4..a7cb0c4da7 100644 --- a/docs/endpointslice-metrics.md +++ b/docs/endpointslice-metrics.md @@ -6,5 +6,6 @@ | kube_endpointslice_info | Gauge | | `endpointslice`=<endpointslice-name>
`namespace`=<endpointslice-namespace> | EXPERIMENTAL | | kube_endpointslice_ports | Gauge | | `endpointslice`=<endpointslice-name>
`namespace`=<endpointslice-namespace>
`port_name`=<endpointslice-port-name>
`port_protocol`=<endpointslice-port-protocol>
`port_number`=<endpointslice-port-number> | EXPERIMENTAL | | kube_endpointslice_endpoints | Gauge | | `endpointslice`=<endpointslice-name>
`namespace`=<endpointslice-namespace>
`ready`=<endpointslice-ready>
`serving`=<endpointslice-serving>
`terminating`=<endpointslice-terminating>
`hostname`=<endpointslice-hostname>
`targetref_kind`=<endpointslice-targetref-kind>
`targetref_name`=<endpointslice-targetref-name>
`targetref_namespace`=<endpointslice-targetref-namespace>
`nodename`=<endpointslice-nodename>
`endpoint_zone`=<endpointslice-zone> | EXPERIMENTAL | +| kube_endpointslice_endpoints_hints | Gauge | Each line is a hint applied to an endpoint-slice | `endpointslice`=<endpointslice-name>
`namespace`=<endpointslice-namespace>
`address`=<endpointslice-address[0]>
`hostname`=<endpointslice-hostname>
`endpoint_zone`=<endpointslice-zone>
`hint`=<endpointslice-hint> | EXPERIMENTAL | | kube_endpointslice_labels | Gauge | Kubernetes labels converted to Prometheus labels controlled via [--metric-labels-allowlist](./cli-arguments.md) | `endpointslice`=<endpointslice-name>
`namespace`=<endpointslice-namespace>
`label_ENDPOINTSLICE_LABEL`=<ENDPOINTSLICE_LABEL> | EXPERIMENTAL | | kube_endpointslice_created | Gauge | | `endpointslice`=<endpointslice-name>
`namespace`=<endpointslice-namespace> | EXPERIMENTAL | diff --git a/internal/store/endpointslice.go b/internal/store/endpointslice.go index e24eb06e61..370b5e84c3 100644 --- a/internal/store/endpointslice.go +++ b/internal/store/endpointslice.go @@ -74,6 +74,56 @@ func endpointSliceMetricFamilies(allowAnnotationsList, allowLabelsList []string) } }), ), + *generator.NewFamilyGeneratorWithStability( + "kube_endpointslice_endpoints_hints", + "Topology routing hints attached to endpoints", + metric.Gauge, + basemetrics.ALPHA, + "", + wrapEndpointSliceFunc(func(e *discoveryv1.EndpointSlice) *metric.Family { + m := []*metric.Metric{} + for _, ep := range e.Endpoints { + // Hint is populated when the endpoint is configured to be zone aware and preferentially route requests to its local zone. + // If there is no hint, skip this metric + if ep.Hints != nil && len(ep.Hints.ForZones) > 0 { + var ( + labelKeys, + labelValues []string + ) + + if ep.Hostname != nil { + labelKeys = append(labelKeys, "hostname") + labelValues = append(labelValues, *ep.Hostname) + } + + // Did you know that k8s will "assign" endpoints from a zone + // This field is useful for debugging weird network routing issues + if ep.Zone != nil { + labelKeys = append(labelKeys, "endpoint_zone") + labelValues = append(labelValues, *ep.Zone) + } + + // Per Docs. + // This must contain at least one address but no more than + // 100. These are all assumed to be fungible and clients may choose to only + // use the first element. Refer to: https://issue.k8s.io/106267 + labelKeys = append(labelKeys, "address") + labelValues = append(labelValues, ep.Addresses[0]) + + for _, zone := range ep.Hints.ForZones { + m = append(m, &metric.Metric{ + LabelKeys: append(labelKeys, "hint"), + LabelValues: append(labelValues, zone.Name), + Value: 1, + }) + } + } + } + return &metric.Family{ + Metrics: m, + } + }), + ), *generator.NewFamilyGeneratorWithStability( "kube_endpointslice_endpoints", "Endpoints attached to the endpointslice.", @@ -136,28 +186,11 @@ func endpointSliceMetricFamilies(allowAnnotationsList, allowLabelsList []string) copy(newlabelValues, labelValues) newlabelValues = append(newlabelValues, address) - // Hint is populated when the endpoint is configured to be zone aware and preferentially route requests to its local zone. - if ep.Hints != nil && len(ep.Hints.ForZones) > 0 { - - // Because each endpoint can have multiple zones, we need to create a metric for each zone. - // and we need to make sure we aren't adding the hint label repeatedly, we need to copy the array - for _, zone := range ep.Hints.ForZones { - zoneLabelValues := make([]string, len(newlabelValues)) - copy(zoneLabelValues, newlabelValues) - zoneLabelValues = append(zoneLabelValues, zone.Name) - m = append(m, &metric.Metric{ - LabelKeys: append(labelKeys, "hint"), - LabelValues: zoneLabelValues, - Value: 1, - }) - } - } else { - m = append(m, &metric.Metric{ - LabelKeys: labelKeys, - LabelValues: newlabelValues, - Value: 1, - }) - } + m = append(m, &metric.Metric{ + LabelKeys: labelKeys, + LabelValues: newlabelValues, + Value: 1, + }) } } return &metric.Family{ diff --git a/internal/store/endpointslice_test.go b/internal/store/endpointslice_test.go index d7d79c5e5c..d86d4e821b 100644 --- a/internal/store/endpointslice_test.go +++ b/internal/store/endpointslice_test.go @@ -113,7 +113,9 @@ func TestEndpointSliceStore(t *testing.T) { }, Want: ` # HELP kube_endpointslice_endpoints Endpoints attached to the endpointslice. + # HELP kube_endpointslice_endpoints_hints Topology routing hints attached to endpoints # TYPE kube_endpointslice_endpoints gauge + # TYPE kube_endpointslice_endpoints_hints gauge kube_endpointslice_endpoints{address="10.0.0.1",endpoint_nodename="node",endpoint_zone="west",endpointslice="test_endpointslice-endpoints",hostname="host",ready="true",terminating="false"} 1 kube_endpointslice_endpoints{address="192.168.1.10",endpoint_nodename="node",endpoint_zone="west",endpointslice="test_endpointslice-endpoints",hostname="host",ready="true",terminating="false"} 1 `, @@ -148,9 +150,12 @@ func TestEndpointSliceStore(t *testing.T) { }, Want: ` # HELP kube_endpointslice_endpoints Endpoints attached to the endpointslice. + # HELP kube_endpointslice_endpoints_hints Topology routing hints attached to endpoints # TYPE kube_endpointslice_endpoints gauge - kube_endpointslice_endpoints{address="10.0.0.1",endpoint_nodename="node",endpoint_zone="west",endpointslice="test_endpointslice-endpoints",hostname="host",ready="true",terminating="false",hint="zone1"} 1 - kube_endpointslice_endpoints{address="192.168.1.10",endpoint_nodename="node",endpoint_zone="west",endpointslice="test_endpointslice-endpoints",hostname="host",ready="true",terminating="false",hint="zone1"} 1 + # TYPE kube_endpointslice_endpoints_hints gauge + kube_endpointslice_endpoints_hints{address="10.0.0.1",endpoint_zone="west",endpointslice="test_endpointslice-endpoints",hint="zone1",hostname="host"} 1 + kube_endpointslice_endpoints{address="10.0.0.1",endpoint_nodename="node",endpoint_zone="west",endpointslice="test_endpointslice-endpoints",hostname="host",ready="true",terminating="false"} 1 + kube_endpointslice_endpoints{address="192.168.1.10",endpoint_nodename="node",endpoint_zone="west",endpointslice="test_endpointslice-endpoints",hostname="host",ready="true",terminating="false"} 1 `, MetricNames: []string{ From ada647eaa1f3e2fc29de126a2d5c5ae345eb3683 Mon Sep 17 00:00:00 2001 From: Mark Robinson Date: Wed, 30 Aug 2023 12:20:50 -0700 Subject: [PATCH 08/13] Update endpointslice.go Remove unneeded label --- internal/store/endpointslice.go | 7 ------- 1 file changed, 7 deletions(-) diff --git a/internal/store/endpointslice.go b/internal/store/endpointslice.go index 370b5e84c3..08be2bdbcb 100644 --- a/internal/store/endpointslice.go +++ b/internal/store/endpointslice.go @@ -96,13 +96,6 @@ func endpointSliceMetricFamilies(allowAnnotationsList, allowLabelsList []string) labelValues = append(labelValues, *ep.Hostname) } - // Did you know that k8s will "assign" endpoints from a zone - // This field is useful for debugging weird network routing issues - if ep.Zone != nil { - labelKeys = append(labelKeys, "endpoint_zone") - labelValues = append(labelValues, *ep.Zone) - } - // Per Docs. // This must contain at least one address but no more than // 100. These are all assumed to be fungible and clients may choose to only From 1d03e5cfdbf308211b053ad24403d63de0a4b0f7 Mon Sep 17 00:00:00 2001 From: Mark Robinson Date: Wed, 30 Aug 2023 12:21:23 -0700 Subject: [PATCH 09/13] Update endpointslice.go --- internal/store/endpointslice.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/store/endpointslice.go b/internal/store/endpointslice.go index 08be2bdbcb..6570f0ad26 100644 --- a/internal/store/endpointslice.go +++ b/internal/store/endpointslice.go @@ -105,7 +105,7 @@ func endpointSliceMetricFamilies(allowAnnotationsList, allowLabelsList []string) for _, zone := range ep.Hints.ForZones { m = append(m, &metric.Metric{ - LabelKeys: append(labelKeys, "hint"), + LabelKeys: append(labelKeys, "for_zone"), LabelValues: append(labelValues, zone.Name), Value: 1, }) From 8215b55e465be2e4b85b47218700c0fa3d309e09 Mon Sep 17 00:00:00 2001 From: Mark Robinson Date: Wed, 30 Aug 2023 12:22:14 -0700 Subject: [PATCH 10/13] Update endpointslice-metrics.md --- docs/endpointslice-metrics.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/endpointslice-metrics.md b/docs/endpointslice-metrics.md index a7cb0c4da7..115f208023 100644 --- a/docs/endpointslice-metrics.md +++ b/docs/endpointslice-metrics.md @@ -6,6 +6,6 @@ | kube_endpointslice_info | Gauge | | `endpointslice`=<endpointslice-name>
`namespace`=<endpointslice-namespace> | EXPERIMENTAL | | kube_endpointslice_ports | Gauge | | `endpointslice`=<endpointslice-name>
`namespace`=<endpointslice-namespace>
`port_name`=<endpointslice-port-name>
`port_protocol`=<endpointslice-port-protocol>
`port_number`=<endpointslice-port-number> | EXPERIMENTAL | | kube_endpointslice_endpoints | Gauge | | `endpointslice`=<endpointslice-name>
`namespace`=<endpointslice-namespace>
`ready`=<endpointslice-ready>
`serving`=<endpointslice-serving>
`terminating`=<endpointslice-terminating>
`hostname`=<endpointslice-hostname>
`targetref_kind`=<endpointslice-targetref-kind>
`targetref_name`=<endpointslice-targetref-name>
`targetref_namespace`=<endpointslice-targetref-namespace>
`nodename`=<endpointslice-nodename>
`endpoint_zone`=<endpointslice-zone> | EXPERIMENTAL | -| kube_endpointslice_endpoints_hints | Gauge | Each line is a hint applied to an endpoint-slice | `endpointslice`=<endpointslice-name>
`namespace`=<endpointslice-namespace>
`address`=<endpointslice-address[0]>
`hostname`=<endpointslice-hostname>
`endpoint_zone`=<endpointslice-zone>
`hint`=<endpointslice-hint> | EXPERIMENTAL | +| kube_endpointslice_endpoints_hints | Gauge | Each line is a hint applied to an endpoint-slice | `endpointslice`=<endpointslice-name>
`namespace`=<endpointslice-namespace>
`address`=<endpointslice-address[0]>
`hostname`=<endpointslice-hostname>
`for_zone`=<endpointslice-hint> | EXPERIMENTAL | | kube_endpointslice_labels | Gauge | Kubernetes labels converted to Prometheus labels controlled via [--metric-labels-allowlist](./cli-arguments.md) | `endpointslice`=<endpointslice-name>
`namespace`=<endpointslice-namespace>
`label_ENDPOINTSLICE_LABEL`=<ENDPOINTSLICE_LABEL> | EXPERIMENTAL | | kube_endpointslice_created | Gauge | | `endpointslice`=<endpointslice-name>
`namespace`=<endpointslice-namespace> | EXPERIMENTAL | From e47e783cc636f4a077b2ee21317d0354c1cf7455 Mon Sep 17 00:00:00 2001 From: Mark Robinson Date: Wed, 30 Aug 2023 12:26:45 -0700 Subject: [PATCH 11/13] Fix test --- internal/store/endpointslice_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/store/endpointslice_test.go b/internal/store/endpointslice_test.go index d86d4e821b..140f90c550 100644 --- a/internal/store/endpointslice_test.go +++ b/internal/store/endpointslice_test.go @@ -153,7 +153,7 @@ func TestEndpointSliceStore(t *testing.T) { # HELP kube_endpointslice_endpoints_hints Topology routing hints attached to endpoints # TYPE kube_endpointslice_endpoints gauge # TYPE kube_endpointslice_endpoints_hints gauge - kube_endpointslice_endpoints_hints{address="10.0.0.1",endpoint_zone="west",endpointslice="test_endpointslice-endpoints",hint="zone1",hostname="host"} 1 + kube_endpointslice_endpoints_hints{address="10.0.0.1",endpointslice="test_endpointslice-endpoints",for_zone="zone1",hostname="host"} 1 kube_endpointslice_endpoints{address="10.0.0.1",endpoint_nodename="node",endpoint_zone="west",endpointslice="test_endpointslice-endpoints",hostname="host",ready="true",terminating="false"} 1 kube_endpointslice_endpoints{address="192.168.1.10",endpoint_nodename="node",endpoint_zone="west",endpointslice="test_endpointslice-endpoints",hostname="host",ready="true",terminating="false"} 1 `, From 92f8173ffa3d1ccdb4038912b02e5af8685cd2f6 Mon Sep 17 00:00:00 2001 From: Mark Robinson Date: Wed, 30 Aug 2023 14:21:38 -0700 Subject: [PATCH 12/13] Remove hostname --- internal/store/endpointslice.go | 5 ----- internal/store/endpointslice_test.go | 2 +- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/internal/store/endpointslice.go b/internal/store/endpointslice.go index 6570f0ad26..bf80cebbd4 100644 --- a/internal/store/endpointslice.go +++ b/internal/store/endpointslice.go @@ -91,11 +91,6 @@ func endpointSliceMetricFamilies(allowAnnotationsList, allowLabelsList []string) labelValues []string ) - if ep.Hostname != nil { - labelKeys = append(labelKeys, "hostname") - labelValues = append(labelValues, *ep.Hostname) - } - // Per Docs. // This must contain at least one address but no more than // 100. These are all assumed to be fungible and clients may choose to only diff --git a/internal/store/endpointslice_test.go b/internal/store/endpointslice_test.go index 140f90c550..16a6ff61d8 100644 --- a/internal/store/endpointslice_test.go +++ b/internal/store/endpointslice_test.go @@ -153,7 +153,7 @@ func TestEndpointSliceStore(t *testing.T) { # HELP kube_endpointslice_endpoints_hints Topology routing hints attached to endpoints # TYPE kube_endpointslice_endpoints gauge # TYPE kube_endpointslice_endpoints_hints gauge - kube_endpointslice_endpoints_hints{address="10.0.0.1",endpointslice="test_endpointslice-endpoints",for_zone="zone1",hostname="host"} 1 + kube_endpointslice_endpoints_hints{address="10.0.0.1",endpointslice="test_endpointslice-endpoints",for_zone="zone1"} 1 kube_endpointslice_endpoints{address="10.0.0.1",endpoint_nodename="node",endpoint_zone="west",endpointslice="test_endpointslice-endpoints",hostname="host",ready="true",terminating="false"} 1 kube_endpointslice_endpoints{address="192.168.1.10",endpoint_nodename="node",endpoint_zone="west",endpointslice="test_endpointslice-endpoints",hostname="host",ready="true",terminating="false"} 1 `, From 2362bf2189f30ade1ec70d8f99a94580f15d07cc Mon Sep 17 00:00:00 2001 From: Damien Grisonnet Date: Thu, 31 Aug 2023 16:21:57 +0200 Subject: [PATCH 13/13] Update docs/endpointslice-metrics.md --- docs/endpointslice-metrics.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/endpointslice-metrics.md b/docs/endpointslice-metrics.md index 115f208023..9b914e3544 100644 --- a/docs/endpointslice-metrics.md +++ b/docs/endpointslice-metrics.md @@ -6,6 +6,6 @@ | kube_endpointslice_info | Gauge | | `endpointslice`=<endpointslice-name>
`namespace`=<endpointslice-namespace> | EXPERIMENTAL | | kube_endpointslice_ports | Gauge | | `endpointslice`=<endpointslice-name>
`namespace`=<endpointslice-namespace>
`port_name`=<endpointslice-port-name>
`port_protocol`=<endpointslice-port-protocol>
`port_number`=<endpointslice-port-number> | EXPERIMENTAL | | kube_endpointslice_endpoints | Gauge | | `endpointslice`=<endpointslice-name>
`namespace`=<endpointslice-namespace>
`ready`=<endpointslice-ready>
`serving`=<endpointslice-serving>
`terminating`=<endpointslice-terminating>
`hostname`=<endpointslice-hostname>
`targetref_kind`=<endpointslice-targetref-kind>
`targetref_name`=<endpointslice-targetref-name>
`targetref_namespace`=<endpointslice-targetref-namespace>
`nodename`=<endpointslice-nodename>
`endpoint_zone`=<endpointslice-zone> | EXPERIMENTAL | -| kube_endpointslice_endpoints_hints | Gauge | Each line is a hint applied to an endpoint-slice | `endpointslice`=<endpointslice-name>
`namespace`=<endpointslice-namespace>
`address`=<endpointslice-address[0]>
`hostname`=<endpointslice-hostname>
`for_zone`=<endpointslice-hint> | EXPERIMENTAL | +| kube_endpointslice_endpoints_hints | Gauge | Each line is a hint applied to an endpoint-slice | `endpointslice`=<endpointslice-name>
`namespace`=<endpointslice-namespace>
`address`=<endpointslice-address[0]>
`for_zone`=<endpointslice-hint> | EXPERIMENTAL | | kube_endpointslice_labels | Gauge | Kubernetes labels converted to Prometheus labels controlled via [--metric-labels-allowlist](./cli-arguments.md) | `endpointslice`=<endpointslice-name>
`namespace`=<endpointslice-namespace>
`label_ENDPOINTSLICE_LABEL`=<ENDPOINTSLICE_LABEL> | EXPERIMENTAL | | kube_endpointslice_created | Gauge | | `endpointslice`=<endpointslice-name>
`namespace`=<endpointslice-namespace> | EXPERIMENTAL |