Skip to content

Commit

Permalink
chore(otel_conf_gen): improve handling of exporter names
Browse files Browse the repository at this point in the history
Signed-off-by: Kristof Gyuracz <[email protected]>
  • Loading branch information
kristofgyuracz committed Apr 22, 2024
1 parent ee94100 commit ad233e8
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 11 deletions.
20 changes: 9 additions & 11 deletions internal/controller/telemetry/otel_conf_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ func (cfgInput *OtelColConfigInput) generateOTLPExporters(ctx context.Context) m

for _, output := range cfgInput.Outputs {
if output.Spec.OTLP != nil {
name := fmt.Sprintf("otlp/%s_%s", output.Namespace, output.Name)
name := GetExporterNameForOtelOutput(output)
otlpGrpcValuesMarshaled, err := yaml.Marshal(output.Spec.OTLP)
if err != nil {
logger.Error(errors.New("failed to compile config for output"), "failed to compile config for output %q", output.NamespacedName().String())
Expand All @@ -269,7 +269,7 @@ func (cfgInput *OtelColConfigInput) generateLokiExporters(ctx context.Context) m
for _, output := range cfgInput.Outputs {
if output.Spec.Loki != nil {

name := fmt.Sprintf("loki/%s_%s", output.Namespace, output.Name)
name := GetExporterNameForOtelOutput(output)
lokiHTTPValuesMarshaled, err := yaml.Marshal(output.Spec.Loki)
if err != nil {
logger.Error(errors.New("failed to compile config for output"), "failed to compile config for output %q", output.NamespacedName().String())
Expand Down Expand Up @@ -505,17 +505,11 @@ func (cfgInput *OtelColConfigInput) generateProcessors() map[string]any {
}

func generateOutputExporterNameProcessor(output v1alpha1.OtelOutput) AttributesProcessor {
var exporterName string
if output.Spec.Loki != nil {
exporterName = fmt.Sprintf("loki/%s_%s", output.Namespace, output.Name)
} else if output.Spec.OTLP != nil {
exporterName = fmt.Sprintf("otlp/%s_%s", output.Namespace, output.Name)
}
processor := AttributesProcessor{
Actions: []AttributesProcessorAction{{
Action: "insert",
Key: "exporter",
Value: exporterName,
Value: GetExporterNameForOtelOutput(output),
}},
}

Expand Down Expand Up @@ -633,11 +627,15 @@ func (cfgInput *OtelColConfigInput) generateNamedPipelines() map[string]Pipeline
output := cfgInput.Outputs[idx]

if output.Spec.Loki != nil {
namedPipelines[outputPipelineName] = generatePipeline([]string{fmt.Sprintf("routing/subscription_%s_%s_outputs", subscription.Namespace, subscription.Name)}, []string{fmt.Sprintf("attributes/exporter_name_%s", output.Name), fmt.Sprintf("attributes/loki_exporter_%s", output.Name), fmt.Sprintf("resource/loki_exporter_%s", output.Name)}, []string{fmt.Sprintf("loki/%s_%s", output.Namespace, output.Name), outputCountConnectorName})
namedPipelines[outputPipelineName] = generatePipeline([]string{fmt.Sprintf("routing/subscription_%s_%s_outputs", subscription.Namespace, subscription.Name)},
[]string{fmt.Sprintf("attributes/exporter_name_%s", output.Name), fmt.Sprintf("attributes/loki_exporter_%s", output.Name), fmt.Sprintf("resource/loki_exporter_%s", output.Name)},
[]string{GetExporterNameForOtelOutput(output), outputCountConnectorName})
}

if output.Spec.OTLP != nil {
namedPipelines[outputPipelineName] = generatePipeline([]string{fmt.Sprintf("routing/subscription_%s_%s_outputs", subscription.Namespace, subscription.Name)}, []string{fmt.Sprintf("attributes/exporter_name_%s", output.Name)}, []string{fmt.Sprintf("otlp/%s_%s", output.Namespace, output.Name), outputCountConnectorName})
namedPipelines[outputPipelineName] = generatePipeline([]string{fmt.Sprintf("routing/subscription_%s_%s_outputs", subscription.Namespace, subscription.Name)},
[]string{fmt.Sprintf("attributes/exporter_name_%s", output.Name)},
[]string{GetExporterNameForOtelOutput(output), outputCountConnectorName})
}
}
}
Expand Down
32 changes: 32 additions & 0 deletions internal/controller/telemetry/utils.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright © 2024 Kube logging authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package telemetry

import (
"fmt"

"github.com/kube-logging/telemetry-controller/api/telemetry/v1alpha1"
)

func GetExporterNameForOtelOutput(output v1alpha1.OtelOutput) string {
var exporterName string
if output.Spec.Loki != nil {
exporterName = fmt.Sprintf("loki/%s_%s", output.Namespace, output.Name)
} else if output.Spec.OTLP != nil {
exporterName = fmt.Sprintf("otlp/%s_%s", output.Namespace, output.Name)
}

return exporterName
}

0 comments on commit ad233e8

Please sign in to comment.