From d42a270da4071e4a12bd19e6ffd907b01f780f94 Mon Sep 17 00:00:00 2001 From: Paulo Janotti Date: Tue, 12 Dec 2023 12:19:37 -0800 Subject: [PATCH] [chore][receiver/iis] Fix lint on Windows issues (#29793) **Description:** Fixing lint issues when GOOS=windows. This is in preparation to eventually include lint with GOOS=windows as part of CI. **Link to tracking Issue:** N/A **Testing:** `make` on component folder on a Windows box **Documentation:** N/A --- receiver/iisreceiver/scraper.go | 6 +++--- receiver/iisreceiver/scraper_test.go | 18 ++++++++++-------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/receiver/iisreceiver/scraper.go b/receiver/iisreceiver/scraper.go index 2bc8fcdbbdfc..c51572c393bb 100644 --- a/receiver/iisreceiver/scraper.go +++ b/receiver/iisreceiver/scraper.go @@ -70,7 +70,7 @@ func newIisReceiver(settings receiver.CreateSettings, cfg *Config, consumer cons } // start builds the paths to the watchers -func (rcvr *iisReceiver) start(ctx context.Context, host component.Host) error { +func (rcvr *iisReceiver) start(_ context.Context, _ component.Host) error { errs := &scrapererror.ScrapeErrors{} rcvr.totalWatcherRecorders = rcvr.buildWatcherRecorders(totalPerfCounterRecorders, errs) @@ -82,7 +82,7 @@ func (rcvr *iisReceiver) start(ctx context.Context, host component.Host) error { } // scrape pulls counter values from the watchers -func (rcvr *iisReceiver) scrape(ctx context.Context) (pmetric.Metrics, error) { +func (rcvr *iisReceiver) scrape(_ context.Context) (pmetric.Metrics, error) { var errs error now := pcommon.NewTimestampFromTime(time.Now()) @@ -197,7 +197,7 @@ func (rcvr *iisReceiver) emitInstanceMap(now pcommon.Timestamp, instanceToRecord } // shutdown closes the watchers -func (rcvr iisReceiver) shutdown(ctx context.Context) error { +func (rcvr iisReceiver) shutdown(_ context.Context) error { var errs error errs = multierr.Append(errs, closeWatcherRecorders(rcvr.totalWatcherRecorders)) errs = multierr.Append(errs, closeWatcherRecorders(rcvr.siteWatcherRecorders)) diff --git a/receiver/iisreceiver/scraper_test.go b/receiver/iisreceiver/scraper_test.go index 425d2f088f89..44203007fe20 100644 --- a/receiver/iisreceiver/scraper_test.go +++ b/receiver/iisreceiver/scraper_test.go @@ -37,7 +37,7 @@ func TestScrape(t *testing.T) { cfg, consumertest.NewNop(), ) - scraper.newWatcher = newMockWatcherFactory(nil, 1) + scraper.newWatcher = newMockWatcherFactory(nil) scraper.newWatcherFromPath = newMockWatcherFactorFromPath(nil, 1) scraper.expandWildcardPath = func(s string) ([]string, error) { return []string{strings.Replace(s, "*", "Instance", 1)}, nil @@ -72,7 +72,7 @@ func TestScrapeFailure(t *testing.T) { ) expectedError := "failure to collect metric" - mockWatcher, err := newMockWatcherFactory(fmt.Errorf(expectedError), 1)("", "", "") + mockWatcher, err := newMockWatcherFactory(fmt.Errorf(expectedError))("", "", "") require.NoError(t, err) scraper.totalWatcherRecorders = []watcherRecorder{ { @@ -83,7 +83,8 @@ func TestScrapeFailure(t *testing.T) { }, } - scraper.scrape(context.Background()) + _, err = scraper.scrape(context.Background()) + require.NoError(t, err) require.Equal(t, 1, obs.Len()) log := obs.All()[0] @@ -107,7 +108,7 @@ func TestMaxQueueItemAgeScrapeFailure(t *testing.T) { ) expectedError := "failure to collect metric" - mockWatcher, err := newMockWatcherFactory(fmt.Errorf(expectedError), 1)("", "", "") + mockWatcher, err := newMockWatcherFactory(fmt.Errorf(expectedError))("", "", "") require.NoError(t, err) scraper.queueMaxAgeWatchers = []instanceWatcher{ { @@ -116,7 +117,8 @@ func TestMaxQueueItemAgeScrapeFailure(t *testing.T) { }, } - scraper.scrape(context.Background()) + _, err = scraper.scrape(context.Background()) + require.NoError(t, err) require.Equal(t, 1, obs.Len()) log := obs.All()[0] @@ -136,7 +138,7 @@ func TestMaxQueueItemAgeNegativeDenominatorScrapeFailure(t *testing.T) { ) expectedError := "Failed to scrape counter \"counter\": A counter with a negative denominator value was detected.\r\n" - mockWatcher, err := newMockWatcherFactory(fmt.Errorf(expectedError), 1)("", "", "") + mockWatcher, err := newMockWatcherFactory(fmt.Errorf(expectedError))("", "", "") require.NoError(t, err) scraper.queueMaxAgeWatchers = []instanceWatcher{ { @@ -162,10 +164,10 @@ type mockPerfCounter struct { value float64 } -func newMockWatcherFactory(watchErr error, value float64) func(string, string, +func newMockWatcherFactory(watchErr error) func(string, string, string) (winperfcounters.PerfCounterWatcher, error) { return func(string, string, string) (winperfcounters.PerfCounterWatcher, error) { - return &mockPerfCounter{watchErr: watchErr, value: value}, nil + return &mockPerfCounter{watchErr: watchErr, value: 1}, nil } }