influxdata / influxdb-java

Java client for InfluxDB
MIT License
1.19k stars 478 forks source link

Incorrect URLs formed if base URL contains a path segment #268

Open retronym opened 7 years ago

retronym commented 7 years ago

(Tested with influxdb-java version 2.5)

We're using a HTTPS reverse proxy in front our influxdb instance.

The external URLs is https://scala-ci.typesafe.com/influx/write.

The URL actually generated by influxdb-java is https://scala-ci.typesafe.com/write.

I believe that changing @POST("/write") to @POST("write"), etc, in InfluxDBService.java would fix this, but haven't verified.

A workaround is to add an interceptor to fixup the URL.

        OkHttpClient.Builder client = new OkHttpClient.Builder();
        client.addNetworkInterceptor(chain -> {
            HttpUrl.Builder fixedUrl = chain.request().url().newBuilder().encodedPath("/influx/" + chain.request().url().encodedPath().replaceFirst("/influxdb", ""));
            return chain.proceed(chain.request().newBuilder().url(fixedUrl.build()).build());
        });
        InfluxDB influxDB = InfluxDBFactory.connect("https://scala-ci.typesafe.com/influx/", user, password, client);
pimeys commented 7 years ago

I'm having the same issue. I use a public influxdb for my test data and the http server forwards the requests from a certain path. This library just skips the path and tries to go directly to /write which obviously fails.

pimeys commented 7 years ago

@retronym Your workaround works for now...

gerbsen commented 7 years ago

worked for me too, but this is not very for newcomers :)

chiefy commented 6 years ago

Just ran into this using the https://github.com/jenkinsci/influxdb-plugin, we switched our config from a staging http://10.x.x.x:8086 to http://internal-alb.fqdn/influx and now we get a 404 exception when trying to write.