Skip to content

Commit

Permalink
added source label to ephemeral_storage_container_limit_percentage (#97)
Browse files Browse the repository at this point in the history
Signed-off-by: Michal Minář <michal.minar@id.ethz.ch>
  • Loading branch information
miminar authored Jul 2, 2024
1 parent a654c7f commit 115e03c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
5 changes: 4 additions & 1 deletion pkg/pod/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
)

Expand Down Expand Up @@ -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
Expand Down
8 changes: 5 additions & 3 deletions tests/e2e/deployment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package e2e

import (
"fmt"
"github.com/onsi/ginkgo/v2"
"github.com/onsi/gomega"
"io"
"net/http"
"os/exec"
Expand All @@ -12,6 +10,9 @@ import (
"strings"
"testing"
"time"

"github.com/onsi/ginkgo/v2"
"github.com/onsi/gomega"
)

var httpClient *http.Client
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 115e03c

Please sign in to comment.