github.com/verrazzano/verrazzano@v1.7.0/tools/psr/tests/scenarios/opensearch/s1/opensearch_s1_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 s1 5 6 import ( 7 "fmt" 8 "github.com/verrazzano/verrazzano/tools/psr/tests/pkg/constants" 9 "net/http" 10 "time" 11 12 "github.com/hashicorp/go-retryablehttp" 13 . "github.com/onsi/ginkgo/v2" 14 . "github.com/onsi/gomega" 15 "github.com/verrazzano/verrazzano/pkg/k8sutil" 16 "github.com/verrazzano/verrazzano/pkg/log/vzlog" 17 "github.com/verrazzano/verrazzano/platform-operator/apis/verrazzano/v1beta1" 18 "github.com/verrazzano/verrazzano/tests/e2e/pkg" 19 "github.com/verrazzano/verrazzano/tools/psr/tests/scenarios/common" 20 ) 21 22 const ( 23 namespace = "psrtest" 24 scenarioID = "ops-s1" 25 26 waitTimeout = 2 * time.Minute 27 pollingInterval = 5 * time.Second 28 ) 29 30 var ( 31 vz *v1beta1.Verrazzano 32 httpClient *retryablehttp.Client 33 vmiCredentials *pkg.UsernamePassword 34 35 kubeconfig string 36 metricsTest pkg.MetricsTest 37 ) 38 39 var beforeSuite = t.BeforeSuiteFunc(func() { 40 var err error 41 vz, err = pkg.GetVerrazzanoV1beta1() 42 Expect(err).To(Not(HaveOccurred())) 43 44 kubeconfig, _ = k8sutil.GetKubeConfigLocation() 45 46 httpClient = pkg.EventuallyVerrazzanoRetryableHTTPClient() 47 vmiCredentials = pkg.EventuallyGetSystemVMICredentials() 48 49 metricsTest, err = pkg.NewMetricsTest(kubeconfig, map[string]string{}) 50 if err != nil { 51 AbortSuite(fmt.Sprintf("Failed to create the Metrics test object: %v", err)) 52 } 53 }) 54 55 func sbsFunc() []byte { 56 // Start the scenario if necessary 57 kubeconfig, _ = k8sutil.GetKubeConfigLocation() 58 common.InitScenario(t, log, scenarioID, namespace, kubeconfig, skipStartScenario) 59 return []byte{} 60 } 61 62 var _ = SynchronizedBeforeSuite(sbsFunc, func(bytes []byte) { 63 // Called for all processes, set up the other initialization 64 beforeSuite() 65 }) 66 67 func sasFunc() { 68 // Stop the scenario if necessary 69 common.StopScenario(t, log, scenarioID, namespace, skipStopScenario) 70 } 71 72 var _ = SynchronizedAfterSuite(func() { 73 // Do nothing, no work for all processes before process1 callback 74 }, sasFunc) 75 76 var log = vzlog.DefaultLogger() 77 78 var _ = t.Describe("ops-s1", Label("f:psr-ops-s1"), func() { 79 // GIVEN a Verrazzano installation with a running PSR ops-s2 scenario 80 // WHEN we wish to validate the PSR workers 81 // THEN the scenario pods are running 82 t.DescribeTable("Scenario pods are deployed,", 83 func(name string, expected bool) { 84 Eventually(func() (bool, error) { 85 exists, err := pkg.DoesPodExist(namespace, name) 86 if exists { 87 t.Logs.Infof("Found pod %s/%s", namespace, name) 88 } 89 return exists, err 90 }, waitTimeout, pollingInterval).Should(Equal(expected)) 91 }, 92 t.Entry("PSR ops-s1 writelogs-0 pods running", "psr-ops-s1-ops-writelogs-0-ops-writelogs", true), 93 ) 94 95 // GIVEN a Verrazzano installation 96 // WHEN we wish to validate the PSR workers 97 // THEN we can successfully access the prometheus endpoint 98 t.DescribeTable("Verify Prometheus Endpoint", 99 func(getURLFromVZStatus func() *string) { 100 url := getURLFromVZStatus() 101 if url != nil { 102 Eventually(func() (int, error) { 103 return common.HTTPGet(*url, httpClient, vmiCredentials) 104 }).WithPolling(pollingInterval).WithTimeout(waitTimeout).Should(Equal(http.StatusOK)) 105 } 106 }, 107 Entry("Prometheus", func() *string { return vz.Status.VerrazzanoInstance.PrometheusURL }), 108 ) 109 110 // GIVEN a Verrazzano installation 111 // WHEN all opensearch PSR workers are running 112 // THEN metrics can be found for all opensearch PSR workers 113 t.DescribeTable("Verify Opensearch ops-s1 Worker Metrics", 114 func(metricName string) { 115 Eventually(func() bool { 116 return metricsTest.MetricsExist(metricName, common.GetMetricLabels("")) 117 }, waitTimeout, pollingInterval).Should(BeTrue(), 118 fmt.Sprintf("No metrics found for %s", metricName)) 119 }, 120 Entry(fmt.Sprintf("Verify metric %s", constants.WriteLogsLoggedCharsTotal), constants.WriteLogsLoggedCharsTotal), 121 Entry(fmt.Sprintf("Verify metric %s", constants.WriteLogsLoggedLinesTotalCountMetric), constants.WriteLogsLoggedLinesTotalCountMetric), 122 Entry(fmt.Sprintf("Verify metric %s", constants.WriteLogsLoopCountTotalMetric), constants.WriteLogsLoopCountTotalMetric), 123 Entry(fmt.Sprintf("Verify metric %s", constants.WriteLogsWorkerLastLoopNanosMetric), constants.WriteLogsWorkerLastLoopNanosMetric), 124 Entry(fmt.Sprintf("Verify metric %s", constants.WriteLogsWorkerRunningSecondsTotalMetric), constants.WriteLogsWorkerRunningSecondsTotalMetric), 125 Entry(fmt.Sprintf("Verify metric %s", constants.WriteLogsWorkerThreadCountTotalMetric), constants.WriteLogsWorkerThreadCountTotalMetric), 126 ) 127 })