diff --git a/internal/collectors/otelcolresources/collector_config_maps.go b/internal/collectors/otelcolresources/collector_config_maps.go index 9ad559f2..50b1b987 100644 --- a/internal/collectors/otelcolresources/collector_config_maps.go +++ b/internal/collectors/otelcolresources/collector_config_maps.go @@ -72,7 +72,8 @@ func (ct *customTransforms) HasLogTransforms() bool { } type collectorConfigurationTemplateValues struct { - Exporters []OtlpExporter + ExportersDefault []OtlpExporter + ExportersRouted []OtlpExporter SendBatchMaxSize *uint32 KubernetesInfrastructureMetricsCollectionEnabled bool CollectPodLabelsAndAnnotationsEnabled bool @@ -183,7 +184,7 @@ func assembleCollectorConfigMap( if forDeletion { configMapData = map[string]string{} } else { - exporters, err := ConvertExportSettingsToExporterList(config.Export) + exporterMap, err := ConvertExportSettingsToExporterMap(config.Export) if err != nil { return nil, fmt.Errorf("%s %w", commonExportErrorPrefix, err) } @@ -208,7 +209,8 @@ func assembleCollectorConfigMap( collectorConfiguration, err := renderCollectorConfiguration(template, &collectorConfigurationTemplateValues{ - Exporters: exporters, + ExportersDefault: exporterMap["default"], + ExportersRouted: exporterMap["routed"], SendBatchMaxSize: config.SendBatchMaxSize, KubernetesInfrastructureMetricsCollectionEnabled: config.KubernetesInfrastructureMetricsCollectionEnabled, CollectPodLabelsAndAnnotationsEnabled: config.CollectPodLabelsAndAnnotationsEnabled, @@ -432,8 +434,9 @@ func compareErrorMode( return errorMode1 } -func ConvertExportSettingsToExporterList(export dash0common.Export) ([]OtlpExporter, error) { - var exporters []OtlpExporter +func ConvertExportSettingsToExporterMap(export dash0common.Export) (map[string][]OtlpExporter, error) { + exporterMap := make(map[string][]OtlpExporter) + exporterMap["default"] = []OtlpExporter{} if export.Dash0 == nil && export.Grpc == nil && export.Http == nil { return nil, fmt.Errorf("%s no exporter configuration found", commonExportErrorPrefix) @@ -454,13 +457,26 @@ func ConvertExportSettingsToExporterList(export dash0common.Export) ([]OtlpExpor Value: d0.Dataset, }) } - dash0Exporter := OtlpExporter{ - Name: "otlp/dash0", + dash0ExporterDefault := OtlpExporter{ + Name: "otlp/dash0/_default", Endpoint: export.Dash0.Endpoint, Headers: headers, } - setGrpcTlsFromPrefix(export.Dash0.Endpoint, &dash0Exporter) - exporters = append(exporters, dash0Exporter) + setGrpcTlsFromPrefix(export.Dash0.Endpoint, &dash0ExporterDefault) + exporterMap["default"] = append(exporterMap["default"], dash0ExporterDefault) + + headersRouted := headers + headersRouted = append(headersRouted, dash0common.Header{ + Name: util.Dash0DatasetHeaderName, + Value: "routed", + }) + dash0ExporterForRoutedNamespace := OtlpExporter{ + Name: "otlp/dash0/routed-namespace", + Endpoint: export.Dash0.Endpoint, + Headers: headersRouted, + } + setGrpcTlsFromPrefix(export.Dash0.Endpoint, &dash0ExporterForRoutedNamespace) + exporterMap["routed"] = []OtlpExporter{dash0ExporterForRoutedNamespace} } if export.Grpc != nil { @@ -482,7 +498,7 @@ func ConvertExportSettingsToExporterList(export dash0common.Export) ([]OtlpExpor if len(grpc.Headers) > 0 { grpcExporter.Headers = grpc.Headers } - exporters = append(exporters, grpcExporter) + exporterMap["default"] = append(exporterMap["default"], grpcExporter) } if export.Http != nil { @@ -503,10 +519,10 @@ func ConvertExportSettingsToExporterList(export dash0common.Export) ([]OtlpExpor if len(http.Headers) > 0 { httpExporter.Headers = http.Headers } - exporters = append(exporters, httpExporter) + exporterMap["default"] = append(exporterMap["default"], httpExporter) } - return exporters, nil + return exporterMap, nil } func renderCollectorConfiguration( diff --git a/internal/collectors/otelcolresources/daemonset.config.yaml.template b/internal/collectors/otelcolresources/daemonset.config.yaml.template index d0c02106..ba51bac6 100644 --- a/internal/collectors/otelcolresources/daemonset.config.yaml.template +++ b/internal/collectors/otelcolresources/daemonset.config.yaml.template @@ -28,6 +28,34 @@ connectors: forward/metrics/prometheus: {} forward/logs: {} + routing/traces: +{{- if .ExportersDefault }} + default_pipelines: [traces/export/_default] +{{- end }} + error_mode: ignore + table: + - context: resource + condition: attributes["k8s.namespace.name"] == "routed-namespace" + pipelines: [traces/export/routed-namespace] + routing/metrics: +{{- if .ExportersDefault }} + default_pipelines: [metrics/export/_default] +{{- end }} + error_mode: ignore + table: + - context: resource + condition: attributes["k8s.namespace.name"] == "routed-namespace" + pipelines: [metrics/export/routed-namespace] + routing/logs: +{{- if .ExportersDefault }} + default_pipelines: [logs/export/_default] +{{- end }} + error_mode: ignore + table: + - context: resource + condition: attributes["k8s.namespace.name"] == "routed-namespace" + pipelines: [logs/export/routed-namespace] + receivers: otlp: @@ -634,7 +662,24 @@ exporters: {{ else if .DevelopmentMode }} debug: {} {{- end }} -{{- range $i, $exporter := .Exporters }} +{{- range $i, $exporter := .ExportersDefault }} + {{ $exporter.Name }}: + endpoint: "{{ $exporter.Endpoint }}" +{{- if $exporter.Insecure }} + tls: + insecure: true +{{ end }} +{{- if $exporter.Headers }} + headers: +{{- range $i, $header := $exporter.Headers }} + "{{ $header.Name }}": "{{ $header.Value }}" +{{- end }} +{{- end }} +{{- if $exporter.Encoding }} + encoding: "{{ $exporter.Encoding }}" +{{- end }} +{{- end }} +{{- range $i, $exporter := .ExportersRouted }} {{ $exporter.Name }}: endpoint: "{{ $exporter.Endpoint }}" {{- if $exporter.Insecure }} @@ -661,7 +706,8 @@ service: - health_check - file_storage/filelogreceiver_offsets pipelines: - traces/downstream: + + traces: receivers: - otlp processors: @@ -680,10 +726,29 @@ service: - memory_limiter - batch exporters: + - routing/traces + + {{- if .ExportersDefault }} + traces/export/_default: + receivers: + - routing/traces + exporters: + {{- if (or .DevelopmentMode .DebugVerbosityDetailed) }} + - debug + {{- end }} + {{- range $i, $exporter := .ExportersDefault }} + - {{ $exporter.Name }} + {{- end }} + {{- end }} + + traces/export/routed-namespace: + receivers: + - routing/traces + exporters: {{- if (or .DevelopmentMode .DebugVerbosityDetailed) }} - debug {{- end }} - {{- range $i, $exporter := .Exporters }} + {{- range $i, $exporter := .ExportersRouted }} - {{ $exporter.Name }} {{- end }} @@ -697,7 +762,7 @@ service: - forward/metrics/prometheus {{- end }} - metrics/downstream: + metrics: receivers: - otlp {{- if .KubeletStatsReceiverConfig.Enabled }} @@ -728,10 +793,29 @@ service: - memory_limiter - batch exporters: + - routing/metrics + + {{- if .ExportersDefault }} + metrics/export/_default: + receivers: + - routing/metrics + exporters: {{- if (or .DevelopmentMode .DebugVerbosityDetailed) }} - debug {{- end }} - {{- range $i, $exporter := .Exporters }} + {{- range $i, $exporter := .ExportersDefault }} + - {{ $exporter.Name }} + {{- end }} + {{- end }} + + metrics/export/routed-namespace: + receivers: + - routing/metrics + exporters: + {{- if (or .DevelopmentMode .DebugVerbosityDetailed) }} + - debug + {{- end }} + {{- range $i, $exporter := .ExportersRouted }} - {{ $exporter.Name }} {{- end }} @@ -754,7 +838,7 @@ service: - forward/logs {{- end }} - logs/downstream: + logs: receivers: - forward/logs processors: @@ -772,10 +856,29 @@ service: - memory_limiter - batch exporters: + - routing/logs + + {{- if .ExportersDefault }} + logs/export/_default: + receivers: + - routing/logs + exporters: + {{- if (or .DevelopmentMode .DebugVerbosityDetailed) }} + - debug + {{- end }} + {{- range $i, $exporter := .ExportersDefault }} + - {{ $exporter.Name }} + {{- end }} + {{- end }} + + logs/export/routed-namespace: + receivers: + - routing/logs + exporters: {{- if (or .DevelopmentMode .DebugVerbosityDetailed) }} - debug {{- end }} - {{- range $i, $exporter := .Exporters }} + {{- range $i, $exporter := .ExportersRouted }} - {{ $exporter.Name }} {{- end }} diff --git a/internal/collectors/otelcolresources/deployment.config.yaml.template b/internal/collectors/otelcolresources/deployment.config.yaml.template index 17908643..5befdb9a 100644 --- a/internal/collectors/otelcolresources/deployment.config.yaml.template +++ b/internal/collectors/otelcolresources/deployment.config.yaml.template @@ -164,7 +164,7 @@ exporters: {{ else if .DevelopmentMode }} debug: {} {{- end }} -{{- range $i, $exporter := .Exporters }} +{{- range $i, $exporter := .ExportersDefault }} {{ $exporter.Name }}: endpoint: "{{ $exporter.Endpoint }}" {{- if $exporter.Insecure }} @@ -217,7 +217,7 @@ service: {{- if (or .DevelopmentMode .DebugVerbosityDetailed) }} - debug {{- end }} - {{- range $i, $exporter := .Exporters }} + {{- range $i, $exporter := .ExportersDefault }} - {{ $exporter.Name }} {{- end }} diff --git a/test-resources/bin/lib/util b/test-resources/bin/lib/util index d1e42a8f..8575c0c1 100644 --- a/test-resources/bin/lib/util +++ b/test-resources/bin/lib/util @@ -619,12 +619,17 @@ install_monitoring_resource() { if [[ "$additional_namespaces" = "true" ]]; then kubectl apply -n test-namespace-2 -f test-resources/customresources/dash0monitoring/dash0monitoring-2.yaml kubectl apply -n test-namespace-3 -f test-resources/customresources/dash0monitoring/dash0monitoring-3.yaml + # TODO remove later + kubectl apply -n routed-namespace -f test-resources/customresources/dash0monitoring/dash0monitoring.yaml fi echo "waiting for the monitoring resource to become available" kubectl wait --namespace ${target_namespace} dash0monitorings.operator.dash0.com/dash0-monitoring-resource --for condition=Available if [[ "$additional_namespaces" = "true" ]]; then kubectl wait --namespace test-namespace-2 dash0monitorings.operator.dash0.com/dash0-monitoring-resource --for condition=Available + kubectl wait --namespace test-namespace-3 dash0monitorings.operator.dash0.com/dash0-monitoring-resource --for condition=Available + # TODO remove later + kubectl wait --namespace routed-namespace dash0monitorings.operator.dash0.com/dash0-monitoring-resource --for condition=Available fi } @@ -667,6 +672,16 @@ deploy_application_under_monitoring() { "$test_app_nodejs_image_tag" \ "$test_app_nodejs_image_pull_policy" \ "$extraValues" + # TODO remove later + helm_install_test_application \ + test-resources/node.js/express/dash0-operator-test-app-nodejs \ + test-app-nodejs-routed \ + routed-namespace \ + replicaset \ + "$test_app_nodejs_image_repository" \ + "$test_app_nodejs_image_tag" \ + "$test_app_nodejs_image_pull_policy" \ + "$extraValues" fi elif [[ "${runtime_under_test:-}" = "jvm" ]]; then build_test_application test-app-image-jvm @@ -699,6 +714,16 @@ deploy_application_under_monitoring() { "$test_app_jvm_image_tag" \ "$test_app_jvm_image_pull_policy" \ "$extraValues" + # TODO remove later + helm_install_test_application \ + "test-resources/jvm/spring-boot/dash0-operator-test-app-jvm" \ + "test-app-jvm-routed" \ + "routed-namespace" \ + "replicaset" \ + "$test_app_jvm_image_repository" \ + "$test_app_jvm_image_tag" \ + "$test_app_jvm_image_pull_policy" \ + "$extraValues" fi elif [[ "${runtime_under_test:-}" = "dotnet" ]]; then build_test_application test-app-image-dotnet @@ -731,6 +756,16 @@ deploy_application_under_monitoring() { "$test_app_dotnet_image_tag" \ "$test_app_dotnet_image_pull_policy" \ "$extraValues" + # TODO remove later + helm_install_test_application \ + "test-resources/dotnet/dash0-operator-test-app-dotnet" \ + "test-app-dotnet-routed" \ + "routed-namespace" \ + "replicaset" \ + "$test_app_dotnet_image_repository" \ + "$test_app_dotnet_image_tag" \ + "$test_app_dotnet_image_pull_policy" \ + "$extraValues" fi elif [[ "${runtime_under_test:-}" = "python" ]]; then build_test_application test-app-image-python @@ -763,6 +798,16 @@ deploy_application_under_monitoring() { "$test_app_python_image_tag" \ "$test_app_python_image_pull_policy" \ "$extraValues" + # TODO remove later + helm_install_test_application \ + "test-resources/python/flask/dash0-operator-test-app-python" \ + "test-app-python-routed" \ + "routed-namespace" \ + "replicaset" \ + "$test_app_python_image_repository" \ + "$test_app_python_image_tag" \ + "$test_app_python_image_pull_policy" \ + "$extraValues" fi else echo "Error: unknown runtime: $runtime_under_test" diff --git a/test-resources/bin/test-cleanup.sh b/test-resources/bin/test-cleanup.sh index fac5b499..7f43940d 100755 --- a/test-resources/bin/test-cleanup.sh +++ b/test-resources/bin/test-cleanup.sh @@ -64,6 +64,7 @@ helm uninstall --namespace "$target_namespace" prometheus-crds --ignore-not-foun kubectl delete -n "$target_namespace" -f test-resources/customresources/dash0monitoring/dash0monitoring.yaml --wait=false || true kubectl delete -n test-namespace-2 -f test-resources/customresources/dash0monitoring/dash0monitoring.yaml --wait=false || true kubectl delete -n test-namespace-3 -f test-resources/customresources/dash0monitoring/dash0monitoring.yaml --wait=false || true +kubectl delete -n routed-namespace -f test-resources/customresources/dash0monitoring/dash0monitoring.yaml --wait=false || true sleep 1 # If the cluster is in a bad state because an operator image has been deployed that terminates abruptly, the monitoring # resource's finalizer will block the deletion of the monitoring resource, and thus also the deletion of the @@ -86,6 +87,7 @@ fi if [[ "${delete_namespaces}" = "true" ]]; then kubectl delete ns test-namespace-2 --ignore-not-found kubectl delete ns test-namespace-3 --ignore-not-found + kubectl delete ns routed-namespace --ignore-not-found fi helm uninstall --namespace "$operator_namespace" dash0-operator --timeout 30s || true diff --git a/test-resources/bin/test-scenario-01-aum-operator-cr.sh b/test-resources/bin/test-scenario-01-aum-operator-cr.sh index 87d57f63..fda15e8e 100755 --- a/test-resources/bin/test-scenario-01-aum-operator-cr.sh +++ b/test-resources/bin/test-scenario-01-aum-operator-cr.sh @@ -38,6 +38,7 @@ ensure_namespace_exists "${target_namespace}" if [[ "$additional_namespaces" = "true" ]]; then ensure_namespace_exists test-namespace-2 ensure_namespace_exists test-namespace-3 + ensure_namespace_exists routed-namespace fi finish_step diff --git a/test-resources/bin/test-scenario-02-operator-cr-aum.sh b/test-resources/bin/test-scenario-02-operator-cr-aum.sh index 61097397..3995817c 100755 --- a/test-resources/bin/test-scenario-02-operator-cr-aum.sh +++ b/test-resources/bin/test-scenario-02-operator-cr-aum.sh @@ -38,6 +38,7 @@ ensure_namespace_exists "${target_namespace}" if [[ "$additional_namespaces" = "true" ]]; then ensure_namespace_exists test-namespace-2 ensure_namespace_exists test-namespace-3 + ensure_namespace_exists routed-namespace fi finish_step diff --git a/test-resources/bin/util b/test-resources/bin/util new file mode 100644 index 00000000..e69de29b