Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add namespace label to endpoinslice metrics #2266

Merged
merged 1 commit into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions internal/store/endpointslice.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ var (
descEndpointSliceAnnotationsHelp = "Kubernetes annotations converted to Prometheus labels."
descEndpointSliceLabelsName = "kube_endpointslice_labels"
descEndpointSliceLabelsHelp = "Kubernetes labels converted to Prometheus labels."
descEndpointSliceLabelsDefaultLabels = []string{"endpointslice"}
descEndpointSliceLabelsDefaultLabels = []string{"endpointslice", "namespace"}
)

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

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

return metricFamily
Expand Down
36 changes: 21 additions & 15 deletions internal/store/endpointslice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,15 @@ func TestEndpointSliceStore(t *testing.T) {
{
Obj: &discoveryv1.EndpointSlice{
ObjectMeta: metav1.ObjectMeta{
Name: "test_endpointslice-info",
Name: "test_endpointslice-info",
Namespace: "test",
},
AddressType: "IPv4",
},
Want: `
# HELP kube_endpointslice_info Information about endpointslice.
# TYPE kube_endpointslice_info gauge
kube_endpointslice_info{endpointslice="test_endpointslice-info",addresstype="IPv4"} 1
kube_endpointslice_info{endpointslice="test_endpointslice-info",addresstype="IPv4",namespace="test"} 1
`,
MetricNames: []string{
"kube_endpointslice_info",
Expand All @@ -57,14 +58,15 @@ func TestEndpointSliceStore(t *testing.T) {
Obj: &discoveryv1.EndpointSlice{
ObjectMeta: metav1.ObjectMeta{
Name: "test_kube_endpointslice-created",
Namespace: "test",
CreationTimestamp: metav1StartTime,
},
AddressType: "IPv4",
},
Want: `
# HELP kube_endpointslice_created Unix creation timestamp
# TYPE kube_endpointslice_created gauge
kube_endpointslice_created{endpointslice="test_kube_endpointslice-created"} 1.501569018e+09
kube_endpointslice_created{endpointslice="test_kube_endpointslice-created",namespace="test"} 1.501569018e+09
`,
MetricNames: []string{
"kube_endpointslice_created",
Expand All @@ -73,7 +75,8 @@ func TestEndpointSliceStore(t *testing.T) {
{
Obj: &discoveryv1.EndpointSlice{
ObjectMeta: metav1.ObjectMeta{
Name: "test_endpointslice-ports",
Name: "test_endpointslice-ports",
Namespace: "test",
},
AddressType: "IPv4",
Ports: []discoveryv1.EndpointPort{
Expand All @@ -86,7 +89,7 @@ func TestEndpointSliceStore(t *testing.T) {
Want: `
# HELP kube_endpointslice_ports Ports attached to the endpointslice.
# TYPE kube_endpointslice_ports gauge
kube_endpointslice_ports{endpointslice="test_endpointslice-ports",port_name="http",port_protocol="TCP",port_number="80"} 1
kube_endpointslice_ports{endpointslice="test_endpointslice-ports",port_name="http",port_protocol="TCP",port_number="80",namespace="test"} 1
`,
MetricNames: []string{
"kube_endpointslice_ports",
Expand All @@ -95,7 +98,8 @@ func TestEndpointSliceStore(t *testing.T) {
{
Obj: &discoveryv1.EndpointSlice{
ObjectMeta: metav1.ObjectMeta{
Name: "test_endpointslice-endpoints",
Name: "test_endpointslice-endpoints",
Namespace: "test",
},
AddressType: "IPv4",
Endpoints: []discoveryv1.Endpoint{
Expand All @@ -116,8 +120,8 @@ func TestEndpointSliceStore(t *testing.T) {
# HELP kube_endpointslice_endpoints_hints Topology routing hints attached to endpoints
# TYPE kube_endpointslice_endpoints gauge
# TYPE kube_endpointslice_endpoints_hints gauge
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
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
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
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
`,

MetricNames: []string{
Expand All @@ -127,7 +131,8 @@ func TestEndpointSliceStore(t *testing.T) {
{
Obj: &discoveryv1.EndpointSlice{
ObjectMeta: metav1.ObjectMeta{
Name: "test_endpointslice-endpoints",
Name: "test_endpointslice-endpoints",
Namespace: "test",
},
AddressType: "IPv4",
Endpoints: []discoveryv1.Endpoint{
Expand All @@ -152,10 +157,10 @@ func TestEndpointSliceStore(t *testing.T) {
# HELP kube_endpointslice_endpoints Endpoints attached to the endpointslice.
# HELP kube_endpointslice_endpoints_hints Topology routing hints attached to endpoints
# TYPE kube_endpointslice_endpoints gauge
# TYPE kube_endpointslice_endpoints_hints gauge
kube_endpointslice_endpoints_hints{address="10.0.0.1",endpointslice="test_endpointslice-endpoints",for_zone="zone1"} 1
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
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
# TYPE kube_endpointslice_endpoints_hints gauge
kube_endpointslice_endpoints_hints{address="10.0.0.1",endpointslice="test_endpointslice-endpoints",for_zone="zone1",namespace="test"} 1
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
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
`,

MetricNames: []string{
Expand All @@ -168,7 +173,8 @@ func TestEndpointSliceStore(t *testing.T) {
},
Obj: &discoveryv1.EndpointSlice{
ObjectMeta: metav1.ObjectMeta{
Name: "test_endpointslice-labels",
Name: "test_endpointslice-labels",
Namespace: "test",
Annotations: map[string]string{
"foo": "baz",
},
Expand All @@ -183,7 +189,7 @@ func TestEndpointSliceStore(t *testing.T) {
# HELP kube_endpointslice_labels Kubernetes labels converted to Prometheus labels.
# TYPE kube_endpointslice_annotations gauge
# TYPE kube_endpointslice_labels gauge
kube_endpointslice_annotations{endpointslice="test_endpointslice-labels",annotation_foo="baz"} 1
kube_endpointslice_annotations{endpointslice="test_endpointslice-labels",annotation_foo="baz",namespace="test"} 1
`,
MetricNames: []string{
"kube_endpointslice_annotations", "kube_endpointslice_labels",
Expand Down