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

InfluxDbHttpSender encodes auth string with newline symbol in the end #80

Open
e-vrvr opened this issue Nov 23, 2017 · 7 comments
Open

Comments

@e-vrvr
Copy link

e-vrvr commented Nov 23, 2017

I'm trying to add authorization to my http(s) reporter, so I set config entry to auth: user:password.
Later, here it gets encrypted to dXNlcjpwYXNzd29yZA==\r\n -note the newline symbols in the end. And then during connection construction, it fails with Illegal character(s) in message header field here .

Full stack trace:

java.lang.IllegalArgumentException: Illegal character(s) in message header value: Basic dXNlcjpwYXNzd29yZA==(newline symbol)

	at sun.net.www.protocol.http.HttpURLConnection.checkMessageHeader(HttpURLConnection.java:507)
	at sun.net.www.protocol.http.HttpURLConnection.isExternalMessageHeaderAllowed(HttpURLConnection.java:459)
	at sun.net.www.protocol.http.HttpURLConnection.setRequestProperty(HttpURLConnection.java:3017)
	at sun.net.www.protocol.https.HttpsURLConnectionImpl.setRequestProperty(HttpsURLConnectionImpl.java:316)
	at com.izettle.metrics.influxdb.InfluxDbHttpSender.writeData(InfluxDbHttpSender.java:68)
	at com.izettle.metrics.influxdb.InfluxDbBaseSender.writeData(InfluxDbBaseSender.java:46)
	at com.izettle.metrics.influxdb.InfluxDbHttpSender.writeData(InfluxDbHttpSender.java:15)
	at com.izettle.metrics.influxdb.InfluxDbReporter.report(InfluxDbReporter.java:240)
	at com.codahale.metrics.ScheduledReporter.report(ScheduledReporter.java:162)
	at com.codahale.metrics.ScheduledReporter$1.run(ScheduledReporter.java:117)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
	at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308)
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180)
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at java.lang.Thread.run(Thread.java:745)

Sample config

metrics:
  frequency: 1m
  reporters:
    - type: influxdb
      protocol: https
      host: influxdb.example.com
      port: 443
      database: test

Is there any way to make this working?

@rickard-von-essen-iz
Copy link
Contributor

Could you give an example of you config with auth where you see this?

@e-vrvr
Copy link
Author

e-vrvr commented Nov 23, 2017

Sure

metrics:
  frequency: 1m
  reporters:
    - type: influxdb
      protocol: https
      host: influxdb.example.com
      port: 443
      database: test
      auth: user:password
      tags:
        host: dev
      prefix: mymetrics_
      precision: 10s
      frequency: 10s
      groupGauges: yes
      includes:
        - memory.heap.usage

UPD. latest version of library, dropwizard 1.2.0

@artragis
Copy link

artragis commented Mar 29, 2018

I have the same issue.

I am using the influxdb docker without any configuration.

I basically call the reporter like this :

new InfluxDbHttpSender(influxUrl.getProtocol(),
                influxUrl.getHost(),
                influxUrl.getPort(),
                db, influxUrl.getUserInfo(), TimeUnit.SECONDS,
                1000, 1000, "")

and influxUrl is http://root:root@influx:8086/dbname

then I get the error :

api-service_1  | 13:47:37.650 [metrics-influxDb-reporter-1-thread-1] WARN com.izettle.metrics.influxdb.InfluxDbReporter - Unable to report to InfluxDB with error 'Illegal character(s) in message header value: Basic cm9vdDpyb290
api-service_1  | 13:48:37.643 [metrics-influxDb-reporter-1-thread-1] WARN com.izettle.metrics.influxdb.InfluxDbReporter - Unable to report to InfluxDB with error 'Illegal character(s) in message header value: Basic cm9vdDpyb290

I'm using the 1.2.2 version.

@artragis
Copy link

I think I have the fix, I try a PR soon. Found from stackoverflow

@e-vrvr
Copy link
Author

e-vrvr commented Mar 29, 2018

what I did was extending InfluxDbHttpSender with this code

if (authString != null && !authString.isEmpty()) {
            this.authStringEncoded = Base64.encodeBase64String(authString.getBytes(Charsets.UTF_8)).trim(); // this is the one single difference from parent class
        } else {
            this.authStringEncoded = "";
        }

@artragis
Copy link

How can you extend as the properties are private final?

@artragis
Copy link

I found the reason of this bug : I was using another dependency that requires commons-condecs at version 1.4, and this version... adds a \n\r.
Once I forced in my own pom the common-codecs to be 1.9 or later (we are at 1.11 today) no problem occures.

@rickard-von-essen-iz To ensure my fix, I have a unittest, do you want me to make a PR for that?

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

No branches or pull requests

3 participants