Skip to content

Commit

Permalink
debug
Browse files Browse the repository at this point in the history
Signed-off-by: Jie Ren <jie.ren@intel.com>
  • Loading branch information
jiere committed Jul 19, 2023
1 parent cae3202 commit 19ee6e9
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 12 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/platform-validation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,6 @@ jobs:
env:
CLUSTER_PROVIDER: ${{matrix.cluster_provider}}
kepler_address: localhost:9102

- name: undeploy cluster
run: make cluster-clean
93 changes: 81 additions & 12 deletions e2e/e2e_metric_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ package e2e_test
import (
"bytes"
"context"
"fmt"
"errors"
"flag"
"io"
Expand All @@ -38,13 +39,23 @@ import (
. "github.com/onsi/gomega"
)

var kMetric map[string]float64
var kMetric map[string][]float64
var podlists []string
var pods *v1.PodList


func updateMetricMap (key string, value float64) {
_, ok := kMetric[key]
if !ok {
kMetric[key] = make([]float64, 0)
}
kMetric[key] = append(kMetric[key], value)
}


var _ = Describe("metrics check should pass", Ordered, func() {
var _ = BeforeAll(func() {
kMetric = make(map[string]float64)
kMetric = make(map[string][]float64)
podlists = make([]string, 0)

kubeconfig := flag.String("kubeconfig", "/tmp/.kube/config", "location to your kubeconfig file")
Expand All @@ -63,6 +74,13 @@ var _ = Describe("metrics check should pass", Ordered, func() {
}
}

fmt.Println("Dump podlist...")
for _, p := range podlists {
fmt.Println(p)
}

fmt.Printf("Fetch metrics from: http://%s/metrics...\n", address)

reader := bytes.NewReader([]byte{})
req, err := http.NewRequest("GET", "http://"+address+"/metrics", reader)
Expect(err).NotTo(HaveOccurred())
Expand All @@ -79,38 +97,64 @@ var _ = Describe("metrics check should pass", Ordered, func() {
for {
et, err := p.Next()
if errors.Is(err, io.EOF) {
fmt.Printf("error: %v\n", err)
break
}
switch et {
case textparse.EntrySeries:
m, _, v := p.Series()
p.Metric(&res)
if res.Has("pod_name") {
kMetric[res.Get("__name__")+res.Get("pod_name")] = v
updateMetricMap(res.Get("__name__")+"@"+res.Get("pod_name"), v)
} else {
kMetric[string(m)] = v
updateMetricMap(string(m), v)
}
fmt.Printf("metric: %s, value: %f\n", m, v)
res = res[:0]
case textparse.EntryType:
m, _ := p.Type()
kMetric[string(m)] = 0
m, t := p.Type()
fmt.Printf("metric: %s, type: %s\n", m, t)
//kMetric[string(m)] = 0
case textparse.EntryHelp:
m, _ := p.Help()
kMetric[string(m)] = 0
m, h := p.Help()
fmt.Printf("metric: %s, help: %s\n", m, h)
//kMetric[string(m)] = 0
}
}
fmt.Println("Dump kMetrics...")
for k, v := range kMetric {
fmt.Printf("metric: %s, value: %v\n", k, v)
}
})

var _ = DescribeTable("Check node level metrics for details",
func(metrics string) {
v, ok := kMetric[metrics]
Expect(ok).To(BeTrue())
//Expect(ok).To(BeTrue())
if !ok {
Skip("skip as " + metrics + " not found")
} else {
fmt.Println(v)
}
nonzero_found := false
for _, val := range v {
if val > 0 {
nonzero_found = true
break
}
}
if !nonzero_found {
Skip("skip as " + metrics + " is zero")
}
Expect(nonzero_found).To(BeTrue())

// TODO: check value in details base on cgroup and gpu etc...
// so far just base check as compare with zero by default
/*
if v == 0 {
Skip("skip as " + metrics + " is zero")
}
Expect(v).To(BeNumerically(">", 0))
Expect(v).To(BeNumerically(">", 0))*/
},
EntryDescription("checking %s"),
Entry(nil, "kepler_exporter_build_info"), // only one
Expand All @@ -127,16 +171,41 @@ var _ = Describe("metrics check should pass", Ordered, func() {

var _ = DescribeTable("Check pod level metrics for details",
func(metrics string) {
nonzero_found := false
var value float64
for _, podname := range podlists {
v, ok := kMetric[metrics+podname]
Expect(ok).To(BeTrue())
if !ok {
fmt.Printf("skip as %s for %s not found\n", metrics, podname)
continue
} else {
fmt.Println(v)
}
for _, val := range v {
if val > 0 {
nonzero_found = true
value = val
break
}
}
if !nonzero_found {
fmt.Printf("skip as %s for %s is zero\n", metrics, podname)
} else {
break
}
//Expect(ok).To(BeTrue())
// TODO: check value in details base on cgroup and gpu etc...
// so far just base check as compare with zero by default
/*
if v == 0 {
Skip("skip as " + metrics + " for " + podname + " is zero")
}
Expect(v).To(BeNumerically(">", 0))
Expect(v).To(BeNumerically(">", 0))*/
}
if !nonzero_found {
Skip("skip as " + metrics + " for all pods are zero")
}
Expect(value).To(BeNumerically(">", 0))
},
EntryDescription("checking %s"),
Entry(nil, "kepler_container_core_joules_total"), // pod level
Expand Down
11 changes: 11 additions & 0 deletions hack/verify.sh
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ function intergration_test() {
tags="bcc"
fi
echo TAGS=$tags
kepler_ready=false
$CTR_CMD ps -a
mkdir -p /tmp/.kube
if [ "$CLUSTER_PROVIDER" == "microshift" ]
Expand All @@ -64,6 +65,16 @@ function intergration_test() {
else
kind get kubeconfig --name=kind > /tmp/.kube/config
fi
until ${kepler_ready} ; do
kubectl logs $(kubectl -n kepler get pods -o name) -n kepler > kepler.log
if [ `grep -c "Started Kepler in" kepler.log` -ne '0' ]; then
echo "Kepler start finish"
kepler_ready=true
else
sleep 10
fi
done
rm -f kepler.log
while true; do kubectl port-forward --address localhost -n kepler service/kepler-exporter 9102:9102; done &
kubectl logs -n kepler daemonset/kepler-exporter
kubectl get pods -n kepler -o yaml
Expand Down

0 comments on commit 19ee6e9

Please sign in to comment.