From 5aa211e0a9c424d3cbb328f07bc2940f3f54f0d3 Mon Sep 17 00:00:00 2001 From: Thomas Casteleyn Date: Mon, 23 Sep 2024 18:21:11 +0200 Subject: [PATCH] fix(inputs.consul): Move config checking to Init method (#15907) --- plugins/inputs/consul/consul.go | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/plugins/inputs/consul/consul.go b/plugins/inputs/consul/consul.go index 2996a34d2..7687eb681 100644 --- a/plugins/inputs/consul/consul.go +++ b/plugins/inputs/consul/consul.go @@ -42,10 +42,6 @@ func (c *Consul) Init() error { c.Log.Warnf("Use of deprecated configuration: 'metric_version = 1'; please update to 'metric_version = 2'") } - return nil -} - -func (c *Consul) createAPIClient() (*api.Client, error) { config := api.DefaultConfig() if c.Address != "" { @@ -77,14 +73,15 @@ func (c *Consul) createAPIClient() (*api.Client, error) { tlsCfg, err := c.ClientConfig.TLSConfig() if err != nil { - return nil, err + return err } config.Transport = &http.Transport{ TLSClientConfig: tlsCfg, } - return api.NewClient(config) + c.client, err = api.NewClient(config) + return err } func (c *Consul) GatherHealthCheck(acc telegraf.Accumulator, checks []*api.HealthCheck) { @@ -129,16 +126,6 @@ func (c *Consul) GatherHealthCheck(acc telegraf.Accumulator, checks []*api.Healt } func (c *Consul) Gather(acc telegraf.Accumulator) error { - if c.client == nil { - newClient, err := c.createAPIClient() - - if err != nil { - return err - } - - c.client = newClient - } - checks, _, err := c.client.Health().State("any", nil) if err != nil {