5454 * <li><code>defaultTags</code> - defaultTags added when writing points to InfluxDB</li>
5555 * <li><code>gzipThreshold</code> - threshold when gzip compression is used for writing points to InfluxDB</li>
5656 * <li><code>writeNoSync</code> - skip waiting for WAL persistence on write</li>
57- * <li><code>responseTimeout</code> - timeout when connecting to InfluxDB</li>
57+ * <li><code>timeout</code> - <i>deprecated in 1.3.0</i> timeout when connecting to InfluxDB,
58+ * please use more informative properties <code>writeTimeout</code> and <code>queryTimeout</code></li>
59+ * <li><code>writeTimeout</code> - timeout when writing data to InfluxDB</li>
60+ * <li><code>queryTimeout</code> - timeout used to calculate a default GRPC deadline when querying InfluxDB.
61+ * Can be <code>null</code>, in which case queries can potentially run forever.</li>
5862 * <li><code>allowHttpRedirects</code> - allow redirects for InfluxDB connections</li>
5963 * <li><code>disableServerCertificateValidation</code> -
6064 * disable server certificate validation for HTTPS connections
@@ -100,6 +104,8 @@ public final class ClientConfig {
100104 private final Boolean writeNoSync ;
101105 private final Map <String , String > defaultTags ;
102106 private final Duration timeout ;
107+ private final Duration writeTimeout ;
108+ private final Duration queryTimeout ;
103109 private final Boolean allowHttpRedirects ;
104110 private final Boolean disableServerCertificateValidation ;
105111 private final String proxyUrl ;
@@ -212,6 +218,28 @@ public Duration getTimeout() {
212218 return timeout ;
213219 }
214220
221+ /**
222+ * Gets the default timeout in seconds to use for REST Write API calls. Default is
223+ * {@value com.influxdb.v3.client.write.WriteOptions#DEFAULT_WRITE_TIMEOUT}
224+ *
225+ * @return the default timeout in seconds to use for REST Write API calls.
226+ */
227+ @ Nonnull
228+ public Duration getWriteTimeout () {
229+ return writeTimeout ;
230+ }
231+
232+ /**
233+ * Gets the default timeout in seconds to use for calculating a GRPC Deadline when making Query API calls.
234+ * Can be null, in which case queries can potentially wait or run forever.
235+ *
236+ * @return the default timeout in seconds to use for Query API calls.
237+ */
238+ @ Nullable
239+ public Duration getQueryTimeout () {
240+ return queryTimeout ;
241+ }
242+
215243 /**
216244 * Gets the automatically following HTTP 3xx redirects. Default to 'false'.
217245 *
@@ -312,6 +340,8 @@ public boolean equals(final Object o) {
312340 && Objects .equals (writeNoSync , that .writeNoSync )
313341 && Objects .equals (defaultTags , that .defaultTags )
314342 && Objects .equals (timeout , that .timeout )
343+ && Objects .equals (writeTimeout , that .writeTimeout )
344+ && Objects .equals (queryTimeout , that .queryTimeout )
315345 && Objects .equals (allowHttpRedirects , that .allowHttpRedirects )
316346 && Objects .equals (disableServerCertificateValidation , that .disableServerCertificateValidation )
317347 && Objects .equals (proxy , that .proxy )
@@ -325,7 +355,7 @@ public boolean equals(final Object o) {
325355 public int hashCode () {
326356 return Objects .hash (host , Arrays .hashCode (token ), authScheme , organization ,
327357 database , writePrecision , gzipThreshold , writeNoSync ,
328- timeout , allowHttpRedirects , disableServerCertificateValidation ,
358+ timeout , writeTimeout , queryTimeout , allowHttpRedirects , disableServerCertificateValidation ,
329359 proxy , proxyUrl , authenticator , headers ,
330360 defaultTags , sslRootsFilePath );
331361 }
@@ -340,6 +370,8 @@ public String toString() {
340370 .add ("gzipThreshold=" + gzipThreshold )
341371 .add ("writeNoSync=" + writeNoSync )
342372 .add ("timeout=" + timeout )
373+ .add ("writeTimeout=" + writeTimeout )
374+ .add ("queryTimeout=" + queryTimeout )
343375 .add ("allowHttpRedirects=" + allowHttpRedirects )
344376 .add ("disableServerCertificateValidation=" + disableServerCertificateValidation )
345377 .add ("proxy=" + proxy )
@@ -367,6 +399,8 @@ public static final class Builder {
367399 private Boolean writeNoSync ;
368400 private Map <String , String > defaultTags ;
369401 private Duration timeout ;
402+ private Duration writeTimeout ;
403+ private Duration queryTimeout ;
370404 private Boolean allowHttpRedirects ;
371405 private Boolean disableServerCertificateValidation ;
372406 private ProxySelector proxy ;
@@ -497,17 +531,50 @@ public Builder defaultTags(@Nullable final Map<String, String> defaultTags) {
497531
498532 /**
499533 * Sets the default timeout to use for the API calls. Default to '10 seconds'.
534+ * <p>
535+ * Note that this parameter is being superseded by clearer writeTimeout.
500536 *
501537 * @param timeout default timeout to use for the API calls. Default to '10 seconds'.
502538 * @return this
503539 */
540+ @ Deprecated
504541 @ Nonnull
505542 public Builder timeout (@ Nullable final Duration timeout ) {
506543
507544 this .timeout = timeout ;
508545 return this ;
509546 }
510547
548+ /**
549+ * Sets the default writeTimeout to use for Write API calls in the REST client.
550+ * Default is {@value com.influxdb.v3.client.write.WriteOptions#DEFAULT_WRITE_TIMEOUT}
551+ *
552+ * @param writeTimeout default timeout to use for REST API write calls. Default is
553+ * {@value com.influxdb.v3.client.write.WriteOptions#DEFAULT_WRITE_TIMEOUT}
554+ * @return - this
555+ */
556+ @ Nonnull
557+ public Builder writeTimeout (@ Nullable final Duration writeTimeout ) {
558+
559+ this .writeTimeout = writeTimeout ;
560+ return this ;
561+ }
562+
563+ /**
564+ * Sets standard query timeout used to calculate a GRPC deadline when making Query API calls.
565+ * If <code>null</code>, queries can potentially wait or run forever.
566+ *
567+ * @param queryTimeout default timeout used to calculate deadline for Query API calls.
568+ * If <code>null</code>, queries can potentially wait or run forever.
569+ * Default value is <code>null</code>.
570+ * @return this
571+ */
572+ @ Nonnull
573+ public Builder queryTimeout (@ Nullable final Duration queryTimeout ) {
574+ this .queryTimeout = queryTimeout ;
575+ return this ;
576+ }
577+
511578 /**
512579 * Sets the automatically following HTTP 3xx redirects. Default to 'false'.
513580 *
@@ -719,6 +786,16 @@ public ClientConfig build(@Nonnull final Map<String, String> env, final Properti
719786 if (writeNoSync != null ) {
720787 this .writeNoSync (Boolean .parseBoolean (writeNoSync ));
721788 }
789+ final String writeTimeout = get .apply ("INFLUX_WRITE_TIMEOUT" , "influx.writeTimeout" );
790+ if (writeTimeout != null ) {
791+ long to = Long .parseLong (writeTimeout );
792+ this .writeTimeout (Duration .ofSeconds (to ));
793+ }
794+ final String queryTimeout = get .apply ("INFLUX_QUERY_TIMEOUT" , "influx.queryTimeout" );
795+ if (queryTimeout != null ) {
796+ long to = Long .parseLong (queryTimeout );
797+ this .queryTimeout (Duration .ofSeconds (to ));
798+ }
722799
723800 return new ClientConfig (this );
724801 }
@@ -761,7 +838,10 @@ private ClientConfig(@Nonnull final Builder builder) {
761838 gzipThreshold = builder .gzipThreshold != null ? builder .gzipThreshold : WriteOptions .DEFAULT_GZIP_THRESHOLD ;
762839 writeNoSync = builder .writeNoSync != null ? builder .writeNoSync : WriteOptions .DEFAULT_NO_SYNC ;
763840 defaultTags = builder .defaultTags ;
764- timeout = builder .timeout != null ? builder .timeout : Duration .ofSeconds (10 );
841+ timeout = builder .timeout != null ? builder .timeout : Duration .ofSeconds (WriteOptions .DEFAULT_WRITE_TIMEOUT );
842+ writeTimeout = builder .writeTimeout != null
843+ ? builder .writeTimeout : Duration .ofSeconds (WriteOptions .DEFAULT_WRITE_TIMEOUT );
844+ queryTimeout = builder .queryTimeout ;
765845 allowHttpRedirects = builder .allowHttpRedirects != null ? builder .allowHttpRedirects : false ;
766846 disableServerCertificateValidation = builder .disableServerCertificateValidation != null
767847 ? builder .disableServerCertificateValidation : false ;
0 commit comments