albertodonato / query-exporter

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

Invalid config at queries/sql: 'SELECT count("id") as metric1 FROM rss' is not of type 'object' #157

Closed BoKKeR closed 1 year ago

BoKKeR commented 1 year ago

Describe the bug

A clear and concise description of what the bug is and when it happens.

Installation details

To Reproduce

I am just a SQL newbie trying to setup my first metric, a simple gauge count based on how many entries there are in the table. The error I get is

Invalid config at queries/sql: 'SELECT count("id") as metric1 FROM rss' is not of type 'object'

  1. Config file content (redacted of secrets if needed)
databases:
  db1:
    dsn: sqlite:////mnt/rss-to-telegram-volume/rss_bot_database.db
    connect-sql:
      - PRAGMA application_id = 123
      - PRAGMA auto_vacuum = 1
    labels:
      app: rsstt-dev-query-exporter

metrics:
  metric1:
    type: gauge
    description: A sample gauge
  metric2:
    type: summary
    description: A sample summary
    labels: [l1, l2]
    expiration: 24h
  metric3:
    type: histogram
    description: A sample histogram
    buckets: [10, 20, 50, 100, 1000]

queries:
  query1:
    interval: 5
    databases: [db1]
    metrics: [metric1]
  sql: SELECT count("id") as metric1 FROM rss
~
~
  1. Ran query-exporter with the following command line ... ran it from docker
  2. Got the error when ... checking logs
albertodonato commented 1 year ago

That's a YAML validation error, I think you need to either quote the whole SQL command, or use something like:

sql: |
    SELECT count("id") as metric1 FROM rss
BoKKeR commented 1 year ago

The problem was that the sql field was mis-indented