Skip to content

Commit cf762ae

Browse files
authored
fix: Issue/623 (#706)
* fix: issue #623 - support IPv6 hosts * chore: troubleshoot Protocol family unavailable in CircleCI * chore: troubleshoot ipv6 enable * chore: troubleshoot of troubleshoot ipv6 enable * chore: specify latest circleci ubuntu image * chore: troubleshoot where to place image definition * chore: investigate ulimit error cause in docker * chore: inspect docker/daemon.json * chore: retry inspection * chore: troubleshoot docker restart * chore: inspect service commands * chore: check docker service status * chore: check service status in circleci * chore: explicit start docker service * chore: troubleshoot tests * chore: try different location for machine * chore: remove machine block * chore: restore config.yml to master verstion * test: removes IPv6 dependent test - not supported by default docker in Circleci * docs: update CHANGELOG.md
1 parent 1b10317 commit cf762ae

File tree

4 files changed

+83
-6
lines changed

4 files changed

+83
-6
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
### Bug Fixes
44

55
1. [#684](https://github.com/influxdata/influxdb-client-java/issues/684): Fix checking for CSV end of table marker when parsing CSV stream to InfluxQLQueryResult, needed for example when parsing the results of a query like "SHOW SERIES".
6-
2. [#662](https://github.com/influxdata/influxdb-client-java/issues/662): Adds to FluxDsl support for the `|> elapsed(unit)` function.
6+
2. [#662](https://github.com/influxdata/influxdb-client-java/issues/662): Adds to FluxDsl support for the `|> elapsed(unit)` function.
7+
3. [#623](https://github.com/influxdata/influxdb-client-java/issues/623): Enables the use of IPv6 addresses.
78

89
### Dependencies
910

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -694,12 +694,13 @@ private ParsedUrl(@Nonnull final String connectionString) {
694694

695695
HttpUrl url = this.httpUrl.newBuilder().build();
696696

697-
String urlWithoutParams = url.scheme() + "://" + url.host() + ":" + url.port() + url.encodedPath();
698-
if (!urlWithoutParams.endsWith("/")) {
699-
urlWithoutParams += "/";
700-
}
697+
//detect IPV6
698+
String host = url.host().contains(":") ? "[" + url.host() + "]" : url.host();
699+
String urlWithoutParams = url.scheme() + "://" + host + ":" + url.port() + url.encodedPath();
701700

702-
this.urlWithoutParams = urlWithoutParams;
701+
this.urlWithoutParams = urlWithoutParams.endsWith("/")
702+
? urlWithoutParams
703+
: urlWithoutParams + "/";
703704
}
704705
}
705706
}

client/src/test/java/com/influxdb/client/InfluxDBClientOptionsTest.java

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,14 @@
2121
*/
2222
package com.influxdb.client;
2323

24+
import java.util.Arrays;
2425
import java.util.Collections;
2526
import java.util.List;
27+
import java.util.Map;
2628

2729
import com.influxdb.client.domain.WritePrecision;
2830

31+
import com.influxdb.exceptions.InfluxException;
2932
import okhttp3.OkHttpClient;
3033
import okhttp3.Protocol;
3134
import org.assertj.core.api.Assertions;
@@ -156,4 +159,71 @@ public void customClientTypeFromProperties() {
156159

157160
Assertions.assertThat(options.getClientType()).isEqualTo("properties-service");
158161
}
162+
163+
@Test
164+
public void ipv6Loopback(){
165+
String[] loopbacks = {"[::1]", "[0000:0000:0000:0000:0000:0000:0000:0001]"};
166+
167+
for (String loopback : loopbacks) {
168+
InfluxDBClientOptions options = InfluxDBClientOptions.builder()
169+
.url(String.format("http://%s:9999/api/v2/", loopback))
170+
.authenticateToken("xyz".toCharArray())
171+
.org("my-org")
172+
.build();
173+
174+
Assertions.assertThat(options.getUrl()).isEqualTo("http://[::1]:9999/api/v2/");
175+
Assertions.assertThat(options.getAuthScheme()).isEqualTo(InfluxDBClientOptions.AuthScheme.TOKEN);
176+
Assertions.assertThat(options.getOkHttpClient()).isNotNull();
177+
Assertions.assertThat(options.getPrecision()).isEqualTo(WritePrecision.NS);
178+
Assertions.assertThat(options.getOrg()).isEqualTo("my-org");
179+
}
180+
}
181+
182+
@Test
183+
public void ipv6General(){
184+
Map<String, String> ipv6Expected = Map.of(
185+
"[2001:db80:0001:1000:1100:0011:1110:0111]", "[2001:db80:1:1000:1100:11:1110:111]",
186+
"[2001:db8:1000:0000:0000:0000:0000:0001]", "[2001:db8:1000::1]",
187+
"[2001:db8f:0ff0:00ee:0ddd:000c:bbbb:aaaa]", "[2001:db8f:ff0:ee:ddd:c:bbbb:aaaa]",
188+
"[2001:0db8:0000:0000:0000:9876:0000:001f]", "[2001:db8::9876:0:1f]",
189+
"[0000:0000:0000:0000:0000:0000:0000:0000]", "[::]",
190+
"[2001:0db8:fedc:edcb:dcba:cba9:ba98:a987]", "[2001:db8:fedc:edcb:dcba:cba9:ba98:a987]"//,
191+
//"[::1]", ""
192+
);
193+
194+
for(String key : ipv6Expected.keySet()){
195+
InfluxDBClientOptions options = InfluxDBClientOptions.builder()
196+
.url(String.format("http://%s:9999/api/v2/query?orgID=my-org", key))
197+
.authenticateToken("xyz".toCharArray())
198+
.build();
199+
200+
System.out.println(key + ": " + options.getUrl());
201+
202+
Assertions.assertThat(options.getUrl())
203+
.isEqualTo(String.format("http://%s:9999/api/v2/query/", ipv6Expected.get(key)));
204+
Assertions.assertThat(options.getToken())
205+
.isEqualTo("xyz".toCharArray());
206+
}
207+
}
208+
209+
@Test
210+
public void ipv6Invalid(){
211+
List<String> invalidIpv6 = Arrays.asList(
212+
"[:1]",
213+
"[:::1]",
214+
"[2001:db8:0000:1]",
215+
"[2001:db8:00000::1]",
216+
"[2001:db8:0000:::1]",
217+
"[:0000::1]",
218+
"[:::0000::1]");
219+
for(String ipv6 : invalidIpv6){
220+
Assertions.assertThatThrownBy(() -> { InfluxDBClientOptions options2 = InfluxDBClientOptions.builder()
221+
.url(String.format("http://%s:9999/api/v2/query?orgID=my-org", ipv6))
222+
.authenticateToken("xyz".toCharArray())
223+
.build();}).isInstanceOf(InfluxException.class)
224+
.hasMessage(String.format("Unable to parse connection string http://%s:9999/api/v2/query?orgID=my-org", ipv6));
225+
}
226+
227+
}
228+
159229
}

client/src/test/java/com/influxdb/client/InfluxDBClientTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
2121
*/
2222
package com.influxdb.client;
2323

24+
import java.io.ByteArrayOutputStream;
2425
import java.io.IOException;
26+
import java.io.OutputStream;
2527
import java.net.InetSocketAddress;
2628
import java.net.Proxy;
2729
import java.util.List;
@@ -31,6 +33,9 @@
3133
import java.util.logging.Logger;
3234
import javax.annotation.Nonnull;
3335

36+
import com.sun.net.httpserver.HttpExchange;
37+
import com.sun.net.httpserver.HttpServer;
38+
import com.sun.net.httpserver.HttpHandler;
3439
import com.influxdb.LogLevel;
3540
import com.influxdb.client.domain.Authorization;
3641
import com.influxdb.client.domain.Run;

0 commit comments

Comments
 (0)