Skip to content

Conversation

santubvb
Copy link
Contributor

Scenario : Initially there is no data or zero rows returned for a SQL query for a particular DB and then if we start sql_exporter (metrics will be empty at this time). In this case, sql_exporter Metrics UI doesn't have any details to show that SQL query is executed and it is failed.

With this change, SQL Exporter Metrics UI helps and gives more detailed info to the user on query execution status. Instead of no logs for failed case (zero rows returned) now Metrics will have failed details.

Below is entry will come in Metrics with this code change.

sql_exporter_last_scrape_failed{database="DB",driver="postgres",host="hostNmae",query="sql_exporter_query",sql_job="sql_exporter_query",user="reader"} 1

Scenario : Initially there is no data or zero rows returned for a SQL query for a particular DB and then if we start sql_exporter . In this case, sql_exporter Metrics UI doesn't have any details to show that SQL query is executed and it is failed.

With this change, SQL Exported Metrics indicates user on SQL query is executed and it is failed.

Below is entry will come in Metrics with this code change.

sql_exporter_last_scrape_failed{database="DB",driver="postgres",host="hostNmae",query="sql_exporter_query",sql_job="sql_exporter_query",user="reader"} 1
@dewey
Copy link
Member

dewey commented Mar 11, 2025

I'm not sure if we would want a .Set() here or a .Inc() as we maybe want to alert on it increasing in case a table permission etc. goes away?

@santubvb
Copy link
Contributor Author

Hi @dewey Thanks for your review comments.
If table permission etc goes away and "AllowZeroRows" is enabled then application will set 0.0, setting 0 is successful.

I think if permission or any other table related table issues will be handled at error block line 35 to line 37 (file query.go) and in this error block, set 1.0 and inc are placed.

The change I wanted add is if zero rows returned and AllowZeroRows disabled then user should be able to understand from metrics that query executed but zero rows returned as it failed collect the data.

Please provide your suggestion.

Thanks,
Santoshkumar

Hello @dewey, Thanks for your review comments. 

As per your previous comments, I have added Inc() and yes this gives more info on number of Query failures. This info really helps in debugging  and understanding the failures.

Please review and let me know if any other suggestion.

Thanks,
Santoshkumar Patil
@santubvb
Copy link
Contributor Author

Hi @dewey, Thanks for your review comments. As per your comments, I have added Inc() for "zero rows returned".

Please review and let me know if any other review comments.

Thanks
Santoshkumar Patil

@dewey dewey merged commit 732df41 into justwatchcom:master Apr 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants