-
Notifications
You must be signed in to change notification settings - Fork 486
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
draft up a way to translate otel loki receiver to flow
Signed-off-by: erikbaranowski <[email protected]>
- Loading branch information
1 parent
5e037eb
commit 0701953
Showing
24 changed files
with
201 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
143 changes: 143 additions & 0 deletions
143
internal/converter/internal/otelcolconvert/converter_lokireceiver.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
package otelcolconvert | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/grafana/agent/internal/component/common/loki" | ||
"github.com/grafana/agent/internal/component/loki/source/api" | ||
"github.com/grafana/agent/internal/component/otelcol" | ||
otel_loki "github.com/grafana/agent/internal/component/otelcol/receiver/loki" | ||
"github.com/grafana/agent/internal/converter/diag" | ||
"github.com/grafana/agent/internal/converter/internal/common" | ||
"github.com/grafana/agent/internal/converter/internal/promtailconvert/build" | ||
"github.com/grafana/dskit/server" | ||
"github.com/grafana/loki/clients/pkg/promtail/scrapeconfig" | ||
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/lokireceiver" | ||
"go.opentelemetry.io/collector/component" | ||
) | ||
|
||
func init() { | ||
converters = append(converters, lokiReceiverConverter{}) | ||
} | ||
|
||
type lokiReceiverConverter struct{} | ||
|
||
func (lokiReceiverConverter) Factory() component.Factory { return lokireceiver.NewFactory() } | ||
|
||
func (lokiReceiverConverter) InputComponentName() string { return "" } | ||
|
||
func (lokiReceiverConverter) ConvertAndAppend(state *State, id component.InstanceID, cfg component.Config) diag.Diagnostics { | ||
var diags diag.Diagnostics | ||
|
||
label := state.FlowComponentLabel() | ||
|
||
otelArgs := toOtelcolReceiverLoki(state, id) | ||
otelBlock := common.NewBlockWithOverride([]string{"otelcol", "receiver", "loki"}, label, otelArgs) | ||
|
||
logsReceivers := []loki.LogsReceiver{common.ConvertLogsReceiver{ | ||
Expr: StringifyBlock(otelBlock) + ".receiver", | ||
}} | ||
apiArgs := toLokiSourceApi(logsReceivers, cfg.(*lokireceiver.Config)) | ||
apiBlock := common.NewBlockWithOverride([]string{"loki", "source", "api"}, label, apiArgs) | ||
|
||
diags.Add( | ||
diag.SeverityLevelInfo, | ||
fmt.Sprintf("Converted %s into %s", StringifyInstanceID(id), StringifyBlock(otelBlock)), | ||
) | ||
|
||
diags.Add( | ||
diag.SeverityLevelInfo, | ||
fmt.Sprintf("Converted %s into %s", StringifyInstanceID(id), StringifyBlock(apiBlock)), | ||
) | ||
|
||
// Do this at the end in reverse order so the pipeline looks a little better | ||
state.Body().AppendBlock(apiBlock) | ||
state.Body().AppendBlock(otelBlock) | ||
return diags | ||
} | ||
|
||
func toOtelcolReceiverLoki(state *State, id component.InstanceID) *otel_loki.Arguments { | ||
var ( | ||
nextLogs = state.Next(id, component.DataTypeLogs) | ||
) | ||
|
||
return &otel_loki.Arguments{ | ||
Output: &otelcol.ConsumerArguments{ | ||
Logs: ToTokenizedConsumers(nextLogs), | ||
}, | ||
} | ||
} | ||
|
||
func toLokiSourceApi(logsReceivers []loki.LogsReceiver, cfg *lokireceiver.Config) *api.Arguments { | ||
ptc := &scrapeconfig.PushTargetConfig{ | ||
Server: toServer(&cfg.Protocols), | ||
Labels: nil, | ||
KeepTimestamp: cfg.KeepTimestamp, | ||
} | ||
|
||
args := build.ToLokiApiArguments(ptc, logsReceivers) | ||
return &args | ||
} | ||
|
||
func toServer(cfg *lokireceiver.Protocols) server.Config { | ||
return server.Config{ | ||
HTTPListenAddress: "", | ||
HTTPListenPort: 0, | ||
HTTPConnLimit: 0, | ||
HTTPServerReadTimeout: 0, | ||
HTTPServerWriteTimeout: 0, | ||
HTTPServerIdleTimeout: 0, | ||
GRPCListenAddress: "", | ||
GRPCListenPort: 0, | ||
GRPCConnLimit: 0, | ||
GRPCServerMaxConnectionAge: 0, | ||
GRPCServerMaxConnectionAgeGrace: 0, | ||
GRPCServerMaxRecvMsgSize: 0, | ||
GRPCServerMaxSendMsgSize: 0, | ||
GRPCServerMaxConcurrentStreams: uint(cfg.GRPC.MaxConcurrentStreams), | ||
GRPCServerMaxConnectionIdle: 0, | ||
ServerGracefulShutdownTimeout: cfg.GRPC.NetAddr.DialerConfig.Timeout, | ||
|
||
// PROMTAIL CONVERTER IGNORES ALL OF THESE | ||
// | ||
// HTTPListenNetwork: "", | ||
// HTTPServerReadHeaderTimeout: 0, | ||
// GRPCListenNetwork: "", | ||
// CipherSuites: "", | ||
// MinVersion: "", | ||
// HTTPTLSConfig: server.TLSConfig{}, | ||
// GRPCTLSConfig: server.TLSConfig{}, | ||
// RegisterInstrumentation: false, | ||
// ReportGRPCCodesInInstrumentationLabel: false, | ||
// ReportHTTP4XXCodesInInstrumentationLabel: false, | ||
// ExcludeRequestInLog: false, | ||
// DisableRequestSuccessLog: false, | ||
// HTTPLogClosedConnectionsWithoutResponse: false, | ||
// GRPCOptions: []grpc.ServerOption{}, | ||
// GRPCMiddleware: []grpc.UnaryServerInterceptor{}, | ||
// GRPCStreamMiddleware: []grpc.StreamServerInterceptor{}, | ||
// HTTPMiddleware: []middleware.Interface{}, | ||
// Router: &mux.Router{}, | ||
// DoNotAddDefaultHTTPMiddleware: false, | ||
// RouteHTTPToGRPC: false, | ||
// GRPCServerTime: 0, | ||
// GRPCServerTimeout: cfg.GRPC.NetAddr.DialerConfig.Timeout, | ||
// GRPCServerMinTimeBetweenPings: 0, | ||
// GRPCServerPingWithoutStreamAllowed: false, | ||
// GRPCServerNumWorkers: 0, | ||
// LogFormat: "", | ||
// LogLevel: log.Level{}, | ||
// Log: nil, | ||
// LogSourceIPs: false, | ||
// LogSourceIPsHeader: "", | ||
// LogSourceIPsRegex: "", | ||
// LogRequestHeaders: false, | ||
// LogRequestAtInfoLevel: false, | ||
// LogRequestExcludeHeadersList: "", | ||
// SignalHandler: nil, | ||
// Registerer: nil, | ||
// Gatherer: nil, | ||
// PathPrefix: "", | ||
// GrpcMethodLimiter: nil, | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
internal/converter/internal/otelcolconvert/testdata/lokireceiver.river
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
loki.source.api "default" { | ||
http { } | ||
|
||
grpc { } | ||
graceful_shutdown_timeout = "10s" | ||
forward_to = [otelcol.receiver.loki.default.receiver] | ||
labels = {} | ||
relabel_rules = null | ||
use_incoming_timestamp = true | ||
} | ||
|
||
otelcol.receiver.loki "default" { | ||
output { | ||
logs = [otelcol.exporter.otlp.default.input] | ||
} | ||
} | ||
|
||
otelcol.exporter.otlp "default" { | ||
client { | ||
endpoint = "database:4317" | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
internal/converter/internal/otelcolconvert/testdata/lokireceiver.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
receivers: | ||
loki: | ||
protocols: | ||
http: | ||
endpoint: 0.0.0.0:3500 | ||
grpc: | ||
endpoint: 0.0.0.0:3600 | ||
dialer: | ||
timeout: 10s | ||
use_incoming_timestamp: true | ||
|
||
exporters: | ||
otlp: | ||
endpoint: database:4317 | ||
|
||
service: | ||
pipelines: | ||
logs: | ||
receivers: [loki] | ||
processors: [] | ||
exporters: [otlp] |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters