github.com/verrazzano/verrazzano@v1.7.1/tests/e2e/upgrade/pre-upgrade/grafana/grafana_test.go (about) 1 // Copyright (c) 2022, 2023, Oracle and/or its affiliates. 2 // Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. 3 4 package grafana 5 6 import ( 7 "encoding/json" 8 "fmt" 9 "net/http" 10 "os" 11 "time" 12 13 . "github.com/onsi/ginkgo/v2" 14 . "github.com/onsi/gomega" 15 "github.com/verrazzano/verrazzano/pkg/k8sutil" 16 "github.com/verrazzano/verrazzano/tests/e2e/pkg" 17 "github.com/verrazzano/verrazzano/tests/e2e/pkg/test/framework" 18 ) 19 20 const ( 21 waitTimeout = 3 * time.Minute 22 pollingInterval = 10 * time.Second 23 documentFile = "testdata/upgrade/grafana/dashboard.json" 24 ) 25 26 var testDashboard pkg.DashboardMetadata 27 var t = framework.NewTestFramework("grafana") 28 29 var beforeSuite = t.BeforeSuiteFunc(func() { 30 kubeconfigPath, err := k8sutil.GetKubeConfigLocation() 31 if err != nil { 32 Fail(fmt.Sprintf(pkg.KubeConfigErrorFmt, err)) 33 } 34 supported := pkg.IsGrafanaEnabled(kubeconfigPath) 35 // Only run tests if Grafana component is enabled in Verrazzano CR 36 if !supported { 37 Skip("Grafana component is not enabled") 38 } 39 // Create the test Grafana dashboard 40 file, err := pkg.FindTestDataFile(documentFile) 41 if err != nil { 42 pkg.Log(pkg.Error, fmt.Sprintf("failed to find test data file: %v", err)) 43 Fail(err.Error()) 44 } 45 data, err := os.ReadFile(file) 46 if err != nil { 47 pkg.Log(pkg.Error, fmt.Sprintf("failed to read test data file: %v", err)) 48 Fail(err.Error()) 49 } 50 Eventually(func() bool { 51 resp, err := pkg.CreateGrafanaDashboard(string(data)) 52 if err != nil { 53 pkg.Log(pkg.Error, fmt.Sprintf("Failed to create Grafana testDashboard: %v", err)) 54 return false 55 } 56 if resp.StatusCode != http.StatusOK { 57 pkg.Log(pkg.Error, fmt.Sprintf("Failed to create Grafana testDashboard: status=%d: body=%s", resp.StatusCode, string(resp.Body))) 58 return false 59 } 60 json.Unmarshal(resp.Body, &testDashboard) 61 return true 62 }).WithPolling(pollingInterval).WithTimeout(waitTimeout).Should(BeTrue(), 63 "It should be possible to create a Grafana dashboard and persist it.") 64 }) 65 66 var _ = BeforeSuite(beforeSuite) 67 68 var _ = t.Describe("Pre Upgrade Grafana Dashboard", Label("f:observability.logging.es"), func() { 69 70 // GIVEN a running grafana instance, 71 // WHEN a GET call is made to Grafana with the UID of the newly created testDashboard, 72 // THEN the testDashboard metadata of the corresponding testDashboard is returned. 73 t.It("Get details of the test Grafana Dashboard", func() { 74 pkg.TestGrafanaTestDashboard(testDashboard, pollingInterval, waitTimeout) 75 }) 76 77 // GIVEN a running Grafana instance, 78 // WHEN a search is done based on the dashboard title, 79 // THEN the details of the dashboards matching the search query is returned. 80 t.It("Search the test Grafana Dashboard using its title", func() { 81 pkg.TestSearchGrafanaDashboard(pollingInterval, waitTimeout) 82 }) 83 84 // GIVEN a running grafana instance, 85 // WHEN a GET call is made to Grafana with the system dashboard UID, 86 // THEN the dashboard metadata of the corresponding testDashboard is returned. 87 t.It("Get details of the system Grafana Dashboard", func() { 88 kubeConfigPath, err := k8sutil.GetKubeConfigLocation() 89 Expect(err).To(BeNil(), fmt.Sprintf(pkg.KubeConfigErrorFmt, err)) 90 systemHealthDashboardExists, err := pkg.IsVerrazzanoMinVersion("1.5.0", kubeConfigPath) 91 Expect(err).To(BeNil(), fmt.Sprintf("could not find verrazzzano min version: %v", err)) 92 if systemHealthDashboardExists { 93 pkg.TestSystemHealthGrafanaDashboard(pollingInterval, waitTimeout) 94 } 95 }) 96 97 kubeconfigPath, err := k8sutil.GetKubeConfigLocation() 98 if err != nil { 99 Expect(err).To(BeNil(), fmt.Sprintf(pkg.KubeConfigErrorFmt, err)) 100 } 101 102 // GIVEN a running grafana instance 103 // WHEN a call is made to Grafana Dashboard with UID corresponding to OpenSearch Summary Dashboard 104 // THEN the dashboard metadata of the corresponding dashboard is returned 105 if ok, _ := pkg.IsVerrazzanoMinVersion("1.3.0", kubeconfigPath); ok { 106 t.It("Get details of the OpenSearch Grafana Dashboard", func() { 107 pkg.TestOpenSearchGrafanaDashBoard(pollingInterval, waitTimeout) 108 }) 109 } 110 })