From aaf8e9e737a30cd2bf233418bdaada23b5282ae8 Mon Sep 17 00:00:00 2001 From: Lam Tran Date: Mon, 5 Feb 2024 22:21:39 +0700 Subject: [PATCH 1/2] [receiver/httpcheck] refactor client length checking --- receiver/httpcheckreceiver/scraper.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/receiver/httpcheckreceiver/scraper.go b/receiver/httpcheckreceiver/scraper.go index 59b467172ea8..f0012c1a2c5d 100644 --- a/receiver/httpcheckreceiver/scraper.go +++ b/receiver/httpcheckreceiver/scraper.go @@ -35,9 +35,9 @@ type httpcheckScraper struct { // start starts the scraper by creating a new HTTP Client on the scraper func (h *httpcheckScraper) start(_ context.Context, host component.Host) (err error) { for _, target := range h.cfg.Targets { - client, clentErr := target.ToClient(host, h.settings) - if clentErr != nil { - err = multierr.Append(err, clentErr) + client, clientErr := target.ToClient(host, h.settings) + if clientErr != nil { + err = multierr.Append(err, clientErr) } h.clients = append(h.clients, client) } @@ -46,12 +46,13 @@ func (h *httpcheckScraper) start(_ context.Context, host component.Host) (err er // scrape connects to the endpoint and produces metrics based on the response func (h *httpcheckScraper) scrape(ctx context.Context) (pmetric.Metrics, error) { - if h.clients == nil || len(h.clients) == 0 { + length := len(h.clients) + if length == 0 { return pmetric.NewMetrics(), errClientNotInit } var wg sync.WaitGroup - wg.Add(len(h.clients)) + wg.Add(length) var mux sync.Mutex for idx, client := range h.clients { From 8b5b433dd951d9895ba8cf3a2ba054e3a326a407 Mon Sep 17 00:00:00 2001 From: Lam Tran Date: Tue, 6 Feb 2024 09:19:49 +0700 Subject: [PATCH 2/2] [receiver/httpcheck] fix typo in test --- receiver/httpcheckreceiver/scraper_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/receiver/httpcheckreceiver/scraper_test.go b/receiver/httpcheckreceiver/scraper_test.go index 25008541d6aa..9a893389c7a0 100644 --- a/receiver/httpcheckreceiver/scraper_test.go +++ b/receiver/httpcheckreceiver/scraper_test.go @@ -89,7 +89,7 @@ func TestScraperStart(t *testing.T) { } } -func TestScaperScrape(t *testing.T) { +func TestScraperScrape(t *testing.T) { testCases := []struct { desc string expectedResponse int