Skip to content

Commit f434171

Browse files
committed
Properly initialize KSM server test
The pkg/app/server test does not properly initialize KSM with an empty metrics opt-in list. This results in opt-in metrics showing up in the expected test results. This commit changes the test to be in line with how KSM is initialized in production code by passing in an empty opt-in list.
1 parent b4c3485 commit f434171

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

pkg/app/server_test.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ import (
2828
"testing"
2929
"time"
3030

31+
"k8s.io/kube-state-metrics/v2/pkg/optin"
32+
3133
"github.com/prometheus/client_golang/prometheus"
3234
v1 "k8s.io/api/core/v1"
3335
"k8s.io/apimachinery/pkg/api/resource"
@@ -151,7 +153,17 @@ func TestFullScrapeCycle(t *testing.T) {
151153
if err != nil {
152154
t.Fatal(err)
153155
}
154-
builder.WithFamilyGeneratorFilter(l)
156+
157+
optInMetrics := make(map[string]struct{})
158+
optInMetricFamilyFilter, err := optin.NewMetricFamilyFilter(optInMetrics)
159+
if err != nil {
160+
t.Fatal(err)
161+
}
162+
163+
builder.WithFamilyGeneratorFilter(generator.NewCompositeFamilyGeneratorFilter(
164+
l,
165+
optInMetricFamilyFilter,
166+
))
155167
builder.WithAllowLabels(map[string][]string{
156168
"kube_pod_labels": {
157169
"namespace",
@@ -207,7 +219,6 @@ func TestFullScrapeCycle(t *testing.T) {
207219
# HELP kube_pod_init_container_status_waiting Describes whether the init container is currently in waiting state.
208220
# HELP kube_pod_init_container_status_waiting_reason Describes the reason the init container is currently in waiting state.
209221
# HELP kube_pod_labels Kubernetes labels converted to Prometheus labels.
210-
# HELP kube_pod_nodeselectors Describes the Pod nodeSelectors.
211222
# HELP kube_pod_overhead_cpu_cores The pod overhead in regards to cpu cores associated with running a pod.
212223
# HELP kube_pod_overhead_memory_bytes The pod overhead in regards to memory associated with running a pod.
213224
# HELP kube_pod_runtimeclass_name_info The runtimeclass associated with the pod.
@@ -251,7 +262,6 @@ func TestFullScrapeCycle(t *testing.T) {
251262
# TYPE kube_pod_init_container_status_waiting gauge
252263
# TYPE kube_pod_init_container_status_waiting_reason gauge
253264
# TYPE kube_pod_labels gauge
254-
# TYPE kube_pod_nodeselectors gauge
255265
# TYPE kube_pod_overhead_cpu_cores gauge
256266
# TYPE kube_pod_overhead_memory_bytes gauge
257267
# TYPE kube_pod_runtimeclass_name_info gauge
@@ -298,7 +308,6 @@ kube_pod_container_status_waiting{namespace="default",pod="pod0",uid="abc-0",con
298308
kube_pod_created{namespace="default",pod="pod0",uid="abc-0"} 1.5e+09
299309
kube_pod_info{namespace="default",pod="pod0",uid="abc-0",host_ip="1.1.1.1",pod_ip="1.2.3.4",node="node1",created_by_kind="<none>",created_by_name="<none>",priority_class="",host_network="false"} 1
300310
kube_pod_labels{namespace="default",pod="pod0",uid="abc-0"} 1
301-
kube_pod_nodeselectors{namespace="default",pod="pod0",uid="abc-0"} 1
302311
kube_pod_owner{namespace="default",pod="pod0",uid="abc-0",owner_kind="<none>",owner_name="<none>",owner_is_controller="<none>"} 1
303312
kube_pod_restart_policy{namespace="default",pod="pod0",uid="abc-0",type="Always"} 1
304313
kube_pod_status_phase{namespace="default",pod="pod0",uid="abc-0",phase="Failed"} 0

0 commit comments

Comments
 (0)