|
| 1 | +// Copyright © 2025 Kube logging authors |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +package exporter |
| 16 | + |
| 17 | +import ( |
| 18 | + "context" |
| 19 | + "encoding/json" |
| 20 | + "errors" |
| 21 | + "fmt" |
| 22 | + |
| 23 | + "sigs.k8s.io/controller-runtime/pkg/log" |
| 24 | + |
| 25 | + "github.com/kube-logging/telemetry-controller/pkg/resources/otel_conf_gen/pipeline/components" |
| 26 | +) |
| 27 | + |
| 28 | +func GenerateFileExporter(ctx context.Context, resourceRelations components.ResourceRelations) map[string]any { |
| 29 | + logger := log.FromContext(ctx) |
| 30 | + |
| 31 | + result := make(map[string]any) |
| 32 | + for _, output := range resourceRelations.OutputsWithSecretData { |
| 33 | + if output.Output.Spec.File != nil { |
| 34 | + fileValuesMarshaled, err := json.Marshal(output.Output.Spec.File) |
| 35 | + if err != nil { |
| 36 | + logger.Error(errors.New("failed to compile config for output"), "failed to compile config for output %q", output.Output.NamespacedName().String()) |
| 37 | + continue |
| 38 | + } |
| 39 | + var fileValues map[string]any |
| 40 | + if err := json.Unmarshal(fileValuesMarshaled, &fileValues); err != nil { |
| 41 | + logger.Error(errors.New("failed to compile config for output"), "failed to compile config for output %q", output.Output.NamespacedName().String()) |
| 42 | + continue |
| 43 | + } |
| 44 | + |
| 45 | + result[fmt.Sprintf("file/%s_%s", output.Output.Namespace, output.Output.Name)] = fileValues |
| 46 | + } |
| 47 | + } |
| 48 | + |
| 49 | + return result |
| 50 | +} |
0 commit comments