Skip to content

Commit 24575d1

Browse files
committed
feat: the url to connect to the InfluxDB is always evaluate as a connection string
1 parent 7b26209 commit 24575d1

10 files changed

Lines changed: 197 additions & 28 deletions

File tree

client-kotlin/src/main/kotlin/com/influxdb/client/kotlin/InfluxDBClientKotlinFactory.kt

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,12 @@ class InfluxDBClientKotlinFactory {
5050
}
5151

5252
/**
53-
* Create an instance of the InfluxDB 2.x client. The url could be a connection string with various configurations.
53+
* Create an instance of the InfluxDB 2.x client.
5454
*
55-
* e.g.: "http://localhost:8086?readTimeout=5000&connectTimeout=5000&logLevel=BASIC
55+
* <p>
56+
* The url could be a connection string with various configurations. For more info
57+
* see: {@link InfluxDBClientOptions.Builder#connectionString(String)}.
58+
* </p>
5659
*
5760
* @param connectionString connection string with various configurations.
5861
* @return client
@@ -76,7 +79,12 @@ class InfluxDBClientKotlinFactory {
7679
* and client produces {@link com.influxdb.exceptions.UnauthorizedException}.
7780
* </p>
7881
*
79-
* @param url the url to connect to the InfluxDB
82+
* <p>
83+
* The url could be a connection string with various configurations. For more info
84+
* see: {@link InfluxDBClientOptions.Builder#connectionString(String)}.
85+
* </p>
86+
*
87+
* @param url the url to connect to InfluxDB (required). Example: http://localhost:8086?readTimeout=5000
8088
* @param username the username to use in the basic auth
8189
* @param password the password to use in the basic auth
8290
* @return client
@@ -97,7 +105,12 @@ class InfluxDBClientKotlinFactory {
97105
/**
98106
* Create an instance of the InfluxDB 2.x reactive client.
99107
*
100-
* @param url the url to connect to the InfluxDB
108+
* <p>
109+
* The url could be a connection string with various configurations. For more info
110+
* see: {@link InfluxDBClientOptions.Builder#connectionString(String)}.
111+
* </p>
112+
*
113+
* @param url the url to connect to InfluxDB (required). Example: http://localhost:8086?readTimeout=5000
101114
* @param token the token to use for the authorization
102115
* @return client
103116
* @see InfluxDBClientOptions.Builder.url
@@ -110,7 +123,12 @@ class InfluxDBClientKotlinFactory {
110123
/**
111124
* Create an instance of the InfluxDB 2.x reactive client.
112125
*
113-
* @param url the url to connect to the InfluxDB
126+
* <p>
127+
* The url could be a connection string with various configurations. For more info
128+
* see: {@link InfluxDBClientOptions.Builder#connectionString(String)}.
129+
* </p>
130+
*
131+
* @param url the url to connect to InfluxDB (required). Example: http://localhost:8086?readTimeout=5000
114132
* @param token the token to use for the authorization
115133
* @param org the name of an organization
116134
* @return client
@@ -124,7 +142,12 @@ class InfluxDBClientKotlinFactory {
124142
/**
125143
* Create an instance of the InfluxDB 2.x reactive client.
126144
*
127-
* @param url the url to connect to the InfluxDB
145+
* <p>
146+
* The url could be a connection string with various configurations. For more info
147+
* see: {@link InfluxDBClientOptions.Builder#connectionString(String)}.
148+
* </p>
149+
*
150+
* @param url the url to connect to InfluxDB (required). Example: http://localhost:8086?readTimeout=5000
128151
* @param token the token to use for the authorization
129152
* @param org the name of an organization
130153
* @param bucket the name of a bucket

client-kotlin/src/test/kotlin/com/influxdb/client/kotlin/InfluxDBClientKotlinFactoryTest.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,13 @@ class InfluxDBClientKotlinFactoryTest : AbstractTest() {
7676
Assertions.assertThat(it).isNotNull
7777
}
7878
}
79+
80+
@Test
81+
@Throws(NoSuchFieldException::class, IllegalAccessException::class)
82+
fun connectionStringConfiguration() {
83+
val client = InfluxDBClientKotlinFactory.create("http://localhost:8086?connectTimeout=45000", "xyz".toCharArray())
84+
val retrofit = getDeclaredField<Retrofit>(client, "retrofit", AbstractInfluxDBClient::class.java)
85+
val okHttpClient = retrofit.callFactory() as OkHttpClient
86+
Assertions.assertThat(okHttpClient.connectTimeoutMillis).isEqualTo(45000)
87+
}
7988
}

client-reactive/src/main/java/com/influxdb/client/reactive/InfluxDBClientReactiveFactory.java

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,12 @@ public static InfluxDBClientReactive create() {
5555
}
5656

5757
/**
58-
* Create an instance of the InfluxDB 2.x client. The url could be a connection string with various configurations.
58+
* Create an instance of the InfluxDB 2.x client.
59+
*
5960
* <p>
60-
* e.g.: "http://localhost:8086?readTimeout=5000&amp;connectTimeout=5000&amp;logLevel=BASIC
61+
* The url could be a connection string with various configurations. For more info
62+
* see: {@link InfluxDBClientOptions.Builder#connectionString(String)}.
63+
* </p>
6164
*
6265
* @param connectionString connection string with various configurations.
6366
* @return client
@@ -82,7 +85,12 @@ public static InfluxDBClientReactive create(@Nonnull final String connectionStri
8285
* and client produces {@link com.influxdb.exceptions.UnauthorizedException}.
8386
* </p>
8487
*
85-
* @param url the url to connect to the InfluxDB
88+
* <p>
89+
* The url could be a connection string with various configurations. For more info
90+
* see: {@link InfluxDBClientOptions.Builder#connectionString(String)}.
91+
* </p>
92+
*
93+
* @param url url the url to connect to InfluxDB (required). Example: http://localhost:8086?readTimeout=5000
8694
* @param username the username to use in the basic auth
8795
* @param password the password to use in the basic auth
8896
* @return client
@@ -104,7 +112,12 @@ public static InfluxDBClientReactive create(@Nonnull final String url,
104112
/**
105113
* Create an instance of the InfluxDB 2.x reactive client.
106114
*
107-
* @param url the url to connect to the InfluxDB
115+
* <p>
116+
* The url could be a connection string with various configurations. For more info
117+
* see: {@link InfluxDBClientOptions.Builder#connectionString(String)}.
118+
* </p>
119+
*
120+
* @param url url the url to connect to InfluxDB (required). Example: http://localhost:8086?readTimeout=5000
108121
* @param token the token to use for the authorization
109122
* @return client
110123
* @see InfluxDBClientOptions.Builder#url(String)
@@ -118,7 +131,12 @@ public static InfluxDBClientReactive create(@Nonnull final String url, @Nonnull
118131
/**
119132
* Create an instance of the InfluxDB 2.x reactive client.
120133
*
121-
* @param url the url to connect to the InfluxDB
134+
* <p>
135+
* The url could be a connection string with various configurations. For more info
136+
* see: {@link InfluxDBClientOptions.Builder#connectionString(String)}.
137+
* </p>
138+
*
139+
* @param url url the url to connect to InfluxDB (required). Example: http://localhost:8086?readTimeout=5000
122140
* @param token the token to use for the authorization
123141
* @param org the name of an organization
124142
* @return client
@@ -135,7 +153,12 @@ public static InfluxDBClientReactive create(@Nonnull final String url,
135153
/**
136154
* Create an instance of the InfluxDB 2.x reactive client.
137155
*
138-
* @param url the url to connect to the InfluxDB
156+
* <p>
157+
* The url could be a connection string with various configurations. For more info
158+
* see: {@link InfluxDBClientOptions.Builder#connectionString(String)}.
159+
* </p>
160+
*
161+
* @param url url the url to connect to InfluxDB (required). Example: http://localhost:8086?readTimeout=5000
139162
* @param token the token to use for the authorization
140163
* @param org the name of an organization
141164
* @param bucket the name of a bucket

client-reactive/src/test/java/com/influxdb/client/reactive/InfluxDBClientReactiveFactoryTest.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,4 +91,16 @@ public void autoClosable() {
9191
Assertions.assertThat(client).isNotNull();
9292
}
9393
}
94+
95+
@Test
96+
void connectionStringConfiguration() throws NoSuchFieldException, IllegalAccessException {
97+
InfluxDBClientReactive client = InfluxDBClientReactiveFactory.create("http://localhost:8086?readTimeout=15000", "xyz".toCharArray());
98+
99+
Assertions.assertThat(client).isNotNull();
100+
101+
Retrofit retrofit = getDeclaredField(client, "retrofit", AbstractInfluxDBClient.class);
102+
OkHttpClient okHttpClient = (OkHttpClient) retrofit.callFactory();
103+
104+
Assertions.assertThat(okHttpClient.readTimeoutMillis()).isEqualTo(15_000);
105+
}
94106
}

client-scala/src/main/scala/com/influxdb/client/scala/InfluxDBClientScalaFactory.scala

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,10 @@ object InfluxDBClientScalaFactory {
5151
}
5252

5353
/**
54-
* Create an instance of the InfluxDB 2.x client. The url could be a connection string with various configurations.
54+
* Create an instance of the InfluxDB 2.x client.
5555
*
56-
* e.g.: "http://localhost:8086?readTimeout=5000&amp;connectTimeout=5000&amp;logLevel=BASIC
56+
* The url could be a connection string with various configurations. For more info
57+
* see: [[InfluxDBClientOptions.Builder#connectionString(connectionString:java.lang.String)]].
5758
*
5859
* @param connectionString connection string with various configurations.
5960
* @return client
@@ -75,7 +76,10 @@ object InfluxDBClientScalaFactory {
7576
* [[http://bit.ly/session-length time-to-live (TTL)]] (default 60 minutes) is reached
7677
* and client produces [[com.influxdb.exceptions.UnauthorizedException]].
7778
*
78-
* @param url the url to connect to the InfluxDB
79+
* The url could be a connection string with various configurations. For more info
80+
* see: [[InfluxDBClientOptions.Builder#connectionString(connectionString:java.lang.String)]].
81+
*
82+
* @param url the url the url to connect to InfluxDB (required). Example: http://localhost:8086?readTimeout=5000
7983
* @param username the username to use in the basic auth
8084
* @param password the password to use in the basic auth
8185
* @return client
@@ -94,7 +98,10 @@ object InfluxDBClientScalaFactory {
9498
/**
9599
* Create an instance of the InfluxDB 2.x reactive client.
96100
*
97-
* @param url the url to connect to the InfluxDB
101+
* The url could be a connection string with various configurations. For more info
102+
* see: [[InfluxDBClientOptions.Builder#connectionString(connectionString:java.lang.String)]].
103+
*
104+
* @param url the url the url to connect to InfluxDB (required). Example: http://localhost:8086?readTimeout=5000
98105
* @param token the token to use for the authorization
99106
* @return client
100107
* @see [[InfluxDBClientOptions.Builder]]
@@ -107,7 +114,10 @@ object InfluxDBClientScalaFactory {
107114
/**
108115
* Create an instance of the InfluxDB 2.x reactive client.
109116
*
110-
* @param url the url to connect to the InfluxDB
117+
* The url could be a connection string with various configurations. For more info
118+
* see: [[InfluxDBClientOptions.Builder#connectionString(connectionString:java.lang.String)]].
119+
*
120+
* @param url the url the url to connect to InfluxDB (required). Example: http://localhost:8086?readTimeout=5000
111121
* @param token the token to use for the authorization
112122
* @param org the name of an organization
113123
* @return client
@@ -121,7 +131,10 @@ object InfluxDBClientScalaFactory {
121131
/**
122132
* Create an instance of the InfluxDB 2.x reactive client.
123133
*
124-
* @param url the url to connect to the InfluxDB
134+
* The url could be a connection string with various configurations. For more info
135+
* see: [[InfluxDBClientOptions.Builder#connectionString(connectionString:java.lang.String)]].
136+
*
137+
* @param url the url the url to connect to InfluxDB (required). Example: http://localhost:8086?readTimeout=5000
125138
* @param token the token to use for the authorization
126139
* @param org the name of an organization
127140
* @param bucket the name of a bucket

client-scala/src/test/scala/com/influxdb/client/scala/InfluxDBClientScalaFactoryTest.scala

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,16 @@ class InfluxDBClientScalaFactoryTest extends AnyFunSuite with Matchers {
6262
okHttpClient.writeTimeoutMillis should be(10000)
6363
okHttpClient.connectTimeoutMillis should be(18000)
6464
}
65+
66+
test("connectionStringConfiguration") {
67+
68+
val utils = new InfluxDBUtils {}
69+
70+
val client = InfluxDBClientScalaFactory.create("http://localhost:8086?readTimeout=55000", "xyz".toCharArray)
71+
72+
val retrofit = utils.getDeclaredField(client, "retrofit", classOf[AbstractInfluxDBClient]).asInstanceOf[Retrofit]
73+
val okHttpClient = retrofit.callFactory.asInstanceOf[OkHttpClient]
74+
75+
okHttpClient.readTimeoutMillis should be(55000)
76+
}
6577
}

client/src/main/java/com/influxdb/client/InfluxDBClientFactory.java

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,12 @@ public static InfluxDBClient create(@Nonnull final String connectionString) {
8484
* and client produces {@link com.influxdb.exceptions.UnauthorizedException}.
8585
* </p>
8686
*
87-
* @param url the url to connect to the InfluxDB
87+
* <p>
88+
* The url could be a connection string with various configurations. For more info
89+
* see: {@link InfluxDBClientOptions.Builder#connectionString(String)}.
90+
* </p>
91+
*
92+
* @param url url the url to connect to InfluxDB (required). Example: http://localhost:8086?readTimeout=5000
8893
* @param username the username to use in the basic auth
8994
* @param password the password to use in the basic auth
9095
* @return client
@@ -106,7 +111,12 @@ public static InfluxDBClient create(@Nonnull final String url,
106111
/**
107112
* Create an instance of the InfluxDB 2.x client.
108113
*
109-
* @param url the url to connect to the InfluxDB
114+
* <p>
115+
* The url could be a connection string with various configurations. For more info
116+
* see: {@link InfluxDBClientOptions.Builder#connectionString(String)}.
117+
* </p>
118+
*
119+
* @param url url the url to connect to InfluxDB (required). Example: http://localhost:8086?readTimeout=5000
110120
* @param token the token to use for the authorization
111121
* @return client
112122
* @see InfluxDBClientOptions.Builder#url(String)
@@ -120,7 +130,12 @@ public static InfluxDBClient create(@Nonnull final String url, @Nonnull final ch
120130
/**
121131
* Create an instance of the InfluxDB 2.x client.
122132
*
123-
* @param url the url to connect to the InfluxDB
133+
* <p>
134+
* The url could be a connection string with various configurations. For more info
135+
* see: {@link InfluxDBClientOptions.Builder#connectionString(String)}.
136+
* </p>
137+
*
138+
* @param url url the url to connect to InfluxDB (required). Example: http://localhost:8086?readTimeout=5000
124139
* @param token the token to use for the authorization
125140
* @param org the name of an organization
126141
* @return client
@@ -137,7 +152,12 @@ public static InfluxDBClient create(@Nonnull final String url,
137152
/**
138153
* Create an instance of the InfluxDB 2.x client.
139154
*
140-
* @param url the url to connect to the InfluxDB
155+
* <p>
156+
* The url could be a connection string with various configurations. For more info
157+
* see: {@link InfluxDBClientOptions.Builder#connectionString(String)}.
158+
* </p>
159+
*
160+
* @param url url the url to connect to InfluxDB (required). Example: http://localhost:8086?readTimeout=5000
141161
* @param token the token to use for the authorization
142162
* @param org the name of an organization
143163
* @param bucket the name of a bucket
@@ -163,7 +183,12 @@ public static InfluxDBClient create(@Nonnull final String url,
163183
/**
164184
* Create an instance of the InfluxDB 2.x client to connect into InfluxDB 1.8.
165185
*
166-
* @param url the url to connect to the InfluxDB 1.8
186+
* <p>
187+
* The url could be a connection string with various configurations. For more info
188+
* see: {@link InfluxDBClientOptions.Builder#connectionString(String)}.
189+
* </p>
190+
*
191+
* @param url the url to connect to InfluxDB 1.8 (required). http://localhost:8086?readTimeout=5000
167192
* @param username authorization username
168193
* @param password authorization password
169194
* @param database database name
@@ -182,7 +207,12 @@ public static InfluxDBClient createV1(@Nonnull final String url,
182207
/**
183208
* Create an instance of the InfluxDB 2.x client to connect into InfluxDB 1.8.
184209
*
185-
* @param url the url to connect to the InfluxDB 1.8
210+
* <p>
211+
* The url could be a connection string with various configurations. For more info
212+
* see: {@link InfluxDBClientOptions.Builder#connectionString(String)}.
213+
* </p>
214+
*
215+
* @param url the url to connect to InfluxDB 1.8 (required). http://localhost:8086?readTimeout=5000
186216
* @param username authorization username
187217
* @param password authorization password
188218
* @param database database name

client/src/main/java/com/influxdb/client/InfluxDBClientOptions.java

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -259,15 +259,19 @@ public static class Builder {
259259

260260
/**
261261
* Set the url to connect to InfluxDB.
262+
* <p>
263+
* The url could be a connection string with various configurations. For more info
264+
* see: {@link #connectionString(String)}.
265+
* </p>
262266
*
263-
* @param url the url to connect to InfluxDB. It must be defined.
267+
* @param url the url to connect to InfluxDB (required). Example: http://localhost:8086?readTimeout=5000
264268
* @return {@code this}
265269
*/
266270
@Nonnull
267271
public InfluxDBClientOptions.Builder url(@Nonnull final String url) {
268272
Arguments.checkNonEmpty(url, "url");
269273

270-
this.url = new ParsedUrl(url).urlWithoutParams;
274+
connectionString(url);
271275

272276
return this;
273277
}
@@ -438,7 +442,24 @@ public InfluxDBClientOptions.Builder addDefaultTag(@Nonnull final String key,
438442
}
439443

