diff --git a/.github/workflows/pr-integration.yml b/.github/workflows/pr-integration.yml index e27382b45..b59d23d3a 100644 --- a/.github/workflows/pr-integration.yml +++ b/.github/workflows/pr-integration.yml @@ -27,7 +27,7 @@ jobs: github-token: ${{ secrets.GITHUB_TOKEN }} - name: Run tests - run: bin/ginkgo run --tags e2e --label-filter="metrics" test/e2e + run: bin/ginkgo run --tags e2e --label-filter="metrics && !v1beta1" test/e2e - name: Finalize test uses: "./.github/template/finalize-test" @@ -68,7 +68,7 @@ jobs: github-token: ${{ secrets.GITHUB_TOKEN }} - name: Run tests - run: bin/ginkgo run --tags e2e --label-filter="traces" test/e2e + run: bin/ginkgo run --tags e2e --label-filter="traces && !v1beta1" test/e2e - name: Finalize Test uses: "./.github/template/finalize-test" @@ -109,7 +109,7 @@ jobs: github-token: ${{ secrets.GITHUB_TOKEN }} - name: Run tests - run: bin/ginkgo run --tags e2e --label-filter="logs" test/e2e + run: bin/ginkgo run --tags e2e --label-filter="logs && !v1beta1" test/e2e - name: Finalize Test uses: "./.github/template/finalize-test" @@ -150,7 +150,7 @@ jobs: github-token: ${{ secrets.GITHUB_TOKEN }} - name: Run tests - run: bin/ginkgo run --tags e2e --label-filter="telemetry" test/e2e + run: bin/ginkgo run --tags e2e --label-filter="telemetry && !v1beta1" test/e2e - name: Finalize Test uses: "./.github/template/finalize-test" diff --git a/.golangci.yaml b/.golangci.yaml index d52a35b5f..8822b4ae6 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -52,6 +52,8 @@ linters-settings: alias: operatorv1alpha1 - pkg: github.com/kyma-project/telemetry-manager/apis/telemetry/v1alpha1 alias: telemetryv1alpha1 + - pkg: github.com/kyma-project/telemetry-manager/apis/telemetry/v1beta1 + alias: telemetryv1beta1 - pkg: github.com/kyma-project/telemetry-manager/controllers/telemetry alias: telemetrycontrollers - pkg: github.com/kyma-project/telemetry-manager/internal/otelcollector/config/metric/agent diff --git a/test/e2e/logs_annotation_test.go b/test/e2e/logs_annotation_test.go index 1082206a3..2039418fe 100644 --- a/test/e2e/logs_annotation_test.go +++ b/test/e2e/logs_annotation_test.go @@ -38,8 +38,8 @@ var _ = Describe("Logs Keep Annotations", Label("logs"), Ordered, func() { objs = append(objs, mockLogProducer.K8sObject(kitk8s.WithLabel("app", "logging-annotation-test"))) telemetryExportURL = mockBackend.TelemetryExportURL(proxyClient) - logPipeline := kitk8s.NewLogPipeline(pipelineName). - WithSecretKeyRef(mockBackend.HostSecretRef()). + logPipeline := kitk8s.NewLogPipelineV1Alpha1(pipelineName). + WithSecretKeyRef(mockBackend.HostSecretRefV1Alpha1()). WithHTTPOutput(). KeepAnnotations(true). DropLabels(true) diff --git a/test/e2e/logs_basic_test.go b/test/e2e/logs_basic_v1alpha1_test.go similarity index 93% rename from test/e2e/logs_basic_test.go rename to test/e2e/logs_basic_v1alpha1_test.go index 8cbae82e0..b6bb866a4 100644 --- a/test/e2e/logs_basic_test.go +++ b/test/e2e/logs_basic_v1alpha1_test.go @@ -14,7 +14,7 @@ import ( "github.com/kyma-project/telemetry-manager/test/testkit/verifiers" ) -var _ = Describe("Logs Basic", Label("logs"), Ordered, func() { +var _ = Describe("Logs Basic v1alpha1", Label("logs"), Ordered, func() { const ( mockBackendName = "log-receiver" mockNs = "log-http-output" @@ -33,8 +33,8 @@ var _ = Describe("Logs Basic", Label("logs"), Ordered, func() { objs = append(objs, mockLogProducer.K8sObject(kitk8s.WithLabel("app", "logging-test"))) telemetryExportURL = mockBackend.TelemetryExportURL(proxyClient) - logPipeline := kitk8s.NewLogPipeline(pipelineName). - WithSecretKeyRef(mockBackend.HostSecretRef()). + logPipeline := kitk8s.NewLogPipelineV1Alpha1(pipelineName). + WithSecretKeyRef(mockBackend.HostSecretRefV1Alpha1()). WithHTTPOutput(). Persistent(isOperational()) objs = append(objs, logPipeline.K8sObject()) diff --git a/test/e2e/logs_basic_v1beta1_test.go b/test/e2e/logs_basic_v1beta1_test.go new file mode 100644 index 000000000..becf52f6a --- /dev/null +++ b/test/e2e/logs_basic_v1beta1_test.go @@ -0,0 +1,75 @@ +//go:build e2e + +package e2e + +import ( + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" + "k8s.io/apimachinery/pkg/types" + "sigs.k8s.io/controller-runtime/pkg/client" + + kitk8s "github.com/kyma-project/telemetry-manager/test/testkit/k8s" + "github.com/kyma-project/telemetry-manager/test/testkit/mocks/backend" + "github.com/kyma-project/telemetry-manager/test/testkit/mocks/loggen" + "github.com/kyma-project/telemetry-manager/test/testkit/verifiers" +) + +var _ = Describe("Logs Basic v1beta1", Label("logs", "v1beta1"), Ordered, func() { + const ( + mockBackendName = "log-receiver" + mockNs = "logs-basic-v1beta1-test" + logProducerName = "log-producer-http-output" //#nosec G101 -- This is a false positive + pipelineName = "http-output-pipeline" + ) + var telemetryExportURL string + + makeResources := func() []client.Object { + var objs []client.Object + objs = append(objs, kitk8s.NewNamespace(mockNs).K8sObject()) + + mockBackend := backend.New(mockBackendName, mockNs, backend.SignalTypeLogs) + mockLogProducer := loggen.New(logProducerName, mockNs) + objs = append(objs, mockBackend.K8sObjects()...) + objs = append(objs, mockLogProducer.K8sObject(kitk8s.WithLabel("app", "logging-test"))) + telemetryExportURL = mockBackend.TelemetryExportURL(proxyClient) + + logPipeline := kitk8s.NewLogPipelineV1Beta1(pipelineName). + WithSecretKeyRef(mockBackend.HostSecretRefV1Beta1()). + WithHTTPOutput() + objs = append(objs, logPipeline.K8sObject()) + + return objs + } + + Context("Before deploying a logpipeline", func() { + It("Should have a healthy webhook", func() { + verifiers.WebhookShouldBeHealthy(ctx, k8sClient) + }) + }) + + Context("When a logpipeline with HTTP output exists", Ordered, func() { + BeforeAll(func() { + k8sObjects := makeResources() + DeferCleanup(func() { + Expect(kitk8s.DeleteObjects(ctx, k8sClient, k8sObjects...)).Should(Succeed()) + }) + Expect(kitk8s.CreateObjects(ctx, k8sClient, k8sObjects...)).Should(Succeed()) + }) + + It("Should have a running logpipeline", func() { + verifiers.LogPipelineShouldBeHealthy(ctx, k8sClient, pipelineName) + }) + + It("Should have a log backend running", func() { + verifiers.DeploymentShouldBeReady(ctx, k8sClient, types.NamespacedName{Namespace: mockNs, Name: mockBackendName}) + }) + + It("Should have a log producer running", func() { + verifiers.DeploymentShouldBeReady(ctx, k8sClient, types.NamespacedName{Namespace: mockNs, Name: logProducerName}) + }) + + It("Should have produced logs in the backend", func() { + verifiers.LogsShouldBeDelivered(proxyClient, logProducerName, telemetryExportURL) + }) + }) +}) diff --git a/test/e2e/logs_custom_output_test.go b/test/e2e/logs_custom_output_test.go index 9c7401595..1581b6a2f 100644 --- a/test/e2e/logs_custom_output_test.go +++ b/test/e2e/logs_custom_output_test.go @@ -33,7 +33,7 @@ var _ = Describe("Logs Custom Output", Label("logs"), Ordered, func() { objs = append(objs, mockLogProducer.K8sObject(kitk8s.WithLabel("app", "logging-test"))) telemetryExportURL = mockBackend.TelemetryExportURL(proxyClient) - logPipeline := kitk8s.NewLogPipeline(pipelineName).WithCustomOutput(mockBackend.ExternalService.Host()) + logPipeline := kitk8s.NewLogPipelineV1Alpha1(pipelineName).WithCustomOutput(mockBackend.ExternalService.Host()) objs = append(objs, logPipeline.K8sObject()) return objs diff --git a/test/e2e/logs_dedot_test.go b/test/e2e/logs_dedot_test.go index aa3e2d2c1..218d0058b 100644 --- a/test/e2e/logs_dedot_test.go +++ b/test/e2e/logs_dedot_test.go @@ -37,8 +37,8 @@ var _ = Describe("Logs Dedot", Label("logs"), Ordered, func() { objs = append(objs, mockLogProducer.K8sObject(kitk8s.WithLabel("dedot.label", "logging-dedot-value"))) telemetryExportURL = mockBackend.TelemetryExportURL(proxyClient) - logPipeline := kitk8s.NewLogPipeline(pipelineName). - WithSecretKeyRef(mockBackend.HostSecretRef()). + logPipeline := kitk8s.NewLogPipelineV1Alpha1(pipelineName). + WithSecretKeyRef(mockBackend.HostSecretRefV1Alpha1()). WithHTTPOutput(). WithIncludeContainers([]string{logProducerName}) objs = append(objs, logPipeline.K8sObject()) diff --git a/test/e2e/logs_exclude_container_test.go b/test/e2e/logs_exclude_container_test.go index 8d6c44834..2cef27e1b 100644 --- a/test/e2e/logs_exclude_container_test.go +++ b/test/e2e/logs_exclude_container_test.go @@ -37,8 +37,8 @@ var _ = Describe("Logs Exclude Container", Label("logs"), Ordered, func() { objs = append(objs, mockLogProducer.K8sObject(kitk8s.WithLabel("app", "logging-exclude-container"))) telemetryExportURL = mockBackend.TelemetryExportURL(proxyClient) - logPipeline := kitk8s.NewLogPipeline(pipelineName). - WithSecretKeyRef(mockBackend.HostSecretRef()). + logPipeline := kitk8s.NewLogPipelineV1Alpha1(pipelineName). + WithSecretKeyRef(mockBackend.HostSecretRefV1Alpha1()). WithHTTPOutput(). WithExcludeContainers([]string{logProducerName}) objs = append(objs, logPipeline.K8sObject()) diff --git a/test/e2e/logs_exclude_namespaces_test.go b/test/e2e/logs_exclude_namespaces_test.go index 987390d63..49a0c27ef 100644 --- a/test/e2e/logs_exclude_namespaces_test.go +++ b/test/e2e/logs_exclude_namespaces_test.go @@ -38,8 +38,8 @@ var _ = Describe("Logs Exclude Namespace", Label("logs"), Ordered, func() { objs = append(objs, mockLogProducer.K8sObject(kitk8s.WithLabel("app", "logging-exclude-namespace"))) telemetryExportURL = mockBackend.TelemetryExportURL(proxyClient) - logPipeline := kitk8s.NewLogPipeline(pipelineName). - WithSecretKeyRef(mockBackend.HostSecretRef()). + logPipeline := kitk8s.NewLogPipelineV1Alpha1(pipelineName). + WithSecretKeyRef(mockBackend.HostSecretRefV1Alpha1()). WithHTTPOutput(). WithExcludeNamespaces([]string{kitkyma.SystemNamespaceName}) objs = append(objs, logPipeline.K8sObject()) diff --git a/test/e2e/logs_include_namespaces_test.go b/test/e2e/logs_include_namespaces_test.go index 1c53ed446..c8ea95514 100644 --- a/test/e2e/logs_include_namespaces_test.go +++ b/test/e2e/logs_include_namespaces_test.go @@ -38,8 +38,8 @@ var _ = Describe("Logs Include Namespaces", Label("logs"), Ordered, func() { objs = append(objs, mockLogProducer.K8sObject(kitk8s.WithLabel("app", "logging-include-namespaces"))) telemetryExportURL = mockBackend.TelemetryExportURL(proxyClient) - logPipeline := kitk8s.NewLogPipeline(pipelineName). - WithSecretKeyRef(mockBackend.HostSecretRef()). + logPipeline := kitk8s.NewLogPipelineV1Alpha1(pipelineName). + WithSecretKeyRef(mockBackend.HostSecretRefV1Alpha1()). WithHTTPOutput(). WithIncludeNamespaces([]string{kitkyma.SystemNamespaceName, mockNs}) objs = append(objs, logPipeline.K8sObject()) diff --git a/test/e2e/logs_label_test.go b/test/e2e/logs_label_test.go index 04159331e..5d68fb61f 100644 --- a/test/e2e/logs_label_test.go +++ b/test/e2e/logs_label_test.go @@ -38,8 +38,8 @@ var _ = Describe("Logs Drop Labels", Label("logs"), Ordered, func() { objs = append(objs, mockLogProducer.K8sObject(kitk8s.WithLabel("app", "logging-label-test"))) telemetryExportURL = mockBackend.TelemetryExportURL(proxyClient) - logPipeline := kitk8s.NewLogPipeline(pipelineName). - WithSecretKeyRef(mockBackend.HostSecretRef()). + logPipeline := kitk8s.NewLogPipelineV1Alpha1(pipelineName). + WithSecretKeyRef(mockBackend.HostSecretRefV1Alpha1()). WithHTTPOutput(). KeepAnnotations(false). DropLabels(false) diff --git a/test/e2e/logs_mtls_test.go b/test/e2e/logs_mtls_test.go index da6813d43..4847a6237 100644 --- a/test/e2e/logs_mtls_test.go +++ b/test/e2e/logs_mtls_test.go @@ -33,8 +33,8 @@ var _ = Describe("Logs mTLS", Label("logs"), Ordered, func() { objs = append(objs, mockLogProducer.K8sObject(kitk8s.WithLabel("app", "logging-mtls-test"))) telemetryExportURL = mockBackend.TelemetryExportURL(proxyClient) - pipeline := kitk8s.NewLogPipeline(pipelineName). - WithSecretKeyRef(mockBackend.HostSecretRef()). + pipeline := kitk8s.NewLogPipelineV1Alpha1(pipelineName). + WithSecretKeyRef(mockBackend.HostSecretRefV1Alpha1()). WithHTTPOutput(). WithTLS(mockBackend.TLSCerts) diff --git a/test/e2e/logs_parser_test.go b/test/e2e/logs_parser_test.go index 0f258cf85..b6d5cdca2 100644 --- a/test/e2e/logs_parser_test.go +++ b/test/e2e/logs_parser_test.go @@ -39,8 +39,8 @@ var _ = Describe("Logs Parser", Label("logs"), Ordered, func() { objs = append(objs, mockLogProducer.K8sObject(kitk8s.WithLabel("app", "regex-parser-testing-service"))) telemetryExportURL = mockBackend.TelemetryExportURL(proxyClient) - logHTTPPipeline := kitk8s.NewLogPipeline(pipelineName). - WithSecretKeyRef(mockBackend.HostSecretRef()). + logHTTPPipeline := kitk8s.NewLogPipelineV1Alpha1(pipelineName). + WithSecretKeyRef(mockBackend.HostSecretRefV1Alpha1()). WithHTTPOutput() parser := `Format regex diff --git a/test/e2e/logs_webhook_test.go b/test/e2e/logs_webhook_test.go index 258d91c6d..fe187db36 100644 --- a/test/e2e/logs_webhook_test.go +++ b/test/e2e/logs_webhook_test.go @@ -30,12 +30,12 @@ var _ = Describe("Logs Validating Webhook", Label("logs"), Ordered, func() { }) It("Should reject a logpipeline with unknown custom filter", func() { - logPipeline := kitk8s.NewLogPipeline("unknown-custom-filter-pipeline").WithStdout().WithFilter("Name unknown") + logPipeline := kitk8s.NewLogPipelineV1Alpha1("unknown-custom-filter-pipeline").WithStdout().WithFilter("Name unknown") Expect(kitk8s.CreateObjects(ctx, k8sClient, logPipeline.K8sObject())).ShouldNot(Succeed()) }) It("Should reject a logpipeline with denied custom filter", func() { - logPipeline := kitk8s.NewLogPipeline("denied-custom-filter-pipeline").WithStdout().WithFilter("Name kubernetes") + logPipeline := kitk8s.NewLogPipelineV1Alpha1("denied-custom-filter-pipeline").WithStdout().WithFilter("Name kubernetes") Expect(kitk8s.CreateObjects(ctx, k8sClient, logPipeline.K8sObject())).ShouldNot(Succeed()) }) diff --git a/test/e2e/metrics_basic_test.go b/test/e2e/metrics_basic_v1alpha1_test.go similarity index 96% rename from test/e2e/metrics_basic_test.go rename to test/e2e/metrics_basic_v1alpha1_test.go index e5cb9ef34..bf045c7bf 100644 --- a/test/e2e/metrics_basic_test.go +++ b/test/e2e/metrics_basic_v1alpha1_test.go @@ -24,7 +24,7 @@ import ( "github.com/kyma-project/telemetry-manager/test/testkit/verifiers" ) -var _ = Describe("Metrics Basic", Label("metrics"), func() { +var _ = Describe("Metrics Basic v1alpha1", Label("metrics"), func() { const ( mockBackendName = "metric-receiver" mockNs = "metric-mocks" @@ -44,8 +44,8 @@ var _ = Describe("Metrics Basic", Label("metrics"), func() { objs = append(objs, mockBackend.K8sObjects()...) telemetryExportURL = mockBackend.TelemetryExportURL(proxyClient) - metricPipeline := kitk8s.NewMetricPipeline(fmt.Sprintf("%s-pipeline", mockBackend.Name())). - WithOutputEndpointFromSecret(mockBackend.HostSecretRef()). + metricPipeline := kitk8s.NewMetricPipelineV1Alpha1(fmt.Sprintf("%s-pipeline", mockBackend.Name())). + WithOutputEndpointFromSecret(mockBackend.HostSecretRefV1Alpha1()). Persistent(isOperational()) pipelineName = metricPipeline.Name() objs = append(objs, metricPipeline.K8sObject()) diff --git a/test/e2e/metrics_basic_v1beta1_test.go b/test/e2e/metrics_basic_v1beta1_test.go new file mode 100644 index 000000000..8b1626133 --- /dev/null +++ b/test/e2e/metrics_basic_v1beta1_test.go @@ -0,0 +1,187 @@ +//go:build e2e + +package e2e + +import ( + "fmt" + "net/http" + + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" + appsv1 "k8s.io/api/apps/v1" + corev1 "k8s.io/api/core/v1" + networkingv1 "k8s.io/api/networking/v1" + "k8s.io/apimachinery/pkg/types" + "sigs.k8s.io/controller-runtime/pkg/client" + + operatorv1alpha1 "github.com/kyma-project/telemetry-manager/apis/operator/v1alpha1" + "github.com/kyma-project/telemetry-manager/internal/otelcollector/ports" + kitk8s "github.com/kyma-project/telemetry-manager/test/testkit/k8s" + kitkyma "github.com/kyma-project/telemetry-manager/test/testkit/kyma" + "github.com/kyma-project/telemetry-manager/test/testkit/mocks/backend" + kitmetrics "github.com/kyma-project/telemetry-manager/test/testkit/otel/metrics" + "github.com/kyma-project/telemetry-manager/test/testkit/periodic" + "github.com/kyma-project/telemetry-manager/test/testkit/verifiers" +) + +var _ = Describe("Metrics Basic v1beta1", Label("metrics", "v1beta1"), func() { + const ( + mockBackendName = "metrics-receiver" + mockNs = "metrics-basic-v1beta1-test" + ) + + var ( + pipelineName string + telemetryExportURL string + ) + + makeResources := func() []client.Object { + var objs []client.Object + + objs = append(objs, kitk8s.NewNamespace(mockNs).K8sObject()) + + mockBackend := backend.New(mockBackendName, mockNs, backend.SignalTypeMetrics) + objs = append(objs, mockBackend.K8sObjects()...) + telemetryExportURL = mockBackend.TelemetryExportURL(proxyClient) + + metricPipeline := kitk8s.NewMetricPipelineV1Beta1(fmt.Sprintf("%s-pipeline", mockBackend.Name())). + WithOutputEndpointFromSecret(mockBackend.HostSecretRefV1Beta1()) + + pipelineName = metricPipeline.Name() + objs = append(objs, metricPipeline.K8sObject()) + + return objs + } + + Context("When a metricpipeline exists", Ordered, func() { + BeforeAll(func() { + k8sObjects := makeResources() + DeferCleanup(func() { + Expect(kitk8s.DeleteObjects(ctx, k8sClient, k8sObjects...)).Should(Succeed()) + }) + Expect(kitk8s.CreateObjects(ctx, k8sClient, k8sObjects...)).Should(Succeed()) + }) + + It("Should have a running metric gateway deployment", func() { + verifiers.DeploymentShouldBeReady(ctx, k8sClient, kitkyma.MetricGatewayName) + }) + + It("Should reject scaling below minimum", func() { + var telemetry operatorv1alpha1.Telemetry + err := k8sClient.Get(ctx, kitkyma.TelemetryName, &telemetry) + Expect(err).NotTo(HaveOccurred()) + + telemetry.Spec.Metric = &operatorv1alpha1.MetricSpec{ + Gateway: operatorv1alpha1.MetricGatewaySpec{ + Scaling: operatorv1alpha1.Scaling{ + Type: operatorv1alpha1.StaticScalingStrategyType, + Static: &operatorv1alpha1.StaticScaling{ + Replicas: -1, + }, + }, + }, + } + err = k8sClient.Update(ctx, &telemetry) + Expect(err).To(HaveOccurred()) + }) + + It("Should scale up metric gateway replicas", func() { + Eventually(func(g Gomega) int32 { + var telemetry operatorv1alpha1.Telemetry + err := k8sClient.Get(ctx, kitkyma.TelemetryName, &telemetry) + g.Expect(err).NotTo(HaveOccurred()) + + telemetry.Spec.Metric = &operatorv1alpha1.MetricSpec{ + Gateway: operatorv1alpha1.MetricGatewaySpec{ + Scaling: operatorv1alpha1.Scaling{ + Type: operatorv1alpha1.StaticScalingStrategyType, + Static: &operatorv1alpha1.StaticScaling{ + Replicas: 4, + }, + }, + }, + } + err = k8sClient.Update(ctx, &telemetry) + g.Expect(err).NotTo(HaveOccurred()) + return telemetry.Spec.Metric.Gateway.Scaling.Static.Replicas + }, periodic.EventuallyTimeout, periodic.DefaultInterval).Should(Equal(int32(4))) + }) + + It("Should have 4 metric gateway replicas after scaling up", func() { + Eventually(func(g Gomega) int32 { + var deployment appsv1.Deployment + err := k8sClient.Get(ctx, kitkyma.MetricGatewayName, &deployment) + g.Expect(err).NotTo(HaveOccurred()) + return *deployment.Spec.Replicas + }, periodic.EventuallyTimeout, periodic.DefaultInterval).Should(Equal(int32(4))) + }) + + It("Should scale down metric gateway replicas", func() { + Eventually(func(g Gomega) int32 { + var telemetry operatorv1alpha1.Telemetry + err := k8sClient.Get(ctx, kitkyma.TelemetryName, &telemetry) + g.Expect(err).NotTo(HaveOccurred()) + + telemetry.Spec.Metric = &operatorv1alpha1.MetricSpec{ + Gateway: operatorv1alpha1.MetricGatewaySpec{ + Scaling: operatorv1alpha1.Scaling{ + Type: operatorv1alpha1.StaticScalingStrategyType, + Static: &operatorv1alpha1.StaticScaling{ + Replicas: 2, + }, + }, + }, + } + err = k8sClient.Update(ctx, &telemetry) + g.Expect(err).NotTo(HaveOccurred()) + return telemetry.Spec.Metric.Gateway.Scaling.Static.Replicas + }, periodic.EventuallyTimeout, periodic.DefaultInterval).Should(Equal(int32(2))) + }) + + It("Should have 2 metric gateway replicas after scaling down", func() { + Eventually(func(g Gomega) int32 { + var deployment appsv1.Deployment + err := k8sClient.Get(ctx, kitkyma.MetricGatewayName, &deployment) + g.Expect(err).NotTo(HaveOccurred()) + return *deployment.Spec.Replicas + }, periodic.EventuallyTimeout, periodic.DefaultInterval).Should(Equal(int32(2))) + }) + + It("Should have a metrics backend running", func() { + verifiers.DeploymentShouldBeReady(ctx, k8sClient, types.NamespacedName{Name: mockBackendName, Namespace: mockNs}) + }) + + It("Should have a running pipeline", func() { + verifiers.MetricPipelineShouldBeHealthy(ctx, k8sClient, pipelineName) + }) + + It("Should verify end-to-end metric delivery", func() { + gatewayPushURL := proxyClient.ProxyURLForService(kitkyma.SystemNamespaceName, "telemetry-otlp-metrics", "v1/metrics/", ports.OTLPHTTP) + gauges := kitmetrics.MakeAndSendGaugeMetrics(proxyClient, gatewayPushURL) + verifiers.MetricsShouldBeDelivered(proxyClient, telemetryExportURL, gauges) + }) + + It("Should be able to get metric gateway metrics endpoint", func() { + gatewayMetricsURL := proxyClient.ProxyURLForService(kitkyma.MetricGatewayMetrics.Namespace, kitkyma.MetricGatewayMetrics.Name, "metrics", ports.Metrics) + verifiers.ShouldExposeCollectorMetrics(proxyClient, gatewayMetricsURL) + }) + + It("Should have a working network policy", func() { + var networkPolicy networkingv1.NetworkPolicy + Expect(k8sClient.Get(ctx, kitkyma.MetricGatewayNetworkPolicy, &networkPolicy)).To(Succeed()) + + Eventually(func(g Gomega) { + var podList corev1.PodList + g.Expect(k8sClient.List(ctx, &podList, client.InNamespace(kitkyma.SystemNamespaceName), client.MatchingLabels{"app.kubernetes.io/name": kitkyma.MetricGatewayBaseName})).To(Succeed()) + g.Expect(podList.Items).NotTo(BeEmpty()) + + metricGatewayPodName := podList.Items[0].Name + pprofEndpoint := proxyClient.ProxyURLForPod(kitkyma.SystemNamespaceName, metricGatewayPodName, "debug/pprof/", ports.Pprof) + + resp, err := proxyClient.Get(pprofEndpoint) + g.Expect(err).NotTo(HaveOccurred()) + g.Expect(resp).To(HaveHTTPStatus(http.StatusServiceUnavailable)) + }, periodic.EventuallyTimeout, periodic.DefaultInterval).Should(Succeed()) + }) + }) +}) diff --git a/test/e2e/metrics_endpoint_path_validation_test.go b/test/e2e/metrics_endpoint_path_validation_test.go index 78f02b47c..13ab0de38 100644 --- a/test/e2e/metrics_endpoint_path_validation_test.go +++ b/test/e2e/metrics_endpoint_path_validation_test.go @@ -11,26 +11,26 @@ import ( var _ = Describe("Metrics Validating Endpoint Path", Label("metrics"), Ordered, func() { - metricPipelineDefaultGRPCWithPath := kitk8s.NewMetricPipeline("metricpipeline-default-reject-with-path"). + metricPipelineDefaultGRPCWithPath := kitk8s.NewMetricPipelineV1Alpha1("metricpipeline-default-reject-with-path"). WithOutputEndpoint("mock-endpoint:4817").WithEndpointPath("/v1/mock/metrics"). Persistent(isOperational()).K8sObject() - metricPipelineWithGRPCAndPath := kitk8s.NewMetricPipeline("metricpipeline-reject-with-grpc-and-path"). + metricPipelineWithGRPCAndPath := kitk8s.NewMetricPipelineV1Alpha1("metricpipeline-reject-with-grpc-and-path"). WithOutputEndpoint("mock-endpoint:4817").WithEndpointPath("/v1/mock/metrics"). WithProtocol("grpc"). Persistent(isOperational()).K8sObject() - metricPipelineWithGRPCAndWithoutPath := kitk8s.NewMetricPipeline("metricpipeline-accept-with-grpc-and-no-path"). + metricPipelineWithGRPCAndWithoutPath := kitk8s.NewMetricPipelineV1Alpha1("metricpipeline-accept-with-grpc-and-no-path"). WithOutputEndpoint("mock-endpoint:4817"). WithProtocol("grpc"). Persistent(isOperational()).K8sObject() - metricPipelineWithHTTPAndPath := kitk8s.NewMetricPipeline("metricpipeline-accept-with-http-and-path"). + metricPipelineWithHTTPAndPath := kitk8s.NewMetricPipelineV1Alpha1("metricpipeline-accept-with-http-and-path"). WithOutputEndpoint("mock-endpoint:4817").WithEndpointPath("/v1/mock/metrics"). WithProtocol("http"). Persistent(isOperational()).K8sObject() - metricPipelineWithHTTPAndWithoutPath := kitk8s.NewMetricPipeline("metricpipeline-accept-with-http-and-no-path"). + metricPipelineWithHTTPAndWithoutPath := kitk8s.NewMetricPipelineV1Alpha1("metricpipeline-accept-with-http-and-no-path"). WithOutputEndpoint("mock-endpoint:4817"). WithProtocol("http"). Persistent(isOperational()).K8sObject() diff --git a/test/e2e/metrics_endpoint_with_path_test.go b/test/e2e/metrics_endpoint_with_path_test.go index 94cabf11b..dc2ff3fd3 100644 --- a/test/e2e/metrics_endpoint_with_path_test.go +++ b/test/e2e/metrics_endpoint_with_path_test.go @@ -25,7 +25,7 @@ var _ = Describe("Metrics Endpoint with Path", Label("metrics"), func() { makeResources := func() []client.Object { var objs []client.Object - metricPipeline := kitk8s.NewMetricPipeline("mock-metric-endpoint-path"). + metricPipeline := kitk8s.NewMetricPipelineV1Alpha1("mock-metric-endpoint-path"). WithProtocol("http"). WithOutputEndpoint(endpoint).WithEndpointPath(path) diff --git a/test/e2e/metrics_mtls_test.go b/test/e2e/metrics_mtls_test.go index fc4eac691..e8aa4f8a0 100644 --- a/test/e2e/metrics_mtls_test.go +++ b/test/e2e/metrics_mtls_test.go @@ -37,8 +37,8 @@ var _ = Describe("Metrics mTLS", Label("metrics"), func() { objs = append(objs, mockBackend.K8sObjects()...) urls.SetMockBackendExport(mockBackend.Name(), mockBackend.TelemetryExportURL(proxyClient)) - metricPipeline := kitk8s.NewMetricPipeline(fmt.Sprintf("%s-%s", mockBackend.Name(), "pipeline")). - WithOutputEndpointFromSecret(mockBackend.HostSecretRef()). + metricPipeline := kitk8s.NewMetricPipelineV1Alpha1(fmt.Sprintf("%s-%s", mockBackend.Name(), "pipeline")). + WithOutputEndpointFromSecret(mockBackend.HostSecretRefV1Alpha1()). WithTLS(mockBackend.TLSCerts) pipelineName = metricPipeline.Name() diff --git a/test/e2e/metrics_multi_pipeline_test.go b/test/e2e/metrics_multi_pipeline_test.go index d74067435..74b6ef55f 100644 --- a/test/e2e/metrics_multi_pipeline_test.go +++ b/test/e2e/metrics_multi_pipeline_test.go @@ -48,7 +48,7 @@ var _ = Describe("Metrics Multi-Pipeline", Label("metrics"), func() { mockNs, mockBackend.Name(), backend.TelemetryDataFilename, backend.HTTPWebPort), ) - metricPipeline := kitk8s.NewMetricPipeline(fmt.Sprintf("%s-%s", mockBackend.Name(), "pipeline")).WithOutputEndpointFromSecret(mockBackend.HostSecretRef()) + metricPipeline := kitk8s.NewMetricPipelineV1Alpha1(fmt.Sprintf("%s-%s", mockBackend.Name(), "pipeline")).WithOutputEndpointFromSecret(mockBackend.HostSecretRefV1Alpha1()) pipelines.Append(metricPipeline.Name()) objs = append(objs, metricPipeline.K8sObject()) } @@ -101,7 +101,7 @@ var _ = Describe("Metrics Multi-Pipeline", Label("metrics"), func() { makeResources := func() []client.Object { var objs []client.Object for i := 0; i < maxNumberOfMetricPipelines; i++ { - pipeline := kitk8s.NewMetricPipeline(fmt.Sprintf("pipeline-%d", i)) + pipeline := kitk8s.NewMetricPipelineV1Alpha1(fmt.Sprintf("pipeline-%d", i)) pipelines.Append(pipeline.Name()) objs = append(objs, pipeline.K8sObject()) @@ -134,7 +134,7 @@ var _ = Describe("Metrics Multi-Pipeline", Label("metrics"), func() { It("Should set ConfigurationGenerated condition to false", func() { By("Creating an additional pipeline", func() { - pipeline := kitk8s.NewMetricPipeline("exceeding-pipeline") + pipeline := kitk8s.NewMetricPipelineV1Alpha1("exceeding-pipeline") pipelineCreatedLater = pipeline.K8sObject() pipelines.Append(pipeline.Name()) @@ -182,13 +182,13 @@ var _ = Describe("Metrics Multi-Pipeline", Label("metrics"), func() { objs = append(objs, mockBackend.K8sObjects()...) urls.SetMockBackendExport(mockBackend.Name(), mockBackend.TelemetryExportURL(proxyClient)) - healthyPipeline := kitk8s.NewMetricPipeline("healthy").WithOutputEndpointFromSecret(mockBackend.HostSecretRef()) + healthyPipeline := kitk8s.NewMetricPipelineV1Alpha1("healthy").WithOutputEndpointFromSecret(mockBackend.HostSecretRefV1Alpha1()) healthyPipelineName = healthyPipeline.Name() objs = append(objs, healthyPipeline.K8sObject()) unreachableHostSecret := kitk8s.NewOpaqueSecret("metric-rcv-hostname-broken", kitkyma.DefaultNamespaceName, kitk8s.WithStringData("metric-host", "http://unreachable:4317")) - brokenPipeline := kitk8s.NewMetricPipeline("broken").WithOutputEndpointFromSecret(unreachableHostSecret.SecretKeyRef("metric-host")) + brokenPipeline := kitk8s.NewMetricPipelineV1Alpha1("broken").WithOutputEndpointFromSecret(unreachableHostSecret.SecretKeyRefV1Alpha1("metric-host")) brokenPipelineName = brokenPipeline.Name() objs = append(objs, brokenPipeline.K8sObject(), unreachableHostSecret.K8sObject()) diff --git a/test/e2e/metrics_namespace_selector_test.go b/test/e2e/metrics_namespace_selector_test.go index 1fc945bd1..71b24968e 100644 --- a/test/e2e/metrics_namespace_selector_test.go +++ b/test/e2e/metrics_namespace_selector_test.go @@ -40,22 +40,22 @@ var _ = Describe("Metrics Namespace Selector", Label("metrics"), func() { telemetryExportURLs[backend1Name] = backend1.TelemetryExportURL(proxyClient) objs = append(objs, backend1.K8sObjects()...) - pipelineIncludeApp1Ns := kitk8s.NewMetricPipeline("include-"+app1Ns). - WithOutputEndpointFromSecret(backend1.HostSecretRef()). - PrometheusInput(true, kitk8s.IncludeNamespaces(app1Ns)). - RuntimeInput(true, kitk8s.IncludeNamespaces(app1Ns)). - OtlpInput(true, kitk8s.IncludeNamespaces(app1Ns)) + pipelineIncludeApp1Ns := kitk8s.NewMetricPipelineV1Alpha1("include-"+app1Ns). + WithOutputEndpointFromSecret(backend1.HostSecretRefV1Alpha1()). + PrometheusInput(true, kitk8s.IncludeNamespacesV1Alpha1(app1Ns)). + RuntimeInput(true, kitk8s.IncludeNamespacesV1Alpha1(app1Ns)). + OtlpInput(true, kitk8s.IncludeNamespacesV1Alpha1(app1Ns)) objs = append(objs, pipelineIncludeApp1Ns.K8sObject()) backend2 := backend.New(backend2Name, backendNs, backend.SignalTypeMetrics) telemetryExportURLs[backend2Name] = backend2.TelemetryExportURL(proxyClient) objs = append(objs, backend2.K8sObjects()...) - pipelineExcludeApp1Ns := kitk8s.NewMetricPipeline("exclude-"+app1Ns). - WithOutputEndpointFromSecret(backend2.HostSecretRef()). - PrometheusInput(true, kitk8s.ExcludeNamespaces(app1Ns)). - RuntimeInput(true, kitk8s.ExcludeNamespaces(app1Ns)). - OtlpInput(true, kitk8s.ExcludeNamespaces(app1Ns)) + pipelineExcludeApp1Ns := kitk8s.NewMetricPipelineV1Alpha1("exclude-"+app1Ns). + WithOutputEndpointFromSecret(backend2.HostSecretRefV1Alpha1()). + PrometheusInput(true, kitk8s.ExcludeNamespacesV1Alpha1(app1Ns)). + RuntimeInput(true, kitk8s.ExcludeNamespacesV1Alpha1(app1Ns)). + OtlpInput(true, kitk8s.ExcludeNamespacesV1Alpha1(app1Ns)) objs = append(objs, pipelineExcludeApp1Ns.K8sObject()) objs = append(objs, diff --git a/test/e2e/metrics_otlp_input_test.go b/test/e2e/metrics_otlp_input_test.go index 51b90885c..65a852355 100644 --- a/test/e2e/metrics_otlp_input_test.go +++ b/test/e2e/metrics_otlp_input_test.go @@ -31,8 +31,8 @@ var _ = Describe("Metrics OTLP Input", Label("metrics"), func() { telemetryExportURL = mockBackend.TelemetryExportURL(proxyClient) objs = append(objs, mockBackend.K8sObjects()...) - pipelineWithoutOTLP := kitk8s.NewMetricPipeline("pipeline-without-otlp-input-enabled"). - WithOutputEndpointFromSecret(mockBackend.HostSecretRef()). + pipelineWithoutOTLP := kitk8s.NewMetricPipelineV1Alpha1("pipeline-without-otlp-input-enabled"). + WithOutputEndpointFromSecret(mockBackend.HostSecretRefV1Alpha1()). OtlpInput(false) objs = append(objs, pipelineWithoutOTLP.K8sObject()) diff --git a/test/e2e/metrics_prometheus_input_diagnostic_metric_test.go b/test/e2e/metrics_prometheus_input_diagnostic_metric_test.go index f45affd41..399180390 100644 --- a/test/e2e/metrics_prometheus_input_diagnostic_metric_test.go +++ b/test/e2e/metrics_prometheus_input_diagnostic_metric_test.go @@ -45,8 +45,8 @@ var _ = Describe("Metrics Prometheus Input Diagnostic Metrics", Label("metrics") telemetryExportURL = mockBackend.TelemetryExportURL(proxyClient) // Default namespace objects. - metricPipeline := kitk8s.NewMetricPipeline("pipeline-with-prometheus-input-diagnostic-enabled"). - WithOutputEndpointFromSecret(mockBackend.HostSecretRef()). + metricPipeline := kitk8s.NewMetricPipelineV1Alpha1("pipeline-with-prometheus-input-diagnostic-enabled"). + WithOutputEndpointFromSecret(mockBackend.HostSecretRefV1Alpha1()). PrometheusInput(true).PrometheusInputDiagnosticMetrics(true) pipelineName = metricPipeline.Name() objs = append(objs, metricPipeline.K8sObject()) diff --git a/test/e2e/metrics_prometheus_input_test.go b/test/e2e/metrics_prometheus_input_test.go index 3e1733d92..5b3472f53 100644 --- a/test/e2e/metrics_prometheus_input_test.go +++ b/test/e2e/metrics_prometheus_input_test.go @@ -46,9 +46,9 @@ var _ = Describe("Metrics Prometheus Input", Label("metrics"), func() { telemetryExportURL = mockBackend.TelemetryExportURL(proxyClient) // Default namespace objects. - metricPipeline := kitk8s.NewMetricPipeline("pipeline-with-prometheus-input-enabled"). - WithOutputEndpointFromSecret(mockBackend.HostSecretRef()). - PrometheusInput(true, kitk8s.IncludeNamespaces(mockNs)) + metricPipeline := kitk8s.NewMetricPipelineV1Alpha1("pipeline-with-prometheus-input-enabled"). + WithOutputEndpointFromSecret(mockBackend.HostSecretRefV1Alpha1()). + PrometheusInput(true, kitk8s.IncludeNamespacesV1Alpha1(mockNs)) pipelineName = metricPipeline.Name() objs = append(objs, metricPipeline.K8sObject()) diff --git a/test/e2e/metrics_runtime_input_test.go b/test/e2e/metrics_runtime_input_test.go index ee4de3389..4993fdcba 100644 --- a/test/e2e/metrics_runtime_input_test.go +++ b/test/e2e/metrics_runtime_input_test.go @@ -41,8 +41,8 @@ var _ = Describe("Metrics Runtime Input", Label("metrics"), func() { objs = append(objs, mockBackend.K8sObjects()...) telemetryExportURL = mockBackend.TelemetryExportURL(proxyClient) - metricPipeline := kitk8s.NewMetricPipeline("pipeline-with-runtime-input-enabled"). - WithOutputEndpointFromSecret(mockBackend.HostSecretRef()). + metricPipeline := kitk8s.NewMetricPipelineV1Alpha1("pipeline-with-runtime-input-enabled"). + WithOutputEndpointFromSecret(mockBackend.HostSecretRefV1Alpha1()). RuntimeInput(true) pipelineName = metricPipeline.Name() objs = append(objs, metricPipeline.K8sObject()) diff --git a/test/e2e/metrics_secret_rotation_test.go b/test/e2e/metrics_secret_rotation_test.go index ad6e97bb5..1744b7e7b 100644 --- a/test/e2e/metrics_secret_rotation_test.go +++ b/test/e2e/metrics_secret_rotation_test.go @@ -23,7 +23,7 @@ var _ = Describe("Metrics Secret Rotation", Label("metrics"), func() { Context("When a metricpipeline with missing secret reference exists", Ordered, func() { hostSecret := kitk8s.NewOpaqueSecret("metric-rcv-hostname", kitkyma.DefaultNamespaceName, kitk8s.WithStringData("metric-host", "http://localhost:4317")) - metricPipeline := kitk8s.NewMetricPipeline("without-secret").WithOutputEndpointFromSecret(hostSecret.SecretKeyRef("metric-host")) + metricPipeline := kitk8s.NewMetricPipelineV1Alpha1("without-secret").WithOutputEndpointFromSecret(hostSecret.SecretKeyRefV1Alpha1("metric-host")) BeforeAll(func() { Expect(kitk8s.CreateObjects(ctx, k8sClient, metricPipeline.K8sObject())).Should(Succeed()) diff --git a/test/e2e/metrics_service_name_test.go b/test/e2e/metrics_service_name_test.go index a8f1a71b9..cdb38959b 100644 --- a/test/e2e/metrics_service_name_test.go +++ b/test/e2e/metrics_service_name_test.go @@ -42,9 +42,9 @@ var _ = Describe("Metrics Service Name", Label("metrics"), func() { telemetryExportURL = mockBackend.TelemetryExportURL(proxyClient) - runtimeInputPipeline := kitk8s.NewMetricPipeline("pipeline-service-name-test"). - WithOutputEndpointFromSecret(mockBackend.HostSecretRef()). - RuntimeInput(true, kitk8s.IncludeNamespaces(kitkyma.SystemNamespaceName)) + runtimeInputPipeline := kitk8s.NewMetricPipelineV1Alpha1("pipeline-service-name-test"). + WithOutputEndpointFromSecret(mockBackend.HostSecretRefV1Alpha1()). + RuntimeInput(true, kitk8s.IncludeNamespacesV1Alpha1(kitkyma.SystemNamespaceName)) runtimeInputPipelineName = runtimeInputPipeline.Name() objs = append(objs, runtimeInputPipeline.K8sObject()) diff --git a/test/e2e/overrides_test.go b/test/e2e/overrides_test.go index 56d29bb01..7f694f873 100644 --- a/test/e2e/overrides_test.go +++ b/test/e2e/overrides_test.go @@ -39,12 +39,12 @@ var _ = Describe("Overrides", Label("telemetry"), Ordered, func() { objs = append(objs, mockBackend.K8sObjects()...) telemetryExportURL = mockBackend.TelemetryExportURL(proxyClient) - logPipeline := kitk8s.NewLogPipeline(pipelineName). + logPipeline := kitk8s.NewLogPipelineV1Alpha1(pipelineName). WithSystemNamespaces(true). - WithSecretKeyRef(mockBackend.HostSecretRef()). + WithSecretKeyRef(mockBackend.HostSecretRefV1Alpha1()). WithHTTPOutput() - metricPipeline := kitk8s.NewMetricPipeline(pipelineName) - tracePipeline := kitk8s.NewTracePipeline(pipelineName) + metricPipeline := kitk8s.NewMetricPipelineV1Alpha1(pipelineName) + tracePipeline := kitk8s.NewTracePipelineV1Alpha1(pipelineName) objs = append(objs, logPipeline.K8sObject(), metricPipeline.K8sObject(), tracePipeline.K8sObject()) return objs diff --git a/test/e2e/suite_test.go b/test/e2e/suite_test.go index 78cb10e77..3b6efba4c 100644 --- a/test/e2e/suite_test.go +++ b/test/e2e/suite_test.go @@ -19,6 +19,7 @@ import ( operatorv1alpha1 "github.com/kyma-project/telemetry-manager/apis/operator/v1alpha1" telemetryv1alpha1 "github.com/kyma-project/telemetry-manager/apis/telemetry/v1alpha1" + telemetryv1beta1 "github.com/kyma-project/telemetry-manager/apis/telemetry/v1beta1" "github.com/kyma-project/telemetry-manager/test/testkit/apiserverproxy" kitk8s "github.com/kyma-project/telemetry-manager/test/testkit/k8s" kitkyma "github.com/kyma-project/telemetry-manager/test/testkit/kyma" @@ -64,6 +65,7 @@ var _ = BeforeSuite(func() { scheme := clientgoscheme.Scheme Expect(telemetryv1alpha1.AddToScheme(scheme)).NotTo(HaveOccurred()) + Expect(telemetryv1beta1.AddToScheme(scheme)).NotTo(HaveOccurred()) Expect(operatorv1alpha1.AddToScheme(scheme)).NotTo(HaveOccurred()) k8sClient, err = client.New(testEnv.Config, client.Options{Scheme: scheme}) Expect(err).NotTo(HaveOccurred()) diff --git a/test/e2e/telemetry_test.go b/test/e2e/telemetry_test.go index e66c76c31..cbe7faa70 100644 --- a/test/e2e/telemetry_test.go +++ b/test/e2e/telemetry_test.go @@ -216,7 +216,7 @@ func testWebhookReconciliation() { } func makeTestPipelineK8sObjects() []client.Object { - logPipeline := kitk8s.NewLogPipeline(telemetryTestK8SObjectName).WithStdout() + logPipeline := kitk8s.NewLogPipelineV1Alpha1(telemetryTestK8SObjectName).WithStdout() return []client.Object{ logPipeline.K8sObject(), } diff --git a/test/e2e/traces_basic_test.go b/test/e2e/traces_basic_v1alpha1_test.go similarity index 96% rename from test/e2e/traces_basic_test.go rename to test/e2e/traces_basic_v1alpha1_test.go index a07b5816f..0e3cf5723 100644 --- a/test/e2e/traces_basic_test.go +++ b/test/e2e/traces_basic_v1alpha1_test.go @@ -24,7 +24,7 @@ import ( "github.com/kyma-project/telemetry-manager/test/testkit/verifiers" ) -var _ = Describe("Traces Basic", Label("traces"), func() { +var _ = Describe("Traces Basic v1alpha1", Label("traces"), func() { const ( mockBackendName = "traces-receiver" mockNs = "traces-basic-test" @@ -44,8 +44,8 @@ var _ = Describe("Traces Basic", Label("traces"), func() { objs = append(objs, mockBackend.K8sObjects()...) telemetryExportURL = mockBackend.TelemetryExportURL(proxyClient) - pipeline := kitk8s.NewTracePipeline(fmt.Sprintf("%s-pipeline", mockBackend.Name())). - WithOutputEndpointFromSecret(mockBackend.HostSecretRef()). + pipeline := kitk8s.NewTracePipelineV1Alpha1(fmt.Sprintf("%s-pipeline", mockBackend.Name())). + WithOutputEndpointFromSecret(mockBackend.HostSecretRefV1Alpha1()). Persistent(isOperational()) pipelineName = pipeline.Name() objs = append(objs, pipeline.K8sObject()) diff --git a/test/e2e/traces_basic_v1beta1_test.go b/test/e2e/traces_basic_v1beta1_test.go new file mode 100644 index 000000000..30d3c3e60 --- /dev/null +++ b/test/e2e/traces_basic_v1beta1_test.go @@ -0,0 +1,196 @@ +//go:build e2e + +package e2e + +import ( + "fmt" + "net/http" + + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" + appsv1 "k8s.io/api/apps/v1" + corev1 "k8s.io/api/core/v1" + networkingv1 "k8s.io/api/networking/v1" + "k8s.io/apimachinery/pkg/types" + "sigs.k8s.io/controller-runtime/pkg/client" + + operatorv1alpha1 "github.com/kyma-project/telemetry-manager/apis/operator/v1alpha1" + "github.com/kyma-project/telemetry-manager/internal/otelcollector/ports" + kitk8s "github.com/kyma-project/telemetry-manager/test/testkit/k8s" + kitkyma "github.com/kyma-project/telemetry-manager/test/testkit/kyma" + "github.com/kyma-project/telemetry-manager/test/testkit/mocks/backend" + kittraces "github.com/kyma-project/telemetry-manager/test/testkit/otel/traces" + "github.com/kyma-project/telemetry-manager/test/testkit/periodic" + "github.com/kyma-project/telemetry-manager/test/testkit/verifiers" +) + +var _ = Describe("Traces Basic v1beta1", Label("traces", "v1beta1"), func() { + const ( + mockBackendName = "traces-receiver" + mockNs = "traces-basic-v1beta1-test" + ) + + var ( + pipelineName string + telemetryExportURL string + ) + + makeResources := func() []client.Object { + var objs []client.Object + + objs = append(objs, kitk8s.NewNamespace(mockNs).K8sObject()) + + mockBackend := backend.New(mockBackendName, mockNs, backend.SignalTypeTraces) + objs = append(objs, mockBackend.K8sObjects()...) + telemetryExportURL = mockBackend.TelemetryExportURL(proxyClient) + + pipeline := kitk8s.NewTracePipelineV1Beta1(fmt.Sprintf("%s-pipeline", mockBackend.Name())). + WithOutputEndpointFromSecret(mockBackend.HostSecretRefV1Beta1()) + pipelineName = pipeline.Name() + objs = append(objs, pipeline.K8sObject()) + + return objs + } + + Context("When a tracepipeline exists", Ordered, func() { + BeforeAll(func() { + k8sObjects := makeResources() + + DeferCleanup(func() { + Expect(kitk8s.DeleteObjects(ctx, k8sClient, k8sObjects...)).Should(Succeed()) + }) + Expect(kitk8s.CreateObjects(ctx, k8sClient, k8sObjects...)).Should(Succeed()) + }) + + It("Should have a running trace gateway deployment", func() { + verifiers.DeploymentShouldBeReady(ctx, k8sClient, kitkyma.TraceGatewayName) + }) + + It("Should have 2 trace gateway replicas", func() { + Eventually(func(g Gomega) int32 { + var deployment appsv1.Deployment + err := k8sClient.Get(ctx, kitkyma.TraceGatewayName, &deployment) + g.Expect(err).NotTo(HaveOccurred()) + return *deployment.Spec.Replicas + }, periodic.EventuallyTimeout, periodic.DefaultInterval).Should(Equal(int32(2))) + }) + + It("Should reject scaling below minimum", func() { + var telemetry operatorv1alpha1.Telemetry + err := k8sClient.Get(ctx, kitkyma.TelemetryName, &telemetry) + Expect(err).NotTo(HaveOccurred()) + + telemetry.Spec.Trace = &operatorv1alpha1.TraceSpec{ + Gateway: operatorv1alpha1.TraceGatewaySpec{ + Scaling: operatorv1alpha1.Scaling{ + Type: operatorv1alpha1.StaticScalingStrategyType, + Static: &operatorv1alpha1.StaticScaling{ + Replicas: -1, + }, + }, + }, + } + err = k8sClient.Update(ctx, &telemetry) + Expect(err).To(HaveOccurred()) + }) + + It("Should scale up trace gateway replicas", func() { + Eventually(func(g Gomega) int32 { + var telemetry operatorv1alpha1.Telemetry + err := k8sClient.Get(ctx, kitkyma.TelemetryName, &telemetry) + g.Expect(err).NotTo(HaveOccurred()) + + telemetry.Spec.Trace = &operatorv1alpha1.TraceSpec{ + Gateway: operatorv1alpha1.TraceGatewaySpec{ + Scaling: operatorv1alpha1.Scaling{ + Type: operatorv1alpha1.StaticScalingStrategyType, + Static: &operatorv1alpha1.StaticScaling{ + Replicas: 4, + }, + }, + }, + } + err = k8sClient.Update(ctx, &telemetry) + g.Expect(err).NotTo(HaveOccurred()) + return telemetry.Spec.Trace.Gateway.Scaling.Static.Replicas + }, periodic.EventuallyTimeout, periodic.DefaultInterval).Should(Equal(int32(4))) + }) + + It("Should have 4 trace gateway replicas after scaling up", func() { + Eventually(func(g Gomega) int32 { + var deployment appsv1.Deployment + err := k8sClient.Get(ctx, kitkyma.TraceGatewayName, &deployment) + g.Expect(err).NotTo(HaveOccurred()) + return *deployment.Spec.Replicas + }, periodic.EventuallyTimeout, periodic.DefaultInterval).Should(Equal(int32(4))) + }) + + It("Should scale down trace gateway replicas", func() { + Eventually(func(g Gomega) int32 { + var telemetry operatorv1alpha1.Telemetry + err := k8sClient.Get(ctx, kitkyma.TelemetryName, &telemetry) + g.Expect(err).NotTo(HaveOccurred()) + + telemetry.Spec.Trace = &operatorv1alpha1.TraceSpec{ + Gateway: operatorv1alpha1.TraceGatewaySpec{ + Scaling: operatorv1alpha1.Scaling{ + Type: operatorv1alpha1.StaticScalingStrategyType, + Static: &operatorv1alpha1.StaticScaling{ + Replicas: 2, + }, + }, + }, + } + err = k8sClient.Update(ctx, &telemetry) + g.Expect(err).NotTo(HaveOccurred()) + return telemetry.Spec.Trace.Gateway.Scaling.Static.Replicas + }, periodic.EventuallyTimeout, periodic.DefaultInterval).Should(Equal(int32(2))) + }) + + It("Should have 2 trace gateway replicas after scaling down", func() { + Eventually(func(g Gomega) int32 { + var deployment appsv1.Deployment + err := k8sClient.Get(ctx, kitkyma.TraceGatewayName, &deployment) + g.Expect(err).NotTo(HaveOccurred()) + return *deployment.Spec.Replicas + }, periodic.EventuallyTimeout, periodic.DefaultInterval).Should(Equal(int32(2))) + }) + + It("Should have a trace backend running", func() { + verifiers.DeploymentShouldBeReady(ctx, k8sClient, types.NamespacedName{Name: mockBackendName, Namespace: mockNs}) + }) + + It("Should have a running pipeline", func() { + verifiers.TracePipelineShouldBeHealthy(ctx, k8sClient, pipelineName) + }) + + It("Should verify end-to-end trace delivery", func() { + gatewayPushURL := proxyClient.ProxyURLForService(kitkyma.SystemNamespaceName, "telemetry-otlp-traces", "v1/traces/", ports.OTLPHTTP) + traceID, spanIDs, attrs := kittraces.MakeAndSendTraces(proxyClient, gatewayPushURL) + verifiers.TracesShouldBeDelivered(proxyClient, telemetryExportURL, traceID, spanIDs, attrs) + }) + + It("Should be able to get trace gateway metrics endpoint", func() { + gatewayMetricsURL := proxyClient.ProxyURLForService(kitkyma.TraceGatewayMetrics.Namespace, kitkyma.TraceGatewayMetrics.Name, "metrics", ports.Metrics) + verifiers.ShouldExposeCollectorMetrics(proxyClient, gatewayMetricsURL) + }) + + It("Should have a working network policy", func() { + var networkPolicy networkingv1.NetworkPolicy + Expect(k8sClient.Get(ctx, kitkyma.TraceGatewayNetworkPolicy, &networkPolicy)).To(Succeed()) + + Eventually(func(g Gomega) { + var podList corev1.PodList + g.Expect(k8sClient.List(ctx, &podList, client.InNamespace(kitkyma.SystemNamespaceName), client.MatchingLabels{"app.kubernetes.io/name": kitkyma.TraceGatewayBaseName})).To(Succeed()) + g.Expect(podList.Items).NotTo(BeEmpty()) + + traceGatewayPodName := podList.Items[0].Name + pprofEndpoint := proxyClient.ProxyURLForPod(kitkyma.SystemNamespaceName, traceGatewayPodName, "debug/pprof/", ports.Pprof) + + resp, err := proxyClient.Get(pprofEndpoint) + g.Expect(err).NotTo(HaveOccurred()) + g.Expect(resp).To(HaveHTTPStatus(http.StatusServiceUnavailable)) + }, periodic.EventuallyTimeout, periodic.DefaultInterval).Should(Succeed()) + }) + }) +}) diff --git a/test/e2e/traces_endpoint_path_validation_test.go b/test/e2e/traces_endpoint_path_validation_test.go index 5ec473e92..c3b3ca584 100644 --- a/test/e2e/traces_endpoint_path_validation_test.go +++ b/test/e2e/traces_endpoint_path_validation_test.go @@ -11,26 +11,26 @@ import ( var _ = Describe("Traces Validating Endpoint Path", Label("tracing"), Ordered, func() { - tracePipelineDefaultGRPCWithPath := kitk8s.NewTracePipeline("tracepipeline-default-reject-with-path"). + tracePipelineDefaultGRPCWithPath := kitk8s.NewTracePipelineV1Alpha1("tracepipeline-default-reject-with-path"). WithOutputEndpoint("mock-endpoint:4817").WithEndpointPath("/v1/mock/traces"). Persistent(isOperational()).K8sObject() - tracePipelineWithGRPCAndPath := kitk8s.NewTracePipeline("tracepipeline-reject-with-grpc-and-path"). + tracePipelineWithGRPCAndPath := kitk8s.NewTracePipelineV1Alpha1("tracepipeline-reject-with-grpc-and-path"). WithOutputEndpoint("mock-endpoint:4817").WithEndpointPath("/v1/mock/traces"). WithProtocol("grpc"). Persistent(isOperational()).K8sObject() - tracePipelineWithGRPCAndWithoutPath := kitk8s.NewTracePipeline("tracepipeline-accept-with-grpc-and-no-path"). + tracePipelineWithGRPCAndWithoutPath := kitk8s.NewTracePipelineV1Alpha1("tracepipeline-accept-with-grpc-and-no-path"). WithOutputEndpoint("mock-endpoint:4817"). WithProtocol("grpc"). Persistent(isOperational()).K8sObject() - tracePipelineWithHTTPAndPath := kitk8s.NewTracePipeline("tracepipeline-accept-with-http-and-path"). + tracePipelineWithHTTPAndPath := kitk8s.NewTracePipelineV1Alpha1("tracepipeline-accept-with-http-and-path"). WithOutputEndpoint("mock-endpoint:4817").WithEndpointPath("/v1/mock/traces"). WithProtocol("http"). Persistent(isOperational()).K8sObject() - tracePipelineWithHTTPAndWithoutPath := kitk8s.NewTracePipeline("tracepipeline-accept-with-http-and-no-path"). + tracePipelineWithHTTPAndWithoutPath := kitk8s.NewTracePipelineV1Alpha1("tracepipeline-accept-with-http-and-no-path"). WithOutputEndpoint("mock-endpoint:4817"). WithProtocol("http"). Persistent(isOperational()).K8sObject() diff --git a/test/e2e/traces_endpoint_with_path_test.go b/test/e2e/traces_endpoint_with_path_test.go index 607ec3cbc..5da5ede50 100644 --- a/test/e2e/traces_endpoint_with_path_test.go +++ b/test/e2e/traces_endpoint_with_path_test.go @@ -25,7 +25,7 @@ var _ = Describe("Traces Endpoint with Path", Label("tracing"), func() { makeResources := func() []client.Object { var objs []client.Object - tracePipeline := kitk8s.NewTracePipeline("mock-trace-endpoint-path"). + tracePipeline := kitk8s.NewTracePipelineV1Alpha1("mock-trace-endpoint-path"). WithProtocol("http"). WithOutputEndpoint(endpoint).WithEndpointPath(path) diff --git a/test/e2e/traces_mtls_test.go b/test/e2e/traces_mtls_test.go index ab08ea946..225f89cf6 100644 --- a/test/e2e/traces_mtls_test.go +++ b/test/e2e/traces_mtls_test.go @@ -37,8 +37,8 @@ var _ = Describe("Traces mTLS", Label("traces"), func() { objs = append(objs, mockBackend.K8sObjects()...) urls.SetMockBackendExport(mockBackend.Name(), mockBackend.TelemetryExportURL(proxyClient)) - pipeline := kitk8s.NewTracePipeline(fmt.Sprintf("%s-%s", mockBackend.Name(), "pipeline")). - WithOutputEndpointFromSecret(mockBackend.HostSecretRef()). + pipeline := kitk8s.NewTracePipelineV1Alpha1(fmt.Sprintf("%s-%s", mockBackend.Name(), "pipeline")). + WithOutputEndpointFromSecret(mockBackend.HostSecretRefV1Alpha1()). WithTLS(mockBackend.TLSCerts) pipelineName = pipeline.Name() diff --git a/test/e2e/traces_multi_pipeline_test.go b/test/e2e/traces_multi_pipeline_test.go index 86920cc03..1c6161c72 100644 --- a/test/e2e/traces_multi_pipeline_test.go +++ b/test/e2e/traces_multi_pipeline_test.go @@ -45,7 +45,7 @@ var _ = Describe("Traces Multi-Pipeline", Label("traces"), func() { objs = append(objs, mockBackend.K8sObjects()...) urls.SetMockBackendExport(mockBackend.Name(), mockBackend.TelemetryExportURL(proxyClient)) - pipeline := kitk8s.NewTracePipeline(fmt.Sprintf("%s-%s", mockBackend.Name(), "pipeline")).WithOutputEndpointFromSecret(mockBackend.HostSecretRef()) + pipeline := kitk8s.NewTracePipelineV1Alpha1(fmt.Sprintf("%s-%s", mockBackend.Name(), "pipeline")).WithOutputEndpointFromSecret(mockBackend.HostSecretRefV1Alpha1()) pipelines.Append(pipeline.Name()) objs = append(objs, pipeline.K8sObject()) } @@ -92,7 +92,7 @@ var _ = Describe("Traces Multi-Pipeline", Label("traces"), func() { makeResources := func() []client.Object { var objs []client.Object for i := 0; i < maxNumberOfTracePipelines; i++ { - pipeline := kitk8s.NewTracePipeline(fmt.Sprintf("pipeline-%d", i)) + pipeline := kitk8s.NewTracePipelineV1Alpha1(fmt.Sprintf("pipeline-%d", i)) pipelines.Append(pipeline.Name()) objs = append(objs, pipeline.K8sObject()) @@ -125,7 +125,7 @@ var _ = Describe("Traces Multi-Pipeline", Label("traces"), func() { It("Should set ConfigurationGenerated condition to false and Pending condition to true", func() { By("Creating an additional pipeline", func() { - pipeline := kitk8s.NewTracePipeline("exceeding-pipeline") + pipeline := kitk8s.NewTracePipelineV1Alpha1("exceeding-pipeline") pipelineCreatedLater = pipeline.K8sObject() pipelines.Append(pipeline.Name()) @@ -182,13 +182,13 @@ var _ = Describe("Traces Multi-Pipeline", Label("traces"), func() { objs = append(objs, mockBackend.K8sObjects()...) urls.SetMockBackendExport(mockBackend.Name(), mockBackend.TelemetryExportURL(proxyClient)) - healthyPipeline := kitk8s.NewTracePipeline("healthy").WithOutputEndpointFromSecret(mockBackend.HostSecretRef()) + healthyPipeline := kitk8s.NewTracePipelineV1Alpha1("healthy").WithOutputEndpointFromSecret(mockBackend.HostSecretRefV1Alpha1()) healthyPipelineName = healthyPipeline.Name() objs = append(objs, healthyPipeline.K8sObject()) unreachableHostSecret := kitk8s.NewOpaqueSecret("metric-rcv-hostname-broken", kitkyma.DefaultNamespaceName, kitk8s.WithStringData("metric-host", "http://unreachable:4317")) - brokenPipeline := kitk8s.NewTracePipeline("broken").WithOutputEndpointFromSecret(unreachableHostSecret.SecretKeyRef("metric-host")) + brokenPipeline := kitk8s.NewTracePipelineV1Alpha1("broken").WithOutputEndpointFromSecret(unreachableHostSecret.SecretKeyRefV1Alpha1("metric-host")) brokenPipelineName = brokenPipeline.Name() objs = append(objs, brokenPipeline.K8sObject(), unreachableHostSecret.K8sObject()) diff --git a/test/e2e/traces_noisy_span_filter_test.go b/test/e2e/traces_noisy_span_filter_test.go index f457e3914..a6d7127a9 100644 --- a/test/e2e/traces_noisy_span_filter_test.go +++ b/test/e2e/traces_noisy_span_filter_test.go @@ -40,8 +40,8 @@ var _ = Describe("Traces Noisy Span Filter", Label("traces"), func() { objs = append(objs, mockBackend.K8sObjects()...) urls.SetMockBackendExport(mockBackend.Name(), mockBackend.TelemetryExportURL(proxyClient)) - pipeline := kitk8s.NewTracePipeline(fmt.Sprintf("%s-pipeline", mockBackend.Name())). - WithOutputEndpointFromSecret(mockBackend.HostSecretRef()) + pipeline := kitk8s.NewTracePipelineV1Alpha1(fmt.Sprintf("%s-pipeline", mockBackend.Name())). + WithOutputEndpointFromSecret(mockBackend.HostSecretRefV1Alpha1()) pipelineName = pipeline.Name() objs = append(objs, pipeline.K8sObject()) diff --git a/test/e2e/traces_secret_rotation_test.go b/test/e2e/traces_secret_rotation_test.go index 0c46304b3..9fff43272 100644 --- a/test/e2e/traces_secret_rotation_test.go +++ b/test/e2e/traces_secret_rotation_test.go @@ -22,7 +22,7 @@ import ( var _ = Describe("Traces Secret Rotation", Label("traces"), func() { Context("When tracepipeline with missing secret reference exists", Ordered, func() { hostSecret := kitk8s.NewOpaqueSecret("trace-rcv-hostname", kitkyma.DefaultNamespaceName, kitk8s.WithStringData("trace-host", "http://localhost:4317")) - tracePipeline := kitk8s.NewTracePipeline("without-secret").WithOutputEndpointFromSecret(hostSecret.SecretKeyRef("trace-host")) + tracePipeline := kitk8s.NewTracePipelineV1Alpha1("without-secret").WithOutputEndpointFromSecret(hostSecret.SecretKeyRefV1Alpha1("trace-host")) BeforeAll(func() { Expect(kitk8s.CreateObjects(ctx, k8sClient, tracePipeline.K8sObject())).Should(Succeed()) diff --git a/test/e2e/traces_service_name_test.go b/test/e2e/traces_service_name_test.go index 365d9dd2c..e20019bc5 100644 --- a/test/e2e/traces_service_name_test.go +++ b/test/e2e/traces_service_name_test.go @@ -42,8 +42,8 @@ var _ = Describe("Traces Service Name", Label("traces"), func() { telemetryExportURL = mockBackend.TelemetryExportURL(proxyClient) - tracePipeline := kitk8s.NewTracePipeline("pipeline-service-name-test"). - WithOutputEndpointFromSecret(mockBackend.HostSecretRef()) + tracePipeline := kitk8s.NewTracePipelineV1Alpha1("pipeline-service-name-test"). + WithOutputEndpointFromSecret(mockBackend.HostSecretRefV1Alpha1()) pipelineName = tracePipeline.Name() objs = append(objs, tracePipeline.K8sObject()) diff --git a/test/integration/istio/access_logs_test.go b/test/integration/istio/access_logs_test.go index 5b0027f9a..ee76c54d1 100644 --- a/test/integration/istio/access_logs_test.go +++ b/test/integration/istio/access_logs_test.go @@ -43,8 +43,8 @@ var _ = Describe("Access Logs", Label("logs"), func() { objs = append(objs, mockBackend.K8sObjects()...) urls.SetMockBackendExport(mockBackend.Name(), mockBackend.TelemetryExportURL(proxyClient)) - istioAccessLogsPipeline := kitk8s.NewLogPipeline("pipeline-istio-access-logs"). - WithSecretKeyRef(mockBackend.HostSecretRef()). + istioAccessLogsPipeline := kitk8s.NewLogPipelineV1Alpha1("pipeline-istio-access-logs"). + WithSecretKeyRef(mockBackend.HostSecretRefV1Alpha1()). WithIncludeContainers([]string{"istio-proxy"}). WithHTTPOutput() pipelineName = istioAccessLogsPipeline.Name() diff --git a/test/integration/istio/metrics_istio_input_test.go b/test/integration/istio/metrics_istio_input_test.go index 53ccfbc3c..ad7348adf 100644 --- a/test/integration/istio/metrics_istio_input_test.go +++ b/test/integration/istio/metrics_istio_input_test.go @@ -115,10 +115,10 @@ var _ = Describe("Metrics Istio Input", Label("metrics"), func() { objs = append(objs, mockBackend.K8sObjects()...) telemetryExportURL = mockBackend.TelemetryExportURL(proxyClient) - metricPipeline := kitk8s.NewMetricPipeline("pipeline-with-istio-input-enabled"). - WithOutputEndpointFromSecret(mockBackend.HostSecretRef()). + metricPipeline := kitk8s.NewMetricPipelineV1Alpha1("pipeline-with-istio-input-enabled"). + WithOutputEndpointFromSecret(mockBackend.HostSecretRefV1Alpha1()). OtlpInput(false). - IstioInput(true, kitk8s.IncludeNamespaces(app1Ns)) + IstioInput(true, kitk8s.IncludeNamespacesV1Alpha1(app1Ns)) objs = append(objs, metricPipeline.K8sObject()) source1 := kitk8s.NewPod("source", app1Ns).WithPodSpec(sourcePodSpec()) diff --git a/test/integration/istio/metrics_otlp_input_test.go b/test/integration/istio/metrics_otlp_input_test.go index 3b2162854..bee57cc44 100644 --- a/test/integration/istio/metrics_otlp_input_test.go +++ b/test/integration/istio/metrics_otlp_input_test.go @@ -42,13 +42,13 @@ var _ = Describe("Metrics OTLP Input", Label("metrics"), func() { objs = append(objs, mockIstiofiedBackend.K8sObjects()...) telemetryIstiofiedExportURL = mockIstiofiedBackend.TelemetryExportURL(proxyClient) - metricPipeline := kitk8s.NewMetricPipeline("pipeline-with-otlp-input-enabled"). - WithOutputEndpointFromSecret(mockBackend.HostSecretRef()). + metricPipeline := kitk8s.NewMetricPipelineV1Alpha1("pipeline-with-otlp-input-enabled"). + WithOutputEndpointFromSecret(mockBackend.HostSecretRefV1Alpha1()). OtlpInput(true) objs = append(objs, metricPipeline.K8sObject()) - metricPipelineIstiofiedBackend := kitk8s.NewMetricPipeline("pipeline-with-otlp-input-enabled-with-istiofied-backend"). - WithOutputEndpointFromSecret(mockIstiofiedBackend.HostSecretRef()). + metricPipelineIstiofiedBackend := kitk8s.NewMetricPipelineV1Alpha1("pipeline-with-otlp-input-enabled-with-istiofied-backend"). + WithOutputEndpointFromSecret(mockIstiofiedBackend.HostSecretRefV1Alpha1()). OtlpInput(true) objs = append(objs, metricPipelineIstiofiedBackend.K8sObject()) diff --git a/test/integration/istio/metrics_prometheus_input_test.go b/test/integration/istio/metrics_prometheus_input_test.go index 2d39c4fdd..39bf6c376 100644 --- a/test/integration/istio/metrics_prometheus_input_test.go +++ b/test/integration/istio/metrics_prometheus_input_test.go @@ -51,8 +51,8 @@ var _ = Describe("Metrics Prometheus Input", Label("metrics"), func() { unannotatedMetricProducer.Service().WithPrometheusAnnotations(prommetricgen.SchemeHTTP).K8sObject(), }...) - metricPipeline := kitk8s.NewMetricPipeline("pipeline-with-prometheus-input-enabled"). - WithOutputEndpointFromSecret(mockBackend.HostSecretRef()). + metricPipeline := kitk8s.NewMetricPipelineV1Alpha1("pipeline-with-prometheus-input-enabled"). + WithOutputEndpointFromSecret(mockBackend.HostSecretRefV1Alpha1()). PrometheusInput(true) objs = append(objs, metricPipeline.K8sObject()) diff --git a/test/integration/istio/traces_test.go b/test/integration/istio/traces_test.go index 27f82ab07..612a216be 100644 --- a/test/integration/istio/traces_test.go +++ b/test/integration/istio/traces_test.go @@ -59,11 +59,11 @@ var _ = Describe("Traces", Label("traces"), Ordered, func() { objs = append(objs, mockIstiofiedBackend.K8sObjects()...) telemetryIstiofiedExportURL = mockBackend.TelemetryExportURL(proxyClient) - istioTracePipeline := kitk8s.NewTracePipeline("istiofied-app-traces").WithOutputEndpointFromSecret(mockIstiofiedBackend.HostSecretRef()) + istioTracePipeline := kitk8s.NewTracePipelineV1Alpha1("istiofied-app-traces").WithOutputEndpointFromSecret(mockIstiofiedBackend.HostSecretRefV1Alpha1()) istiofiedPipelineName = istioTracePipeline.Name() objs = append(objs, istioTracePipeline.K8sObject()) - tracePipeline := kitk8s.NewTracePipeline("app-traces").WithOutputEndpointFromSecret(mockBackend.HostSecretRef()) + tracePipeline := kitk8s.NewTracePipelineV1Alpha1("app-traces").WithOutputEndpointFromSecret(mockBackend.HostSecretRefV1Alpha1()) pipelineName = tracePipeline.Name() objs = append(objs, tracePipeline.K8sObject()) diff --git a/test/testkit/k8s/log_pipeline.go b/test/testkit/k8s/log_pipeline_v1alpha1.go similarity index 65% rename from test/testkit/k8s/log_pipeline.go rename to test/testkit/k8s/log_pipeline_v1alpha1.go index 891f5ddce..822f98ac1 100644 --- a/test/testkit/k8s/log_pipeline.go +++ b/test/testkit/k8s/log_pipeline_v1alpha1.go @@ -1,3 +1,4 @@ +//nolint:dupl //There is duplication between logPipelineV1Beta1 and logPipelineV1Alpha1, but we need them as separate builders because they are using different API versions package k8s import ( @@ -9,7 +10,7 @@ import ( "github.com/kyma-project/telemetry-manager/test/testkit/mocks/backend/tls" ) -type LogPipeline struct { +type logPipelineV1Alpha1 struct { persistent bool name string @@ -25,64 +26,64 @@ type LogPipeline struct { filters []telemetryv1alpha1.Filter } -func NewLogPipeline(name string) *LogPipeline { - return &LogPipeline{ +func NewLogPipelineV1Alpha1(name string) *logPipelineV1Alpha1 { + return &logPipelineV1Alpha1{ name: name, } } -func (p *LogPipeline) Name() string { +func (p *logPipelineV1Alpha1) Name() string { return p.name } -func (p *LogPipeline) WithSecretKeyRef(secretKeyRef *telemetryv1alpha1.SecretKeyRef) *LogPipeline { +func (p *logPipelineV1Alpha1) WithSecretKeyRef(secretKeyRef *telemetryv1alpha1.SecretKeyRef) *logPipelineV1Alpha1 { p.secretKeyRef = secretKeyRef return p } -func (p *LogPipeline) WithSystemNamespaces(enable bool) *LogPipeline { +func (p *logPipelineV1Alpha1) WithSystemNamespaces(enable bool) *logPipelineV1Alpha1 { p.systemNamespaces = enable return p } -func (p *LogPipeline) WithIncludeNamespaces(namespaces []string) *LogPipeline { +func (p *logPipelineV1Alpha1) WithIncludeNamespaces(namespaces []string) *logPipelineV1Alpha1 { p.includeNamespaces = namespaces return p } -func (p *LogPipeline) WithExcludeNamespaces(namespaces []string) *LogPipeline { +func (p *logPipelineV1Alpha1) WithExcludeNamespaces(namespaces []string) *logPipelineV1Alpha1 { p.excludeNamespaces = namespaces return p } -func (p *LogPipeline) WithIncludeContainers(names []string) *LogPipeline { +func (p *logPipelineV1Alpha1) WithIncludeContainers(names []string) *logPipelineV1Alpha1 { p.includeContainers = names return p } -func (p *LogPipeline) WithExcludeContainers(names []string) *LogPipeline { +func (p *logPipelineV1Alpha1) WithExcludeContainers(names []string) *logPipelineV1Alpha1 { p.excludeContainers = names return p } -func (p *LogPipeline) KeepAnnotations(enable bool) *LogPipeline { +func (p *logPipelineV1Alpha1) KeepAnnotations(enable bool) *logPipelineV1Alpha1 { p.keepAnnotations = enable return p } -func (p *LogPipeline) DropLabels(enable bool) *LogPipeline { +func (p *logPipelineV1Alpha1) DropLabels(enable bool) *logPipelineV1Alpha1 { p.dropLabels = enable return p } -func (p *LogPipeline) WithStdout() *LogPipeline { +func (p *logPipelineV1Alpha1) WithStdout() *logPipelineV1Alpha1 { p.output = telemetryv1alpha1.Output{ Custom: "Name stdout", } return p } -func (p *LogPipeline) WithHTTPOutput() *LogPipeline { +func (p *logPipelineV1Alpha1) WithHTTPOutput() *logPipelineV1Alpha1 { p.output = telemetryv1alpha1.Output{ HTTP: &telemetryv1alpha1.HTTPOutput{ Dedot: true, @@ -103,7 +104,7 @@ func (p *LogPipeline) WithHTTPOutput() *LogPipeline { return p } -func (p *LogPipeline) WithTLS(certs tls.Certs) *LogPipeline { +func (p *logPipelineV1Alpha1) WithTLS(certs tls.Certs) *logPipelineV1Alpha1 { if !p.output.IsHTTPDefined() { return p } @@ -125,7 +126,7 @@ func (p *LogPipeline) WithTLS(certs tls.Certs) *LogPipeline { return p } -func (p *LogPipeline) WithCustomOutput(host string) *LogPipeline { +func (p *logPipelineV1Alpha1) WithCustomOutput(host string) *logPipelineV1Alpha1 { const customOutputTemplate = ` name http port 9880 @@ -138,20 +139,20 @@ func (p *LogPipeline) WithCustomOutput(host string) *LogPipeline { return p } -func (p *LogPipeline) WithFilter(filter string) *LogPipeline { +func (p *logPipelineV1Alpha1) WithFilter(filter string) *logPipelineV1Alpha1 { p.filters = append(p.filters, telemetryv1alpha1.Filter{ Custom: filter, }) return p } -func (p *LogPipeline) Persistent(persistent bool) *LogPipeline { +func (p *logPipelineV1Alpha1) Persistent(persistent bool) *logPipelineV1Alpha1 { p.persistent = persistent return p } -func (p *LogPipeline) K8sObject() *telemetryv1alpha1.LogPipeline { +func (p *logPipelineV1Alpha1) K8sObject() *telemetryv1alpha1.LogPipeline { var labels Labels if p.persistent { labels = PersistentLabel diff --git a/test/testkit/k8s/log_pipeline_v1beta1.go b/test/testkit/k8s/log_pipeline_v1beta1.go new file mode 100644 index 000000000..085b74b3e --- /dev/null +++ b/test/testkit/k8s/log_pipeline_v1beta1.go @@ -0,0 +1,186 @@ +//nolint:dupl //There is duplication between logPipelineV1Beta1 and logPipelineV1Alpha1, but we need them as separate builders because they are using different API versions +package k8s + +import ( + "strings" + + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + + telemetryv1beta1 "github.com/kyma-project/telemetry-manager/apis/telemetry/v1beta1" + "github.com/kyma-project/telemetry-manager/test/testkit/mocks/backend/tls" +) + +type logPipelineV1Beta1 struct { + persistent bool + + name string + secretKeyRef *telemetryv1beta1.SecretKeyRef + systemNamespaces bool + includeNamespaces []string + excludeNamespaces []string + includeContainers []string + excludeContainers []string + keepAnnotations bool + dropLabels bool + output telemetryv1beta1.Output + filters []telemetryv1beta1.Filter +} + +func NewLogPipelineV1Beta1(name string) *logPipelineV1Beta1 { + return &logPipelineV1Beta1{ + name: name, + } +} + +func (p *logPipelineV1Beta1) Name() string { + return p.name +} + +func (p *logPipelineV1Beta1) WithSecretKeyRef(secretKeyRef *telemetryv1beta1.SecretKeyRef) *logPipelineV1Beta1 { + p.secretKeyRef = secretKeyRef + return p +} + +func (p *logPipelineV1Beta1) WithSystemNamespaces(enable bool) *logPipelineV1Beta1 { + p.systemNamespaces = enable + return p +} + +func (p *logPipelineV1Beta1) WithIncludeNamespaces(namespaces []string) *logPipelineV1Beta1 { + p.includeNamespaces = namespaces + return p +} + +func (p *logPipelineV1Beta1) WithExcludeNamespaces(namespaces []string) *logPipelineV1Beta1 { + p.excludeNamespaces = namespaces + return p +} + +func (p *logPipelineV1Beta1) WithIncludeContainers(names []string) *logPipelineV1Beta1 { + p.includeContainers = names + return p +} + +func (p *logPipelineV1Beta1) WithExcludeContainers(names []string) *logPipelineV1Beta1 { + p.excludeContainers = names + return p +} + +func (p *logPipelineV1Beta1) KeepAnnotations(enable bool) *logPipelineV1Beta1 { + p.keepAnnotations = enable + return p +} + +func (p *logPipelineV1Beta1) DropLabels(enable bool) *logPipelineV1Beta1 { + p.dropLabels = enable + return p +} + +func (p *logPipelineV1Beta1) WithStdout() *logPipelineV1Beta1 { + p.output = telemetryv1beta1.Output{ + Custom: "Name stdout", + } + return p +} + +func (p *logPipelineV1Beta1) WithHTTPOutput() *logPipelineV1Beta1 { + p.output = telemetryv1beta1.Output{ + HTTP: &telemetryv1beta1.HTTPOutput{ + Dedot: true, + Host: telemetryv1beta1.ValueType{ + ValueFrom: &telemetryv1beta1.ValueFromSource{ + SecretKeyRef: p.secretKeyRef, + }, + }, + Port: "9880", + URI: "/", + Format: "json", + TLSConfig: telemetryv1beta1.TLSConfig{ + Disabled: true, + SkipCertificateValidation: true, + }, + }, + } + return p +} + +func (p *logPipelineV1Beta1) WithTLS(certs tls.Certs) *logPipelineV1Beta1 { + if !p.output.IsHTTPDefined() { + return p + } + + p.output.HTTP.TLSConfig = telemetryv1beta1.TLSConfig{ + Disabled: false, + SkipCertificateValidation: false, + CA: &telemetryv1beta1.ValueType{ + Value: certs.CaCertPem.String(), + }, + Cert: &telemetryv1beta1.ValueType{ + Value: certs.ClientCertPem.String(), + }, + Key: &telemetryv1beta1.ValueType{ + Value: certs.ClientKeyPem.String(), + }, + } + + return p +} + +func (p *logPipelineV1Beta1) WithCustomOutput(host string) *logPipelineV1Beta1 { + const customOutputTemplate = ` + name http + port 9880 + host {{ HOST }} + format json` + customOutput := strings.Replace(customOutputTemplate, "{{ HOST }}", host, 1) + p.output = telemetryv1beta1.Output{ + Custom: customOutput, + } + return p +} + +func (p *logPipelineV1Beta1) WithFilter(filter string) *logPipelineV1Beta1 { + p.filters = append(p.filters, telemetryv1beta1.Filter{ + Custom: filter, + }) + return p +} + +func (p *logPipelineV1Beta1) Persistent(persistent bool) *logPipelineV1Beta1 { + p.persistent = persistent + + return p +} + +func (p *logPipelineV1Beta1) K8sObject() *telemetryv1beta1.LogPipeline { + var labels Labels + if p.persistent { + labels = PersistentLabel + } + + return &telemetryv1beta1.LogPipeline{ + ObjectMeta: metav1.ObjectMeta{ + Name: p.name, + Labels: labels, + }, + Spec: telemetryv1beta1.LogPipelineSpec{ + Input: telemetryv1beta1.Input{ + Application: telemetryv1beta1.ApplicationInput{ + Namespaces: telemetryv1beta1.InputNamespaces{ + System: p.systemNamespaces, + Include: p.includeNamespaces, + Exclude: p.excludeNamespaces, + }, + Containers: telemetryv1beta1.InputContainers{ + Include: p.includeContainers, + Exclude: p.excludeContainers, + }, + KeepAnnotations: p.keepAnnotations, + DropLabels: p.dropLabels, + }, + }, + Output: p.output, + Filters: p.filters, + }, + } +} diff --git a/test/testkit/k8s/metric_pipeline.go b/test/testkit/k8s/metric_pipeline_v1alpha1.go similarity index 67% rename from test/testkit/k8s/metric_pipeline.go rename to test/testkit/k8s/metric_pipeline_v1alpha1.go index 3bb73595b..832284977 100644 --- a/test/testkit/k8s/metric_pipeline.go +++ b/test/testkit/k8s/metric_pipeline_v1alpha1.go @@ -1,3 +1,4 @@ +//nolint:dupl //There is duplication between metricPipelineV1Beta1 and metricPipelineV1Alpha1, but we need them as separate builders because they are using different API versions package k8s import ( @@ -10,9 +11,7 @@ import ( "github.com/kyma-project/telemetry-manager/test/testkit/mocks/backend/tls" ) -const version = "1.0.0" - -type MetricPipeline struct { +type metricPipelineV1Alpha1 struct { persistent bool id string @@ -28,51 +27,51 @@ type MetricPipeline struct { endpointPath string } -func NewMetricPipeline(name string) *MetricPipeline { - return &MetricPipeline{ +func NewMetricPipelineV1Alpha1(name string) *metricPipelineV1Alpha1 { + return &metricPipelineV1Alpha1{ id: uuid.New().String(), name: name, otlpEndpoint: "http://unreachable:4317", } } -func (p *MetricPipeline) WithOutputEndpoint(otlpEndpoint string) *MetricPipeline { +func (p *metricPipelineV1Alpha1) WithOutputEndpoint(otlpEndpoint string) *metricPipelineV1Alpha1 { p.otlpEndpoint = otlpEndpoint return p } -func (p *MetricPipeline) WithOutputEndpointFromSecret(otlpEndpointRef *telemetryv1alpha1.SecretKeyRef) *MetricPipeline { +func (p *metricPipelineV1Alpha1) WithOutputEndpointFromSecret(otlpEndpointRef *telemetryv1alpha1.SecretKeyRef) *metricPipelineV1Alpha1 { p.otlpEndpointRef = otlpEndpointRef return p } -func (p *MetricPipeline) Name() string { +func (p *metricPipelineV1Alpha1) Name() string { if p.persistent { return p.name } return fmt.Sprintf("%s-%s", p.name, p.id) } -func (p *MetricPipeline) Persistent(persistent bool) *MetricPipeline { +func (p *metricPipelineV1Alpha1) Persistent(persistent bool) *metricPipelineV1Alpha1 { p.persistent = persistent return p } -type InputOptions func(selector *telemetryv1alpha1.MetricPipelineInputNamespaceSelector) +type InputOptionsV1Alpha1 func(selector *telemetryv1alpha1.MetricPipelineInputNamespaceSelector) -func IncludeNamespaces(namespaces ...string) InputOptions { +func IncludeNamespacesV1Alpha1(namespaces ...string) InputOptionsV1Alpha1 { return func(selector *telemetryv1alpha1.MetricPipelineInputNamespaceSelector) { selector.Include = namespaces } } -func ExcludeNamespaces(namespaces ...string) InputOptions { +func ExcludeNamespacesV1Alpha1(namespaces ...string) InputOptionsV1Alpha1 { return func(selector *telemetryv1alpha1.MetricPipelineInputNamespaceSelector) { selector.Exclude = namespaces } } -func (p *MetricPipeline) OtlpInput(enable bool, opts ...InputOptions) *MetricPipeline { +func (p *metricPipelineV1Alpha1) OtlpInput(enable bool, opts ...InputOptionsV1Alpha1) *metricPipelineV1Alpha1 { p.otlp = &telemetryv1alpha1.MetricPipelineOtlpInput{ Disabled: !enable, } @@ -88,7 +87,7 @@ func (p *MetricPipeline) OtlpInput(enable bool, opts ...InputOptions) *MetricPip return p } -func (p *MetricPipeline) RuntimeInput(enable bool, opts ...InputOptions) *MetricPipeline { +func (p *metricPipelineV1Alpha1) RuntimeInput(enable bool, opts ...InputOptionsV1Alpha1) *metricPipelineV1Alpha1 { p.runtime = &telemetryv1alpha1.MetricPipelineRuntimeInput{ Enabled: enable, } @@ -104,7 +103,7 @@ func (p *MetricPipeline) RuntimeInput(enable bool, opts ...InputOptions) *Metric return p } -func (p *MetricPipeline) PrometheusInput(enable bool, opts ...InputOptions) *MetricPipeline { +func (p *metricPipelineV1Alpha1) PrometheusInput(enable bool, opts ...InputOptionsV1Alpha1) *metricPipelineV1Alpha1 { p.prometheus = &telemetryv1alpha1.MetricPipelinePrometheusInput{ Enabled: enable, } @@ -120,7 +119,7 @@ func (p *MetricPipeline) PrometheusInput(enable bool, opts ...InputOptions) *Met return p } -func (p *MetricPipeline) IstioInput(enable bool, opts ...InputOptions) *MetricPipeline { +func (p *metricPipelineV1Alpha1) IstioInput(enable bool, opts ...InputOptionsV1Alpha1) *metricPipelineV1Alpha1 { p.istio = &telemetryv1alpha1.MetricPipelineIstioInput{ Enabled: enable, } @@ -136,21 +135,21 @@ func (p *MetricPipeline) IstioInput(enable bool, opts ...InputOptions) *MetricPi return p } -func (p *MetricPipeline) PrometheusInputDiagnosticMetrics(enable bool) *MetricPipeline { +func (p *metricPipelineV1Alpha1) PrometheusInputDiagnosticMetrics(enable bool) *metricPipelineV1Alpha1 { p.prometheus.DiagnosticMetrics = &telemetryv1alpha1.DiagnosticMetrics{ Enabled: enable, } return p } -func (p *MetricPipeline) IstioInputDiagnosticMetrics(enable bool) *MetricPipeline { +func (p *metricPipelineV1Alpha1) IstioInputDiagnosticMetrics(enable bool) *metricPipelineV1Alpha1 { p.istio.DiagnosticMetrics = &telemetryv1alpha1.DiagnosticMetrics{ Enabled: enable, } return p } -func (p *MetricPipeline) WithTLS(certs tls.Certs) *MetricPipeline { +func (p *metricPipelineV1Alpha1) WithTLS(certs tls.Certs) *metricPipelineV1Alpha1 { p.tls = &telemetryv1alpha1.OtlpTLS{ Insecure: false, InsecureSkipVerify: false, @@ -168,17 +167,17 @@ func (p *MetricPipeline) WithTLS(certs tls.Certs) *MetricPipeline { return p } -func (p *MetricPipeline) WithProtocol(protocol string) *MetricPipeline { +func (p *metricPipelineV1Alpha1) WithProtocol(protocol string) *metricPipelineV1Alpha1 { p.protocol = protocol return p } -func (p *MetricPipeline) WithEndpointPath(path string) *MetricPipeline { +func (p *metricPipelineV1Alpha1) WithEndpointPath(path string) *metricPipelineV1Alpha1 { p.endpointPath = path return p } -func (p *MetricPipeline) K8sObject() *telemetryv1alpha1.MetricPipeline { +func (p *metricPipelineV1Alpha1) K8sObject() *telemetryv1alpha1.MetricPipeline { var labels Labels if p.persistent { labels = PersistentLabel diff --git a/test/testkit/k8s/metric_pipeline_v1beta1.go b/test/testkit/k8s/metric_pipeline_v1beta1.go new file mode 100644 index 000000000..ba3416b35 --- /dev/null +++ b/test/testkit/k8s/metric_pipeline_v1beta1.go @@ -0,0 +1,228 @@ +//nolint:dupl //There is duplication between metricPipelineV1Beta1 and metricPipelineV1Alpha1, but we need them as separate builders because they are using different API versions +package k8s + +import ( + "fmt" + + "github.com/google/uuid" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + + telemetryv1beta1 "github.com/kyma-project/telemetry-manager/apis/telemetry/v1beta1" + "github.com/kyma-project/telemetry-manager/test/testkit/mocks/backend/tls" +) + +const version = "1.0.0" + +type metricPipelineV1Beta1 struct { + persistent bool + + id string + name string + otlpEndpointRef *telemetryv1beta1.SecretKeyRef + otlpEndpoint string + runtime *telemetryv1beta1.MetricPipelineRuntimeInput + prometheus *telemetryv1beta1.MetricPipelinePrometheusInput + istio *telemetryv1beta1.MetricPipelineIstioInput + otlp *telemetryv1beta1.MetricPipelineOTLPInput + tls *telemetryv1beta1.OTLPTLS + protocol string + endpointPath string +} + +func NewMetricPipelineV1Beta1(name string) *metricPipelineV1Beta1 { + return &metricPipelineV1Beta1{ + id: uuid.New().String(), + name: name, + otlpEndpoint: "http://unreachable:4317", + } +} + +func (p *metricPipelineV1Beta1) WithOutputEndpoint(otlpEndpoint string) *metricPipelineV1Beta1 { + p.otlpEndpoint = otlpEndpoint + return p +} + +func (p *metricPipelineV1Beta1) WithOutputEndpointFromSecret(otlpEndpointRef *telemetryv1beta1.SecretKeyRef) *metricPipelineV1Beta1 { + p.otlpEndpointRef = otlpEndpointRef + return p +} + +func (p *metricPipelineV1Beta1) Name() string { + if p.persistent { + return p.name + } + return fmt.Sprintf("%s-%s", p.name, p.id) +} + +func (p *metricPipelineV1Beta1) Persistent(persistent bool) *metricPipelineV1Beta1 { + p.persistent = persistent + return p +} + +type InputOptionsV1Beta1 func(selector *telemetryv1beta1.MetricPipelineInputNamespaceSelector) + +func IncludeNamespacesV1Beta1(namespaces ...string) InputOptionsV1Beta1 { + return func(selector *telemetryv1beta1.MetricPipelineInputNamespaceSelector) { + selector.Include = namespaces + } +} + +func ExcludeNamespacesV1Beta1(namespaces ...string) InputOptionsV1Beta1 { + return func(selector *telemetryv1beta1.MetricPipelineInputNamespaceSelector) { + selector.Exclude = namespaces + } +} + +func (p *metricPipelineV1Beta1) OtlpInput(enable bool, opts ...InputOptionsV1Beta1) *metricPipelineV1Beta1 { + p.otlp = &telemetryv1beta1.MetricPipelineOTLPInput{ + Disabled: !enable, + } + + if len(opts) == 0 { + return p + } + + p.otlp.Namespaces = &telemetryv1beta1.MetricPipelineInputNamespaceSelector{} + for _, opt := range opts { + opt(p.otlp.Namespaces) + } + return p +} + +func (p *metricPipelineV1Beta1) RuntimeInput(enable bool, opts ...InputOptionsV1Beta1) *metricPipelineV1Beta1 { + p.runtime = &telemetryv1beta1.MetricPipelineRuntimeInput{ + Enabled: enable, + } + + if len(opts) == 0 { + return p + } + + p.runtime.Namespaces = &telemetryv1beta1.MetricPipelineInputNamespaceSelector{} + for _, opt := range opts { + opt(p.runtime.Namespaces) + } + return p +} + +func (p *metricPipelineV1Beta1) PrometheusInput(enable bool, opts ...InputOptionsV1Beta1) *metricPipelineV1Beta1 { + p.prometheus = &telemetryv1beta1.MetricPipelinePrometheusInput{ + Enabled: enable, + } + + if len(opts) == 0 { + return p + } + + p.prometheus.Namespaces = &telemetryv1beta1.MetricPipelineInputNamespaceSelector{} + for _, opt := range opts { + opt(p.prometheus.Namespaces) + } + return p +} + +func (p *metricPipelineV1Beta1) IstioInput(enable bool, opts ...InputOptionsV1Beta1) *metricPipelineV1Beta1 { + p.istio = &telemetryv1beta1.MetricPipelineIstioInput{ + Enabled: enable, + } + + if len(opts) == 0 { + return p + } + + p.istio.Namespaces = &telemetryv1beta1.MetricPipelineInputNamespaceSelector{} + for _, opt := range opts { + opt(p.istio.Namespaces) + } + return p +} + +func (p *metricPipelineV1Beta1) PrometheusInputDiagnosticMetrics(enable bool) *metricPipelineV1Beta1 { + p.prometheus.DiagnosticMetrics = &telemetryv1beta1.DiagnosticMetrics{ + Enabled: enable, + } + return p +} + +func (p *metricPipelineV1Beta1) IstioInputDiagnosticMetrics(enable bool) *metricPipelineV1Beta1 { + p.istio.DiagnosticMetrics = &telemetryv1beta1.DiagnosticMetrics{ + Enabled: enable, + } + return p +} + +func (p *metricPipelineV1Beta1) WithTLS(certs tls.Certs) *metricPipelineV1Beta1 { + p.tls = &telemetryv1beta1.OTLPTLS{ + Insecure: false, + InsecureSkipVerify: false, + CA: &telemetryv1beta1.ValueType{ + Value: certs.CaCertPem.String(), + }, + Cert: &telemetryv1beta1.ValueType{ + Value: certs.ClientCertPem.String(), + }, + Key: &telemetryv1beta1.ValueType{ + Value: certs.ClientKeyPem.String(), + }, + } + + return p +} + +func (p *metricPipelineV1Beta1) WithProtocol(protocol string) *metricPipelineV1Beta1 { + p.protocol = protocol + return p +} + +func (p *metricPipelineV1Beta1) WithEndpointPath(path string) *metricPipelineV1Beta1 { + p.endpointPath = path + return p +} + +func (p *metricPipelineV1Beta1) K8sObject() *telemetryv1beta1.MetricPipeline { + var labels Labels + if p.persistent { + labels = PersistentLabel + } + labels.Version(version) + + otlpOutput := &telemetryv1beta1.OTLPOutput{ + Endpoint: telemetryv1beta1.ValueType{}, + TLS: p.tls, + } + if p.otlpEndpointRef != nil { + otlpOutput.Endpoint.ValueFrom = &telemetryv1beta1.ValueFromSource{ + SecretKeyRef: p.otlpEndpointRef, + } + } else { + otlpOutput.Endpoint.Value = p.otlpEndpoint + } + + if len(p.protocol) > 0 { + otlpOutput.Protocol = p.protocol + } + + if len(p.endpointPath) > 0 { + otlpOutput.Path = p.endpointPath + } + + metricPipeline := telemetryv1beta1.MetricPipeline{ + ObjectMeta: metav1.ObjectMeta{ + Name: p.Name(), + Labels: labels, + }, + Spec: telemetryv1beta1.MetricPipelineSpec{ + Input: telemetryv1beta1.MetricPipelineInput{ + OTLP: p.otlp, + Runtime: p.runtime, + Prometheus: p.prometheus, + Istio: p.istio, + }, + Output: telemetryv1beta1.MetricPipelineOutput{ + OTLP: otlpOutput, + }, + }, + } + + return &metricPipeline +} diff --git a/test/testkit/k8s/secret.go b/test/testkit/k8s/secret.go index bed54f5c5..50c843a11 100644 --- a/test/testkit/k8s/secret.go +++ b/test/testkit/k8s/secret.go @@ -6,6 +6,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" telemetryv1alpha1 "github.com/kyma-project/telemetry-manager/apis/telemetry/v1alpha1" + telemetryv1beta1 "github.com/kyma-project/telemetry-manager/apis/telemetry/v1beta1" "github.com/kyma-project/telemetry-manager/test/testkit" ) @@ -45,7 +46,7 @@ func (s *Secret) K8sObject() *corev1.Secret { } } -func (s *Secret) SecretKeyRef(key string) *telemetryv1alpha1.SecretKeyRef { +func (s *Secret) SecretKeyRefV1Alpha1(key string) *telemetryv1alpha1.SecretKeyRef { return &telemetryv1alpha1.SecretKeyRef{ Name: s.name, Namespace: s.namespace, @@ -53,6 +54,14 @@ func (s *Secret) SecretKeyRef(key string) *telemetryv1alpha1.SecretKeyRef { } } +func (s *Secret) SecretKeyRefV1Beta1(key string) *telemetryv1beta1.SecretKeyRef { + return &telemetryv1beta1.SecretKeyRef{ + Name: s.name, + Namespace: s.namespace, + Key: key, + } +} + func (s *Secret) Persistent(p bool) *Secret { s.persistent = p diff --git a/test/testkit/k8s/trace_pipeline.go b/test/testkit/k8s/trace_pipeline_v1alpha1.go similarity index 67% rename from test/testkit/k8s/trace_pipeline.go rename to test/testkit/k8s/trace_pipeline_v1alpha1.go index d1d16d4bd..a95a32b16 100644 --- a/test/testkit/k8s/trace_pipeline.go +++ b/test/testkit/k8s/trace_pipeline_v1alpha1.go @@ -1,3 +1,4 @@ +//nolint:dupl //There is duplication between tracePipelineV1Beta1 and tracePipelineV1Alpha1, but we need them as separate builders because they are using different API versions package k8s import ( @@ -10,7 +11,7 @@ import ( "github.com/kyma-project/telemetry-manager/test/testkit/mocks/backend/tls" ) -type TracePipeline struct { +type tracePipelineV1Alpha1 struct { persistent bool id string @@ -22,25 +23,25 @@ type TracePipeline struct { endpointPath string } -func NewTracePipeline(name string) *TracePipeline { - return &TracePipeline{ +func NewTracePipelineV1Alpha1(name string) *tracePipelineV1Alpha1 { + return &tracePipelineV1Alpha1{ id: uuid.New().String(), name: name, otlpEndpoint: "http://unreachable:4317", } } -func (p *TracePipeline) WithOutputEndpoint(otlpEndpoint string) *TracePipeline { +func (p *tracePipelineV1Alpha1) WithOutputEndpoint(otlpEndpoint string) *tracePipelineV1Alpha1 { p.otlpEndpoint = otlpEndpoint return p } -func (p *TracePipeline) WithOutputEndpointFromSecret(otlpEndpointRef *telemetryv1alpha1.SecretKeyRef) *TracePipeline { +func (p *tracePipelineV1Alpha1) WithOutputEndpointFromSecret(otlpEndpointRef *telemetryv1alpha1.SecretKeyRef) *tracePipelineV1Alpha1 { p.otlpEndpointRef = otlpEndpointRef return p } -func (p *TracePipeline) WithTLS(certs tls.Certs) *TracePipeline { +func (p *tracePipelineV1Alpha1) WithTLS(certs tls.Certs) *tracePipelineV1Alpha1 { p.tls = &telemetryv1alpha1.OtlpTLS{ Insecure: false, InsecureSkipVerify: false, @@ -58,7 +59,7 @@ func (p *TracePipeline) WithTLS(certs tls.Certs) *TracePipeline { return p } -func (p *TracePipeline) Name() string { +func (p *tracePipelineV1Alpha1) Name() string { if p.persistent { return p.name } @@ -66,23 +67,23 @@ func (p *TracePipeline) Name() string { return fmt.Sprintf("%s-%s", p.name, p.id) } -func (p *TracePipeline) Persistent(persistent bool) *TracePipeline { +func (p *tracePipelineV1Alpha1) Persistent(persistent bool) *tracePipelineV1Alpha1 { p.persistent = persistent return p } -func (p *TracePipeline) WithProtocol(protocol string) *TracePipeline { +func (p *tracePipelineV1Alpha1) WithProtocol(protocol string) *tracePipelineV1Alpha1 { p.protocol = protocol return p } -func (p *TracePipeline) WithEndpointPath(path string) *TracePipeline { +func (p *tracePipelineV1Alpha1) WithEndpointPath(path string) *tracePipelineV1Alpha1 { p.endpointPath = path return p } -func (p *TracePipeline) K8sObject() *telemetryv1alpha1.TracePipeline { +func (p *tracePipelineV1Alpha1) K8sObject() *telemetryv1alpha1.TracePipeline { var labels Labels if p.persistent { labels = PersistentLabel diff --git a/test/testkit/k8s/trace_pipeline_v1beta1.go b/test/testkit/k8s/trace_pipeline_v1beta1.go new file mode 100644 index 000000000..e644000db --- /dev/null +++ b/test/testkit/k8s/trace_pipeline_v1beta1.go @@ -0,0 +1,126 @@ +//nolint:dupl //There is duplication between tracePipelineV1Beta1 and tracePipelineV1Alpha1, but we need them as separate builders because they are using different API versions +package k8s + +import ( + "fmt" + + "github.com/google/uuid" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + + telemetryv1beta1 "github.com/kyma-project/telemetry-manager/apis/telemetry/v1beta1" + "github.com/kyma-project/telemetry-manager/test/testkit/mocks/backend/tls" +) + +type tracePipelineV1Beta1 struct { + persistent bool + + id string + name string + otlpEndpointRef *telemetryv1beta1.SecretKeyRef + otlpEndpoint string + tls *telemetryv1beta1.OTLPTLS + protocol string + endpointPath string +} + +func NewTracePipelineV1Beta1(name string) *tracePipelineV1Beta1 { + return &tracePipelineV1Beta1{ + id: uuid.New().String(), + name: name, + otlpEndpoint: "http://unreachable:4317", + } +} + +func (p *tracePipelineV1Beta1) WithOutputEndpoint(otlpEndpoint string) *tracePipelineV1Beta1 { + p.otlpEndpoint = otlpEndpoint + return p +} + +func (p *tracePipelineV1Beta1) WithOutputEndpointFromSecret(otlpEndpointRef *telemetryv1beta1.SecretKeyRef) *tracePipelineV1Beta1 { + p.otlpEndpointRef = otlpEndpointRef + return p +} + +func (p *tracePipelineV1Beta1) WithTLS(certs tls.Certs) *tracePipelineV1Beta1 { + p.tls = &telemetryv1beta1.OTLPTLS{ + Insecure: false, + InsecureSkipVerify: false, + CA: &telemetryv1beta1.ValueType{ + Value: certs.CaCertPem.String(), + }, + Cert: &telemetryv1beta1.ValueType{ + Value: certs.ClientCertPem.String(), + }, + Key: &telemetryv1beta1.ValueType{ + Value: certs.ClientKeyPem.String(), + }, + } + + return p +} + +func (p *tracePipelineV1Beta1) Name() string { + if p.persistent { + return p.name + } + + return fmt.Sprintf("%s-%s", p.name, p.id) +} + +func (p *tracePipelineV1Beta1) Persistent(persistent bool) *tracePipelineV1Beta1 { + p.persistent = persistent + + return p +} + +func (p *tracePipelineV1Beta1) WithProtocol(protocol string) *tracePipelineV1Beta1 { + p.protocol = protocol + return p +} + +func (p *tracePipelineV1Beta1) WithEndpointPath(path string) *tracePipelineV1Beta1 { + p.endpointPath = path + return p +} + +func (p *tracePipelineV1Beta1) K8sObject() *telemetryv1beta1.TracePipeline { + var labels Labels + if p.persistent { + labels = PersistentLabel + } + labels.Version(version) + + otlpOutput := &telemetryv1beta1.OTLPOutput{ + Endpoint: telemetryv1beta1.ValueType{}, + TLS: p.tls, + } + if p.otlpEndpointRef != nil { + otlpOutput.Endpoint.ValueFrom = &telemetryv1beta1.ValueFromSource{ + SecretKeyRef: p.otlpEndpointRef, + } + } else { + otlpOutput.Endpoint.Value = p.otlpEndpoint + } + + if len(p.protocol) > 0 { + otlpOutput.Protocol = p.protocol + } + + if len(p.endpointPath) > 0 { + otlpOutput.Path = p.endpointPath + } + + pipeline := telemetryv1beta1.TracePipeline{ + ObjectMeta: metav1.ObjectMeta{ + Name: p.Name(), + Labels: labels, + }, + Spec: telemetryv1beta1.TracePipelineSpec{ + Output: telemetryv1beta1.TracePipelineOutput{ + OTLP: otlpOutput, + }, + }, + } + + return &pipeline +} diff --git a/test/testkit/mocks/backend/backend.go b/test/testkit/mocks/backend/backend.go index 0b3d93c64..fa06d4bbe 100644 --- a/test/testkit/mocks/backend/backend.go +++ b/test/testkit/mocks/backend/backend.go @@ -8,6 +8,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" telemetryv1alpha1 "github.com/kyma-project/telemetry-manager/apis/telemetry/v1alpha1" + telemetryv1beta1 "github.com/kyma-project/telemetry-manager/apis/telemetry/v1beta1" "github.com/kyma-project/telemetry-manager/test/testkit/apiserverproxy" kitk8s "github.com/kyma-project/telemetry-manager/test/testkit/k8s" "github.com/kyma-project/telemetry-manager/test/testkit/mocks/backend/fluentd" @@ -108,8 +109,12 @@ func (b *Backend) Name() string { return b.name } -func (b *Backend) HostSecretRef() *telemetryv1alpha1.SecretKeyRef { - return b.HostSecret.SecretKeyRef("host") +func (b *Backend) HostSecretRefV1Alpha1() *telemetryv1alpha1.SecretKeyRef { + return b.HostSecret.SecretKeyRefV1Alpha1("host") +} + +func (b *Backend) HostSecretRefV1Beta1() *telemetryv1beta1.SecretKeyRef { + return b.HostSecret.SecretKeyRefV1Beta1("host") } func (b *Backend) TelemetryExportURL(proxyClient *apiserverproxy.Client) string {