Commit 52d75d21 authored by Yu-Ju Hong's avatar Yu-Ju Hong

e2e: print runtime MemStats when memory usage exceeds expectation

parent d6440624
...@@ -99,7 +99,7 @@ func runResourceTrackingTest(framework *Framework, podsPerNode int, nodeNames se ...@@ -99,7 +99,7 @@ func runResourceTrackingTest(framework *Framework, podsPerNode int, nodeNames se
usageSummary, err := rm.GetLatest() usageSummary, err := rm.GetLatest()
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
Logf("%s", rm.FormatResourceUsage(usageSummary)) Logf("%s", rm.FormatResourceUsage(usageSummary))
verifyMemoryLimits(expectedMemory, usageSummary) verifyMemoryLimits(framework.Client, expectedMemory, usageSummary)
cpuSummary := rm.GetCPUSummary() cpuSummary := rm.GetCPUSummary()
Logf("%s", rm.FormatCPUSummary(cpuSummary)) Logf("%s", rm.FormatCPUSummary(cpuSummary))
...@@ -109,7 +109,7 @@ func runResourceTrackingTest(framework *Framework, podsPerNode int, nodeNames se ...@@ -109,7 +109,7 @@ func runResourceTrackingTest(framework *Framework, podsPerNode int, nodeNames se
DeleteRC(framework.Client, framework.Namespace.Name, rcName) DeleteRC(framework.Client, framework.Namespace.Name, rcName)
} }
func verifyMemoryLimits(expected resourceUsagePerContainer, actual resourceUsagePerNode) { func verifyMemoryLimits(c *client.Client, expected resourceUsagePerContainer, actual resourceUsagePerNode) {
if expected == nil { if expected == nil {
return return
} }
...@@ -132,10 +132,16 @@ func verifyMemoryLimits(expected resourceUsagePerContainer, actual resourceUsage ...@@ -132,10 +132,16 @@ func verifyMemoryLimits(expected resourceUsagePerContainer, actual resourceUsage
} }
if len(nodeErrs) > 0 { if len(nodeErrs) > 0 {
errList = append(errList, fmt.Sprintf("node %v:\n %s", nodeName, strings.Join(nodeErrs, ", "))) errList = append(errList, fmt.Sprintf("node %v:\n %s", nodeName, strings.Join(nodeErrs, ", ")))
heapStats, err := getKubeletHeapStats(c, nodeName)
if err != nil {
Logf("Unable to get heap stats from %q", nodeName)
} else {
Logf("Heap stats on %q\n:%v", nodeName, heapStats)
}
} }
} }
if len(errList) > 0 { if len(errList) > 0 {
Failf("CPU usage exceeding limits:\n %s", strings.Join(errList, "\n")) Failf("Memory usage exceeding limits:\n %s", strings.Join(errList, "\n"))
} }
} }
......
...@@ -391,6 +391,22 @@ func getKubeletMetricsThroughNode(nodeName string) (string, error) { ...@@ -391,6 +391,22 @@ func getKubeletMetricsThroughNode(nodeName string) (string, error) {
return string(body), nil return string(body), nil
} }
func getKubeletHeapStats(c *client.Client, nodeName string) (string, error) {
client, err := nodeProxyRequest(c, nodeName, "debug/pprof/heap")
if err != nil {
return "", err
}
raw, errRaw := client.Raw()
if errRaw != nil {
return "", err
}
stats := string(raw)
// Only dumping the runtime.MemStats numbers to avoid polluting the log.
numLines := 23
lines := strings.Split(stats, "\n")
return strings.Join(lines[len(lines)-numLines:], "\n"), nil
}
// GetKubeletPods retrieves the list of running pods on the kubelet. The pods // GetKubeletPods retrieves the list of running pods on the kubelet. The pods
// includes necessary information (e.g., UID, name, namespace for // includes necessary information (e.g., UID, name, namespace for
// pods/containers), but do not contain the full spec. // pods/containers), but do not contain the full spec.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment