From 115e03cc62936439ac92867acea4e0884c3ab20e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Min=C3=A1=C5=99?= Date: Tue, 2 Jul 2024 23:49:14 +0200 Subject: [PATCH] added source label to ephemeral_storage_container_limit_percentage (#97) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Michal Minář --- pkg/pod/metrics.go | 5 ++++- tests/e2e/deployment_test.go | 8 +++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/pkg/pod/metrics.go b/pkg/pod/metrics.go index a83d8c1..e4c5080 100644 --- a/pkg/pod/metrics.go +++ b/pkg/pod/metrics.go @@ -76,6 +76,8 @@ func (cr Collector) createMetrics() { "node_name", // Name of container "container", + // Source of the limit (either "container" for pod.spec.containers.resources.limits or "node") + "source", }, ) @@ -164,10 +166,11 @@ func (cr Collector) SetMetrics(podName string, podNamespace string, nodeName str if okPodResult { for _, c := range podResult.containers { labels := prometheus.Labels{"pod_namespace": podNamespace, - "pod_name": podName, "node_name": nodeName, "container": c.name} + "pod_name": podName, "node_name": nodeName, "container": c.name, "source": "node"} if c.limit != 0 { // Use Limit from Container setValue = (usedBytes / c.limit) * 100.0 + labels["source"] = "container" } else if capacityBytes > 0. { // Default to Node Used Ephemeral Storage setValue = math.Max(capacityBytes-availableBytes, 0.) * 100.0 / capacityBytes diff --git a/tests/e2e/deployment_test.go b/tests/e2e/deployment_test.go index 956f968..d4bd119 100644 --- a/tests/e2e/deployment_test.go +++ b/tests/e2e/deployment_test.go @@ -2,8 +2,6 @@ package e2e import ( "fmt" - "github.com/onsi/ginkgo/v2" - "github.com/onsi/gomega" "io" "net/http" "os/exec" @@ -12,6 +10,9 @@ import ( "strings" "testing" "time" + + "github.com/onsi/ginkgo/v2" + "github.com/onsi/gomega" ) var httpClient *http.Client @@ -120,9 +121,10 @@ func checkPrometheus(checkSlice []string, inverse bool) { func WatchContainerPercentage() { status := 0 - re := regexp.MustCompile(`ephemeral_storage_container_limit_percentage{container="grow-test",node_name="minikube".+,pod_namespace="ephemeral-metrics"}\s+(.+)`) + re := regexp.MustCompile(`ephemeral_storage_container_limit_percentage{container="grow-test",node_name="minikube".+,pod_namespace="ephemeral-metrics",source="container"}\s+(.+)`) output := requestPrometheusString() match := re.FindAllStringSubmatch(output, -1) + gomega.Expect(match).ShouldNot(gomega.BeEmpty()) floatValue, _ := strconv.ParseFloat(match[0][1], 64) if floatValue < 100.0 { status = 1