Skip to content

Commit

Permalink
fix(inputs.consul): Move config checking to Init method (#15907)
Browse files Browse the repository at this point in the history
  • Loading branch information
Hipska committed Sep 23, 2024
1 parent 97f3d1f commit 5aa211e
Showing 1 changed file with 3 additions and 16 deletions.
19 changes: 3 additions & 16 deletions plugins/inputs/consul/consul.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 != "" {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 5aa211e

Please sign in to comment.