Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 28 additions & 12 deletions internal/collectors/otelcolresources/collector_config_maps.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@
}

type collectorConfigurationTemplateValues struct {
Exporters []OtlpExporter
ExportersDefault []OtlpExporter
ExportersRouted []OtlpExporter
SendBatchMaxSize *uint32
KubernetesInfrastructureMetricsCollectionEnabled bool
CollectPodLabelsAndAnnotationsEnabled bool
Expand Down Expand Up @@ -183,7 +184,7 @@
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)
}
Expand All @@ -208,7 +209,8 @@

collectorConfiguration, err := renderCollectorConfiguration(template,
&collectorConfigurationTemplateValues{
Exporters: exporters,
ExportersDefault: exporterMap["default"],
ExportersRouted: exporterMap["routed"],
SendBatchMaxSize: config.SendBatchMaxSize,
KubernetesInfrastructureMetricsCollectionEnabled: config.KubernetesInfrastructureMetricsCollectionEnabled,
CollectPodLabelsAndAnnotationsEnabled: config.CollectPodLabelsAndAnnotationsEnabled,
Expand Down Expand Up @@ -432,8 +434,9 @@
return errorMode1
}

func ConvertExportSettingsToExporterList(export dash0common.Export) ([]OtlpExporter, error) {
var exporters []OtlpExporter
func ConvertExportSettingsToExporterMap(export dash0common.Export) (map[string][]OtlpExporter, error) {

Check failure on line 437 in internal/collectors/otelcolresources/collector_config_maps.go

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor this method to reduce its Cognitive Complexity from 23 to the 15 allowed.

See more on https://sonarcloud.io/project/issues?id=dash0hq_dash0-operator&issues=AZrPCXjK73gg9spo__z4&open=AZrPCXjK73gg9spo__z4&pullRequest=469
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)
Expand All @@ -454,13 +457,26 @@
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 {
Expand All @@ -482,7 +498,7 @@
if len(grpc.Headers) > 0 {
grpcExporter.Headers = grpc.Headers
}
exporters = append(exporters, grpcExporter)
exporterMap["default"] = append(exporterMap["default"], grpcExporter)
}

if export.Http != nil {
Expand All @@ -503,10 +519,10 @@
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(
Expand Down
117 changes: 110 additions & 7 deletions internal/collectors/otelcolresources/daemonset.config.yaml.template
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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 }}
Expand All @@ -661,7 +706,8 @@ service:
- health_check
- file_storage/filelogreceiver_offsets
pipelines:
traces/downstream:

traces:
receivers:
- otlp
processors:
Expand All @@ -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 }}

Expand All @@ -697,7 +762,7 @@ service:
- forward/metrics/prometheus
{{- end }}

metrics/downstream:
metrics:
receivers:
- otlp
{{- if .KubeletStatsReceiverConfig.Enabled }}
Expand Down Expand Up @@ -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 }}

Expand All @@ -754,7 +838,7 @@ service:
- forward/logs
{{- end }}

logs/downstream:
logs:
receivers:
- forward/logs
processors:
Expand All @@ -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 }}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down Expand Up @@ -217,7 +217,7 @@ service:
{{- if (or .DevelopmentMode .DebugVerbosityDetailed) }}
- debug
{{- end }}
{{- range $i, $exporter := .Exporters }}
{{- range $i, $exporter := .ExportersDefault }}
- {{ $exporter.Name }}
{{- end }}

Expand Down
45 changes: 45 additions & 0 deletions test-resources/bin/lib/util
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down
2 changes: 2 additions & 0 deletions test-resources/bin/test-cleanup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Loading