Skip to content

Commit 14e935a

Browse files
authored
Merge pull request #2266 from mrueg/endpointslices-namespaces
feat: Add namespace label to endpoinslice metrics
2 parents 622efee + ca569e1 commit 14e935a

File tree

2 files changed

+23
-17
lines changed

2 files changed

+23
-17
lines changed

internal/store/endpointslice.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ var (
3535
descEndpointSliceAnnotationsHelp = "Kubernetes annotations converted to Prometheus labels."
3636
descEndpointSliceLabelsName = "kube_endpointslice_labels"
3737
descEndpointSliceLabelsHelp = "Kubernetes labels converted to Prometheus labels."
38-
descEndpointSliceLabelsDefaultLabels = []string{"endpointslice"}
38+
descEndpointSliceLabelsDefaultLabels = []string{"endpointslice", "namespace"}
3939
)
4040

4141
func endpointSliceMetricFamilies(allowAnnotationsList, allowLabelsList []string) []generator.FamilyGenerator {
@@ -261,7 +261,7 @@ func wrapEndpointSliceFunc(f func(*discoveryv1.EndpointSlice) *metric.Family) fu
261261
metricFamily := f(endpointSlice)
262262

263263
for _, m := range metricFamily.Metrics {
264-
m.LabelKeys, m.LabelValues = mergeKeyValues(descEndpointSliceLabelsDefaultLabels, []string{endpointSlice.Name}, m.LabelKeys, m.LabelValues)
264+
m.LabelKeys, m.LabelValues = mergeKeyValues(descEndpointSliceLabelsDefaultLabels, []string{endpointSlice.Name, endpointSlice.Namespace}, m.LabelKeys, m.LabelValues)
265265
}
266266

267267
return metricFamily

internal/store/endpointslice_test.go

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,15 @@ func TestEndpointSliceStore(t *testing.T) {
4040
{
4141
Obj: &discoveryv1.EndpointSlice{
4242
ObjectMeta: metav1.ObjectMeta{
43-
Name: "test_endpointslice-info",
43+
Name: "test_endpointslice-info",
44+
Namespace: "test",
4445
},
4546
AddressType: "IPv4",
4647
},
4748
Want: `
4849
# HELP kube_endpointslice_info Information about endpointslice.
4950
# TYPE kube_endpointslice_info gauge
50-
kube_endpointslice_info{endpointslice="test_endpointslice-info",addresstype="IPv4"} 1
51+
kube_endpointslice_info{endpointslice="test_endpointslice-info",addresstype="IPv4",namespace="test"} 1
5152
`,
5253
MetricNames: []string{
5354
"kube_endpointslice_info",
@@ -57,14 +58,15 @@ func TestEndpointSliceStore(t *testing.T) {
5758
Obj: &discoveryv1.EndpointSlice{
5859
ObjectMeta: metav1.ObjectMeta{
5960
Name: "test_kube_endpointslice-created",
61+
Namespace: "test",
6062
CreationTimestamp: metav1StartTime,
6163
},
6264
AddressType: "IPv4",
6365
},
6466
Want: `
6567
# HELP kube_endpointslice_created Unix creation timestamp
6668
# TYPE kube_endpointslice_created gauge
67-
kube_endpointslice_created{endpointslice="test_kube_endpointslice-created"} 1.501569018e+09
69+
kube_endpointslice_created{endpointslice="test_kube_endpointslice-created",namespace="test"} 1.501569018e+09
6870
`,
6971
MetricNames: []string{
7072
"kube_endpointslice_created",
@@ -73,7 +75,8 @@ func TestEndpointSliceStore(t *testing.T) {
7375
{
7476
Obj: &discoveryv1.EndpointSlice{
7577
ObjectMeta: metav1.ObjectMeta{
76-
Name: "test_endpointslice-ports",
78+
Name: "test_endpointslice-ports",
79+
Namespace: "test",
7780
},
7881
AddressType: "IPv4",
7982
Ports: []discoveryv1.EndpointPort{
@@ -86,7 +89,7 @@ func TestEndpointSliceStore(t *testing.T) {
8689
Want: `
8790
# HELP kube_endpointslice_ports Ports attached to the endpointslice.
8891
# TYPE kube_endpointslice_ports gauge
89-
kube_endpointslice_ports{endpointslice="test_endpointslice-ports",port_name="http",port_protocol="TCP",port_number="80"} 1
92+
kube_endpointslice_ports{endpointslice="test_endpointslice-ports",port_name="http",port_protocol="TCP",port_number="80",namespace="test"} 1
9093
`,
9194
MetricNames: []string{
9295
"kube_endpointslice_ports",
@@ -95,7 +98,8 @@ func TestEndpointSliceStore(t *testing.T) {
9598
{
9699
Obj: &discoveryv1.EndpointSlice{
97100
ObjectMeta: metav1.ObjectMeta{
98-
Name: "test_endpointslice-endpoints",
101+
Name: "test_endpointslice-endpoints",
102+
Namespace: "test",
99103
},
100104
AddressType: "IPv4",
101105
Endpoints: []discoveryv1.Endpoint{
@@ -116,8 +120,8 @@ func TestEndpointSliceStore(t *testing.T) {
116120
# HELP kube_endpointslice_endpoints_hints Topology routing hints attached to endpoints
117121
# TYPE kube_endpointslice_endpoints gauge
118122
# TYPE kube_endpointslice_endpoints_hints gauge
119-
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
120-
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
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
121125
`,
122126

123127
MetricNames: []string{
@@ -127,7 +131,8 @@ func TestEndpointSliceStore(t *testing.T) {
127131
{
128132
Obj: &discoveryv1.EndpointSlice{
129133
ObjectMeta: metav1.ObjectMeta{
130-
Name: "test_endpointslice-endpoints",
134+
Name: "test_endpointslice-endpoints",
135+
Namespace: "test",
131136
},
132137
AddressType: "IPv4",
133138
Endpoints: []discoveryv1.Endpoint{
@@ -152,10 +157,10 @@ func TestEndpointSliceStore(t *testing.T) {
152157
# HELP kube_endpointslice_endpoints Endpoints attached to the endpointslice.
153158
# HELP kube_endpointslice_endpoints_hints Topology routing hints attached to endpoints
154159
# TYPE kube_endpointslice_endpoints gauge
155-
# TYPE kube_endpointslice_endpoints_hints gauge
156-
kube_endpointslice_endpoints_hints{address="10.0.0.1",endpointslice="test_endpointslice-endpoints",for_zone="zone1"} 1
157-
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
158-
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
160+
# TYPE kube_endpointslice_endpoints_hints gauge
161+
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
159164
`,
160165

161166
MetricNames: []string{
@@ -168,7 +173,8 @@ func TestEndpointSliceStore(t *testing.T) {
168173
},
169174
Obj: &discoveryv1.EndpointSlice{
170175
ObjectMeta: metav1.ObjectMeta{
171-
Name: "test_endpointslice-labels",
176+
Name: "test_endpointslice-labels",
177+
Namespace: "test",
172178
Annotations: map[string]string{
173179
"foo": "baz",
174180
},
@@ -183,7 +189,7 @@ func TestEndpointSliceStore(t *testing.T) {
183189
# HELP kube_endpointslice_labels Kubernetes labels converted to Prometheus labels.
184190
# TYPE kube_endpointslice_annotations gauge
185191
# TYPE kube_endpointslice_labels gauge
186-
kube_endpointslice_annotations{endpointslice="test_endpointslice-labels",annotation_foo="baz"} 1
192+
kube_endpointslice_annotations{endpointslice="test_endpointslice-labels",annotation_foo="baz",namespace="test"} 1
187193
`,
188194
MetricNames: []string{
189195
"kube_endpointslice_annotations", "kube_endpointslice_labels",

0 commit comments

Comments
 (0)