Skip to content

Commit

Permalink
[influxdb] Improve connection handling (#15879)
Browse files Browse the repository at this point in the history
* [influxdb] Improve connection handling

Especially for InfluxDB2 the connection check was not properly implemented. It only checked if a connections was ever successfully established. Since we removed the full crash when a write error occured, this lead to a situation where a broken connection was not detected. A ping is now implemented and also a failed write results in a disconnect.

---------

Signed-off-by: Jan N. Klug <[email protected]>
  • Loading branch information
J-N-K authored Nov 11, 2023
1 parent 1b466fb commit 2892731
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ private void commit() {
if (!influxDBRepository.write(points)) {
logger.warn("Re-queuing {} elements, failed to write batch.", points.size());
pointsQueue.addAll(points);
influxDBRepository.disconnect();
} else {
logger.trace("Wrote {} elements to database", points.size());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import com.influxdb.client.InfluxDBClientOptions;
import com.influxdb.client.QueryApi;
import com.influxdb.client.WriteApi;
import com.influxdb.client.domain.HealthCheck;
import com.influxdb.client.domain.Ready;
import com.influxdb.client.domain.WritePrecision;
import com.influxdb.client.write.Point;
Expand Down Expand Up @@ -76,7 +77,8 @@ public InfluxDB2RepositoryImpl(InfluxDBConfiguration configuration,

@Override
public boolean isConnected() {
return client != null;
InfluxDBClient client = this.client;
return client != null && client.health().getStatus() == HealthCheck.StatusEnum.PASS;
}

@Override
Expand Down

0 comments on commit 2892731

Please sign in to comment.