Skip to content

Commit

Permalink
feat(endpoints): Move ports into address metric
Browse files Browse the repository at this point in the history
This marks kube_endpoint_ports as deprecated

Fixes #2408
  • Loading branch information
mrueg committed Oct 16, 2024
1 parent e295191 commit 2764e17
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 30 deletions.
4 changes: 2 additions & 2 deletions docs/metrics/service/endpoint-metrics.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
| kube_endpoint_info | Gauge | | `endpoint`=&lt;endpoint-name&gt; <br> `namespace`=&lt;endpoint-namespace&gt; | STABLE |
| kube_endpoint_labels | Gauge | Kubernetes labels converted to Prometheus labels controlled via [--metric-labels-allowlist](../../developer/cli-arguments.md) | `endpoint`=&lt;endpoint-name&gt; <br> `namespace`=&lt;endpoint-namespace&gt; <br> `label_ENDPOINT_LABEL`=&lt;ENDPOINT_LABEL&gt; | STABLE |
| kube_endpoint_created | Gauge | | `endpoint`=&lt;endpoint-name&gt; <br> `namespace`=&lt;endpoint-namespace&gt; | STABLE |
| kube_endpoint_ports | Gauge | | `endpoint`=&lt;endpoint-name&gt; <br> `namespace`=&lt;endpoint-namespace&gt; <br> `port_name`=&lt;endpoint-port-name&gt; <br> `port_protocol`=&lt;endpoint-port-protocol&gt; <br> `port_number`=&lt;endpoint-port-number&gt; | STABLE |
| kube_endpoint_address | Gauge | | `endpoint`=&lt;endpoint-name&gt; <br> `namespace`=&lt;endpoint-namespace&gt; <br> `ip`=&lt;endpoint-ip&gt; <br> `ready`=&lt;true if available, false if unavailalbe&gt; | STABLE |
| kube_endpoint_ports | Gauge | | `endpoint`=&lt;endpoint-name&gt; <br> `namespace`=&lt;endpoint-namespace&gt; <br> `port_name`=&lt;endpoint-port-name&gt; <br> `port_protocol`=&lt;endpoint-port-protocol&gt; <br> `port_number`=&lt;endpoint-port-number&gt; | STABLE (Deprecated from 2.14.0) |
| kube_endpoint_address | Gauge | | `endpoint`=&lt;endpoint-name&gt; <br> `namespace`=&lt;endpoint-namespace&gt; <br> `ip`=&lt;endpoint-ip&gt; <br> `port_name`=&lt;endpoint-port-name&gt; <br> `port_protocol`=&lt;endpoint-port-protocol&gt; <br> `port_number`=&lt;endpoint-port-number&gt;`ready`=&lt;true if available, false if unavailalbe&gt; | STABLE |
33 changes: 19 additions & 14 deletions internal/store/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,19 +173,24 @@ func endpointMetricFamilies(allowAnnotationsList, allowLabelsList []string) []ge
wrapEndpointFunc(func(e *v1.Endpoints) *metric.Family {
ms := []*metric.Metric{}
for _, s := range e.Subsets {
for _, available := range s.Addresses {
ms = append(ms, &metric.Metric{
LabelValues: []string{available.IP, "true"},
LabelKeys: []string{"ip", "ready"},
Value: 1,
})
}
for _, notReadyAddresses := range s.NotReadyAddresses {
ms = append(ms, &metric.Metric{
LabelValues: []string{notReadyAddresses.IP, "false"},
LabelKeys: []string{"ip", "ready"},
Value: 1,
})
for _, port := range s.Ports {
labelValues := []string{port.Name, string(port.Protocol), strconv.FormatInt(int64(port.Port), 10)}
labelKeys := []string{"port_name", "port_protocol", "port_number"}

for _, available := range s.Addresses {
ms = append(ms, &metric.Metric{
LabelValues: append(labelValues, available.IP, "true"),
LabelKeys: append(labelKeys, "ip", "ready"),
Value: 1,
})
}
for _, notReadyAddresses := range s.NotReadyAddresses {
ms = append(ms, &metric.Metric{
LabelValues: append(labelValues, notReadyAddresses.IP, "false"),
LabelKeys: append(labelKeys, "ip", "ready"),
Value: 1,
})
}
}
}
return &metric.Family{
Expand All @@ -198,7 +203,7 @@ func endpointMetricFamilies(allowAnnotationsList, allowLabelsList []string) []ge
"Information about the Endpoint ports.",
metric.Gauge,
basemetrics.STABLE,
"",
"v2.14.0",
wrapEndpointFunc(func(e *v1.Endpoints) *metric.Family {
ms := []*metric.Metric{}
for _, s := range e.Subsets {
Expand Down
40 changes: 26 additions & 14 deletions internal/store/endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func TestEndpointStore(t *testing.T) {
# TYPE kube_endpoint_info gauge
# HELP kube_endpoint_labels [STABLE] Kubernetes labels converted to Prometheus labels.
# TYPE kube_endpoint_labels gauge
# HELP kube_endpoint_ports [STABLE] Information about the Endpoint ports.
# HELP kube_endpoint_ports [STABLE] (Deprecated since v2.14.0) Information about the Endpoint ports.
# TYPE kube_endpoint_ports gauge
# HELP kube_endpoint_address [STABLE] Information about Endpoint available and non available addresses.
# TYPE kube_endpoint_address gauge
Expand Down Expand Up @@ -93,18 +93,24 @@ func TestEndpointStore(t *testing.T) {
kube_endpoint_address_not_ready{endpoint="test-endpoint",namespace="default"} 6
kube_endpoint_created{endpoint="test-endpoint",namespace="default"} 1.5e+09
kube_endpoint_info{endpoint="test-endpoint",namespace="default"} 1
kube_endpoint_address{endpoint="test-endpoint",ip="10.0.0.1",namespace="default",port_name="app",port_number="8081",port_protocol="TCP",ready="true"} 1
kube_endpoint_address{endpoint="test-endpoint",ip="10.0.0.1",namespace="default",port_name="http",port_number="8080",port_protocol="TCP",ready="true"} 1
kube_endpoint_address{endpoint="test-endpoint",ip="10.0.0.10",namespace="default",port_name="app",port_number="8081",port_protocol="TCP",ready="false"} 1
kube_endpoint_address{endpoint="test-endpoint",ip="10.0.0.10",namespace="default",port_name="http",port_number="8080",port_protocol="TCP",ready="false"} 1
kube_endpoint_address{endpoint="test-endpoint",ip="127.0.0.1",namespace="default",port_name="app",port_number="8081",port_protocol="TCP",ready="true"} 1
kube_endpoint_address{endpoint="test-endpoint",ip="127.0.0.1",namespace="default",port_name="http",port_number="8080",port_protocol="TCP",ready="true"} 1
kube_endpoint_address{endpoint="test-endpoint",ip="172.22.23.202",namespace="default",port_name="https",port_number="8443",port_protocol="TCP",ready="true"} 1
kube_endpoint_address{endpoint="test-endpoint",ip="172.22.23.202",namespace="default",port_name="prometheus",port_number="9090",port_protocol="TCP",ready="true"} 1
kube_endpoint_address{endpoint="test-endpoint",ip="192.168.1.3",namespace="default",port_name="syslog",port_number="1234",port_protocol="UDP",ready="false"} 1
kube_endpoint_address{endpoint="test-endpoint",ip="192.168.1.3",namespace="default",port_name="syslog-tcp",port_number="5678",port_protocol="TCP",ready="false"} 1
kube_endpoint_address{endpoint="test-endpoint",ip="192.168.2.2",namespace="default",port_name="syslog",port_number="1234",port_protocol="UDP",ready="false"} 1
kube_endpoint_address{endpoint="test-endpoint",ip="192.168.2.2",namespace="default",port_name="syslog-tcp",port_number="5678",port_protocol="TCP",ready="false"} 1
kube_endpoint_ports{endpoint="test-endpoint",namespace="default",port_name="http",port_protocol="TCP",port_number="8080"} 1
kube_endpoint_ports{endpoint="test-endpoint",namespace="default",port_name="app",port_protocol="TCP",port_number="8081"} 1
kube_endpoint_ports{endpoint="test-endpoint",namespace="default",port_name="https",port_protocol="TCP",port_number="8443"} 1
kube_endpoint_ports{endpoint="test-endpoint",namespace="default",port_name="prometheus",port_protocol="TCP",port_number="9090"} 1
kube_endpoint_ports{endpoint="test-endpoint",namespace="default",port_name="syslog",port_protocol="UDP",port_number="1234"} 1
kube_endpoint_ports{endpoint="test-endpoint",namespace="default",port_name="syslog-tcp",port_protocol="TCP",port_number="5678"} 1
kube_endpoint_address{endpoint="test-endpoint",namespace="default",ip="127.0.0.1",ready="true"} 1
kube_endpoint_address{endpoint="test-endpoint",namespace="default",ip="10.0.0.1",ready="true"} 1
kube_endpoint_address{endpoint="test-endpoint",namespace="default",ip="172.22.23.202",ready="true"} 1
kube_endpoint_address{endpoint="test-endpoint",namespace="default",ip="192.168.1.3",ready="false"} 1
kube_endpoint_address{endpoint="test-endpoint",namespace="default",ip="192.168.2.2",ready="false"} 1
kube_endpoint_address{endpoint="test-endpoint",namespace="default",ip="10.0.0.10",ready="false"} 1
`,
},
{
Expand Down Expand Up @@ -168,7 +174,7 @@ func TestEndpointStoreWithLabels(t *testing.T) {
# TYPE kube_endpoint_info gauge
# HELP kube_endpoint_labels [STABLE] Kubernetes labels converted to Prometheus labels.
# TYPE kube_endpoint_labels gauge
# HELP kube_endpoint_ports [STABLE] Information about the Endpoint ports.
# HELP kube_endpoint_ports [STABLE] (Deprecated since v2.14.0) Information about the Endpoint ports.
# TYPE kube_endpoint_ports gauge
# HELP kube_endpoint_address [STABLE] Information about Endpoint available and non available addresses.
# TYPE kube_endpoint_address gauge
Expand Down Expand Up @@ -230,12 +236,18 @@ func TestEndpointStoreWithLabels(t *testing.T) {
kube_endpoint_ports{endpoint="test-endpoint",namespace="default",port_name="prometheus",port_protocol="TCP",port_number="9090"} 1
kube_endpoint_ports{endpoint="test-endpoint",namespace="default",port_name="syslog",port_protocol="UDP",port_number="1234"} 1
kube_endpoint_ports{endpoint="test-endpoint",namespace="default",port_name="syslog-tcp",port_protocol="TCP",port_number="5678"} 1
kube_endpoint_address{endpoint="test-endpoint",namespace="default",ip="127.0.0.1",ready="true"} 1
kube_endpoint_address{endpoint="test-endpoint",namespace="default",ip="10.0.0.1",ready="true"} 1
kube_endpoint_address{endpoint="test-endpoint",namespace="default",ip="172.22.23.202",ready="true"} 1
kube_endpoint_address{endpoint="test-endpoint",namespace="default",ip="192.168.1.3",ready="false"} 1
kube_endpoint_address{endpoint="test-endpoint",namespace="default",ip="192.168.2.2",ready="false"} 1
kube_endpoint_address{endpoint="test-endpoint",namespace="default",ip="10.0.0.10",ready="false"} 1
kube_endpoint_address{endpoint="test-endpoint",ip="10.0.0.1",namespace="default",port_name="app",port_number="8081",port_protocol="TCP",ready="true"} 1
kube_endpoint_address{endpoint="test-endpoint",ip="10.0.0.1",namespace="default",port_name="http",port_number="8080",port_protocol="TCP",ready="true"} 1
kube_endpoint_address{endpoint="test-endpoint",ip="10.0.0.10",namespace="default",port_name="app",port_number="8081",port_protocol="TCP",ready="false"} 1
kube_endpoint_address{endpoint="test-endpoint",ip="10.0.0.10",namespace="default",port_name="http",port_number="8080",port_protocol="TCP",ready="false"} 1
kube_endpoint_address{endpoint="test-endpoint",ip="127.0.0.1",namespace="default",port_name="app",port_number="8081",port_protocol="TCP",ready="true"} 1
kube_endpoint_address{endpoint="test-endpoint",ip="127.0.0.1",namespace="default",port_name="http",port_number="8080",port_protocol="TCP",ready="true"} 1
kube_endpoint_address{endpoint="test-endpoint",ip="172.22.23.202",namespace="default",port_name="https",port_number="8443",port_protocol="TCP",ready="true"} 1
kube_endpoint_address{endpoint="test-endpoint",ip="172.22.23.202",namespace="default",port_name="prometheus",port_number="9090",port_protocol="TCP",ready="true"} 1
kube_endpoint_address{endpoint="test-endpoint",ip="192.168.1.3",namespace="default",port_name="syslog",port_number="1234",port_protocol="UDP",ready="false"} 1
kube_endpoint_address{endpoint="test-endpoint",ip="192.168.1.3",namespace="default",port_name="syslog-tcp",port_number="5678",port_protocol="TCP",ready="false"} 1
kube_endpoint_address{endpoint="test-endpoint",ip="192.168.2.2",namespace="default",port_name="syslog",port_number="1234",port_protocol="UDP",ready="false"} 1
kube_endpoint_address{endpoint="test-endpoint",ip="192.168.2.2",namespace="default",port_name="syslog-tcp",port_number="5678",port_protocol="TCP",ready="false"} 1
`,
},
{
Expand Down

0 comments on commit 2764e17

Please sign in to comment.