generic_soak.go 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /*
  2. Copyright 2017 The Kubernetes Authors.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package logging
  14. import (
  15. "fmt"
  16. "strconv"
  17. "strings"
  18. "sync"
  19. "time"
  20. "github.com/onsi/ginkgo"
  21. "github.com/onsi/gomega"
  22. "k8s.io/api/core/v1"
  23. "k8s.io/kubernetes/test/e2e/framework"
  24. "k8s.io/kubernetes/test/e2e/framework/config"
  25. e2elog "k8s.io/kubernetes/test/e2e/framework/log"
  26. instrumentation "k8s.io/kubernetes/test/e2e/instrumentation/common"
  27. imageutils "k8s.io/kubernetes/test/utils/image"
  28. )
  29. var loggingSoak struct {
  30. Scale int `default:"1" usage:"number of waves of pods"`
  31. TimeBetweenWaves time.Duration `default:"5000ms" usage:"time to wait before dumping the next wave of pods"`
  32. }
  33. var _ = config.AddOptions(&loggingSoak, "instrumentation.logging.soak")
  34. var _ = instrumentation.SIGDescribe("Logging soak [Performance] [Slow] [Disruptive]", func() {
  35. f := framework.NewDefaultFramework("logging-soak")
  36. // Not a global constant (irrelevant outside this test), also not a parameter (if you want more logs, use --scale=).
  37. kbRateInSeconds := 1 * time.Second
  38. totalLogTime := 2 * time.Minute
  39. // This test is designed to run and confirm that logs are being generated at a large scale, and that they can be grabbed by the kubelet.
  40. // By running it repeatedly in the background, you can simulate large collections of chatty containers.
  41. // This can expose problems in your docker configuration (logging), log searching infrastructure, to tune deployments to match high load
  42. // scenarios. TODO jayunit100 add this to the kube CI in a follow on infra patch.
  43. ginkgo.It(fmt.Sprintf("should survive logging 1KB every %v seconds, for a duration of %v", kbRateInSeconds, totalLogTime), func() {
  44. ginkgo.By(fmt.Sprintf("scaling up to %v pods per node", loggingSoak.Scale))
  45. defer ginkgo.GinkgoRecover()
  46. var wg sync.WaitGroup
  47. wg.Add(loggingSoak.Scale)
  48. for i := 0; i < loggingSoak.Scale; i++ {
  49. go func() {
  50. defer wg.Done()
  51. defer ginkgo.GinkgoRecover()
  52. wave := fmt.Sprintf("wave%v", strconv.Itoa(i))
  53. e2elog.Logf("Starting logging soak, wave = %v", wave)
  54. RunLogPodsWithSleepOf(f, kbRateInSeconds, wave, totalLogTime)
  55. e2elog.Logf("Completed logging soak, wave %v", i)
  56. }()
  57. // Niceness.
  58. time.Sleep(loggingSoak.TimeBetweenWaves)
  59. }
  60. e2elog.Logf("Waiting on all %v logging soak waves to complete", loggingSoak.Scale)
  61. wg.Wait()
  62. })
  63. })
  64. // RunLogPodsWithSleepOf creates a pod on every node, logs continuously (with "sleep" pauses), and verifies that the log string
  65. // was produced in each and every pod at least once. The final arg is the timeout for the test to verify all the pods got logs.
  66. func RunLogPodsWithSleepOf(f *framework.Framework, sleep time.Duration, podname string, timeout time.Duration) {
  67. nodes := framework.GetReadySchedulableNodesOrDie(f.ClientSet)
  68. totalPods := len(nodes.Items)
  69. gomega.Expect(totalPods).NotTo(gomega.Equal(0))
  70. kilobyte := strings.Repeat("logs-123", 128) // 8*128=1024 = 1KB of text.
  71. appName := "logging-soak" + podname
  72. podlables := f.CreatePodsPerNodeForSimpleApp(
  73. appName,
  74. func(n v1.Node) v1.PodSpec {
  75. return v1.PodSpec{
  76. Containers: []v1.Container{{
  77. Name: "logging-soak",
  78. Image: imageutils.GetE2EImage(imageutils.BusyBox),
  79. Args: []string{
  80. "/bin/sh",
  81. "-c",
  82. fmt.Sprintf("while true ; do echo %v ; sleep %v; done", kilobyte, sleep.Seconds()),
  83. },
  84. }},
  85. NodeName: n.Name,
  86. RestartPolicy: v1.RestartPolicyAlways,
  87. }
  88. },
  89. totalPods,
  90. )
  91. logSoakVerification := f.NewClusterVerification(
  92. f.Namespace,
  93. framework.PodStateVerification{
  94. Selectors: podlables,
  95. ValidPhases: []v1.PodPhase{v1.PodRunning, v1.PodSucceeded},
  96. // we don't validate total log data, since there is no guarantee all logs will be stored forever.
  97. // instead, we just validate that some logs are being created in std out.
  98. Verify: func(p v1.Pod) (bool, error) {
  99. s, err := framework.LookForStringInLog(f.Namespace.Name, p.Name, "logging-soak", "logs-123", 1*time.Second)
  100. return s != "", err
  101. },
  102. },
  103. )
  104. largeClusterForgiveness := time.Duration(len(nodes.Items)/5) * time.Second // i.e. a 100 node cluster gets an extra 20 seconds to complete.
  105. pods, err := logSoakVerification.WaitFor(totalPods, timeout+largeClusterForgiveness)
  106. if err != nil {
  107. framework.Failf("Error in wait... %v", err)
  108. } else if len(pods) < totalPods {
  109. framework.Failf("Only got %v out of %v", len(pods), totalPods)
  110. }
  111. }