Skip to content

Commit 75e7841

Browse files
committed
endpointslices: Expose empty labels
1 parent 3c6bc83 commit 75e7841

File tree

2 files changed

+22
-35
lines changed

2 files changed

+22
-35
lines changed

internal/store/endpointslice.go

Lines changed: 17 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -121,54 +121,41 @@ func endpointSliceMetricFamilies(allowAnnotationsList, allowLabelsList []string)
121121
wrapEndpointSliceFunc(func(e *discoveryv1.EndpointSlice) *metric.Family {
122122
m := []*metric.Metric{}
123123
for _, ep := range e.Endpoints {
124-
var (
125-
labelKeys,
126-
labelValues []string
127-
)
124+
125+
var ready, serving, terminating, hostname, targetrefKind, targetrefName, targetrefNamespace, endpointNodename, endpointZone string
128126

129127
if ep.Conditions.Ready != nil {
130-
labelKeys = append(labelKeys, "ready")
131-
labelValues = append(labelValues, strconv.FormatBool(*ep.Conditions.Ready))
128+
ready = strconv.FormatBool(*ep.Conditions.Ready)
132129
}
130+
133131
if ep.Conditions.Serving != nil {
134-
labelKeys = append(labelKeys, "serving")
135-
labelValues = append(labelValues, strconv.FormatBool(*ep.Conditions.Serving))
132+
serving = strconv.FormatBool(*ep.Conditions.Serving)
136133
}
134+
137135
if ep.Conditions.Terminating != nil {
138-
labelKeys = append(labelKeys, "terminating")
139-
labelValues = append(labelValues, strconv.FormatBool(*ep.Conditions.Terminating))
136+
serving = strconv.FormatBool(*ep.Conditions.Terminating)
140137
}
141-
142138
if ep.Hostname != nil {
143-
labelKeys = append(labelKeys, "hostname")
144-
labelValues = append(labelValues, *ep.Hostname)
139+
hostname = *ep.Hostname
145140
}
146141

147142
if ep.TargetRef != nil {
148-
if ep.TargetRef.Kind != "" {
149-
labelKeys = append(labelKeys, "targetref_kind")
150-
labelValues = append(labelValues, ep.TargetRef.Kind)
151-
}
152-
if ep.TargetRef.Name != "" {
153-
labelKeys = append(labelKeys, "targetref_name")
154-
labelValues = append(labelValues, ep.TargetRef.Name)
155-
}
156-
if ep.TargetRef.Namespace != "" {
157-
labelKeys = append(labelKeys, "targetref_namespace")
158-
labelValues = append(labelValues, ep.TargetRef.Namespace)
159-
}
143+
targetrefKind = ep.TargetRef.Kind
144+
targetrefName = ep.TargetRef.Name
145+
targetrefNamespace = ep.TargetRef.Namespace
160146
}
161147

162148
if ep.NodeName != nil {
163-
labelKeys = append(labelKeys, "endpoint_nodename")
164-
labelValues = append(labelValues, *ep.NodeName)
149+
endpointNodename = *ep.NodeName
165150
}
166151

167152
if ep.Zone != nil {
168-
labelKeys = append(labelKeys, "endpoint_zone")
169-
labelValues = append(labelValues, *ep.Zone)
153+
endpointZone = *ep.Zone
170154
}
171-
labelKeys = append(labelKeys, "address")
155+
156+
labelKeys := []string{"ready", "serving", "hostname", "terminating", "targetref_kind", "targetref_name", "targetref_namespace", "endpoint_nodename", "endpoint_zone", "address"}
157+
labelValues := []string{ready, serving, terminating, hostname, targetrefKind, targetrefName, targetrefNamespace, endpointNodename, endpointZone}
158+
172159
for _, address := range ep.Addresses {
173160
newlabelValues := make([]string, len(labelValues))
174161
copy(newlabelValues, labelValues)

internal/store/endpointslice_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ func TestEndpointSliceStore(t *testing.T) {
120120
# HELP kube_endpointslice_endpoints_hints Topology routing hints attached to endpoints
121121
# TYPE kube_endpointslice_endpoints gauge
122122
# TYPE kube_endpointslice_endpoints_hints gauge
123-
kube_endpointslice_endpoints{address="10.0.0.1",endpoint_nodename="node",endpoint_zone="west",endpointslice="test_endpointslice-endpoints",hostname="host",ready="true",terminating="false",namespace="test"} 1
124-
kube_endpointslice_endpoints{address="192.168.1.10",endpoint_nodename="node",endpoint_zone="west",endpointslice="test_endpointslice-endpoints",hostname="host",ready="true",terminating="false",namespace="test"} 1
123+
kube_endpointslice_endpoints{address="10.0.0.1",endpoint_nodename="node",endpoint_zone="west",endpointslice="test_endpointslice-endpoints",hostname="",namespace="test",ready="true",serving="false",targetref_kind="",targetref_name="",targetref_namespace="",terminating="host"} 1
124+
kube_endpointslice_endpoints{address="192.168.1.10",endpoint_nodename="node",endpoint_zone="west",endpointslice="test_endpointslice-endpoints",hostname="",namespace="test",ready="true",serving="false",targetref_kind="",targetref_name="",targetref_namespace="",terminating="host"} 1
125125
`,
126126

127127
MetricNames: []string{
@@ -159,9 +159,9 @@ func TestEndpointSliceStore(t *testing.T) {
159159
# TYPE kube_endpointslice_endpoints gauge
160160
# TYPE kube_endpointslice_endpoints_hints gauge
161161
kube_endpointslice_endpoints_hints{address="10.0.0.1",endpointslice="test_endpointslice-endpoints",for_zone="zone1",namespace="test"} 1
162-
kube_endpointslice_endpoints{address="10.0.0.1",endpoint_nodename="node",endpoint_zone="west",endpointslice="test_endpointslice-endpoints",hostname="host",ready="true",terminating="false",namespace="test"} 1
163-
kube_endpointslice_endpoints{address="192.168.1.10",endpoint_nodename="node",endpoint_zone="west",endpointslice="test_endpointslice-endpoints",hostname="host",ready="true",terminating="false",namespace="test"} 1
164-
`,
162+
kube_endpointslice_endpoints{address="10.0.0.1",endpoint_nodename="node",endpoint_zone="west",endpointslice="test_endpointslice-endpoints",hostname="",namespace="test",ready="true",serving="false",targetref_kind="",targetref_name="",targetref_namespace="",terminating="host"} 1
163+
kube_endpointslice_endpoints{address="192.168.1.10",endpoint_nodename="node",endpoint_zone="west",endpointslice="test_endpointslice-endpoints",hostname="",namespace="test",ready="true",serving="false",targetref_kind="",targetref_name="",targetref_namespace="",terminating="host"} 1
164+
`,
165165

166166
MetricNames: []string{
167167
"kube_endpointslice_endpoints",

0 commit comments

Comments
 (0)