Skip to content

Commit

Permalink
Fix attempt to connect to an empty list of servers. (#9503)
Browse files Browse the repository at this point in the history
(cherry picked from commit 80829b3)
  • Loading branch information
srebhan authored and reimda committed Jul 28, 2021
1 parent f13d7d7 commit a6b6039
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions plugins/inputs/nsq_consumer/nsq_consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package nsq_consumer

import (
"context"
"fmt"
"sync"

"github.com/influxdata/telegraf"
Expand Down Expand Up @@ -134,15 +135,28 @@ func (n *NSQConsumer) Start(ac telegraf.Accumulator) error {
return nil
}))

// For backward compatibility
if n.Server != "" {
n.Nsqd = append(n.Nsqd, n.Server)
}

// Check if we have anything to connect to
if len(n.Nsqlookupd) == 0 && len(n.Nsqd) == 0 {
return fmt.Errorf("either 'nsqd' or 'nsqlookupd' needs to be specified")
}

if len(n.Nsqlookupd) > 0 {
err := n.consumer.ConnectToNSQLookupds(n.Nsqlookupd)
if err != nil && err != nsq.ErrAlreadyConnected {
return err
}
}
err := n.consumer.ConnectToNSQDs(append(n.Nsqd, n.Server))
if err != nil && err != nsq.ErrAlreadyConnected {
return err

if len(n.Nsqd) > 0 {
err := n.consumer.ConnectToNSQDs(n.Nsqd)
if err != nil && err != nsq.ErrAlreadyConnected {
return err
}
}

n.wg.Add(1)
Expand Down

0 comments on commit a6b6039

Please sign in to comment.