albertodonato / query-exporter

Export Prometheus metrics from SQL queries
GNU General Public License v3.0
436 stars 101 forks source link

Metric name length #183

Closed ygueguindecath closed 8 months ago

ygueguindecath commented 8 months ago

Describe the bug

Hi, we use query exporer for a lot of metrics, but one configuration make us struggler and i do not know why.

We have a definition of metric like this

xxx_1d:
  type: counter
  description: xxx
  increment: false
xxx_1d:
  databases: [xxx]
  metrics:
    - xxx_1d
  sql: >
    select count(1) as xxx_1d from xxx;
  interval: 24h

But at the start we got an error saying it search for metric xxx_1. I suspect a metric name length restriction as, this occur only for this query, and it's the only one that the name is more than 64 characters, but i'm not sure at all

Installation details

To Reproduce

If possible, please provide detailed steps to reproduce the behavior:

  1. Config file content (redacted of secrets if needed)
metrics:
    xxxxxxxx_xxxxxx_xxxxxxx_xxxxx_xxxxxxx_xxxxxxxxx_xxxxxxxxxxxxx_1d:
      type: counter
      description: desc
      increment: false
queries:
  xxxxxxxx_xxxxxx_xxxxxxx_xxxxx_xxxxxxx_xxxxxxxxx_xxxxxxxxxxxxx_1d:
    databases: [database]
    metrics:
      - xxxxxxxx_xxxxxx_xxxxxxx_xxxxx_xxxxxxx_xxxxxxxxx_xxxxxxxxxxxxx_1d
    sql: >
      select count(1) as xxxxxxxx_xxxxxx_xxxxxxx_xxxxx_xxxxxxx_xxxxxxxxx_xxxxxxxxxxxxx_1d from database.table;
    interval: 24h
  1. Ran query-exporter with the following command line ... run the docker image with final cmd query-exporter /config.yaml -H 0.0.0.0
  2. Got the error when ... Running the query first
albertodonato commented 8 months ago

can you paste the exact error?

This might depend on your database engine, I've tried the config above with sqllite and it works with no error (and metrics are reported correctly in the output of the /metrics endpoint.

ygueguindecath commented 8 months ago

Yes no problem, see error : 2024-01-09 10:49:38,140 - ERROR - query-exporter - query "xxxxxxxx_xxxxxx_xxxxxxx_xxxxx_xxxxxxx_xxxxxxxxx_xxxxxxxxxxxxx_1d" on database "xxx" failed: Wrong column names from query: expected (xxxxxxxx_xxxxxx_xxxxxxx_xxxxx_xxxxxxx_xxxxxxxxx_xxxxxxxxxxxxx_1), got (xxxxxxxx_xxxxxx_xxxxxxx_xxxxx_xxxxxxx_xxxxxxxxx_xxxxxxxxxxxxx_1d)

Our database is a postgresql from Aiven, you think this can occur cause of a database settings ? Thanks for your answers 😃

albertodonato commented 8 months ago

Oh, that's a different issue, see that the name of the column is different from the metric one (ends in _1 instead of _1d).

ygueguindecath commented 8 months ago

It s what i said, the configuration is ok but the log trunk my metric name, the config file is correct

albertodonato commented 8 months ago

I'll take a closer look

albertodonato commented 8 months ago

It seems the metric name is hitting the name length limitation in PostgreSQL.

This is the output running a similar query on standard Postgres:

postgres=# select count(1) as xxxxxxxx_xxxxxx_xxxxxxx_xxxxx_xxxxxxx_xxxxxxxxx_xxxxxxxxxxxxx_1d;
NOTICE:  identifier "xxxxxxxx_xxxxxx_xxxxxxx_xxxxx_xxxxxxx_xxxxxxxxx_xxxxxxxxxxxxx_1d" will be truncated to "xxxxxxxx_xxxxxx_xxxxxxx_xxxxx_xxxxxxx_xxxxxxxxx_xxxxxxxxxxxxx_1"
 xxxxxxxx_xxxxxx_xxxxxxx_xxxxx_xxxxxxx_xxxxxxxxx_xxxxxxxxxxxxx_1 
-----------------------------------------------------------------
                                                               1
(1 row)
ygueguindecath commented 8 months ago

Thanks for your investigation 🙏