diff --git a/Makefile b/Makefile index 6a7f3d0d..a278b71d 100644 --- a/Makefile +++ b/Makefile @@ -191,7 +191,7 @@ $(CONTROLLER_GEN): $(LOCALBIN) GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION) -ENVTEST_OTEL_OPERATOR_VERSION=v0.94.0 +ENVTEST_OTEL_OPERATOR_VERSION=v0.96.0 # Download CRDs for envtest crddir/github.com/open-telemetry/opentelemetry-operator: git clone --depth 1 --branch ${ENVTEST_OTEL_OPERATOR_VERSION} https://github.com/open-telemetry/opentelemetry-operator.git crddir/github.com/open-telemetry/opentelemetry-operator diff --git a/internal/controller/telemetry/collector_controller.go b/internal/controller/telemetry/collector_controller.go index 6b2f368b..1c51a8f9 100644 --- a/internal/controller/telemetry/collector_controller.go +++ b/internal/controller/telemetry/collector_controller.go @@ -143,7 +143,7 @@ func (r *CollectorReconciler) Reconcile(ctx context.Context, req ctrl.Request) ( return ctrl.Result{}, err } - otelConfig, err := otelConfigInput.ToIntermediateRepresentation().ToYAML() + otelConfig, err := otelConfigInput.ToIntermediateRepresentation(ctx).ToYAML() if err != nil { return ctrl.Result{}, err } diff --git a/internal/controller/telemetry/otel_conf_gen.go b/internal/controller/telemetry/otel_conf_gen.go index 929aa619..44a6ccf5 100644 --- a/internal/controller/telemetry/otel_conf_gen.go +++ b/internal/controller/telemetry/otel_conf_gen.go @@ -15,12 +15,15 @@ package telemetry import ( + "context" + "errors" "fmt" "slices" "strings" "golang.org/x/exp/maps" "gopkg.in/yaml.v3" + "sigs.k8s.io/controller-runtime/pkg/log" "github.com/kube-logging/telemetry-controller/api/telemetry/v1alpha1" ) @@ -99,19 +102,20 @@ type OtelColConfigIR struct { Services Services `yaml:"service,omitempty"` } -func (cfgInput *OtelColConfigInput) generateExporters() map[string]any { +func (cfgInput *OtelColConfigInput) generateExporters(ctx context.Context) map[string]any { exporters := map[string]any{} // TODO: add proper error handling - maps.Copy(exporters, cfgInput.generateOTLPExporters()) - maps.Copy(exporters, cfgInput.generateLokiExporters()) + maps.Copy(exporters, cfgInput.generateOTLPExporters(ctx)) + maps.Copy(exporters, cfgInput.generateLokiExporters(ctx)) exporters["logging/debug"] = map[string]any{ "verbosity": "detailed", } return exporters } -func (cfgInput *OtelColConfigInput) generateOTLPExporters() map[string]any { +func (cfgInput *OtelColConfigInput) generateOTLPExporters(ctx context.Context) map[string]any { + logger := log.FromContext(ctx) var result = make(map[string]any) for _, output := range cfgInput.Outputs { @@ -119,11 +123,11 @@ func (cfgInput *OtelColConfigInput) generateOTLPExporters() map[string]any { name := fmt.Sprintf("otlp/%s_%s", output.Namespace, output.Name) otlpGrpcValuesMarshaled, err := yaml.Marshal(output.Spec.OTLP) if err != nil { - panic(fmt.Errorf("failed to compile config for output %q", output.NamespacedName().String())) + logger.Error(errors.New("failed to compile config for output"), "failed to compile config for output %q", output.NamespacedName().String()) } var otlpGrpcValues map[string]any if err := yaml.Unmarshal(otlpGrpcValuesMarshaled, &otlpGrpcValues); err != nil { - panic(fmt.Errorf("failed to compile config for output %q", output.NamespacedName().String())) + logger.Error(errors.New("failed to compile config for output"), "failed to compile config for output %q", output.NamespacedName().String()) } result[name] = otlpGrpcValues @@ -132,7 +136,9 @@ func (cfgInput *OtelColConfigInput) generateOTLPExporters() map[string]any { return result } -func (cfgInput *OtelColConfigInput) generateLokiExporters() map[string]any { +func (cfgInput *OtelColConfigInput) generateLokiExporters(ctx context.Context) map[string]any { + logger := log.FromContext(ctx) + var result = make(map[string]any) for _, output := range cfgInput.Outputs { @@ -142,11 +148,11 @@ func (cfgInput *OtelColConfigInput) generateLokiExporters() map[string]any { name := fmt.Sprintf("loki/%s_%s", output.Namespace, output.Name) lokiHTTPValuesMarshaled, err := yaml.Marshal(output.Spec.Loki) if err != nil { - return result + logger.Error(errors.New("failed to compile config for output"), "failed to compile config for output %q", output.NamespacedName().String()) } var lokiHTTPValues map[string]any if err := yaml.Unmarshal(lokiHTTPValuesMarshaled, &lokiHTTPValues); err != nil { - return result + logger.Error(errors.New("failed to compile config for output"), "failed to compile config for output %q", output.NamespacedName().String()) } result[name] = lokiHTTPValues @@ -565,11 +571,11 @@ func (cfgInput *OtelColConfigInput) generateDefaultKubernetesReceiver() map[stri } -func (cfgInput *OtelColConfigInput) ToIntermediateRepresentation() *OtelColConfigIR { +func (cfgInput *OtelColConfigInput) ToIntermediateRepresentation(ctx context.Context) *OtelColConfigIR { result := OtelColConfigIR{} // Get outputs based tenant names - result.Exporters = cfgInput.generateExporters() + result.Exporters = cfgInput.generateExporters(ctx) // Add processors result.Processors = cfgInput.generateProcessors() diff --git a/internal/controller/telemetry/otel_conf_gen_test.go b/internal/controller/telemetry/otel_conf_gen_test.go index 95ac3fe3..799da042 100644 --- a/internal/controller/telemetry/otel_conf_gen_test.go +++ b/internal/controller/telemetry/otel_conf_gen_test.go @@ -160,7 +160,7 @@ func TestOtelColConfComplex(t *testing.T) { inputCfg.TenantSubscriptionMap[tenant.Name] = seqs.ToSlice(mapseqs.KeysOf(inputCfg.Subscriptions)) // IR - generatedIR := inputCfg.ToIntermediateRepresentation() + generatedIR := inputCfg.ToIntermediateRepresentation(ctx) // Final YAML _, err := generatedIR.ToYAML()