Skip to content

Commit e36e27c

Browse files
committed
feat: add file exporter
Signed-off-by: Bence Csati <bence.csati@axoflow.com>
1 parent 069ecea commit e36e27c

File tree

3 files changed

+58
-0
lines changed

3 files changed

+58
-0
lines changed

pkg/resources/otel_conf_gen/otel_conf_gen.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ func (cfgInput *OtelColConfigInput) generateExporters(ctx context.Context) map[s
6666
maps.Copy(exporters, exporter.GenerateOTLPGRPCExporters(ctx, cfgInput.ResourceRelations))
6767
maps.Copy(exporters, exporter.GenerateOTLPHTTPExporters(ctx, cfgInput.ResourceRelations))
6868
maps.Copy(exporters, exporter.GenerateFluentforwardExporters(ctx, cfgInput.ResourceRelations))
69+
maps.Copy(exporters, exporter.GenerateFileExporter(ctx, cfgInput.ResourceRelations))
6970
if cfgInput.Debug {
7071
maps.Copy(exporters, exporter.GenerateDebugExporters())
7172
}
@@ -244,6 +245,11 @@ func (cfgInput *OtelColConfigInput) generateNamedPipelines() map[string]*otelv1b
244245
if output.Output.Spec.Fluentforward != nil {
245246
exporters = []string{components.GetExporterNameForOutput(output.Output), outputCountConnectorName, outputBytesConnectorName}
246247
}
248+
249+
if output.Output.Spec.File != nil {
250+
exporters = []string{components.GetExporterNameForOutput(output.Output), outputCountConnectorName, outputBytesConnectorName}
251+
}
252+
247253
if cfgInput.Debug {
248254
exporters = append(exporters, "debug")
249255
}

pkg/resources/otel_conf_gen/pipeline/components/common.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ func GetExporterNameForOutput(output v1alpha1.Output) string {
4949
exporterName = fmt.Sprintf("otlphttp/%s_%s", output.Namespace, output.Name)
5050
} else if output.Spec.Fluentforward != nil {
5151
exporterName = fmt.Sprintf("fluentforwardexporter/%s_%s", output.Namespace, output.Name)
52+
} else if output.Spec.File != nil {
53+
exporterName = fmt.Sprintf("file/%s_%s", output.Namespace, output.Name)
5254
}
5355

5456
return exporterName
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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

Comments
 (0)