github.com/verrazzano/verrazzano@v1.7.1/tools/psr/tests/scenarios/opensearch/s2/opensearch_s2_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 s2 5 6 import ( 7 "fmt" 8 "net/http" 9 "time" 10 11 "github.com/hashicorp/go-retryablehttp" 12 . "github.com/onsi/ginkgo/v2" 13 . "github.com/onsi/gomega" 14 "github.com/verrazzano/verrazzano/pkg/k8sutil" 15 "github.com/verrazzano/verrazzano/pkg/log/vzlog" 16 "github.com/verrazzano/verrazzano/platform-operator/apis/verrazzano/v1beta1" 17 "github.com/verrazzano/verrazzano/tests/e2e/pkg" 18 "github.com/verrazzano/verrazzano/tools/psr/tests/pkg/constants" 19 "github.com/verrazzano/verrazzano/tools/psr/tests/scenarios/common" 20 ) 21 22 const ( 23 namespace = "psrtest" 24 scenarioID = "ops-s2" 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-s2", Label("f:psr-ops-s2"), 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-s2 getlogs-0 pods running", "psr-ops-s2-ops-getlogs-0-ops-getlogs", true), 93 t.Entry("PSR ops-s2 getlogs-1 pods running", "psr-ops-s2-ops-getlogs-1-ops-getlogs", true), 94 t.Entry("PSR ops-s2 writelogs-1 pods running", "psr-ops-s2-ops-writelogs-2-ops-writelogs", true), 95 ) 96 97 // GIVEN a Verrazzano installation 98 // WHEN we wish to validate the PSR workers 99 // THEN we can successfully access the prometheus endpoint 100 t.DescribeTable("Verify Prometheus Endpoint", 101 func(getURLFromVZStatus func() *string) { 102 url := getURLFromVZStatus() 103 if url != nil { 104 Eventually(func() (int, error) { 105 return common.HTTPGet(*url, httpClient, vmiCredentials) 106 }).WithPolling(pollingInterval).WithTimeout(waitTimeout).Should(Equal(http.StatusOK)) 107 } 108 }, 109 Entry("Prometheus", func() *string { return vz.Status.VerrazzanoInstance.PrometheusURL }), 110 ) 111 112 // GIVEN a Verrazzano installation 113 // WHEN all opensearch PSR workers are running 114 // THEN metrics can be found for all opensearch PSR workers 115 t.DescribeTable("Verify Opensearch ops-s2 Worker Metrics", 116 func(metricName string) { 117 Eventually(func() bool { 118 return metricsTest.MetricsExist(metricName, common.GetMetricLabels("")) 119 }, waitTimeout, pollingInterval).Should(BeTrue(), 120 fmt.Sprintf("No metrics found for %s", metricName)) 121 }, 122 Entry(fmt.Sprintf("Verify metric %s", constants.GetLogsDataCharsTotalMetric), constants.GetLogsDataCharsTotalMetric), 123 Entry(fmt.Sprintf("Verify metric %s", constants.GetLogsFailureCountTotalMetric), constants.GetLogsFailureCountTotalMetric), 124 Entry(fmt.Sprintf("Verify metric %s", constants.GetLogsFailureLatencyNanosMetric), constants.GetLogsFailureLatencyNanosMetric), 125 Entry(fmt.Sprintf("Verify metric %s", constants.GetLogsLoopCountTotalMetric), constants.GetLogsLoopCountTotalMetric), 126 Entry(fmt.Sprintf("Verify metric %s", constants.GetLogsSuccessCountTotalMetric), constants.GetLogsSuccessCountTotalMetric), 127 Entry(fmt.Sprintf("Verify metric %s", constants.GetLogsSuccessLatencyNanosMetric), constants.GetLogsSuccessLatencyNanosMetric), 128 Entry(fmt.Sprintf("Verify metric %s", constants.GetLogsWorkerLastLoopNanosMetric), constants.GetLogsWorkerLastLoopNanosMetric), 129 Entry(fmt.Sprintf("Verify metric %s", constants.GetLogsWorkerRunningSecondsTotalMetric), constants.GetLogsWorkerRunningSecondsTotalMetric), 130 Entry(fmt.Sprintf("Verify metric %s", constants.GetLogsWorkerThreadCountTotalMetric), constants.GetLogsWorkerThreadCountTotalMetric), 131 132 Entry(fmt.Sprintf("Verify metric %s", constants.WriteLogsLoggedCharsTotal), constants.WriteLogsLoggedCharsTotal), 133 Entry(fmt.Sprintf("Verify metric %s", constants.WriteLogsLoggedLinesTotalCountMetric), constants.WriteLogsLoggedLinesTotalCountMetric), 134 Entry(fmt.Sprintf("Verify metric %s", constants.WriteLogsLoopCountTotalMetric), constants.WriteLogsLoopCountTotalMetric), 135 Entry(fmt.Sprintf("Verify metric %s", constants.WriteLogsWorkerLastLoopNanosMetric), constants.WriteLogsWorkerLastLoopNanosMetric), 136 Entry(fmt.Sprintf("Verify metric %s", constants.WriteLogsWorkerRunningSecondsTotalMetric), constants.WriteLogsWorkerRunningSecondsTotalMetric), 137 Entry(fmt.Sprintf("Verify metric %s", constants.WriteLogsWorkerThreadCountTotalMetric), constants.WriteLogsWorkerThreadCountTotalMetric), 138 ) 139 })