[influxdb] Improve connection handling (#15879)

* [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 <github@klug.nrw>
This commit is contained in:
J-N-K 2023-11-11 23:15:21 +01:00 committed by GitHub
parent 1b466fb319
commit 28927310eb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 1 deletions

View File

@ -286,6 +286,7 @@ public class InfluxDBPersistenceService implements ModifiablePersistenceService
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());
}

View File

@ -44,6 +44,7 @@ import com.influxdb.client.InfluxDBClientFactory;
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;
@ -76,7 +77,8 @@ public class InfluxDB2RepositoryImpl implements InfluxDBRepository {
@Override
public boolean isConnected() {
return client != null;
InfluxDBClient client = this.client;
return client != null && client.health().getStatus() == HealthCheck.StatusEnum.PASS;
}
@Override