From fd1c85b2402876d582c197d3d335dca11e3f3ba9 Mon Sep 17 00:00:00 2001 From: Mohamed Osman Date: Tue, 20 Jun 2023 03:49:33 -0400 Subject: [PATCH] lint --- exporter/fileexporter/config_test.go | 3 +-- exporter/fileexporter/factory.go | 7 +++---- exporter/fileexporter/factory_test.go | 3 ++- exporter/fileexporter/file_exporter.go | 13 +++++------- exporter/fileexporter/file_exporter_test.go | 23 ++++++++++----------- 5 files changed, 22 insertions(+), 27 deletions(-) diff --git a/exporter/fileexporter/config_test.go b/exporter/fileexporter/config_test.go index c2bfdb17822b..bb8bc809a6f8 100644 --- a/exporter/fileexporter/config_test.go +++ b/exporter/fileexporter/config_test.go @@ -8,12 +8,11 @@ import ( "testing" "time" + "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/fileexporter/internal/metadata" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/confmap/confmaptest" - - "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/fileexporter/internal/metadata" ) func TestLoadConfig(t *testing.T) { diff --git a/exporter/fileexporter/factory.go b/exporter/fileexporter/factory.go index 07145a4521c2..e351c12254c9 100644 --- a/exporter/fileexporter/factory.go +++ b/exporter/fileexporter/factory.go @@ -8,15 +8,14 @@ import ( "io" "os" + "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/fileexporter/internal/metadata" + "github.com/open-telemetry/opentelemetry-collector-contrib/internal/sharedcomponent" "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/consumer" "go.opentelemetry.io/collector/exporter" "go.opentelemetry.io/collector/exporter/exporterhelper" - "gopkg.in/natefinch/lumberjack.v2" "go.uber.org/zap" - - "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/fileexporter/internal/metadata" - "github.com/open-telemetry/opentelemetry-collector-contrib/internal/sharedcomponent" + "gopkg.in/natefinch/lumberjack.v2" ) const ( diff --git a/exporter/fileexporter/factory_test.go b/exporter/fileexporter/factory_test.go index 8a0281416a7a..3597b145c5f7 100644 --- a/exporter/fileexporter/factory_test.go +++ b/exporter/fileexporter/factory_test.go @@ -12,8 +12,8 @@ import ( "github.com/stretchr/testify/require" "go.opentelemetry.io/collector/component/componenttest" "go.opentelemetry.io/collector/exporter/exportertest" - "gopkg.in/natefinch/lumberjack.v2" "go.uber.org/zap" + "gopkg.in/natefinch/lumberjack.v2" ) func TestCreateDefaultConfig(t *testing.T) { @@ -157,6 +157,7 @@ func TestBuildFileWriter(t *testing.T) { bc, ok := fl.getFile().(interface{ getWrapped() io.Closer }) assert.True(t, ok) writer, ok := bc.getWrapped().(*lumberjack.Logger) + assert.True(t, ok) assert.Equal(t, 3, writer.MaxBackups) assert.Equal(t, 30, writer.MaxSize) diff --git a/exporter/fileexporter/file_exporter.go b/exporter/fileexporter/file_exporter.go index 174551aa66f6..9a6846110e3a 100644 --- a/exporter/fileexporter/file_exporter.go +++ b/exporter/fileexporter/file_exporter.go @@ -39,10 +39,9 @@ type WriteCloseFlusher interface { // fileExporter is the implementation of file exporter that writes telemetry data to a file type fileExporter struct { - path string - file WriteCloseFlusher - mutex sync.Mutex - logger *zap.Logger + path string + file WriteCloseFlusher + mutex sync.Mutex tracesMarshaler ptrace.Marshaler metricsMarshaler pmetric.Marshaler @@ -96,9 +95,8 @@ func NewLineWriter(cfg *Config, logger *zap.Logger, file io.WriteCloser) WriteCl if cw, err := zstd.NewWriter(file); err == nil { lw.file = cw return lw - } else { - logger.Debug("Unable to create compressed writer", zap.Error(err)) } + logger.Debug("Unable to create compressed writer", zap.Error(err)) } lw.file = newBufferedWriteCloser(file) @@ -143,9 +141,8 @@ func NewFileWriter(cfg *Config, logger *zap.Logger, file io.WriteCloser) WriteCl if cw, err := zstd.NewWriter(file); err == nil { fw.file = cw return fw - } else { - logger.Debug("Unable to create compressed writer", zap.Error(err)) } + logger.Debug("Unable to create compressed writer", zap.Error(err)) } fw.file = newBufferedWriteCloser(file) diff --git a/exporter/fileexporter/file_exporter_test.go b/exporter/fileexporter/file_exporter_test.go index 15cd1c9da561..ff70d3e5d0b2 100644 --- a/exporter/fileexporter/file_exporter_test.go +++ b/exporter/fileexporter/file_exporter_test.go @@ -16,16 +16,15 @@ import ( "time" "github.com/klauspost/compress/zstd" + "github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal/testdata" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "go.opentelemetry.io/collector/component/componenttest" "go.opentelemetry.io/collector/pdata/plog" "go.opentelemetry.io/collector/pdata/pmetric" "go.opentelemetry.io/collector/pdata/ptrace" - "gopkg.in/natefinch/lumberjack.v2" "go.uber.org/zap" - - "github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal/testdata" + "gopkg.in/natefinch/lumberjack.v2" ) func TestFileTracesExporter(t *testing.T) { @@ -170,8 +169,8 @@ func TestFileTracesExporter(t *testing.T) { func TestFileTracesExporterError(t *testing.T) { mf := &errorWriter{} fe := &fileExporter{ - file: mf, - formatType: formatTypeJSON, + file: mf, + formatType: formatTypeJSON, tracesMarshaler: tracesMarshalers[formatTypeJSON], compressor: noneCompress, } @@ -286,7 +285,7 @@ func TestFileMetricsExporter(t *testing.T) { } for { buf, isEnd, err := func() ([]byte, bool, error) { - if fe.formatType == formatTypeJSON { + if fe.formatType == formatTypeJSON { return readJSONMessage(br) } return readMessageFromStream(br) @@ -308,8 +307,8 @@ func TestFileMetricsExporter(t *testing.T) { func TestFileMetricsExporterError(t *testing.T) { mf := &errorWriter{} fe := &fileExporter{ - file: mf, - formatType: formatTypeJSON, + file: mf, + formatType: formatTypeJSON, metricsMarshaler: metricsMarshalers[formatTypeJSON], compressor: noneCompress, } @@ -449,7 +448,7 @@ func TestFileLogsExporterErrors(t *testing.T) { file: mf, formatType: formatTypeJSON, logsMarshaler: logsMarshalers[formatTypeJSON], - compressor: noneCompress, + compressor: noneCompress, } require.NotNil(t, fe) @@ -482,9 +481,9 @@ func TestExportMessageAsBuffer(t *testing.T) { MaxSize: 1, } fe := &fileExporter{ - path: path, - formatType: formatTypeProto, - file: &testWriter{writer: fw}, + path: path, + formatType: formatTypeProto, + file: &testWriter{writer: fw}, logsMarshaler: logsMarshalers[formatTypeProto], } require.NotNil(t, fe)