github.com/verrazzano/verrazzano@v1.7.1/tests/e2e/opensearch-operator/infra/infra_test.go (about)

     1  // Copyright (C) 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 infra
     5  
     6  import (
     7  	"fmt"
     8  	"time"
     9  
    10  	"github.com/verrazzano/verrazzano/pkg/vzcr"
    11  	"github.com/verrazzano/verrazzano/platform-operator/apis/verrazzano/v1beta1"
    12  	"github.com/verrazzano/verrazzano/platform-operator/controllers/verrazzano/component/nginx"
    13  	prometheusOperator "github.com/verrazzano/verrazzano/platform-operator/controllers/verrazzano/component/prometheus/operator"
    14  
    15  	. "github.com/onsi/ginkgo/v2"
    16  	. "github.com/onsi/gomega"
    17  
    18  	"github.com/verrazzano/verrazzano/platform-operator/constants"
    19  	"github.com/verrazzano/verrazzano/tests/e2e/jaeger"
    20  	"github.com/verrazzano/verrazzano/tests/e2e/pkg"
    21  	dump "github.com/verrazzano/verrazzano/tests/e2e/pkg/test/clusterdump"
    22  	"github.com/verrazzano/verrazzano/tests/e2e/pkg/test/framework"
    23  	"github.com/verrazzano/verrazzano/tests/e2e/pkg/test/framework/metrics"
    24  )
    25  
    26  const (
    27  	longWaitTimeout          = 20 * time.Minute
    28  	longPollingInterval      = 20 * time.Second
    29  	shortPollingInterval     = 10 * time.Second
    30  	shortWaitTimeout         = 5 * time.Minute
    31  	imagePullWaitTimeout     = 30 * time.Minute
    32  	imagePullPollingInterval = 30 * time.Second
    33  )
    34  
    35  var (
    36  	t                        = framework.NewTestFramework("infra")
    37  	namespace                = pkg.GenerateNamespace("hello-helidon")
    38  	expectedPodsHelloHelidon = []string{"hello-helidon-deployment"}
    39  	inClusterVZ              *v1beta1.Verrazzano
    40  )
    41  
    42  var whenJaegerOperatorEnabledIt = t.WhenMeetsConditionFunc(jaeger.OperatorCondition, jaeger.IsJaegerEnabled)
    43  var _ = t.AfterEach(func() {})
    44  
    45  var beforeSuite = t.BeforeSuiteFunc(func() {
    46  	var err error
    47  	inClusterVZ, err = pkg.GetVerrazzanoV1beta1()
    48  	if err != nil {
    49  		AbortSuite(fmt.Sprintf("Failed to get Verrazzano from the cluster: %v", err))
    50  	}
    51  	pkg.DeployHelloHelidonApplication(namespace, "", "enabled", "", "")
    52  
    53  	t.Logs.Info("Container image pull check")
    54  	Eventually(func() bool {
    55  		return pkg.ContainerImagePullWait(namespace, expectedPodsHelloHelidon)
    56  	}, imagePullWaitTimeout, imagePullPollingInterval).Should(BeTrue())
    57  
    58  	t.Logs.Info("Helidon Example: check expected pods are running")
    59  	Eventually(func() bool {
    60  		result, err := pkg.PodsRunning(namespace, expectedPodsHelloHelidon)
    61  		if err != nil {
    62  			AbortSuite(fmt.Sprintf("One or more pods are not running in the namespace: %v, error: %v", namespace, err))
    63  		}
    64  		return result
    65  	}, longWaitTimeout, longPollingInterval).Should(BeTrue(), "Helidon Example Failed to Deploy: Pods are not ready")
    66  
    67  	beforeSuitePassed = true
    68  })
    69  var _ = BeforeSuite(beforeSuite)
    70  
    71  var beforeSuitePassed = false
    72  
    73  var afterSuite = t.AfterSuiteFunc(func() {
    74  	if !beforeSuitePassed {
    75  		dump.ExecuteBugReport(namespace)
    76  	}
    77  	start := time.Now()
    78  	pkg.UndeployHelloHelidonApplication(namespace, "", "")
    79  	metrics.Emit(t.Metrics.With("undeployment_elapsed_time", time.Since(start).Milliseconds()))
    80  })
    81  
    82  var _ = AfterSuite(afterSuite)
    83  
    84  var _ = t.Describe("Verify OpenSearch infra", func() {
    85  
    86  	t.It("ingress exists", func() {
    87  		Expect(pkg.IngressesExist(inClusterVZ, constants.VerrazzanoSystemNamespace, []string{"opensearch", "opensearch-dashboards"})).To(BeTrue())
    88  	})
    89  
    90  	t.It("verrazzano-system index is present", func() {
    91  		Eventually(func() bool {
    92  			return pkg.LogIndexFound("verrazzano-system")
    93  		}, shortWaitTimeout, shortPollingInterval).Should(BeTrue())
    94  	})
    95  
    96  	whenJaegerOperatorEnabledIt("traces from verrazzano system components should be available in the OS backend storage.", func() {
    97  		validatorFn := pkg.ValidateSystemTracesInOSFunc(time.Now().Add(-24 * time.Hour))
    98  		Eventually(validatorFn).WithPolling(longPollingInterval).WithTimeout(longWaitTimeout).Should(BeTrue())
    99  	})
   100  
   101  	t.It("prometheus should scrape opensearch metrics", func() {
   102  		verifyScrapeTargets := func() (bool, error) {
   103  			targets := []string{"serviceMonitor/verrazzano-monitoring/opensearch-cluster"}
   104  			if vzcr.IsComponentStatusEnabled(inClusterVZ, prometheusOperator.ComponentName) {
   105  				if !vzcr.IsComponentStatusEnabled(inClusterVZ, nginx.ComponentName) {
   106  					return pkg.ScrapeTargetsHealthyFromExec(targets)
   107  				}
   108  				return pkg.ScrapeTargetsHealthy(targets)
   109  			}
   110  			return true, nil
   111  		}
   112  		Eventually(verifyScrapeTargets, longWaitTimeout, longPollingInterval).Should(BeTrue())
   113  	})
   114  
   115  	t.Context("hello-helidon application logs are present.", func() {
   116  		var err error
   117  		var indexName string
   118  		Eventually(func() error {
   119  			indexName, err = pkg.GetOpenSearchAppIndex(namespace)
   120  			return err
   121  		}, shortWaitTimeout, shortPollingInterval).Should(BeNil(), "Expected to get OpenSearch App Index")
   122  
   123  		// GIVEN an application with logging enabled
   124  		// WHEN the Opensearch index for hello-helidon namespace is retrieved
   125  		// THEN verify that it is found
   126  		t.It("Verify Opensearch index for Logging exists", func() {
   127  			Eventually(func() bool {
   128  				return pkg.LogIndexFound(indexName)
   129  			}, longWaitTimeout, longPollingInterval).Should(BeTrue(), "Expected to find log index for hello-helidon-container")
   130  		})
   131  		pkg.Concurrently(
   132  			func() {
   133  				// GIVEN an application with logging enabled
   134  				// WHEN the log records are retrieved from the Opensearch index for hello-helidon-container
   135  				// THEN verify that at least one recent log record is found
   136  				t.It("Verify recent Opensearch log record exists", func() {
   137  					Eventually(func() bool {
   138  						return pkg.LogRecordFound(indexName, time.Now().Add(-24*time.Hour), map[string]string{
   139  							"kubernetes.labels.app_oam_dev\\/name": "hello-helidon",
   140  							"kubernetes.container_name":            "hello-helidon-container"})
   141  					}, longWaitTimeout, longPollingInterval).Should(BeTrue(), "Expected to find a recent log record for container hello-helidon-container")
   142  				})
   143  			},
   144  			func() {
   145  				// GIVEN an application with logging enabled
   146  				// WHEN the log records are retrieved from the Openearch index for other-container
   147  				// THEN verify that at least one recent log record is found
   148  				t.It("Verify recent Opensearch log record of other-container exists", func() {
   149  					Eventually(func() bool {
   150  						return pkg.LogRecordFound(indexName, time.Now().Add(-24*time.Hour), map[string]string{
   151  							"kubernetes.labels.app_oam_dev\\/name": "hello-helidon",
   152  							"kubernetes.container_name":            "other-container"})
   153  					}, longWaitTimeout, longPollingInterval).Should(BeTrue(), "Expected to find a recent log record for other-container")
   154  				})
   155  			},
   156  		)
   157  	})
   158  })