mirror of
https://github.com/ClusterCockpit/cc-metric-collector.git
synced 2025-08-14 22:53:01 +02:00
Ping InfluxDB server after connecting to recognize faulty connections
This commit is contained in:
@@ -54,6 +54,13 @@ func (s *InfluxSink) connect() error {
|
||||
)
|
||||
s.client = influxdb2.NewClientWithOptions(uri, auth, clientOptions)
|
||||
s.writeApi = s.client.WriteAPIBlocking(s.config.Organization, s.config.Database)
|
||||
ok, err := s.client.Ping(context.Background())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !ok {
|
||||
return fmt.Errorf("connection to %s not healthy", uri)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -94,7 +101,7 @@ func NewInfluxSink(name string, config json.RawMessage) (Sink, error) {
|
||||
|
||||
// Connect to InfluxDB server
|
||||
if err := s.connect(); err != nil {
|
||||
return nil, fmt.Errorf("Unable to connect: %v", err)
|
||||
return nil, fmt.Errorf("unable to connect: %v", err)
|
||||
}
|
||||
return s, nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user