kibana.go 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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 elasticsearch
  14. import (
  15. "context"
  16. "time"
  17. metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
  18. "k8s.io/apimachinery/pkg/labels"
  19. "k8s.io/apimachinery/pkg/util/wait"
  20. "k8s.io/kubernetes/test/e2e/framework"
  21. e2epod "k8s.io/kubernetes/test/e2e/framework/pod"
  22. e2eservice "k8s.io/kubernetes/test/e2e/framework/service"
  23. e2eskipper "k8s.io/kubernetes/test/e2e/framework/skipper"
  24. instrumentation "k8s.io/kubernetes/test/e2e/instrumentation/common"
  25. "github.com/onsi/ginkgo"
  26. )
  27. var _ = instrumentation.SIGDescribe("Kibana Logging Instances Is Alive [Feature:Elasticsearch]", func() {
  28. f := framework.NewDefaultFramework("kibana-logging")
  29. ginkgo.BeforeEach(func() {
  30. // TODO: For now assume we are only testing cluster logging with Elasticsearch
  31. // and Kibana on GCE. Once we are sure that Elasticsearch and Kibana cluster level logging
  32. // works for other providers we should widen this scope of this test.
  33. e2eskipper.SkipUnlessProviderIs("gce")
  34. })
  35. ginkgo.It("should check that the Kibana logging instance is alive", func() {
  36. ClusterLevelLoggingWithKibana(f)
  37. })
  38. })
  39. const (
  40. kibanaKey = "k8s-app"
  41. kibanaValue = "kibana-logging"
  42. )
  43. // ClusterLevelLoggingWithKibana is an end to end test that checks to see if Kibana is alive.
  44. func ClusterLevelLoggingWithKibana(f *framework.Framework) {
  45. const pollingInterval = 10 * time.Second
  46. const pollingTimeout = 20 * time.Minute
  47. // Check for the existence of the Kibana service.
  48. ginkgo.By("Checking the Kibana service exists.")
  49. s := f.ClientSet.CoreV1().Services(metav1.NamespaceSystem)
  50. // Make a few attempts to connect. This makes the test robust against
  51. // being run as the first e2e test just after the e2e cluster has been created.
  52. err := wait.Poll(pollingInterval, pollingTimeout, func() (bool, error) {
  53. if _, err := s.Get(context.TODO(), "kibana-logging", metav1.GetOptions{}); err != nil {
  54. framework.Logf("Kibana is unreachable: %v", err)
  55. return false, nil
  56. }
  57. return true, nil
  58. })
  59. framework.ExpectNoError(err)
  60. // Wait for the Kibana pod(s) to enter the running state.
  61. ginkgo.By("Checking to make sure the Kibana pods are running")
  62. label := labels.SelectorFromSet(labels.Set(map[string]string{kibanaKey: kibanaValue}))
  63. options := metav1.ListOptions{LabelSelector: label.String()}
  64. pods, err := f.ClientSet.CoreV1().Pods(metav1.NamespaceSystem).List(context.TODO(), options)
  65. framework.ExpectNoError(err)
  66. for _, pod := range pods.Items {
  67. err = e2epod.WaitForPodRunningInNamespace(f.ClientSet, &pod)
  68. framework.ExpectNoError(err)
  69. }
  70. ginkgo.By("Checking to make sure we get a response from the Kibana UI.")
  71. err = wait.Poll(pollingInterval, pollingTimeout, func() (bool, error) {
  72. req, err := e2eservice.GetServicesProxyRequest(f.ClientSet, f.ClientSet.CoreV1().RESTClient().Get())
  73. if err != nil {
  74. framework.Logf("Failed to get services proxy request: %v", err)
  75. return false, nil
  76. }
  77. ctx, cancel := context.WithTimeout(context.Background(), framework.SingleCallTimeout)
  78. defer cancel()
  79. _, err = req.Namespace(metav1.NamespaceSystem).
  80. Name("kibana-logging").
  81. DoRaw(ctx)
  82. if err != nil {
  83. framework.Logf("Proxy call to kibana-logging failed: %v", err)
  84. return false, nil
  85. }
  86. return true, nil
  87. })
  88. framework.ExpectNoError(err)
  89. }