Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
moh-osman3 committed Jun 21, 2023
1 parent 387e4dc commit fd1c85b
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 27 deletions.
3 changes: 1 addition & 2 deletions exporter/fileexporter/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
7 changes: 3 additions & 4 deletions exporter/fileexporter/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
3 changes: 2 additions & 1 deletion exporter/fileexporter/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
Expand Down
13 changes: 5 additions & 8 deletions exporter/fileexporter/file_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
23 changes: 11 additions & 12 deletions exporter/fileexporter/file_exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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,
}
Expand Down Expand Up @@ -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)
Expand All @@ -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,
}
Expand Down Expand Up @@ -449,7 +448,7 @@ func TestFileLogsExporterErrors(t *testing.T) {
file: mf,
formatType: formatTypeJSON,
logsMarshaler: logsMarshalers[formatTypeJSON],
compressor: noneCompress,
compressor: noneCompress,
}
require.NotNil(t, fe)

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit fd1c85b

Please sign in to comment.