albertodonato / query-exporter

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

query "query2" on database "db2" failed: Wrong column names from query #156

Closed connorourke closed 1 year ago

connorourke commented 1 year ago

Describe the bug

I am testing using query-exporter but when executing a query I get:

query-exporter - query "query2" on database "db2" failed: Wrong column names from query

Installation details

To Reproduce

I am using the folloiwing config file:

databases:
   db1:
     dsn: sqlite:////test.db
     connect-sql:
       - PRAGMA application_id = 123
       - PRAGMA auto_vacuum = 1
     labels:
        region: us1
        app: app1
   db2:
     dsn: sqlite:////data.db
     connect-sql:
       - PRAGMA application_id = 123
       - PRAGMA auto_vacuum = 1
     labels:
        region: us1
        app: app2

metrics:
  metric1:
    type: gauge
    description: A sample gauge
  award_metric:
    type: gauge
    description: Award amount

queries:
  query1:
    interval: 5
    databases: [db1]
    metrics: [metric1]
    sql: SELECT random() / 1000000000000000 AS metric1
  query2:
    interval: 5
    databases: [db2]
    metrics: [award_metric]
    sql: SELECT sum(amount) from awards AS award_metric

I can connect to the data.db and run the query SELECT sum(amount) from awards AS award_metric fine with sqlite3.

Any idea why I am getting this error?

albertodonato commented 1 year ago

Have you tried SELECT sum(amount) AS award_metric from awards ?

connorourke commented 1 year ago

Yes! That works. Thank you.

Can you explain why the original query doesn't?

connorourke commented 1 year ago

I guess from https://github.com/albertodonato/query-exporter/issues/149 if I were to install from git, not pip I would get a bit more information as to what the issue was?

albertodonato commented 1 year ago

The original query was aliasing the query itself, not the column, so the column name in that case was still "sum"