albertodonato / query-exporter

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

psql query works, but doesnt in query-exporter #195

Closed connorourke closed 1 month ago

connorourke commented 1 month ago

In my config file I have a query that works fine on a postgres DB, but throws an error when executed by query-exporter.

Installation details

To Reproduce

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

  1. The following is the relevant part of the config file:
      WITH top_python_users AS (
      SELECT
          u.user_name,
          SUM(j."gpuHours") AS total_gpuHours
      FROM
          jobs j
      JOIN
          users u ON j.user_name = u.user_name
      JOIN
        modules m ON j.job_id_date = m.job_id_date
      WHERE
        m.module = 'python' or m.module = 'conda' AND j.partition = 'a100' 
        AND j.start >= current_date - interval '6 months'
      GROUP BY
        u.user_name
      ORDER BY
          total_gpuHours DESC
      )
      SELECT
        user_name AS "User",
        total_gpuHours AS "Python_a100_6m"
      FROM
        top_python_users
      ORDER BY
        "Python_a100_6m" DESC
      LIMIT 20;

and the AND j.start >= current_date - interval '6 months' line is what is causing the following error:

TypeError: unsupported operand type(s) for +=: 'float' and 'datetime.date'