mirror of https://github.com/k3s-io/k3s
Moved writePerfData to utils. #7572
parent
a89121cb70
commit
bd3306c845
|
@ -37,26 +37,6 @@ import (
|
||||||
. "github.com/onsi/gomega"
|
. "github.com/onsi/gomega"
|
||||||
)
|
)
|
||||||
|
|
||||||
func writePerfData(c *client.Client, dirName string, postfix string) {
|
|
||||||
defer GinkgoRecover()
|
|
||||||
|
|
||||||
hdnl, err := os.Create(fmt.Sprintf("%s/metrics_%s.txt", dirName, postfix))
|
|
||||||
expectNoError(err)
|
|
||||||
metrics, err := GetMetrics(c)
|
|
||||||
expectNoError(err)
|
|
||||||
_, err = hdnl.WriteString(metrics)
|
|
||||||
expectNoError(err)
|
|
||||||
expectNoError(hdnl.Close())
|
|
||||||
debug, err := GetDebugInfo(c)
|
|
||||||
for key, value := range debug {
|
|
||||||
hdnl, err = os.Create(fmt.Sprintf("%s/%s_%s.txt", dirName, key, postfix))
|
|
||||||
expectNoError(err)
|
|
||||||
_, err = hdnl.WriteString(value)
|
|
||||||
expectNoError(err)
|
|
||||||
expectNoError(hdnl.Close())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// This test suite can take a long time to run, so by default it is added to
|
// This test suite can take a long time to run, so by default it is added to
|
||||||
// the ginkgo.skip list (see driver.go).
|
// the ginkgo.skip list (see driver.go).
|
||||||
// To run this suite you must explicitly ask for it by setting the
|
// To run this suite you must explicitly ask for it by setting the
|
||||||
|
@ -81,7 +61,7 @@ var _ = Describe("Density", func() {
|
||||||
expectNoError(err)
|
expectNoError(err)
|
||||||
uuid = string(util.NewUUID())
|
uuid = string(util.NewUUID())
|
||||||
expectNoError(os.Mkdir(uuid, 0777))
|
expectNoError(os.Mkdir(uuid, 0777))
|
||||||
writePerfData(c, uuid, "before")
|
expectNoError(writePerfData(c, uuid, "before"))
|
||||||
})
|
})
|
||||||
|
|
||||||
AfterEach(func() {
|
AfterEach(func() {
|
||||||
|
@ -107,7 +87,7 @@ var _ = Describe("Density", func() {
|
||||||
highLatencyRequests, err := HighLatencyRequests(c, 10*time.Second, util.NewStringSet("events"))
|
highLatencyRequests, err := HighLatencyRequests(c, 10*time.Second, util.NewStringSet("events"))
|
||||||
expectNoError(err)
|
expectNoError(err)
|
||||||
Expect(highLatencyRequests).NotTo(BeNumerically(">", 0))
|
Expect(highLatencyRequests).NotTo(BeNumerically(">", 0))
|
||||||
writePerfData(c, uuid, "after")
|
expectNoError(writePerfData(c, uuid, "after"))
|
||||||
})
|
})
|
||||||
|
|
||||||
// Tests with "Skipped" substring in their name will be skipped when running
|
// Tests with "Skipped" substring in their name will be skipped when running
|
||||||
|
|
|
@ -950,7 +950,7 @@ func HighLatencyRequests(c *client.Client, threshold time.Duration, ignoredResou
|
||||||
}
|
}
|
||||||
|
|
||||||
// Retrieve metrics information
|
// Retrieve metrics information
|
||||||
func GetMetrics(c *client.Client) (string, error) {
|
func getMetrics(c *client.Client) (string, error) {
|
||||||
body, err := c.Get().AbsPath("/metrics").DoRaw()
|
body, err := c.Get().AbsPath("/metrics").DoRaw()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
|
@ -959,7 +959,7 @@ func GetMetrics(c *client.Client) (string, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Retrieve debug information
|
// Retrieve debug information
|
||||||
func GetDebugInfo(c *client.Client) (map[string]string, error) {
|
func getDebugInfo(c *client.Client) (map[string]string, error) {
|
||||||
data := make(map[string]string)
|
data := make(map[string]string)
|
||||||
for _, key := range []string{"block", "goroutine", "heap", "threadcreate"} {
|
for _, key := range []string{"block", "goroutine", "heap", "threadcreate"} {
|
||||||
body, err := c.Get().AbsPath(fmt.Sprintf("/debug/pprof/%s", key)).DoRaw()
|
body, err := c.Get().AbsPath(fmt.Sprintf("/debug/pprof/%s", key)).DoRaw()
|
||||||
|
@ -970,3 +970,50 @@ func GetDebugInfo(c *client.Client) (map[string]string, error) {
|
||||||
}
|
}
|
||||||
return data, nil
|
return data, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func writePerfData(c *client.Client, dirName string, postfix string) error {
|
||||||
|
fname := fmt.Sprintf("%s/metrics_%s.txt", dirName, postfix)
|
||||||
|
|
||||||
|
hdnl, err := os.Create(fname)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("Error creating file '%s': %v", fname, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
metrics, err := getMetrics(c)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("Error retrieving metrics: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = hdnl.WriteString(metrics)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("Error writing metrics: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
err = hdnl.Close()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("Error closing '%s': %v", fname, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
debug, err := getDebugInfo(c)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("Error retrieving debug information: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for key, value := range debug {
|
||||||
|
fname := fmt.Sprintf("%s/%s_%s.txt", dirName, key, postfix)
|
||||||
|
hdnl, err = os.Create(fname)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("Error creating file '%s': %v", fname, err)
|
||||||
|
}
|
||||||
|
_, err = hdnl.WriteString(value)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("Error writing %s: %v", key, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
err = hdnl.Close()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("Error closing '%s': %v", fname, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue