From 2126d79e7984b61fc3d084e04eb30a67109877bb Mon Sep 17 00:00:00 2001 From: Paulo Janotti Date: Fri, 5 Jan 2024 14:47:08 -0800 Subject: [PATCH] [chore][receiver/sqlserver] Fix lint on Windows (#30312) **Description:** Fixing lint issues when GOOS=windows. This is in preparation to eventually include lint with GOOS=windows as part of CI. --- receiver/sqlserverreceiver/factory_windows.go | 6 ++--- .../sqlserverreceiver/factory_windows_test.go | 2 +- receiver/sqlserverreceiver/scraper.go | 10 +++---- receiver/sqlserverreceiver/scraper_test.go | 26 ++++++++----------- 4 files changed, 20 insertions(+), 24 deletions(-) diff --git a/receiver/sqlserverreceiver/factory_windows.go b/receiver/sqlserverreceiver/factory_windows.go index bb59a1a3b0f9..f11c466a2f24 100644 --- a/receiver/sqlserverreceiver/factory_windows.go +++ b/receiver/sqlserverreceiver/factory_windows.go @@ -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( @@ -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), diff --git a/receiver/sqlserverreceiver/factory_windows_test.go b/receiver/sqlserverreceiver/factory_windows_test.go index b26c1bcf53f1..0f2eef62c7b7 100644 --- a/receiver/sqlserverreceiver/factory_windows_test.go +++ b/receiver/sqlserverreceiver/factory_windows_test.go @@ -47,7 +47,7 @@ func TestCreateMetricsReceiver(t *testing.T) { nil, consumertest.NewNop(), ) - require.ErrorIs(t, err, errConfigNotSqlServer) + require.ErrorIs(t, err, errConfigNotSQLServer) }, }, } diff --git a/receiver/sqlserverreceiver/scraper.go b/receiver/sqlserverreceiver/scraper.go index f5dcf543a5e8..8e57f3e7044d 100644 --- a/receiver/sqlserverreceiver/scraper.go +++ b/receiver/sqlserverreceiver/scraper.go @@ -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, @@ -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 { @@ -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 { @@ -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() diff --git a/receiver/sqlserverreceiver/scraper_test.go b/receiver/sqlserverreceiver/scraper_test.go index 8050f5338072..b262564fb6ec 100644 --- a/receiver/sqlserverreceiver/scraper_test.go +++ b/receiver/sqlserverreceiver/scraper_test.go @@ -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 @@ -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 @@ -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 @@ -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()) @@ -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, }) } @@ -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, }) }