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.4.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
@@ -99,7 +103,10 @@ public final class ClientConfig {
99103 private final Integer gzipThreshold ;
100104 private final Boolean writeNoSync ;
101105 private final Map <String , String > defaultTags ;
106+ @ Deprecated
102107 private final Duration timeout ;
108+ private final Duration writeTimeout ;
109+ private final Duration queryTimeout ;
103110 private final Boolean allowHttpRedirects ;
104111 private final Boolean disableServerCertificateValidation ;
105112 private final String proxyUrl ;
@@ -203,15 +210,42 @@ public Map<String, String> getDefaultTags() {
203210 }
204211
205212 /**
206- * Gets the default timeout to use for the API calls. Default to '10 seconds'.
213+ * Gets the default timeout to use for write API calls.
214+ * Defaults to '{@value com.influxdb.v3.client.write.WriteOptions#DEFAULT_WRITE_TIMEOUT} seconds'.
215+ * <p>
216+ * Deprecated in v1.4.0. Please use more informative <code>getWriteTimeout()</code>.
207217 *
208- * @return the default timeout to use for the API calls
218+ * @return the default timeout to use for write API calls
219+ * @see #getWriteTimeout()
209220 */
210221 @ Nonnull
222+ @ Deprecated
211223 public Duration getTimeout () {
212224 return timeout ;
213225 }
214226
227+ /**
228+ * Gets the default timeout to use for REST Write API calls. Default is
229+ * {@value com.influxdb.v3.client.write.WriteOptions#DEFAULT_WRITE_TIMEOUT} seconds.
230+ *
231+ * @return the default timeout to use for REST Write API calls.
232+ */
233+ @ Nonnull
234+ public Duration getWriteTimeout () {
235+ return writeTimeout ;
236+ }
237+
238+ /**
239+ * Gets the default timeout Duration to use for calculating a gRPC Deadline when making Query API calls.
240+ * Can be null, in which case queries can potentially wait or run forever.
241+ *
242+ * @return the default timeout Duration to use for Query API calls.
243+ */
244+ @ Nullable
245+ public Duration getQueryTimeout () {
246+ return queryTimeout ;
247+ }
248+
215249 /**
216250 * Gets the automatically following HTTP 3xx redirects. Default to 'false'.
217251 *
@@ -312,6 +346,8 @@ public boolean equals(final Object o) {
312346 && Objects .equals (writeNoSync , that .writeNoSync )
313347 && Objects .equals (defaultTags , that .defaultTags )
314348 && Objects .equals (timeout , that .timeout )
349+ && Objects .equals (writeTimeout , that .writeTimeout )
350+ && Objects .equals (queryTimeout , that .queryTimeout )
315351 && Objects .equals (allowHttpRedirects , that .allowHttpRedirects )
316352 && Objects .equals (disableServerCertificateValidation , that .disableServerCertificateValidation )
317353 && Objects .equals (proxy , that .proxy )
@@ -325,7 +361,7 @@ public boolean equals(final Object o) {
325361 public int hashCode () {
326362 return Objects .hash (host , Arrays .hashCode (token ), authScheme , organization ,
327363 database , writePrecision , gzipThreshold , writeNoSync ,
328- timeout , allowHttpRedirects , disableServerCertificateValidation ,
364+ timeout , writeTimeout , queryTimeout , allowHttpRedirects , disableServerCertificateValidation ,
329365 proxy , proxyUrl , authenticator , headers ,
330366 defaultTags , sslRootsFilePath );
331367 }
@@ -340,6 +376,8 @@ public String toString() {
340376 .add ("gzipThreshold=" + gzipThreshold )
341377 .add ("writeNoSync=" + writeNoSync )
342378 .add ("timeout=" + timeout )
379+ .add ("writeTimeout=" + writeTimeout )
380+ .add ("queryTimeout=" + queryTimeout )
343381 .add ("allowHttpRedirects=" + allowHttpRedirects )
344382 .add ("disableServerCertificateValidation=" + disableServerCertificateValidation )
345383 .add ("proxy=" + proxy )
@@ -366,7 +404,10 @@ public static final class Builder {
366404 private Integer gzipThreshold ;
367405 private Boolean writeNoSync ;
368406 private Map <String , String > defaultTags ;
407+ @ Deprecated
369408 private Duration timeout ;
409+ private Duration writeTimeout ;
410+ private Duration queryTimeout ;
370411 private Boolean allowHttpRedirects ;
371412 private Boolean disableServerCertificateValidation ;
372413 private ProxySelector proxy ;
@@ -496,18 +537,55 @@ public Builder defaultTags(@Nullable final Map<String, String> defaultTags) {
496537 }
497538
498539 /**
499- * Sets the default timeout to use for the API calls. Default to '10 seconds'.
540+ * Sets the default timeout to use for Write API calls. Defaults to
541+ * '{@value com.influxdb.v3.client.write.WriteOptions#DEFAULT_WRITE_TIMEOUT} seconds'.
542+ * <p>
543+ * Deprecated in v1.4.0. This setter is superseded by the clearer <code>writeTimeout()</code>.
500544 *
501- * @param timeout default timeout to use for the API calls. Default to '10 seconds'.
545+ * @param timeout default timeout to use for Write API calls. Default to
546+ * ''{@value com.influxdb.v3.client.write.WriteOptions#DEFAULT_WRITE_TIMEOUT} seconds'.
502547 * @return this
548+ *
549+ * @see #writeTimeout(Duration writeTimeout)
503550 */
551+ @ Deprecated
504552 @ Nonnull
505553 public Builder timeout (@ Nullable final Duration timeout ) {
506554
507555 this .timeout = timeout ;
508556 return this ;
509557 }
510558
559+ /**
560+ * Sets the default writeTimeout to use for Write API calls in the REST client.
561+ * Default is {@value com.influxdb.v3.client.write.WriteOptions#DEFAULT_WRITE_TIMEOUT}
562+ *
563+ * @param writeTimeout default timeout to use for REST API write calls. Default is
564+ * {@value com.influxdb.v3.client.write.WriteOptions#DEFAULT_WRITE_TIMEOUT}
565+ * @return - this
566+ */
567+ @ Nonnull
568+ public Builder writeTimeout (@ Nullable final Duration writeTimeout ) {
569+
570+ this .writeTimeout = writeTimeout ;
571+ return this ;
572+ }
573+
574+ /**
575+ * Sets standard query timeout used to calculate a gRPC deadline when making Query API calls.
576+ * If <code>null</code>, queries can potentially wait or run forever.
577+ *
578+ * @param queryTimeout default timeout used to calculate deadline for Query API calls.
579+ * If <code>null</code>, queries can potentially wait or run forever.
580+ * Default value is <code>null</code>.
581+ * @return this
582+ */
583+ @ Nonnull
584+ public Builder queryTimeout (@ Nullable final Duration queryTimeout ) {
585+ this .queryTimeout = queryTimeout ;
586+ return this ;
587+ }
588+
511589 /**
512590 * Sets the automatically following HTTP 3xx redirects. Default to 'false'.
513591 *
@@ -719,6 +797,16 @@ public ClientConfig build(@Nonnull final Map<String, String> env, final Properti
719797 if (writeNoSync != null ) {
720798 this .writeNoSync (Boolean .parseBoolean (writeNoSync ));
721799 }
800+ final String writeTimeout = get .apply ("INFLUX_WRITE_TIMEOUT" , "influx.writeTimeout" );
801+ if (writeTimeout != null ) {
802+ long to = Long .parseLong (writeTimeout );
803+ this .writeTimeout (Duration .ofSeconds (to ));
804+ }
805+ final String queryTimeout = get .apply ("INFLUX_QUERY_TIMEOUT" , "influx.queryTimeout" );
806+ if (queryTimeout != null ) {
807+ long to = Long .parseLong (queryTimeout );
808+ this .queryTimeout (Duration .ofSeconds (to ));
809+ }
722810
723811 return new ClientConfig (this );
724812 }
@@ -761,7 +849,11 @@ private ClientConfig(@Nonnull final Builder builder) {
761849 gzipThreshold = builder .gzipThreshold != null ? builder .gzipThreshold : WriteOptions .DEFAULT_GZIP_THRESHOLD ;
762850 writeNoSync = builder .writeNoSync != null ? builder .writeNoSync : WriteOptions .DEFAULT_NO_SYNC ;
763851 defaultTags = builder .defaultTags ;
764- timeout = builder .timeout != null ? builder .timeout : Duration .ofSeconds (10 );
852+ timeout = builder .timeout != null ? builder .timeout : Duration .ofSeconds (WriteOptions .DEFAULT_WRITE_TIMEOUT );
853+ writeTimeout = builder .writeTimeout != null
854+ ? builder .writeTimeout : builder .timeout != null
855+ ? builder .timeout : Duration .ofSeconds (WriteOptions .DEFAULT_WRITE_TIMEOUT );
856+ queryTimeout = builder .queryTimeout ;
765857 allowHttpRedirects = builder .allowHttpRedirects != null ? builder .allowHttpRedirects : false ;
766858 disableServerCertificateValidation = builder .disableServerCertificateValidation != null
767859 ? builder .disableServerCertificateValidation : false ;
0 commit comments