diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index ed0ca86..0e4bc1f 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -19,7 +19,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v4 with: - go-version: '1.20' + go-version: '1.22' - name: Build run: go build -v ./... diff --git a/config.go b/config.go index d12740b..723854b 100644 --- a/config.go +++ b/config.go @@ -14,6 +14,7 @@ import ( "go.opentelemetry.io/collector/exporter/exporterhelper" ) +// TCPClientSettings defines common settings for a TCP client. type TCPClientSettings struct { // The target endpoint URI to send data to (e.g.: some.url:24224). Endpoint string `mapstructure:"endpoint"` @@ -21,8 +22,8 @@ type TCPClientSettings struct { // Connection Timeout parameter configures `net.Dialer`. ConnectionTimeout time.Duration `mapstructure:"connection_timeout"` - // TLSSetting struct exposes TLS client configuration. - TLSSetting configtls.ClientConfig `mapstructure:"tls"` + // ClientConfig struct exposes TLS client configuration. + ClientConfig configtls.ClientConfig `mapstructure:"tls"` // SharedKey is used for authorization with the server that knows it. SharedKey string `mapstructure:"shared_key"` @@ -78,6 +79,7 @@ type KubernetesMetadata struct { var _ component.Config = (*Config)(nil) +// Validate checks if the configuration is valid func (config *Config) Validate() error { if err := config.QueueConfig.Validate(); err != nil { return fmt.Errorf("queue settings has invalid configuration: %w", err) diff --git a/config_test.go b/config_test.go index 993e113..8b47641 100644 --- a/config_test.go +++ b/config_test.go @@ -37,38 +37,38 @@ func TestLoadConfigNewExporter(t *testing.T) { TCPClientSettings: TCPClientSettings{ Endpoint: validEndpoint, ConnectionTimeout: time.Second * 30, - TLSSetting: configtls.ClientConfig{ - Insecure: false, - InsecureSkipVerify: true, + ClientConfig: configtls.ClientConfig{ + Insecure: true, + InsecureSkipVerify: false, Config: configtls.Config{ - CAFile: "ca.crt", - CertFile: "client.crt", - KeyFile: "client.key", + CAFile: "", + CertFile: "", + KeyFile: "", }, }, - SharedKey: "otelcol-dev", + SharedKey: "", }, - RequireAck: true, - Tag: "nginx", - CompressGzip: true, + RequireAck: false, + Tag: "tag", + CompressGzip: false, DefaultLabelsEnabled: map[string]bool{ "time": true, - "exporter": false, - "job": false, - "instance": false, + "exporter": true, + "job": true, + "instance": true, }, BackOffConfig: configretry.BackOffConfig{ Enabled: true, - InitialInterval: 10 * time.Second, - MaxInterval: 1 * time.Minute, - MaxElapsedTime: 10 * time.Minute, + InitialInterval: 5 * time.Second, + MaxInterval: 30 * time.Second, + MaxElapsedTime: 5 * time.Minute, RandomizationFactor: backoff.DefaultRandomizationFactor, Multiplier: backoff.DefaultMultiplier, }, QueueConfig: exporterhelper.QueueConfig{ Enabled: true, - NumConsumers: 2, - QueueSize: 10, + NumConsumers: 10, + QueueSize: 1000, }, }, }, @@ -81,7 +81,7 @@ func TestLoadConfigNewExporter(t *testing.T) { sub, err := cm.Sub(tt.id.String()) require.NoError(t, err) - require.NoError(t, component.UnmarshalConfig(sub, cfg)) + require.NoError(t, sub.Unmarshal(cfg)) assert.NoError(t, component.ValidateConfig(cfg)) assert.Equal(t, tt.expected, cfg) diff --git a/exporter.go b/exporter.go index db53db8..a11cb84 100644 --- a/exporter.go +++ b/exporter.go @@ -33,12 +33,12 @@ func newExporter(config *Config, settings component.TelemetrySettings) *fluentfo } } -func (f *fluentforwardExporter) start(_ context.Context, host component.Host) error { +func (f *fluentforwardExporter) start(ctx context.Context, host component.Host) error { connOptions := fclient.ConnectionOptions{ RequireAck: f.config.RequireAck, } - tlsConfig, err := f.config.TLSSetting.LoadTLSConfig() + tlsConfig, err := f.config.ClientConfig.LoadTLSConfig(ctx) if err != nil { return err } diff --git a/exporter_test.go b/exporter_test.go index 1e5e834..30ce4fd 100644 --- a/exporter_test.go +++ b/exporter_test.go @@ -2,6 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 package fluentforwardexporter // import "github.com/r0mdau/fluentforwardexporter" + import ( "context" "testing" diff --git a/factory.go b/factory.go index f4c507c..44f6b37 100644 --- a/factory.go +++ b/factory.go @@ -33,7 +33,7 @@ func createDefaultConfig() component.Config { TCPClientSettings: TCPClientSettings{ Endpoint: "localhost:24224", ConnectionTimeout: time.Second * 30, - TLSSetting: configtls.ClientConfig{ + ClientConfig: configtls.ClientConfig{ Insecure: true, InsecureSkipVerify: false, Config: configtls.Config{ @@ -58,7 +58,7 @@ func createDefaultConfig() component.Config { } } -func createLogsExporter(ctx context.Context, set exporter.CreateSettings, config component.Config) (exporter.Logs, error) { +func createLogsExporter(ctx context.Context, set exporter.Settings, config component.Config) (exporter.Logs, error) { exporterConfig := config.(*Config) exp := newExporter(exporterConfig, set.TelemetrySettings) diff --git a/factory_test.go b/factory_test.go index bf45231..c9bb536 100644 --- a/factory_test.go +++ b/factory_test.go @@ -45,7 +45,7 @@ func TestNewExporterFullConfig(t *testing.T) { TCPClientSettings: TCPClientSettings{ Endpoint: validEndpoint, ConnectionTimeout: time.Second * 30, - TLSSetting: configtls.TLSClientSetting{ + ClientConfig: configtls.ClientConfig{ Insecure: true, InsecureSkipVerify: false, }, diff --git a/go.mod b/go.mod index 8047e37..7969740 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.22.0 toolchain go1.23.2 require ( - github.com/IBM/fluent-forward-go v0.2.3-0.20240418091724-720f8df4306a + github.com/IBM/fluent-forward-go v0.2.2 github.com/cenkalti/backoff/v4 v4.3.0 github.com/stretchr/testify v1.9.0 go.opentelemetry.io/collector/component v0.112.0 @@ -14,17 +14,18 @@ require ( go.opentelemetry.io/collector/confmap v1.18.0 go.opentelemetry.io/collector/exporter v0.112.0 go.opentelemetry.io/collector/pdata v1.18.0 + go.opentelemetry.io/otel/metric v1.31.0 + go.opentelemetry.io/otel/trace v1.31.0 go.uber.org/zap v1.27.0 ) require ( github.com/davecgh/go-spew v1.1.1 // indirect github.com/fsnotify/fsnotify v1.7.0 // indirect - github.com/go-logr/logr v1.4.1 // indirect + github.com/go-logr/logr v1.4.2 // indirect github.com/go-logr/stdr v1.2.2 // indirect github.com/go-viper/mapstructure/v2 v2.2.1 // indirect github.com/gogo/protobuf v1.3.2 // indirect - github.com/golang/protobuf v1.5.3 // indirect github.com/google/uuid v1.6.0 // indirect github.com/gorilla/websocket v1.4.2 // indirect github.com/json-iterator/go v1.1.12 // indirect @@ -47,10 +48,8 @@ require ( go.opentelemetry.io/collector/pdata/pprofile v0.112.0 // indirect go.opentelemetry.io/collector/pipeline v0.112.0 // indirect go.opentelemetry.io/otel v1.31.0 // indirect - go.opentelemetry.io/otel/metric v1.31.0 // indirect go.opentelemetry.io/otel/sdk v1.31.0 // indirect go.opentelemetry.io/otel/sdk/metric v1.31.0 // indirect - go.opentelemetry.io/otel/trace v1.31.0 // indirect go.uber.org/multierr v1.11.0 // indirect golang.org/x/net v0.28.0 // indirect golang.org/x/sys v0.26.0 // indirect diff --git a/go.sum b/go.sum index e317dfc..02faa0f 100644 --- a/go.sum +++ b/go.sum @@ -8,8 +8,8 @@ github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA= github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM= github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= -github.com/go-logr/logr v1.4.1 h1:pKouT5E8xu9zeFC39JXRDukb6JFQPXM5p5I91188VAQ= -github.com/go-logr/logr v1.4.1/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= +github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY= +github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= github.com/go-viper/mapstructure/v2 v2.2.1 h1:ZAaOCxANMuZx5RCeg0mBdEZk7DZasvvZIxtHqx8aGss= @@ -19,8 +19,6 @@ github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69 github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= -github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38 h1:yAJXTCF9TqKcTiHJAE8dj7HMvPfh66eeA2JYW7eFpSE= -github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc= @@ -150,6 +148,7 @@ golang.org/x/text v0.17.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= +golang.org/x/tools v0.0.0-20201022035929-9cf592e881e9/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= diff --git a/metadata.yaml b/metadata.yaml index 1eddb73..d7a0f61 100644 --- a/metadata.yaml +++ b/metadata.yaml @@ -6,4 +6,4 @@ status: development: [logs] distributions: [contrib] codeowners: - active: [r0mdau] \ No newline at end of file + active: [r0mdau] diff --git a/testdata/config.yaml b/testdata/config.yaml index f140d0b..8d8a572 100644 --- a/testdata/config.yaml +++ b/testdata/config.yaml @@ -26,4 +26,4 @@ fluentforward/allsettings: enabled: true initial_interval: 10s max_interval: 60s - max_elapsed_time: 10m \ No newline at end of file + max_elapsed_time: 10m