From 486c845cd59f2236b366f7a79c315e1ee98f68c0 Mon Sep 17 00:00:00 2001 From: Christoph Kleineweber Date: Wed, 20 Dec 2023 10:17:56 +0100 Subject: [PATCH 1/2] test: Use custom workload for Istio metrics test --- Makefile | 2 +- .../istio/metrics_istio_input_test.go | 48 ++++++++++++++++--- 2 files changed, 43 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index 43d8bb2d7..a8a41f579 100644 --- a/Makefile +++ b/Makefile @@ -79,7 +79,7 @@ fmt: ## Run go fmt against code. .PHONY: vet vet: ## Run go vet against code. - go vet ./... + go vet --tags e2e,istio ./... .PHONY: tidy tidy: ## Check if there any dirty change for go mod tidy. diff --git a/test/integration/istio/metrics_istio_input_test.go b/test/integration/istio/metrics_istio_input_test.go index 34469dc44..2aca66a30 100644 --- a/test/integration/istio/metrics_istio_input_test.go +++ b/test/integration/istio/metrics_istio_input_test.go @@ -7,6 +7,7 @@ import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" + corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/types" "sigs.k8s.io/controller-runtime/pkg/client" @@ -15,7 +16,6 @@ import ( kitmetricpipeline "github.com/kyma-project/telemetry-manager/test/testkit/kyma/telemetry/metric" . "github.com/kyma-project/telemetry-manager/test/testkit/matchers/metric" "github.com/kyma-project/telemetry-manager/test/testkit/mocks/backend" - "github.com/kyma-project/telemetry-manager/test/testkit/mocks/telemetrygen" "github.com/kyma-project/telemetry-manager/test/testkit/periodic" "github.com/kyma-project/telemetry-manager/test/testkit/verifiers" ) @@ -26,6 +26,8 @@ var _ = Describe("Metrics Istio Input", Label("metrics"), func() { backendName = "backend" app1Ns = "app-1" app2Ns = "app-2" + nginxImage = "europe-docker.pkg.dev/kyma-project/prod/external/nginx:1.23.3" + curlImage = "europe-docker.pkg.dev/kyma-project/prod/external/curlimages/curl:7.78.0" ) // https://istio.io/latest/docs/reference/config/metrics/ @@ -87,9 +89,43 @@ var _ = Describe("Metrics Istio Input", Label("metrics"), func() { IstioInput(true, kitmetricpipeline.IncludeNamespaces(app1Ns)) objs = append(objs, metricPipeline.K8sObject()) - app1 := kitk8s.NewPod("app-1", app1Ns).WithPodSpec(telemetrygen.PodSpec(telemetrygen.SignalTypeMetrics)) - app2 := kitk8s.NewPod("app-2", app2Ns).WithPodSpec(telemetrygen.PodSpec(telemetrygen.SignalTypeMetrics)) - objs = append(objs, app1.K8sObject(), app2.K8sObject()) + sourceSpec := corev1.PodSpec{ + Containers: []corev1.Container{ + { + Name: "source", + Image: curlImage, + Command: []string{ + "/bin/sh", + "-c", + "while true; do curl http://destination:80; sleep 1; done", + }, + }, + }, + } + destinationSpec := corev1.PodSpec{ + Containers: []corev1.Container{ + { + Name: "destination", + Image: nginxImage, + Ports: []corev1.ContainerPort{ + { + ContainerPort: 80, + Protocol: corev1.ProtocolTCP, + }, + }, + }, + }, + } + + source1 := kitk8s.NewPod("source", app1Ns).WithPodSpec(sourceSpec) + destination1 := kitk8s.NewPod("destination", app1Ns).WithPodSpec(destinationSpec).WithLabel("app", "destination") + service1 := kitk8s.NewService("destination", app1Ns).WithPort("http", 80) + + source2 := kitk8s.NewPod("source", app2Ns).WithPodSpec(sourceSpec) + destination2 := kitk8s.NewPod("destination", app2Ns).WithPodSpec(destinationSpec).WithLabel("app", "destination") + service2 := kitk8s.NewService("destination", app2Ns).WithPort("http", 80) + + objs = append(objs, source1.K8sObject(), destination1.K8sObject(), service1.K8sObject(kitk8s.WithLabel("app", "destination")), source2.K8sObject(), destination2.K8sObject(), service2.K8sObject(kitk8s.WithLabel("app", "destination"))) return objs } @@ -142,11 +178,11 @@ var _ = Describe("Metrics Istio Input", Label("metrics"), func() { }, periodic.TelemetryEventuallyTimeout, periodic.TelemetryInterval).Should(Succeed()) }) - It("Should deliver metrics from app1Ns", func() { + It("Should deliver metrics from app-1 namespace", func() { verifiers.MetricsFromNamespaceShouldBeDelivered(proxyClient, telemetryExportURL, app1Ns, istioProxyMetricNames) }) - It("Should not deliver metrics from app2Ns", func() { + It("Should not deliver metrics from app-2 namespace", func() { verifiers.MetricsFromNamespaceShouldNotBeDelivered(proxyClient, telemetryExportURL, app2Ns) }) }) From 69228a309cd771a5f54821c8963e1b4af7442a43 Mon Sep 17 00:00:00 2001 From: Christoph Kleineweber Date: Wed, 20 Dec 2023 13:20:48 +0100 Subject: [PATCH 2/2] Small refactorings --- .../istio/metrics_istio_input_test.go | 49 ++++++++++--------- 1 file changed, 27 insertions(+), 22 deletions(-) diff --git a/test/integration/istio/metrics_istio_input_test.go b/test/integration/istio/metrics_istio_input_test.go index 2aca66a30..7df469afa 100644 --- a/test/integration/istio/metrics_istio_input_test.go +++ b/test/integration/istio/metrics_istio_input_test.go @@ -73,23 +73,8 @@ var _ = Describe("Metrics Istio Input", Label("metrics"), func() { telemetryExportURL string ) - makeResources := func() []client.Object { - var objs []client.Object - objs = append(objs, kitk8s.NewNamespace(backendNs).K8sObject(), - kitk8s.NewNamespace(app1Ns, kitk8s.WithIstioInjection()).K8sObject(), - kitk8s.NewNamespace(app2Ns, kitk8s.WithIstioInjection()).K8sObject()) - - mockBackend := backend.New(backendName, backendNs, backend.SignalTypeMetrics) - objs = append(objs, mockBackend.K8sObjects()...) - telemetryExportURL = mockBackend.TelemetryExportURL(proxyClient) - - metricPipeline := kitmetricpipeline.NewPipeline("pipeline-with-istio-input-enabled"). - WithOutputEndpointFromSecret(mockBackend.HostSecretRef()). - OtlpInput(false). - IstioInput(true, kitmetricpipeline.IncludeNamespaces(app1Ns)) - objs = append(objs, metricPipeline.K8sObject()) - - sourceSpec := corev1.PodSpec{ + sourcePodSpec := func() corev1.PodSpec { + return corev1.PodSpec{ Containers: []corev1.Container{ { Name: "source", @@ -102,7 +87,10 @@ var _ = Describe("Metrics Istio Input", Label("metrics"), func() { }, }, } - destinationSpec := corev1.PodSpec{ + } + + destinationPodSpec := func() corev1.PodSpec { + return corev1.PodSpec{ Containers: []corev1.Container{ { Name: "destination", @@ -116,13 +104,30 @@ var _ = Describe("Metrics Istio Input", Label("metrics"), func() { }, }, } + } + + makeResources := func() []client.Object { + var objs []client.Object + objs = append(objs, kitk8s.NewNamespace(backendNs).K8sObject(), + kitk8s.NewNamespace(app1Ns, kitk8s.WithIstioInjection()).K8sObject(), + kitk8s.NewNamespace(app2Ns, kitk8s.WithIstioInjection()).K8sObject()) + + mockBackend := backend.New(backendName, backendNs, backend.SignalTypeMetrics) + objs = append(objs, mockBackend.K8sObjects()...) + telemetryExportURL = mockBackend.TelemetryExportURL(proxyClient) + + metricPipeline := kitmetricpipeline.NewPipeline("pipeline-with-istio-input-enabled"). + WithOutputEndpointFromSecret(mockBackend.HostSecretRef()). + OtlpInput(false). + IstioInput(true, kitmetricpipeline.IncludeNamespaces(app1Ns)) + objs = append(objs, metricPipeline.K8sObject()) - source1 := kitk8s.NewPod("source", app1Ns).WithPodSpec(sourceSpec) - destination1 := kitk8s.NewPod("destination", app1Ns).WithPodSpec(destinationSpec).WithLabel("app", "destination") + source1 := kitk8s.NewPod("source", app1Ns).WithPodSpec(sourcePodSpec()) + destination1 := kitk8s.NewPod("destination", app1Ns).WithPodSpec(destinationPodSpec()).WithLabel("app", "destination") service1 := kitk8s.NewService("destination", app1Ns).WithPort("http", 80) - source2 := kitk8s.NewPod("source", app2Ns).WithPodSpec(sourceSpec) - destination2 := kitk8s.NewPod("destination", app2Ns).WithPodSpec(destinationSpec).WithLabel("app", "destination") + source2 := kitk8s.NewPod("source", app2Ns).WithPodSpec(sourcePodSpec()) + destination2 := kitk8s.NewPod("destination", app2Ns).WithPodSpec(destinationPodSpec()).WithLabel("app", "destination") service2 := kitk8s.NewService("destination", app2Ns).WithPort("http", 80) objs = append(objs, source1.K8sObject(), destination1.K8sObject(), service1.K8sObject(kitk8s.WithLabel("app", "destination")), source2.K8sObject(), destination2.K8sObject(), service2.K8sObject(kitk8s.WithLabel("app", "destination")))