justwatchcom / sql_exporter

Flexible SQL Exporter for Prometheus.
MIT License
393 stars 108 forks source link

Cannot connect to clickhouse #62

Closed lainiwa closed 2 years ago

lainiwa commented 2 years ago

Hi! I'm trying to connect to my clickhouse. I place this in the yaml:

jobs:
- name: "example"
  # ...
  connections:
  - 'clickhouse://default:password@host:9000'

I then run LOGLEVEL=debug sql_exporter and get this output:

...
{"caller":"job.go:174","job":"example","level":"debug","msg":"Starting","ts":"2022-05-19T15:53:31.482395619Z"}
{"caller":"job.go:190","err":"code: 516, message: default: Authentication failed: password is incorrect or there is no user with such na
me","job":"example","level":"warn","msg":"Failed to connect","ts":"2022-05-19T15:53:31.583273404Z"}                                     {"caller":"job.go:190","err":"code: 516, message: default: Authentication failed: password is incorrect or there is no user with such na
me","job":"example","level":"warn","msg":"Failed to connect","ts":"2022-05-19T15:53:32.227874497Z"}   
...

Is it possible for me to debug it somehow? I checked and it works for clickhouse-client:

clickhouse-client --host host --password password --user default --port 9000

What might be the problem here?

dewey commented 2 years ago

I'm not familiar with CH so I can't really help there unfortunately. You could check out the source and print some more information to see what exactly gets passed to CH.

lainiwa commented 2 years ago

Here's what I've found yet:

This format doesn't work: clickhouse://default:password@host:9000 But this does: clickhouse://host:9000?user=default&password=password Works with native protocol, but not with http.

However, I tested it with two servers, and it would only work with the older one (21.12.2), but not with the newer (22.3.5 - says user/login incorrect). I'm not familiar with go and it's ecosystem, but I guess this could be bc some of the dependencies did not catch up with some recent changes (if any) in clickhouse auth protocol.

Could you bump the dependencies (or alternatively tell me how to do it myself) so I could test if my guess is correct?

dewey commented 2 years ago

Hey, can you checkout that branch and see if that works for you? If yes then I'll merge it to master, unfortunately I don't have a way to test it myself right now.

lainiwa commented 2 years ago

It wёrks! :)

A note on the credentials format: It is either that:

Either way, the URI that works for me now is clickhouse://user:password@host:9000.

Another issue was could not load time location: unknown time zone when running in docker. It could be fixed in two ways:

Although either works, I like the latter more, as it doesn't rely on the host.

dewey commented 2 years ago

Thanks for checking, I added the tzdata dependency too now. Once you confirm that everything is working I'll merge it and tag a new release.

lainiwa commented 2 years ago

Yes, my last message was about #63. Confirm, works like a charm.

dewey commented 2 years ago

Great, merged it and released it as v0.4.4. Thanks for testing this!