Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Two queries use the same database, in different time periods, the last query reports an error #143

Open
ilanni2460 opened this issue Mar 27, 2023 · 2 comments
Labels

Comments

@ilanni2460
Copy link

ilanni2460 commented Mar 27, 2023

Two queries use the same database, in different time periods, the last query reports an error.

this is config:
`
databases:
mysql:
dsn: mysql://root:[email protected]:3306/test1
labels:
env: PROD

metrics:
ncc_file:
type: gauge
description: NCC_DFT
expiration: 1h

tem_file:
type: gauge
description:TEM_DFT
expiration: 1h

queries:
ncc_file:
timeout: 1
schedule: "05 22 * * "
databases: [mysql]
metrics:
- ncc_file
sql: |
SELECT count(
) as ncc_file FROM transfer WHERE sender_file LIKE '%NCC%' ;

tem_file:
timeout: 1
schedule: "30 22 * * "
databases: [mysql]
metrics:
- tem_file
sql: |
SELECT count(
) as tem_file FROM transfer WHERE file_name LIKE '%TEM%';

this is error log:
2023-03-27 22:30:00,001 - DEBUG - query-exporter - running query "tem_file" on database "mysql"
2023-03-27 22:30:00,003 - ERROR - query-exporter - query "tem_file" on database "mysql" failed: (MySQLdb.OperationalError) (2013, 'Lost connection to MySQL server during query')
[SQL: SELECT count(*) as tem_fileFROM transfer_info WHERE file_name LIKE '%%TEM%%';]
(Background on this error at: http://sqlalche.me/e/13/e3q8)
2023-03-27 22:30:00,097 - DEBUG - query-exporter - File "/virtualenv/lib/python3.10/site-packages/query_exporter/db.py", line 312, in execute
result = await self._execute_query(query)
File "/virtualenv/lib/python3.10/site-packages/query_exporter/db.py", line 345, in _execute_query
return await self.execute_sql(
File "/virtualenv/lib/python3.10/site-packages/query_exporter/db.py", line 338, in execute_sql
return await asyncio.wait_for(
File "/usr/local/lib/python3.10/asyncio/tasks.py", line 445, in wait_for
return fut.result()
File "/virtualenv/lib/python3.10/site-packages/sqlalchemy_aio/base.py", line 291, in execute
rp = await self._run_in_thread(
File "/virtualenv/lib/python3.10/site-packages/sqlalchemy_aio/base.py", line 234, in _run_in_thread
return await _self._worker.run(_func, args, kwargs)
File "/virtualenv/lib/python3.10/site-packages/sqlalchemy_aio/asyncio.py", line 70, in run
return request.response.unwrap()
File "/virtualenv/lib/python3.10/site-packages/outcome/_impl.py", line 138, in unwrap
raise captured_error
File "/virtualenv/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 1011, in execute
return meth(self, multiparams, params)
File "/virtualenv/lib/python3.10/site-packages/sqlalchemy/sql/elements.py", line 298, in _execute_on_connection
return connection._execute_clauseelement(self, multiparams, params)
File "/virtualenv/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 1124, in _execute_clauseelement
ret = self._execute_context(
File "/virtualenv/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 1316, in _execute_context
self.handle_dbapi_exception(
File "/virtualenv/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 1510, in handle_dbapi_exception
util.raise
(
File "/virtualenv/lib/python3.10/site-packages/sqlalchemy/util/compat.py", line 182, in raise

raise exception
File "/virtualenv/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 1276, in _execute_context
self.dialect.do_execute(
File "/virtualenv/lib/python3.10/site-packages/sqlalchemy/engine/default.py", line 608, in do_execute
cursor.execute(statement, parameters)
File "/virtualenv/lib/python3.10/site-packages/MySQLdb/cursors.py", line 206, in execute
res = self._query(query)
File "/virtualenv/lib/python3.10/site-packages/MySQLdb/cursors.py", line 319, in _query
db.query(q)
File "/virtualenv/lib/python3.10/site-packages/MySQLdb/connections.py", line 254, in query
_mysql.connection.query(self, query)

2023-03-27 22:30:00,098 - DEBUG - query-exporter - updating metric "queries" inc 1 {database="mysql",env="PROD",query="tem_file",status="error"}
2023-03-27 22:30:04,219 - INFO - aiohttp.access - 169.254.30.1 "GET /metrics HTTP/1.1" 200 2957 "-" "Prometheus/2.41.0"
2023-03-27 22:30:19,219 - INFO - aiohttp.access - 169.254.30.1 "GET /metrics HTTP/1.1" 200 2957 "-" "Prometheus/2.41.0"
2023-03-27 22:30:34,219 - INFO - aiohttp.access - 169.254.30.1 "GET /metrics HTTP/1.1" 200 2957 "-" "Prometheus/2.41.0"
2023-03-27 22:30:49,219 - INFO - aiohttp.access - 169.254.30.1 "GET /metrics HTTP/1.1" 200 2957 "-" "Prometheus/2.41.0"
2023-03-27 22:31:04,218 - INFO - aiohttp.access - 169.254.30.1 "GET /metrics HTTP/1.1" 200 2957 "-" "Prometheus/2.41.0"
`

@ilanni2460 ilanni2460 added the bug label Mar 27, 2023
@yumitsu
Copy link

yumitsu commented Apr 4, 2023

@ilanni2460 Try to add keep-connected: true configuration option to databases section of your config.yaml.

@yumitsu
Copy link

yumitsu commented Apr 4, 2023

Also try to slightly increase timeout value in queries section.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants