github.com/verrazzano/verrazzano@v1.7.1/tests/e2e/update/jaeger/jaeger_update_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 jaeger
     5  
     6  import (
     7  	"fmt"
     8  	"strings"
     9  	"time"
    10  
    11  	. "github.com/onsi/ginkgo/v2"
    12  	. "github.com/onsi/gomega"
    13  	"github.com/verrazzano/verrazzano/pkg/k8sutil"
    14  	"github.com/verrazzano/verrazzano/platform-operator/constants"
    15  	"github.com/verrazzano/verrazzano/tests/e2e/jaeger"
    16  	"github.com/verrazzano/verrazzano/tests/e2e/pkg"
    17  	"github.com/verrazzano/verrazzano/tests/e2e/pkg/test/framework"
    18  	"github.com/verrazzano/verrazzano/tests/e2e/pkg/update"
    19  )
    20  
    21  const (
    22  	shortPollingInterval = 10 * time.Second
    23  	shortWaitTimeout     = 5 * time.Minute
    24  	disableErrorMsg      = "disabling component jaegerOperator is not allowed"
    25  )
    26  
    27  var (
    28  	// Initialize the Test Framework
    29  	t     = framework.NewTestFramework("update jaeger operator")
    30  	start = time.Now()
    31  )
    32  
    33  var whenJaegerOperatorEnabledIt = t.WhenMeetsConditionFunc(jaeger.OperatorCondition, jaeger.IsJaegerEnabled)
    34  var kubeconfigPath string
    35  var metricsTest pkg.MetricsTest
    36  
    37  var beforeSuite = t.BeforeSuiteFunc(func() {
    38  	m := JaegerOperatorEnabledModifier{}
    39  	update.UpdateCRWithRetries(m, pollingInterval, waitTimeout)
    40  
    41  	// GIVEN a VZ custom resource in dev profile,
    42  	// WHEN Jaeger operator is enabled,
    43  	// THEN Jaeger operator and pods for jaeger-collector and jaeger-query components gets created.
    44  	update.ValidatePods(jaegerOperatorLabelValue, jaegerComponentLabel, constants.VerrazzanoMonitoringNamespace, 1, false)
    45  	update.ValidatePods(jaegerCollectorLabelValue, jaegerComponentLabel, constants.VerrazzanoMonitoringNamespace, 1, false)
    46  	update.ValidatePods(jaegerQueryLabelValue, jaegerComponentLabel, constants.VerrazzanoMonitoringNamespace, 1, false)
    47  
    48  	var err error
    49  	kubeconfigPath, err = k8sutil.GetKubeConfigLocation()
    50  	if err != nil {
    51  		AbortSuite(fmt.Sprintf("Failed to find Kubeconfig location: %v", err))
    52  	}
    53  	metricsTest, err = pkg.NewMetricsTest(kubeconfigPath, map[string]string{})
    54  	if err != nil {
    55  		AbortSuite(fmt.Sprintf("Failed to create the Metrics test object: %v", err))
    56  	}
    57  })
    58  
    59  var _ = BeforeSuite(beforeSuite)
    60  
    61  var _ = t.Describe("Update Jaeger", Label("f:platform-lcm.update"), func() {
    62  
    63  	// GIVEN a VZ custom resource in dev profile,
    64  	// WHEN Jaeger operator is enabled,
    65  	// THEN Jaeger OpenSearch Index Cleaner cron job exists
    66  	whenJaegerOperatorEnabledIt("should have a Jaeger OpenSearch Index Cleaner cron job", func() {
    67  		validatorFn := pkg.ValidateEsIndexCleanerCronJobFunc()
    68  		Eventually(validatorFn).WithPolling(pollingInterval).WithTimeout(waitTimeout).Should(BeTrue())
    69  	})
    70  
    71  	// GIVEN a VZ custom resource in dev profile,
    72  	// WHEN Jaeger operator is enabled,
    73  	// THEN we are able to get the traces
    74  	whenJaegerOperatorEnabledIt("traces from verrazzano system components should be available when queried from Jaeger", func() {
    75  		validatorFn := pkg.ValidateSystemTracesFuncInCluster(kubeconfigPath, start, "local")
    76  		Eventually(validatorFn).WithPolling(shortPollingInterval).WithTimeout(shortWaitTimeout).Should(BeTrue())
    77  	})
    78  
    79  	// GIVEN a VZ custom resource in dev profile,
    80  	// WHEN Jaeger operator is enabled,
    81  	// THEN we are able to get the traces
    82  	whenJaegerOperatorEnabledIt("traces from verrazzano system components should be available in the OS backend storage.", func() {
    83  		validatorFn := pkg.ValidateSystemTracesInOSFunc(start)
    84  		Eventually(validatorFn).WithPolling(shortPollingInterval).WithTimeout(shortWaitTimeout).Should(BeTrue())
    85  	})
    86  
    87  	// GIVEN a VZ custom resource in dev profile,
    88  	// WHEN Jaeger operator is enabled,
    89  	// THEN we see that the metrics of Jaeger operator are present in prometheus
    90  	whenJaegerOperatorEnabledIt("metrics of jaeger operator are available in prometheus", func() {
    91  		validatorFn := pkg.ValidateJaegerOperatorMetricFunc(metricsTest)
    92  		Eventually(validatorFn).WithPolling(shortPollingInterval).WithTimeout(shortWaitTimeout).Should(BeTrue())
    93  	})
    94  
    95  	// GIVEN a VZ custom resource in dev profile,
    96  	// WHEN Jaeger operator is enabled,
    97  	// THEN we see that the metrics of Jaeger collector are present in prometheus
    98  	whenJaegerOperatorEnabledIt("metrics of jaeger collector are available in prometheus", func() {
    99  		validatorFn := pkg.ValidateJaegerCollectorMetricFunc(metricsTest)
   100  		Eventually(validatorFn).WithPolling(shortPollingInterval).WithTimeout(shortWaitTimeout).Should(BeTrue())
   101  	})
   102  
   103  	// GIVEN a VZ custom resource in dev profile,
   104  	// WHEN Jaeger operator is enabled,
   105  	// THEN we see that the metrics of Jaeger query are present in prometheus
   106  	whenJaegerOperatorEnabledIt("metrics of jaeger query are available in prometheus", func() {
   107  		validatorFn := pkg.ValidateJaegerQueryMetricFunc(metricsTest)
   108  		Eventually(validatorFn).WithPolling(shortPollingInterval).WithTimeout(shortWaitTimeout).Should(BeTrue())
   109  	})
   110  
   111  	// GIVEN a VZ custom resource in dev profile,
   112  	// WHEN Jaeger operator is enabled,
   113  	// THEN we see that the metrics of Jaeger agent are present in prometheus
   114  	whenJaegerOperatorEnabledIt("metrics of jaeger agent are available in prometheus", func() {
   115  		validatorFn := pkg.ValidateJaegerAgentMetricFunc(metricsTest)
   116  		Eventually(validatorFn).WithPolling(shortPollingInterval).WithTimeout(shortWaitTimeout).Should(BeTrue())
   117  	})
   118  
   119  	// GIVEN a VZ custom resource in dev profile with Jaeger operator enabled,
   120  	// WHEN user tries to disable it,
   121  	// THEN the operation should be denied with an error
   122  	whenJaegerOperatorEnabledIt("disabling previously enabled Jaeger operator should be disallowed", func() {
   123  		m := JaegerOperatorCleanupModifier{}
   124  		Eventually(func() bool {
   125  			err := update.UpdateCR(m)
   126  			foundExpectedErr := err != nil && strings.Contains(err.Error(), disableErrorMsg)
   127  			return foundExpectedErr
   128  		}).WithPolling(pollingInterval).WithTimeout(waitTimeout).Should(BeTrue())
   129  	})
   130  })