github.com/redhat-appstudio/e2e-tests@v0.0.0-20230619105049-9a422b2094d7/tests/o11y/o11y-deployments.go (about) 1 package o11y 2 3 import ( 4 "fmt" 5 6 . "github.com/onsi/ginkgo/v2" 7 . "github.com/onsi/gomega" 8 9 "github.com/redhat-appstudio/e2e-tests/pkg/framework" 10 "github.com/redhat-appstudio/e2e-tests/pkg/utils" 11 ) 12 13 var _ = framework.O11ySuiteDescribe("O11Y E2E tests for Deployments", Label("o11y", "HACBS"), Pending, func() { 14 15 defer GinkgoRecover() 16 var f *framework.Framework 17 var err error 18 19 Describe("O11y test", func() { 20 var testNamespace string 21 22 BeforeAll(func() { 23 24 f, err = framework.NewFramework(O11yUserDeployments) 25 Expect(err).NotTo(HaveOccurred()) 26 testNamespace = f.UserNamespace 27 28 // Get Quay Token from ENV 29 quayToken := utils.GetEnv("QUAY_TOKEN", "") 30 Expect(quayToken).ToNot(BeEmpty()) 31 32 _, err := f.AsKubeAdmin.CommonController.CreateRegistryAuthSecret(o11yUserSecret, testNamespace, quayToken) 33 Expect(err).ToNot(HaveOccurred()) 34 35 err = f.AsKubeAdmin.CommonController.LinkSecretToServiceAccount(testNamespace, o11yUserSecret, O11ySA, true) 36 Expect(err).ToNot(HaveOccurred()) 37 38 }) 39 AfterAll(func() { 40 if !CurrentSpecReport().Failed() { 41 Expect(f.SandboxController.DeleteUserSignup(f.UserName)).NotTo(BeFalse()) 42 } 43 }) 44 45 It("E2E test to measure Egress pod by pushing images to quay - Deployments", func() { 46 47 // Get Quay Organization from ENV 48 quayOrg := utils.GetEnv("QUAY_E2E_ORGANIZATION", "") 49 Expect(quayOrg).ToNot(BeEmpty()) 50 51 deployment, err := f.AsKubeAdmin.O11yController.QuayImagePushDeployment(quayOrg, o11yUserSecret, testNamespace) 52 Expect(err).NotTo(HaveOccurred()) 53 54 Expect(utils.WaitUntil(f.AsKubeAdmin.CommonController.DeploymentIsCompleted(deployment.Name, testNamespace, 1), deploymentTimeout)).To(Succeed()) 55 56 podNameRegex := "deployment-egress-.*" 57 query := fmt.Sprintf("last_over_time(container_network_transmit_bytes_total{namespace='%s', pod=~'%s'}[1h])", testNamespace, podNameRegex) 58 result, err := f.AsKubeAdmin.O11yController.GetMetrics(query) 59 Expect(err).NotTo(HaveOccurred()) 60 61 err = f.AsKubeAdmin.O11yController.WaitForScriptCompletion(deployment, egressSuccessMessage, logScriptTimeout) 62 Expect(err).NotTo(HaveOccurred()) 63 64 podNamesWithResult, err := f.AsKubeAdmin.O11yController.GetRegexPodNameWithResult(podNameRegex, result) 65 Expect(err).NotTo(HaveOccurred()) 66 67 podNameWithMB, err := f.AsKubeAdmin.O11yController.ConvertValuesToMB(podNamesWithResult) 68 Expect(err).NotTo(HaveOccurred()) 69 70 for podName, podSize := range podNameWithMB { 71 // Range limits are measured as part of STONEO11Y-15 72 Expect(podSize).To(And( 73 BeNumerically(">=", 106), 74 BeNumerically("<=", 109), 75 ), fmt.Sprintf("%s: %d MB is not within the expected range.\n", podName, podSize)) 76 } 77 }) 78 79 It("E2E test to measure vCPU minutes - Deployments", func() { 80 81 deployment, err := f.AsKubeAdmin.O11yController.VCPUMinutesDeployment(testNamespace) 82 Expect(err).NotTo(HaveOccurred()) 83 84 Expect(utils.WaitUntil(f.AsKubeAdmin.CommonController.DeploymentIsCompleted(deployment.Name, testNamespace, 1), deploymentTimeout)).To(Succeed()) 85 86 err = f.AsKubeAdmin.O11yController.WaitForScriptCompletion(deployment, vCPUSuccessMessage, logScriptTimeout) 87 Expect(err).NotTo(HaveOccurred()) 88 89 podNameRegex := "deployment-vcpu-.*" 90 query := fmt.Sprintf("{__name__=~'kube_pod_container_resource_limits', namespace='%s', resource='cpu', pod=~'%s'}", testNamespace, podNameRegex) 91 metricsResult, err := f.AsKubeAdmin.O11yController.GetMetrics(query) 92 Expect(err).NotTo(HaveOccurred()) 93 94 podNamesWithResult, err := f.AsKubeAdmin.O11yController.GetRegexPodNameWithResult(podNameRegex, metricsResult) 95 Expect(err).NotTo(HaveOccurred()) 96 97 for podName, result := range podNamesWithResult { 98 // CPU Limits of 200 millicores set within deployments 99 Expect(result).To(Equal("0.2"), fmt.Sprintf("%s: %s millicores is not within the expected range.\n", podName, result)) 100 } 101 }) 102 103 It("E2E test to measure Memory minutes - Deployments", func() { 104 // Calculate Memory minutes based on value set within vCPU deployment 105 podNameRegex := "deployment-vcpu-.*" 106 query := fmt.Sprintf("{__name__=~'kube_pod_container_resource_limits', namespace='%s', resource='memory', pod=~'%s'}", testNamespace, podNameRegex) 107 metricsResult, err := f.AsKubeAdmin.O11yController.GetMetrics(query) 108 Expect(err).NotTo(HaveOccurred()) 109 110 podNamesWithResult, err := f.AsKubeAdmin.O11yController.GetRegexPodNameWithResult(podNameRegex, metricsResult) 111 Expect(err).NotTo(HaveOccurred()) 112 113 podNameWithMB, err := f.AsKubeAdmin.O11yController.ConvertValuesToMB(podNamesWithResult) 114 Expect(err).NotTo(HaveOccurred()) 115 116 for podName, result := range podNameWithMB { 117 // Memory Limits of 200MB set within deployments 118 Expect(result).To(Equal(209), fmt.Sprintf("%s: %d MB is not within the expected range.\n", podName, result)) 119 } 120 }) 121 }) 122 })