Skip to content

fix: add skip fail flag #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ type TCPClientSettings struct {
type Config struct {
TCPClientSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct.

// SkipFailOnInvalidTCPEndpoint controls whether to fail if the endpoint is invalid.
// This is useful for cases where the collector is started before the endpoint becomes available.
SkipFailOnInvalidTCPEndpoint bool `mapstructure:"skip_fail_on_invalid_tcp_endpoint"`

// RequireAck enables the acknowledgement feature.
RequireAck bool `mapstructure:"require_ack"`

Expand Down Expand Up @@ -87,8 +91,11 @@ func (config *Config) Validate() error {

// Resolve TCP address just to ensure that it is a valid one. It is better
// to fail here than at when the exporter is started.
if _, err := net.ResolveTCPAddr("tcp", config.Endpoint); err != nil {
return fmt.Errorf("exporter has an invalid TCP endpoint: %w", err)
if !config.SkipFailOnInvalidTCPEndpoint {
if _, err := net.ResolveTCPAddr("tcp", config.Endpoint); err != nil {
return fmt.Errorf("exporter has an invalid TCP endpoint: %w", err)
}
}

return nil
}
11 changes: 11 additions & 0 deletions config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,17 @@ func TestConfigValidate(t *testing.T) {
},
err: fmt.Errorf("exporter has an invalid TCP endpoint: address http://localhost:24224: too many colons in address"),
},
{
desc: "Endpoint is invalid but SkipFailOnInvalidTCPEndpoint is false",
cfg: &Config{
TCPClientSettings: TCPClientSettings{
Endpoint: "http://localhost:24224",
ConnectionTimeout: time.Second * 30,
},
SkipFailOnInvalidTCPEndpoint: true,
},
err: nil,
},
{
desc: "Config is valid",
cfg: &Config{
Expand Down
13 changes: 6 additions & 7 deletions exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (

fclient "github.com/IBM/fluent-forward-go/fluent/client"
"github.com/IBM/fluent-forward-go/fluent/protocol"
fproto "github.com/IBM/fluent-forward-go/fluent/protocol"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/pdata/pcommon"
"go.opentelemetry.io/collector/pdata/plog"
Expand Down Expand Up @@ -87,7 +86,7 @@ func (f *fluentforwardExporter) connectForward() {

func (f *fluentforwardExporter) pushLogData(ctx context.Context, ld plog.Logs) error {
// move for loops into a translator
entries := []fproto.EntryExt{}
entries := []protocol.EntryExt{}
rls := ld.ResourceLogs()
for i := 0; i < rls.Len(); i++ {
ills := rls.At(i).ScopeLogs()
Expand All @@ -96,8 +95,8 @@ func (f *fluentforwardExporter) pushLogData(ctx context.Context, ld plog.Logs) e
logs := ills.At(j).LogRecords()
for k := 0; k < logs.Len(); k++ {
log := logs.At(k)
entry := fproto.EntryExt{
Timestamp: fproto.EventTimeNow(),
entry := protocol.EntryExt{
Timestamp: protocol.EventTimeNow(),
Record: f.convertLogToMap(log, rls.At(i)),
}
entries = append(entries, entry)
Expand Down Expand Up @@ -176,7 +175,7 @@ func (f *fluentforwardExporter) convertLogToMap(lr plog.LogRecord, res plog.Reso

type sendFunc func(string, protocol.EntryList) error

func (f *fluentforwardExporter) send(sendMethod sendFunc, entries []fproto.EntryExt) error {
func (f *fluentforwardExporter) send(sendMethod sendFunc, entries []protocol.EntryExt) error {
err := sendMethod(f.config.Tag, entries)
// sometimes the connection is lost, we try to reconnect and send the data again
if err != nil {
Expand All @@ -193,10 +192,10 @@ func (f *fluentforwardExporter) send(sendMethod sendFunc, entries []fproto.Entry
return nil
}

func (f *fluentforwardExporter) sendCompressed(entries []fproto.EntryExt) error {
func (f *fluentforwardExporter) sendCompressed(entries []protocol.EntryExt) error {
return f.send(f.client.SendCompressed, entries)
}

func (f *fluentforwardExporter) sendForward(entries []fproto.EntryExt) error {
func (f *fluentforwardExporter) sendForward(entries []protocol.EntryExt) error {
return f.send(f.client.SendForward, entries)
}
2 changes: 1 addition & 1 deletion factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func createLogsExporter(ctx context.Context, set exporter.Settings, config compo
exporterConfig := config.(*Config)
exp := newExporter(exporterConfig, set.TelemetrySettings)

return exporterhelper.NewLogsExporter(
return exporterhelper.NewLogs(
ctx,
set,
config,
Expand Down
Loading