Skip to content

Commit

Permalink
fix(metrics): kube-state-metrics pod metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
swiatekm committed Oct 14, 2023
1 parent 70af83f commit b5abe25
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 5 deletions.
1 change: 1 addition & 0 deletions .changelog/3323.fixed.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fix(metrics): kube-state-metrics pod metadata
9 changes: 5 additions & 4 deletions deploy/helm/sumologic/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1062,16 +1062,17 @@ kube-prometheus-stack:
sourceLabels: [__name__]
## Drop unnecessary labels Prometheus adds to these metrics
## We don't want container=kube-state-metrics on everything
## But we do want to keep these on pod metrics, which we check for via the `uid` attribute
- action: labeldrop
regex: service
- action: replace
sourceLabels: [container]
regex: kube-state-metrics
sourceLabels: [container, uid]
regex: kube-state-metrics;
targetLabel: container
replacement: ""
- action: replace
sourceLabels: [pod]
regex: ".*kube-state-metrics.*"
sourceLabels: [pod, uid]
regex: ".*kube-state-metrics.*;"
targetLabel: pod
replacement: ""
- action: labelmap
Expand Down
44 changes: 43 additions & 1 deletion tests/integration/features.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func GetMetricsFeature(expectedMetrics []string, metricsCollector MetricsCollect
return stepfuncs.WaitUntilExpectedMetricLabelsPresent(metricFilters, expectedLabels, waitDuration, tickDuration)(ctx, t, envConf)
},
).
Assess("expected labels are present for kube-state-metrics",
Assess("expected labels are present for non-pod kube-state-metrics",
func(ctx context.Context, t *testing.T, envConf *envconf.Config) context.Context {
metricFilters := receivermock.MetadataFilters{
"__name__": "kube_deployment_spec_replicas",
Expand All @@ -126,6 +126,48 @@ func GetMetricsFeature(expectedMetrics []string, metricsCollector MetricsCollect
return stepfuncs.WaitUntilExpectedMetricLabelsPresent(metricFilters, expectedLabels, waitDuration, tickDuration)(ctx, t, envConf)
},
).
Assess("expected labels are present for pod kube-state-metrics",
func(ctx context.Context, t *testing.T, envConf *envconf.Config) context.Context {
releaseName := ctxopts.HelmRelease(ctx)
deployment := fmt.Sprintf("%s-kube-state-metrics", releaseName)
metricFilters := receivermock.MetadataFilters{
"__name__": "kube_pod_status_phase",
"phase": "Running",
"deployment": deployment,
}
namespace := ctxopts.Namespace(ctx)
expectedLabels := receivermock.Labels{
"cluster": "kubernetes",
"_origin": "kubernetes",
"container": "kube-state-metrics",
"deployment": deployment,
"endpoint": "http",
"job": "kube-state-metrics",
"namespace": namespace,
"node": internal.NodeNameRegex,
"phase": "Running",
"pod_labels_app.kubernetes.io/component": "metrics",
"pod_labels_app.kubernetes.io/instance": releaseName,
"pod_labels_app.kubernetes.io/managed-by": "Helm",
"pod_labels_app.kubernetes.io/name": "kube-state-metrics",
"pod_labels_app.kubernetes.io/part-of": "kube-state-metrics",
"pod_labels_app.kubernetes.io/version": "\\d+\\.\\d+\\.\\d+",
"pod_labels_helm.sh/chart": "kube-state-metrics-\\d+\\.\\d+\\.\\d+",
"pod_labels_release": releaseName,
"pod_labels_pod-template-hash": ".+",
"pod": fmt.Sprintf("%s-.+", deployment),
"replicaset": fmt.Sprintf("%s-.+", deployment),
"service": deployment,
"service_discovery_pod": fmt.Sprintf("%s-.+", deployment),
"uid": ".+",
}
expectedLabels = addCollectorSpecificMetricLabels(expectedLabels, releaseName, namespace, metricsCollector)
// drop some unnecessary labels
delete(expectedLabels, "prometheus_service")

return stepfuncs.WaitUntilExpectedMetricLabelsPresent(metricFilters, expectedLabels, waitDuration, tickDuration)(ctx, t, envConf)
},
).
Feature()
}

Expand Down

0 comments on commit b5abe25

Please sign in to comment.