Skip to content

Commit

Permalink
Converter automatic logging processor (#6711)
Browse files Browse the repository at this point in the history
* add otel conversion to otelcol.exporter.logging

Signed-off-by: erikbaranowski <[email protected]>

* reorganize static builder code and stub out automatic_logging for traces handling

Signed-off-by: erikbaranowski <[email protected]>

* wire up default otelcol.exporter.logging to replace the automatic_logging processor

Signed-off-by: erikbaranowski <[email protected]>

---------

Signed-off-by: erikbaranowski <[email protected]>
  • Loading branch information
erikbaranowski authored Mar 18, 2024
1 parent e4aaea4 commit c80c234
Show file tree
Hide file tree
Showing 15 changed files with 648 additions and 434 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package otelcolconvert

import (
"fmt"

"github.com/grafana/agent/internal/component/otelcol/exporter/logging"
"github.com/grafana/agent/internal/converter/diag"
"github.com/grafana/agent/internal/converter/internal/common"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/exporter/loggingexporter"
"go.uber.org/zap/zapcore"
)

func init() {
converters = append(converters, loggingExporterConverter{})
}

type loggingExporterConverter struct{}

func (loggingExporterConverter) Factory() component.Factory {
return loggingexporter.NewFactory()
}

func (loggingExporterConverter) InputComponentName() string {
return "otelcol.exporter.logging"
}

func (loggingExporterConverter) ConvertAndAppend(state *state, id component.InstanceID, cfg component.Config) diag.Diagnostics {
var diags diag.Diagnostics

label := state.FlowComponentLabel()
args := toOtelcolExporterLogging(cfg.(*loggingexporter.Config))
block := common.NewBlockWithOverrideFn([]string{"otelcol", "exporter", "logging"}, label, args, nil)

diags.Add(
diag.SeverityLevelInfo,
fmt.Sprintf("Converted %s into %s", stringifyInstanceID(id), stringifyBlock(block)),
)

diags.AddAll(common.ValidateSupported(common.NotEquals,
cfg.(*loggingexporter.Config).LogLevel,
zapcore.InfoLevel,
"otelcol logging exporter loglevel",
"use verbosity instead since loglevel is deprecated"))

state.Body().AppendBlock(block)
return diags
}

func toOtelcolExporterLogging(cfg *loggingexporter.Config) *logging.Arguments {
return &logging.Arguments{
Verbosity: cfg.Verbosity,
SamplingInitial: cfg.SamplingInitial,
SamplingThereafter: cfg.SamplingThereafter,
DebugMetrics: common.DefaultValue[logging.Arguments]().DebugMetrics,
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(Error) The converter does not support converting the provided otelcol logging exporter loglevel config: use verbosity instead since loglevel is deprecated
23 changes: 23 additions & 0 deletions internal/converter/internal/otelcolconvert/testdata/logging.river
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
otelcol.receiver.otlp "default" {
grpc { }

http { }

output {
metrics = [otelcol.exporter.logging.default.input, otelcol.exporter.logging.default_2.input]
logs = [otelcol.exporter.logging.default.input, otelcol.exporter.logging.default_2.input]
traces = [otelcol.exporter.logging.default.input, otelcol.exporter.logging.default_2.input]
}
}

otelcol.exporter.logging "default" {
verbosity = "Detailed"
sampling_initial = 5
sampling_thereafter = 200
}

otelcol.exporter.logging "default_2" {
verbosity = "Detailed"
sampling_initial = 5
sampling_thereafter = 200
}
30 changes: 30 additions & 0 deletions internal/converter/internal/otelcolconvert/testdata/logging.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
receivers:
otlp:
protocols:
grpc:
http:

exporters:
logging:
verbosity: detailed
sampling_initial: 5
sampling_thereafter: 200
logging/2:
sampling_initial: 5
sampling_thereafter: 200
loglevel: debug

service:
pipelines:
metrics:
receivers: [otlp]
processors: []
exporters: [logging,logging/2]
logs:
receivers: [otlp]
processors: []
exporters: [logging,logging/2]
traces:
receivers: [otlp]
processors: []
exporters: [logging,logging/2]
Loading

0 comments on commit c80c234

Please sign in to comment.