Skip to content

More useful connection logging #164

@Kricket

Description

@Kricket

Is your feature request related to a problem? Please describe.

I'm currently trying to use sql_exporter to fetch data from a Clickhouse database.
For now, I'm just trying to get a simple query to work.
Here's my configuration:

global:
  scrape_timeout_offset: 500ms
  min_interval: 0s
  max_connections: 3
  max_idle_connections: 3
reuse.
  max_connection_lifetime: 5m

target:
  data_source_name: 'ch://user:pass@myhost:8123/default'
  collectors: [my_clickhouse]

collector_files:
  - "*.collector.yml"

With the collector file:

collector_name: my_clickhouse

metrics:
  - metric_name: row_count_my_table
    type: gauge
    help: 'Number of rows in table my_table.'
    values: [num_rows]
    query: |
      SELECT COUNT(*) AS num_rows FROM my_table;

When I run it, I get the following output:

$ ./sql_exporter -log.level debug
ts=2022-11-14T08:30:25.473Z caller=klog.go:108 level=warn func=Warningf msg="Starting SQL exporter (version=0.9.1, branch=HEAD, revision=aa29c91a6d31d614dc2b20c429d6fd8699a12d1c) (go=go1.19.1, user=root@11ce5d80fd8d, date=20220921-15:11:16)"
ts=2022-11-14T08:30:25.473Z caller=klog.go:84 level=debug func=Infof msg="Loading configuration from sql_exporter.yml"
ts=2022-11-14T08:30:25.473Z caller=klog.go:84 level=debug func=Infof msg="Loaded collector 'my_clickhouse' from clickhouse.collector.yml"
ts=2022-11-14T08:30:25.473Z caller=klog.go:96 level=warn func=Warning msg="Listening on :9399"
ts=2022-11-14T08:30:25.473Z caller=tls_config.go:195 level=info msg="TLS is disabled." http2=false
ts=2022-11-14T08:30:31.754Z caller=klog.go:84 level=debug func=Infof msg="Database handle successfully opened with 'clickhouse' driver"
ts=2022-11-14T08:30:41.254Z caller=klog.go:84 level=debug func=Infof msg="Error gathering metrics: [from Gatherer #1] context deadline exceeded"

As you can see, even with debug logging, I have no idea what the problem is:

  • I've verified that the credentials are correct, using a different clickhouse client
  • I've verified that the SQL is correct and works

As a test, I tried changing the database connection string:

  • from "ch" to "sqlserver" or "mysql"
  • using a nonexistent username
    The result was the exact same log message (just with the driver name changed)!

Describe the solution you'd like

At the very least, the logging should provide more information about what's going on with the database. As it is, I have no idea what the problem is, much less what I might do about it.

  • Did the database connection work? Obviously there's something wrong if I can use the wrong driver and it still thinks it connected OK.
  • Did the query timeout? Or was there an error in the query? Or unable to connect?
  • Shouldn't the program exit with an error if it can't connect to the database?

Describe alternatives you've considered

Using a different tool

Additional context

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions