Skip to content

Commit

Permalink
[chore][receiver/sqlserver] Fix lint on Windows (open-telemetry#30312)
Browse files Browse the repository at this point in the history
**Description:**
Fixing lint issues when GOOS=windows. This is in preparation to
eventually include lint with GOOS=windows as part of CI.
  • Loading branch information
pjanotti authored and cparkins committed Jan 10, 2024
1 parent 8305b7e commit 2126d79
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 24 deletions.
6 changes: 3 additions & 3 deletions receiver/sqlserverreceiver/factory_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/sqlserverreceiver/internal/metadata"
)

var errConfigNotSqlServer = errors.New("config was not a sqlserver receiver config")
var errConfigNotSQLServer = errors.New("config was not a sqlserver receiver config")

// createMetricsReceiver creates a metrics receiver based on provided config.
func createMetricsReceiver(
Expand All @@ -29,9 +29,9 @@ func createMetricsReceiver(
) (receiver.Metrics, error) {
cfg, ok := receiverCfg.(*Config)
if !ok {
return nil, errConfigNotSqlServer
return nil, errConfigNotSQLServer
}
sqlServerScraper := newSqlServerScraper(params, cfg)
sqlServerScraper := newSQLServerScraper(params, cfg)

scraper, err := scraperhelper.NewScraper(metadata.Type, sqlServerScraper.scrape,
scraperhelper.WithStart(sqlServerScraper.start),
Expand Down
2 changes: 1 addition & 1 deletion receiver/sqlserverreceiver/factory_windows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func TestCreateMetricsReceiver(t *testing.T) {
nil,
consumertest.NewNop(),
)
require.ErrorIs(t, err, errConfigNotSqlServer)
require.ErrorIs(t, err, errConfigNotSQLServer)
},
},
}
Expand Down
10 changes: 5 additions & 5 deletions receiver/sqlserverreceiver/scraper.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ type watcherRecorder struct {
// it needs metadata.MetricsBuilder and timestamp as arguments.
type curriedRecorder func(*metadata.MetricsBuilder, pcommon.Timestamp)

// newSqlServerScraper returns a new sqlServerScraper.
func newSqlServerScraper(params receiver.CreateSettings, cfg *Config) *sqlServerScraper {
// newSQLServerScraper returns a new sqlServerScraper.
func newSQLServerScraper(params receiver.CreateSettings, cfg *Config) *sqlServerScraper {
return &sqlServerScraper{
logger: params.Logger,
config: cfg,
Expand All @@ -48,7 +48,7 @@ func newSqlServerScraper(params receiver.CreateSettings, cfg *Config) *sqlServer
}

// start creates and sets the watchers for the scraper.
func (s *sqlServerScraper) start(ctx context.Context, host component.Host) error {
func (s *sqlServerScraper) start(_ context.Context, _ component.Host) error {
s.watcherRecorders = []watcherRecorder{}

for _, pcr := range perfCounterRecorders {
Expand All @@ -72,7 +72,7 @@ func (s *sqlServerScraper) start(ctx context.Context, host component.Host) error
}

// scrape collects windows performance counter data from all watchers and then records/emits it using the metricBuilder
func (s *sqlServerScraper) scrape(ctx context.Context) (pmetric.Metrics, error) {
func (s *sqlServerScraper) scrape(_ context.Context) (pmetric.Metrics, error) {
recordersByDatabase, errs := recordersPerDatabase(s.watcherRecorders)

for dbName, recorders := range recordersByDatabase {
Expand Down Expand Up @@ -133,7 +133,7 @@ func (s *sqlServerScraper) emitMetricGroup(recorders []curriedRecorder, database
}

// shutdown stops all of the watchers for the scraper.
func (s sqlServerScraper) shutdown(ctx context.Context) error {
func (s sqlServerScraper) shutdown(_ context.Context) error {
var errs error
for _, wr := range s.watcherRecorders {
err := wr.watcher.Close()
Expand Down
26 changes: 11 additions & 15 deletions receiver/sqlserverreceiver/scraper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type mockPerfCounterWatcher struct {
}

// Close provides a mock function with given fields:
func (_m mockPerfCounterWatcher) Close() error {
func (_m *mockPerfCounterWatcher) Close() error {
ret := _m.Called()

var r0 error
Expand All @@ -44,7 +44,7 @@ func (_m mockPerfCounterWatcher) Close() error {
}

// Path provides a mock function with given fields:
func (_m mockPerfCounterWatcher) Path() string {
func (_m *mockPerfCounterWatcher) Path() string {
ret := _m.Called()

var r0 string
Expand All @@ -58,16 +58,14 @@ func (_m mockPerfCounterWatcher) Path() string {
}

// ScrapeData provides a mock function with given fields:
func (_m mockPerfCounterWatcher) ScrapeData() ([]winperfcounters.CounterValue, error) {
func (_m *mockPerfCounterWatcher) ScrapeData() ([]winperfcounters.CounterValue, error) {
ret := _m.Called()

var r0 []winperfcounters.CounterValue
if rf, ok := ret.Get(0).(func() []winperfcounters.CounterValue); ok {
r0 = rf()
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).([]winperfcounters.CounterValue)
}
} else if ret.Get(0) != nil {
r0 = ret.Get(0).([]winperfcounters.CounterValue)
}

var r1 error
Expand All @@ -86,9 +84,9 @@ func TestSqlServerScraper(t *testing.T) {
logger, obsLogs := observer.New(zap.WarnLevel)
settings := receivertest.NewNopCreateSettings()
settings.Logger = zap.New(logger)
s := newSqlServerScraper(settings, cfg)
s := newSQLServerScraper(settings, cfg)

s.start(context.Background(), nil)
assert.NoError(t, s.start(context.Background(), nil))
assert.Equal(t, 0, len(s.watcherRecorders))
assert.Equal(t, 21, obsLogs.Len())
assert.Equal(t, 21, obsLogs.FilterMessageSnippet("failed to create perf counter with path \\SQLServer:").Len())
Expand Down Expand Up @@ -117,15 +115,14 @@ func TestScrape(t *testing.T) {
factory := NewFactory()
cfg := factory.CreateDefaultConfig().(*Config)
settings := receivertest.NewNopCreateSettings()
scraper := newSqlServerScraper(settings, cfg)
scraper := newSQLServerScraper(settings, cfg)

for i, rec := range perfCounterRecorders {
perfCounterWatcher := &mockPerfCounterWatcher{}
perfCounterWatcher.On("ScrapeData").Return([]winperfcounters.CounterValue{{InstanceName: dbInstance, Value: float64(i)}}, nil)
i++
for _, recorder := range rec.recorders {
scraper.watcherRecorders = append(scraper.watcherRecorders, watcherRecorder{
watcher: *perfCounterWatcher,
watcher: perfCounterWatcher,
recorder: recorder,
})
}
Expand Down Expand Up @@ -162,15 +159,14 @@ func TestScrape(t *testing.T) {
cfg.InstanceName = "CustomInstance"

settings := receivertest.NewNopCreateSettings()
scraper := newSqlServerScraper(settings, cfg)
scraper := newSQLServerScraper(settings, cfg)

for i, rec := range perfCounterRecorders {
perfCounterWatcher := &mockPerfCounterWatcher{}
perfCounterWatcher.On("ScrapeData").Return([]winperfcounters.CounterValue{{InstanceName: dbInstance, Value: float64(i)}}, nil)
i++
for _, recorder := range rec.recorders {
scraper.watcherRecorders = append(scraper.watcherRecorders, watcherRecorder{
watcher: *perfCounterWatcher,
watcher: perfCounterWatcher,
recorder: recorder,
})
}
Expand Down

0 comments on commit 2126d79

Please sign in to comment.