440444
/**
441-
* Configure Builder via connection string.
445+
* Configure Builder via connection string. The allowed configuration:
446+
*
447+
* <ul>
448+
* <li><code>org</code> - default destination organization for writes and queries</li>
449+
* <li><code>bucket</code> - default destination bucket for writes</li>
450+
* <li><code>token</code> - the token to use for the authorization</li>
451+
* <li><code>logLevel</code> - rest client verbosity level</li>
452+
* <li><code>readTimeout</code> - read timeout</li>
453+
* <li><code>writeTimeout</code> - write timeout</li>
454+
* <li><code>connectTimeout</code> - socket timeout</li>
455+
* <li><code>precision</code> - default precision for unix timestamps in the line protocol</li>
456+
* <li><code>consistency</code> - specify the write consistency for the point</li>
457+
* </ul>
458+
*
459+
* Connection string example:
460+
* <pre>
461+
* http://localhost:8086?readTimeout=30000&amp;token=my-token&amp;bucket=my-bucket&amp;org=my-org
462+
* </pre>
442463
*
443464
* @return {@code this}
444465
*/
@@ -547,7 +568,7 @@ private InfluxDBClientOptions.Builder configure(@Nonnull final String url,
547568
@Nullable final String precision,
548569
@Nullable final String consistency) {
549570

550-
url(url);
571+
this.url = new ParsedUrl(url).urlWithoutParams;
551572
org(org);
552573
bucket(bucket);
553574

0 commit comments

Comments
 (0)