github.com/verrazzano/verrazzano@v1.7.1/tests/e2e/jaeger/helidon/jaeger_helidon_test.go (about)

     1  // Copyright (c) 2022, 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 helidon
     5  
     6  import (
     7  	dump "github.com/verrazzano/verrazzano/tests/e2e/pkg/test/clusterdump"
     8  	"time"
     9  
    10  	. "github.com/onsi/ginkgo/v2"
    11  	. "github.com/onsi/gomega"
    12  	"github.com/verrazzano/verrazzano/pkg/k8sutil"
    13  	"github.com/verrazzano/verrazzano/tests/e2e/jaeger"
    14  	"github.com/verrazzano/verrazzano/tests/e2e/pkg"
    15  	"github.com/verrazzano/verrazzano/tests/e2e/pkg/test/framework"
    16  	"github.com/verrazzano/verrazzano/tests/e2e/pkg/test/framework/metrics"
    17  )
    18  
    19  const (
    20  	shortPollingInterval = 10 * time.Second
    21  	shortWaitTimeout     = 5 * time.Minute
    22  )
    23  
    24  const (
    25  	testAppComponentFilePath     = "testdata/jaeger/helidon/helidon-tracing-comp.yaml"
    26  	testAppConfigurationFilePath = "testdata/jaeger/helidon/helidon-tracing-app.yaml"
    27  )
    28  
    29  var (
    30  	t                        = framework.NewTestFramework("jaeger-helidon")
    31  	generatedNamespace       = pkg.GenerateNamespace("jaeger-tracing")
    32  	expectedPodsHelloHelidon = []string{"hello-helidon-deployment"}
    33  	beforeSuitePassed        = false
    34  	failed                   = false
    35  	start                    = time.Now()
    36  	helloHelidonServiceName  = "hello-helidon"
    37  )
    38  
    39  var whenJaegerOperatorEnabledIt = t.WhenMeetsConditionFunc(jaeger.OperatorCondition, jaeger.IsJaegerEnabled)
    40  
    41  var beforeSuite = t.BeforeSuiteFunc(func() {
    42  	start = time.Now()
    43  	kubeconfigPath, err := k8sutil.GetKubeConfigLocation()
    44  	if err != nil {
    45  		AbortSuite("Unable to get the default kubeconfig path")
    46  	}
    47  	jaeger.DeployApplication(namespace, testAppComponentFilePath, testAppConfigurationFilePath, expectedPodsHelloHelidon)
    48  
    49  	metrics.Emit(t.Metrics.With("deployment_elapsed_time", time.Since(start).Milliseconds()))
    50  	err = pkg.GenerateTrafficForTraces(namespace, "", "greet", kubeconfigPath)
    51  	if err != nil {
    52  		pkg.Log(pkg.Error, "Unable to send traffic requests to generate traces")
    53  	}
    54  	beforeSuitePassed = true
    55  })
    56  
    57  var _ = BeforeSuite(beforeSuite)
    58  
    59  var _ = t.AfterEach(func() {
    60  	failed = failed || CurrentSpecReport().Failed()
    61  })
    62  
    63  var afterSuite = t.AfterSuiteFunc(func() {
    64  	if failed || !beforeSuitePassed {
    65  		dump.ExecuteBugReport(namespace)
    66  	}
    67  	// undeploy the application here
    68  	start := time.Now()
    69  
    70  	jaeger.UndeployApplication(namespace, testAppComponentFilePath, testAppConfigurationFilePath, expectedPodsHelloHelidon)
    71  	metrics.Emit(t.Metrics.With("undeployment_elapsed_time", time.Since(start).Milliseconds()))
    72  })
    73  
    74  var _ = AfterSuite(afterSuite)
    75  
    76  var _ = t.Describe("Helidon App with Jaeger Traces", Label("f:jaeger.helidon-workload"), func() {
    77  	t.Context("after successful installation", func() {
    78  		// GIVEN the Jaeger Operator is enabled and a sample application is installed,
    79  		// WHEN we check for traces for that service,
    80  		// THEN we are able to get the traces
    81  		whenJaegerOperatorEnabledIt("traces for the helidon app should be available when queried from Jaeger", func() {
    82  			kubeconfigPath, err := k8sutil.GetKubeConfigLocation()
    83  			if err != nil {
    84  				Fail(err.Error())
    85  			}
    86  			validatorFn := pkg.ValidateApplicationTracesInCluster(kubeconfigPath, start, helloHelidonServiceName, "local")
    87  			Eventually(validatorFn).WithPolling(shortPollingInterval).WithTimeout(shortWaitTimeout).Should(BeTrue())
    88  		})
    89  
    90  		// GIVEN the Jaeger Operator component is enabled,
    91  		// WHEN a sample application is installed,
    92  		// THEN the traces are found in OpenSearch Backend
    93  		whenJaegerOperatorEnabledIt("traces for the helidon app should be available in the OS backend storage.", func() {
    94  			validatorFn := pkg.ValidateApplicationTracesInOS(start, helloHelidonServiceName)
    95  			Eventually(validatorFn).WithPolling(shortPollingInterval).WithTimeout(shortWaitTimeout).Should(BeTrue())
    96  		})
    97  	})
    98  
    99  })