From 15ebd27716660e33014f150ee61ea005144b0899 Mon Sep 17 00:00:00 2001 From: Alex Boten Date: Fri, 25 Aug 2023 08:30:19 -0700 Subject: [PATCH] [receiver/zookeeper] remove duplicate Timeout field (#26082) Rely on the scraper helper's Timeout instead --------- Signed-off-by: Alex Boten --- .../codeboten_rm-dupe-timeout-zookeeper.yaml | 27 +++++++++++++++++++ receiver/zookeeperreceiver/config.go | 5 ---- receiver/zookeeperreceiver/factory.go | 2 +- receiver/zookeeperreceiver/scraper.go | 7 ++--- receiver/zookeeperreceiver/scraper_test.go | 5 ++-- 5 files changed, 32 insertions(+), 14 deletions(-) create mode 100755 .chloggen/codeboten_rm-dupe-timeout-zookeeper.yaml diff --git a/.chloggen/codeboten_rm-dupe-timeout-zookeeper.yaml b/.chloggen/codeboten_rm-dupe-timeout-zookeeper.yaml new file mode 100755 index 000000000000..c20b7a75f533 --- /dev/null +++ b/.chloggen/codeboten_rm-dupe-timeout-zookeeper.yaml @@ -0,0 +1,27 @@ +# Use this changelog template to create an entry for release notes. + +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: breaking + +# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver) +component: zookeeperreceiver + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: "Removes duplicate `Timeout` field. This change has no impact on end users of the component." + +# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. +issues: [26082] + +# (Optional) One or more lines of additional information to render under the primary note. +# These lines will be padded with 2 spaces and then inserted directly into the document. +# Use pipe (|) for multiline entries. +subtext: + +# If your change doesn't affect end users or the exported elements of any package, +# you should instead start your pull request title with [chore] or use the "Skip Changelog" label. +# Optional: The change log or logs in which this entry should be included. +# e.g. '[user]' or '[user, api]' +# Include 'user' if the change is relevant to end users. +# Include 'api' if there is a change to a library API. +# Default: '[user]' +change_logs: [api] diff --git a/receiver/zookeeperreceiver/config.go b/receiver/zookeeperreceiver/config.go index b96b80e44fd0..cde56452312e 100644 --- a/receiver/zookeeperreceiver/config.go +++ b/receiver/zookeeperreceiver/config.go @@ -4,8 +4,6 @@ package zookeeperreceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/zookeeperreceiver" import ( - "time" - "go.opentelemetry.io/collector/config/confignet" "go.opentelemetry.io/collector/receiver/scraperhelper" @@ -16,7 +14,4 @@ type Config struct { scraperhelper.ScraperControllerSettings `mapstructure:",squash"` confignet.TCPAddr `mapstructure:",squash"` metadata.MetricsBuilderConfig `mapstructure:",squash"` - - // Timeout within which requests should be completed. - Timeout time.Duration `mapstructure:"timeout"` } diff --git a/receiver/zookeeperreceiver/factory.go b/receiver/zookeeperreceiver/factory.go index 082660a98819..4c8fffc8ca7f 100644 --- a/receiver/zookeeperreceiver/factory.go +++ b/receiver/zookeeperreceiver/factory.go @@ -32,13 +32,13 @@ func NewFactory() receiver.Factory { func createDefaultConfig() component.Config { cfg := scraperhelper.NewDefaultScraperControllerSettings(metadata.Type) cfg.CollectionInterval = defaultCollectionInterval + cfg.Timeout = defaultTimeout return &Config{ ScraperControllerSettings: cfg, TCPAddr: confignet.TCPAddr{ Endpoint: ":2181", }, - Timeout: defaultTimeout, MetricsBuilderConfig: metadata.DefaultMetricsBuilderConfig(), } } diff --git a/receiver/zookeeperreceiver/scraper.go b/receiver/zookeeperreceiver/scraper.go index 414e9cf83f8b..6d08a49fc12f 100644 --- a/receiver/zookeeperreceiver/scraper.go +++ b/receiver/zookeeperreceiver/scraper.go @@ -77,15 +77,12 @@ func (z *zookeeperMetricsScraper) shutdown(_ context.Context) error { } func (z *zookeeperMetricsScraper) scrape(ctx context.Context) (pmetric.Metrics, error) { - var ctxWithTimeout context.Context - ctxWithTimeout, z.cancel = context.WithTimeout(ctx, z.config.Timeout) - - responseMntr, err := z.runCommand(ctxWithTimeout, "mntr") + responseMntr, err := z.runCommand(ctx, "mntr") if err != nil { return pmetric.NewMetrics(), err } - responseRuok, err := z.runCommand(ctxWithTimeout, "ruok") + responseRuok, err := z.runCommand(ctx, "ruok") if err != nil { return pmetric.NewMetrics(), err } diff --git a/receiver/zookeeperreceiver/scraper_test.go b/receiver/zookeeperreceiver/scraper_test.go index 794c418fe542..03f77a58e838 100644 --- a/receiver/zookeeperreceiver/scraper_test.go +++ b/receiver/zookeeperreceiver/scraper_test.go @@ -288,8 +288,6 @@ func TestZookeeperMetricsScraperScrape(t *testing.T) { require.NoError(t, err) require.Equal(t, "zookeeper", z.Name()) - ctx := context.Background() - if tt.setConnectionDeadline != nil { z.setConnectionDeadline = tt.setConnectionDeadline } @@ -301,7 +299,8 @@ func TestZookeeperMetricsScraperScrape(t *testing.T) { if tt.sendCmd != nil { z.sendCmd = tt.sendCmd } - + ctx, cancel := context.WithTimeout(context.Background(), z.config.Timeout) + defer cancel() actualMetrics, err := z.scrape(ctx) require.NoError(t, z.shutdown(ctx))