Skip to content

Commit

Permalink
endpoints: Expose empty labels
Browse files Browse the repository at this point in the history
  • Loading branch information
mrueg committed Oct 31, 2024
1 parent d15363d commit 2e52268
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 22 deletions.
22 changes: 6 additions & 16 deletions internal/store/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,35 +131,25 @@ func endpointMetricFamilies(allowAnnotationsList, allowLabelsList []string) []ge
"",
wrapEndpointFunc(func(e *v1.Endpoints) *metric.Family {
ms := []*metric.Metric{}
labelKeys := []string{"port_protocol", "port_number", "port_name", "ip", "ready"}

for _, s := range e.Subsets {
for _, port := range s.Ports {
for _, available := range s.Addresses {
labelValues := []string{string(port.Protocol), strconv.FormatInt(int64(port.Port), 10)}
labelKeys := []string{"port_protocol", "port_number"}

if port.Name != "" {
labelKeys = append(labelKeys, "port_name")
labelValues = append(labelValues, port.Name)
}
labelValues := []string{string(port.Protocol), strconv.FormatInt(int64(port.Port), 10), port.Name}

ms = append(ms, &metric.Metric{
LabelValues: append(labelValues, available.IP, "true"),
LabelKeys: append(labelKeys, "ip", "ready"),
LabelKeys: labelKeys,
Value: 1,
})
}
for _, notReadyAddresses := range s.NotReadyAddresses {
labelValues := []string{string(port.Protocol), strconv.FormatInt(int64(port.Port), 10)}
labelKeys := []string{"port_protocol", "port_number"}

if port.Name != "" {
labelKeys = append(labelKeys, "port_name")
labelValues = append(labelValues, port.Name)
}
labelValues := []string{string(port.Protocol), strconv.FormatInt(int64(port.Port), 10), port.Name}

ms = append(ms, &metric.Metric{
LabelValues: append(labelValues, notReadyAddresses.IP, "false"),
LabelKeys: append(labelKeys, "ip", "ready"),
LabelKeys: labelKeys,
Value: 1,
})
}
Expand Down
12 changes: 6 additions & 6 deletions internal/store/endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,9 @@ func TestEndpointStore(t *testing.T) {
kube_endpoint_created{endpoint="single-port-endpoint",namespace="default"} 1.5e+09
kube_endpoint_info{endpoint="single-port-endpoint",namespace="default"} 1
kube_endpoint_ports{endpoint="single-port-endpoint",namespace="default",port_name="",port_number="8080",port_protocol="TCP"} 1
kube_endpoint_address{endpoint="single-port-endpoint",ip="10.0.0.1",namespace="default",port_number="8080",port_protocol="TCP",ready="true"} 1
kube_endpoint_address{endpoint="single-port-endpoint",ip="10.0.0.10",namespace="default",port_number="8080",port_protocol="TCP",ready="false"} 1
kube_endpoint_address{endpoint="single-port-endpoint",ip="127.0.0.1",namespace="default",port_number="8080",port_protocol="TCP",ready="true"} 1
kube_endpoint_address{endpoint="single-port-endpoint",ip="10.0.0.1",namespace="default",port_name="",port_number="8080",port_protocol="TCP",ready="true"} 1
kube_endpoint_address{endpoint="single-port-endpoint",ip="10.0.0.10",namespace="default",port_name="",port_number="8080",port_protocol="TCP",ready="false"} 1
kube_endpoint_address{endpoint="single-port-endpoint",ip="127.0.0.1",namespace="default",port_name="",port_number="8080",port_protocol="TCP",ready="true"} 1
`,
},
}
Expand Down Expand Up @@ -269,9 +269,9 @@ func TestEndpointStoreWithLabels(t *testing.T) {
kube_endpoint_info{endpoint="single-port-endpoint",namespace="default"} 1
kube_endpoint_labels{endpoint="single-port-endpoint",label_app="single-foobar",namespace="default"} 1
kube_endpoint_ports{endpoint="single-port-endpoint",namespace="default",port_name="",port_number="8080",port_protocol="TCP"} 1
kube_endpoint_address{endpoint="single-port-endpoint",ip="10.0.0.1",namespace="default",port_number="8080",port_protocol="TCP",ready="true"} 1
kube_endpoint_address{endpoint="single-port-endpoint",ip="10.0.0.10",namespace="default",port_number="8080",port_protocol="TCP",ready="false"} 1
kube_endpoint_address{endpoint="single-port-endpoint",ip="127.0.0.1",namespace="default",port_number="8080",port_protocol="TCP",ready="true"} 1
kube_endpoint_address{endpoint="single-port-endpoint",ip="10.0.0.1",namespace="default",port_name="",port_number="8080",port_protocol="TCP",ready="true"} 1
kube_endpoint_address{endpoint="single-port-endpoint",ip="10.0.0.10",namespace="default",port_name="",port_number="8080",port_protocol="TCP",ready="false"} 1
kube_endpoint_address{endpoint="single-port-endpoint",ip="127.0.0.1",namespace="default",port_name="",port_number="8080",port_protocol="TCP",ready="true"} 1
`,
},
}
Expand Down

0 comments on commit 2e52268

Please sign in to comment.