Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug report] InfluxDBUploader: Write to InfluxDB failed: java.lang.RuntimeException #2494

Open
erkexzcx opened this issue Nov 23, 2022 · 8 comments

Comments

@erkexzcx
Copy link

I am trying to setup Cloud Upload --> InfluxDB functionality, which seems to be broken. I constantly get the following error (I confirm that I've entered correct details):
image

The same TSDB configuration works with other utilities without any issues. For example, connecting to the same InfluxDB from Telegraf, I use below configuration fragment:

[[outputs.influxdb]]
  urls = ["https://example.com/"]
  username = "myuser"
  password = "mypass"

Caddy (reverse proxy that adds TLS as well as basic HTTP auth) - works fine with Telegraf too. Maybe because it has HTTP3 enabled and okhttp3 dependency does not support it?

example.com {
    reverse_proxy victoria-metrics:8428
    basicauth * {
        myuser XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    }
    encode * zstd gzip
}

I literally have zero clue of what might cause this behavior, but it is clear to me - there is a bug somewhere in the app. It should work fine, but it does not.

Please contact me via [email protected] (prior let me know your email here from which you will be contacting) so I can setup a playground instance for you using the same configuration.

I guess I should tag @pimeys as you've been mentioned as an author of this integration. :)

EDIT: Looks like this is part that is failing: https://github.com/NightscoutFoundation/xDrip/blob/master/app/src/main/java/com/eveningoutpost/dexdrip/InfluxDB/InfluxDBUploader.java#L116

@erkexzcx
Copy link
Author

I've found the exception:

java.lang.RuntimeException: okhttp3.internal.http2.StreamResetException: stream was reset: NO_ERROR

Quick Google revealed that it could be fixed by adding these (maybe because I am using HTTP3 caused this error?):

// Import this one too
import okhttp3.Protocol;

// When setting up client, add protocols line, so it looks like this
        client = new OkHttpClient.Builder()
                .connectTimeout(CONNECTION_TIMEOUT, TimeUnit.MILLISECONDS)
                .readTimeout(SOCKET_TIMEOUT, TimeUnit.MILLISECONDS)
                .writeTimeout(SOCKET_TIMEOUT, TimeUnit.MILLISECONDS)
                .protocols(Collections.singletonList(Protocol.HTTP_1_1))
                .addNetworkInterceptor(new Interceptor() {
                ...
                ...
                ...

Then goes another issue:
image

Not sure what above errors mean, but it looks like there were zero points as well:
image

Could it be that the method upload is called when data is submitted manually, but data is not being given to that method? As you can see in the picture - method was called and there were only zeroes passed. In the Android emulator I've added glucose measurement manually.
image

@erkexzcx
Copy link
Author

I've tried to hardcode some dummy point, so points list wouldn't be empty - same issue.

@erkexzcx
Copy link
Author

Looks like there is an update for influxdb-java dependency: https://mvnrepository.com/artifact/org.influxdb/influxdb-java

Also tried old version without okhttp3 (http client) - same thing happens, so I assume it's influxdb-java that is failing. I don't know. Or maybe because I have HTTP3 for TSDB connections. 🤷

@Navid200
Copy link
Collaborator

Please don't open an issue unless you are asked to do so by a developer.

@jamorham jamorham reopened this Nov 24, 2022
@jamorham
Copy link
Collaborator

Its okay we can discuss this issue here. Its possible that the influxdb client is outdated. @erkexzcx can you describe what you are connecting to.

The code you pasted above looks like it would lock to http protocol 1.1 - I'm not sure I understand the significance of that. From your investigations have you been able to replicate and then resolve the problems or are you still trying to find a resolution?

@erkexzcx
Copy link
Author

erkexzcx commented Nov 25, 2022

Hi.

@erkexzcx can you describe what you are connecting to.

There is a not-so-well known TSDB called VictoriaMetrics. It is basically a "Prometheus on steroids" kind of TSDB that can also accept InfluxDB metrics through it's HTTP endpoint. I've been using this setup for almost a year without any issues, including querying metrics via Grafana (using PromQL) as well as pushing metrics (as InfluxDB endpoint) from my personal servers. The same setup I have in corporate environment where VictoriaMetrics ingests metrics via InfluxDB (influx line protocol) and works perfectly.

I've tried to push data from xDrip+ application (via Cloud Upload -> InfluxDB) to the same VictoriaMetrics HTTP endpoint that I am using with my other projects/servers and they all work just fine, except xDrip+. Whatever I do, I just end up with java.lang.RuntimeException exception and I can't figure out why it is throwing this error. To me it looks like that influxdb-java is throwing this error as it attempts to write data to TSDB, but behind the scenes it is using okhttp3 HTTP client (the reason why this HTTP client is used because this is the only way to implement HTTP timeout (by passing a modified HTTP client to influxdb-java)).

I have suspicion that it is failing because I am using HTTPS, more specifically HTTP3 (with TLS). As far as I know, if client does not support HTTP3, it will default back to HTTP2. Note that TLS (as well as HTTP3 and basic auth) is added by a reverse proxy (Caddy), but IMO it does not matter if it's Caddy, Nginx, Traefik or any other reverse proxy.

If you provide me your email, later today I can provide you a playground instance (TSDB and Grafana) for you, so you don't have to setup your own test environment.

I believe you should try the following:

  1. Update okhttp3 and influxdb-java gradle dependencies to check if it fixes the issue.
  2. If HTTP3 is an issue (which I believe is not as it should default back to HTTP2 if HTTP3 not supported), this could also be tried to add HTTP3 support for okhttp3 HTTP client (also did not work to me).

Note that I have zero Android development experience and a bit of Java. I especially struggled with Gradle stuff as my attempts to upgrade those dependencies ended up breaking a whole build of the project. ☹️

@erkexzcx
Copy link
Author

The code you pasted above looks like it would lock to http protocol 1.1 - I'm not sure I understand the significance of that.

It's just what quick Google suggested me to do. 🤷‍♂️ You can ignore this part I would say...

From your investigations have you been able to replicate and then resolve the problems or are you still trying to find a resolution?

I am still trying to find a solution. See my previous message, I believe you should try the following part.

@erkexzcx
Copy link
Author

@jamorham - I've sent you an email to your Gmail with playground TSDB instance url/credentials. Also included curl examples for you to try.

Hopefully updating dependencies okhttp3 and influxdb-java might be enough...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants