albertodonato / query-exporter

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

query-exporter -L DEBUG config.yaml only shows 2 lines of output #96

Closed imavo closed 2 years ago

imavo commented 2 years ago

I am trying out query-exporter (first time user) on ubuntu 20.04 x64 , with python 3.8.10 in a virtualenv.

I installed query-exporter with pip 21.3.1 (pip install query-exporter).

python ibm_db (3.1.0) works fine in this environment to connect to the database and run queries.

SQLAlchemy with ibm_db_sa (0.3.7) works on this environment to connect to the database and run queries.

The database is local.

I configured a config.yaml (see below) to connect to Db2-LUW , using the same working dsn string that works for plain SQLAlchemy connections in python scripts.

But when I run query-exporter -L DEBUG config.yaml, it shows two lines of output and then appears to hang indefinitely without further messages. And I see no queries running in my database. So my configuration is invalid somehow, I'm missing some config/setup detail. I was expecting to see a lot more output on the console to help me see what is happening under the covers.

Output:


$ query-exporter -LDEBUG /home/user1/py/config.yaml
2021-11-04 07:54:45,604 - INFO - aiohttp.web - Listening on http://localhost:9560
2021-11-04 07:54:45,605 - INFO - query-exporter - version 2.7.0 starting up

If I press Control-C , it shows (before stopping):

^CTask was destroyed but it is pending!
task: <Task pending name='Task-3' coro=<QueryLoop._execute_query() running at /home/user1/djenv2/lib/python3.8/site-packages/query_exporter/loop.py:151>>
/usr/lib/python3.8/asyncio/base_events.py:641: RuntimeWarning: coroutine 'QueryLoop._execute_query' was never awaited
Task was destroyed but it is pending!
task: <Task pending name='Task-4' coro=<QueryLoop._execute_query() running at /home/user1/djenv2/lib/python3.8/site-packages/query_exporter/loop.py:151>>
Task was destroyed but it is pending!
task: <Task pending name='Task-5' coro=<QueryLoop._execute_query() running at /home/user1/djenv2/lib/python3.8/site-packages/query_exporter/loop.py:151>>

The pip freeze shows the following:

$ pip freeze
aiohttp==3.8.0
aiosignal==1.2.0
argcomplete==1.12.3
asgiref==3.4.1
async-timeout==4.0.0
attrs==21.2.0
charset-normalizer==2.0.7
croniter==1.0.15
Django==3.2
frozenlist==1.2.0
greenlet==1.1.2
ibm-db==3.1.0
ibm-db-django==1.5.0.0
ibm-db-sa==0.3.7
idna==3.3
jsonschema==4.1.2
multidict==5.2.0
outcome==1.1.0
pkg_resources==0.0.0
prometheus-aioexporter==1.6.3
prometheus-client==0.12.0
pyrsistent==0.18.0
python-dateutil==2.8.2
pytz==2021.3
PyYAML==6.0
query-exporter==2.7.0
regex==2021.10.23
Represent==1.6.0.post0
six==1.16.0
SQLAlchemy==1.3.24
sqlalchemy-aio==0.16.0
sqlparse==0.4.2
toolrack==3.0.1
typing-extensions==3.10.0.2
yarl==1.7.2

My config.yaml (redacted) is:

databases:
  db1:
    dsn: ibm_db_sa://username:password@myhostname:60000/sample7
    autocommit: true
    labels:
      region: us
      app: app1

metrics:
  metric1:
    type: gauge
    description: A sample gauge

queries:
  query1:
    interval: 5
    databases: [db1]
    metrics: [metric1]
    sql: SELECT rand() as "metric1" FROM "SYSIBM".SYSDUMMY1

Additional information: if I use the docker adonato/query-exporter:latest (on a different hostname, with the same config.yaml file), and supply the "-LDEBUG" as an argument to the docuer run ... line then I successfully get the query running. So it appears that on my first environment, there is something missing or misconfigured. Advice needed.

AravindCTS003 commented 2 years ago

I am also facing the same issue. I am running it in the local Docker App in Windows. Is there any workaround or solution available?

AravindCTS003 commented 2 years ago

We are able to fix this by taking dependencies version (from docker hub image) using "pip freeze" and incorporating it in custom docker file @albertodonato

jzielke84 commented 2 years ago

Confirmed this behavior on debian stretch using python 3.7. With the latest SQLAlchemy==1.4.27 the query exporter is not serving any http at all. I had to downgrade it to SQLAlchemy==1.3.24. However, using only that version the metric endpoint only shows the metric descriptions but not any data. I also had to downgrade another package to aiohttp==3.7.4.post0. After that everything was working fine again. So please consider updating the query exporter code to run with the latest pip packages.

rubyjedi commented 2 years ago

2nd confirmation, the issue is with recent releases of aiohttp and async-timeout. Downgrading aiohttp to 3.7.4.post0 as suggested above works.

ismailhammounou commented 2 years ago

Same for me, I downgraded the package aiohttp to aiohttp==3.7.4.post0 as suggested above and it works : pip install aiohttp==3.7.4.post0 . the database is sometimes accessible only with ssh, please, think of using the ssh forwarding so you can test on your local environment.

albertodonato commented 2 years ago

This should be now fixed in master

jzielke84 commented 2 years ago

@albertodonato Still broken with SQLAlchemy-1.4.27. Exporter runs but http endpoint is down. Runs fine with 1.3.24.

albertodonato commented 2 years ago

@jzielke84 that is expected, SQLAlchemy 1.4 is not backwards compatible with 1.3. How did you get it installed? From https://github.com/albertodonato/query-exporter/blob/master/setup.cfg#L35 it should not get installed by default.

jzielke84 commented 2 years ago

@albertodonato It is provided when I upgrade all installed pip packages in python3.7 to the latest version. I always keep my packages updated. Perhaps this exporter should be patched to run without outdated packages.

albertodonato commented 2 years ago

If you pip install query-exporter in a clean virtualenv you should get 2.7.1 installed with sqlalchemy 1.3

jzielke84 commented 2 years ago

Right, but that's not my point here. I could do a virtualenv for everything but sooner or later a new SQL-DB Version might break the compatibility with the older sqlalchemy version and then I'm stuck. Hence I suggested you try to update to the latest version of that library.

albertodonato commented 2 years ago

The reason of the currently pin to SQLAlchemy < 1.4 is that sqlalchemy_aio (which is used by query-exporter) doesn't support 1.4 (and also doesn't work on python3.10).

I have a branch (sqlalchemy-async-wrapper) on this repo which reimplements some parts of that library and supports SQLAlchemy 1.4. It's work in progress, but feel free to try it and report issues. Once I get test passing and a bit more testing I'll merge it to main