Skip to content

Commit 63749c5

Browse files
committed
endpoints: Expose empty labels
1 parent 75e7841 commit 63749c5

File tree

2 files changed

+12
-22
lines changed

2 files changed

+12
-22
lines changed

internal/store/endpoint.go

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -131,35 +131,25 @@ func endpointMetricFamilies(allowAnnotationsList, allowLabelsList []string) []ge
131131
"",
132132
wrapEndpointFunc(func(e *v1.Endpoints) *metric.Family {
133133
ms := []*metric.Metric{}
134+
labelKeys := []string{"port_protocol", "port_number", "port_name", "ip", "ready"}
135+
134136
for _, s := range e.Subsets {
135137
for _, port := range s.Ports {
136138
for _, available := range s.Addresses {
137-
labelValues := []string{string(port.Protocol), strconv.FormatInt(int64(port.Port), 10)}
138-
labelKeys := []string{"port_protocol", "port_number"}
139-
140-
if port.Name != "" {
141-
labelKeys = append(labelKeys, "port_name")
142-
labelValues = append(labelValues, port.Name)
143-
}
139+
labelValues := []string{string(port.Protocol), strconv.FormatInt(int64(port.Port), 10), port.Name}
144140

145141
ms = append(ms, &metric.Metric{
146142
LabelValues: append(labelValues, available.IP, "true"),
147-
LabelKeys: append(labelKeys, "ip", "ready"),
143+
LabelKeys: labelKeys,
148144
Value: 1,
149145
})
150146
}
151147
for _, notReadyAddresses := range s.NotReadyAddresses {
152-
labelValues := []string{string(port.Protocol), strconv.FormatInt(int64(port.Port), 10)}
153-
labelKeys := []string{"port_protocol", "port_number"}
154-
155-
if port.Name != "" {
156-
labelKeys = append(labelKeys, "port_name")
157-
labelValues = append(labelValues, port.Name)
158-
}
148+
labelValues := []string{string(port.Protocol), strconv.FormatInt(int64(port.Port), 10), port.Name}
159149

160150
ms = append(ms, &metric.Metric{
161151
LabelValues: append(labelValues, notReadyAddresses.IP, "false"),
162-
LabelKeys: append(labelKeys, "ip", "ready"),
152+
LabelKeys: labelKeys,
163153
Value: 1,
164154
})
165155
}

internal/store/endpoint_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,9 @@ func TestEndpointStore(t *testing.T) {
135135
kube_endpoint_created{endpoint="single-port-endpoint",namespace="default"} 1.5e+09
136136
kube_endpoint_info{endpoint="single-port-endpoint",namespace="default"} 1
137137
kube_endpoint_ports{endpoint="single-port-endpoint",namespace="default",port_name="",port_number="8080",port_protocol="TCP"} 1
138-
kube_endpoint_address{endpoint="single-port-endpoint",ip="10.0.0.1",namespace="default",port_number="8080",port_protocol="TCP",ready="true"} 1
139-
kube_endpoint_address{endpoint="single-port-endpoint",ip="10.0.0.10",namespace="default",port_number="8080",port_protocol="TCP",ready="false"} 1
140-
kube_endpoint_address{endpoint="single-port-endpoint",ip="127.0.0.1",namespace="default",port_number="8080",port_protocol="TCP",ready="true"} 1
138+
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
139+
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
140+
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
141141
`,
142142
},
143143
}
@@ -269,9 +269,9 @@ func TestEndpointStoreWithLabels(t *testing.T) {
269269
kube_endpoint_info{endpoint="single-port-endpoint",namespace="default"} 1
270270
kube_endpoint_labels{endpoint="single-port-endpoint",label_app="single-foobar",namespace="default"} 1
271271
kube_endpoint_ports{endpoint="single-port-endpoint",namespace="default",port_name="",port_number="8080",port_protocol="TCP"} 1
272-
kube_endpoint_address{endpoint="single-port-endpoint",ip="10.0.0.1",namespace="default",port_number="8080",port_protocol="TCP",ready="true"} 1
273-
kube_endpoint_address{endpoint="single-port-endpoint",ip="10.0.0.10",namespace="default",port_number="8080",port_protocol="TCP",ready="false"} 1
274-
kube_endpoint_address{endpoint="single-port-endpoint",ip="127.0.0.1",namespace="default",port_number="8080",port_protocol="TCP",ready="true"} 1
272+
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
273+
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
274+
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
275275
`,
276276
},
277277
}

0 commit comments

Comments
 (0)