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

Add workaround for MySQL bug #173

Merged
merged 1 commit into from
Nov 25, 2016
Merged

Add workaround for MySQL bug #173

merged 1 commit into from
Nov 25, 2016

Conversation

SuperQ
Copy link
Member

@SuperQ SuperQ commented Nov 24, 2016

Workaround bug reported by #127.

  • Use a sub-select and group by to limit to one digest/schema pair.

Workaround bug reported by #127.
* Use a sub-select and group by to limit to one digest/schema pair.
@SuperQ
Copy link
Member Author

SuperQ commented Nov 24, 2016

@beorn7 This fixes the bug, but we don't have a test file for this collector yet. I will add one.

WHERE SCHEMA_NAME NOT IN ('mysql', 'performance_schema', 'information_schema')
AND LAST_SEEN > DATE_SUB(NOW(), INTERVAL %d SECOND)
ORDER BY LAST_SEEN DESC
)Q
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Q? Is that the super-Q?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hah, no, it's an implementation detail of having to assign the sub-query to a virtual table.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My SQL foo is weak.

I just have to believe you that the query is correct.

@beorn7
Copy link
Member

beorn7 commented Nov 25, 2016

We should also use a custom handler in https://github.com/prometheus/mysqld_exporter/blob/master/mysqld_exporter.go#L446 . One that continues on error but logs the errors so that we get metrics even if MySQL misbehaves, but we also see them in the log to be aware of them.

@brian-brazil
Copy link
Contributor

mysqld_up should be 0 in that case.

@beorn7
Copy link
Member

beorn7 commented Nov 25, 2016

If a collection fails outright, we can do that. But if the collection results in inconsistent metrics (which is only detected once the collection is over), we cannot insert new metrics at that point (or let's say that would require a new feature in the client library).

@brian-brazil
Copy link
Contributor

The way I generally handle that is only to send the _up at the very end of the collector, when we know if things have worked.

@beorn7
Copy link
Member

beorn7 commented Nov 25, 2016

Yes, that works within a collector. But if inconsistent metrics are created for some reason the collector hasn't detected, it's only detected once all the metrics are ready for shipping. Inserting an additional metric then is an interesting approach to communicate that problem but that's not implemented yet.
By default, we return 500 and no metrics. But right now, you can configure to return what's there and log the error.

@beorn7
Copy link
Member

beorn7 commented Nov 25, 2016

We can go with the change in this PR for now, but keep in mind that the scrape will result in 500 in case of any inconsistencies (which is arguably better than the previous state).

@SuperQ
Copy link
Member Author

SuperQ commented Nov 25, 2016

With the new query, the previous issues will be gone.

@beorn7
Copy link
Member

beorn7 commented Nov 25, 2016

👍 Let's discuss error handling separately later.

@beorn7 beorn7 merged commit 82e9cb5 into master Nov 25, 2016
@beorn7 beorn7 deleted the bjk/workaround_127 branch November 25, 2016 21:34
SuperQ added a commit that referenced this pull request Mar 22, 2017
* [FEATURE] Add read/write query response time #166
* [FEATURE] Add Galera gcache size metric #169
* [FEATURE] Add MariaDB multi source replication support #178
* [FEATURE] Implement heartbeat metrics #183
* [FEATURE] Add basic file_summary_by_instance metrics #189
* [BUGFIX] Workaround MySQL bug 79533 #173
@SuperQ SuperQ mentioned this pull request Mar 22, 2017
SuperQ added a commit that referenced this pull request Mar 22, 2017
* [FEATURE] Add read/write query response time #166
* [FEATURE] Add Galera gcache size metric #169
* [FEATURE] Add MariaDB multi source replication support #178
* [FEATURE] Implement heartbeat metrics #183
* [FEATURE] Add basic file_summary_by_instance metrics #189
* [BUGFIX] Workaround MySQL bug 79533 #173
SuperQ added a commit that referenced this pull request Apr 25, 2017
* [FEATURE] Add read/write query response time #166
* [FEATURE] Add Galera gcache size metric #169
* [FEATURE] Add MariaDB multi source replication support #178
* [FEATURE] Implement heartbeat metrics #183
* [FEATURE] Add basic file_summary_by_instance metrics #189
* [BUGFIX] Workaround MySQL bug 79533 #173
SuperQ added a commit that referenced this pull request Apr 25, 2017
* [FEATURE] Add read/write query response time #166
* [FEATURE] Add Galera gcache size metric #169
* [FEATURE] Add MariaDB multi source replication support #178
* [FEATURE] Implement heartbeat metrics #183
* [FEATURE] Add basic file_summary_by_instance metrics #189
* [BUGFIX] Workaround MySQL bug 79533 #173
@jeremy
Copy link

jeremy commented Jan 20, 2022

Still seeing duplicates with this query. Two options:

  • Use rank/partition to limit the subquery to a single row per digest. A bit fiddly. Easier on MySQL 8 with row_number().
  • Assume multiple digests rather than trying to eliminate them. Use aggregate SUM() to combine summary data. This is simpler and doesn't need a subquery.

Example with row_number (MySQL 8 only) to select just the latest row per digest:

@@ -16,28 +16,14 @@
 	    SUM_SORT_ROWS,
 	    SUM_NO_INDEX_USED
 	  FROM (
-	    SELECT *
+	    SELECT *, row_number() over (partition by DIGEST order by last_seen DESC)
+
 	    FROM performance_schema.events_statements_summary_by_digest
 	    WHERE SCHEMA_NAME NOT IN ('mysql', 'performance_schema', 'information_schema')
 	      AND LAST_SEEN > DATE_SUB(NOW(), INTERVAL %d SECOND)
-	    ORDER BY LAST_SEEN DESC
+	    GROUP BY SCHEMA_NAME, DIGEST
 	  )Q
-	  GROUP BY
-	    Q.SCHEMA_NAME,
-	    Q.DIGEST,
-	    Q.DIGEST_TEXT,
-	    Q.COUNT_STAR,
-	    Q.SUM_TIMER_WAIT,
-	    Q.SUM_ERRORS,
-	    Q.SUM_WARNINGS,
-	    Q.SUM_ROWS_AFFECTED,
-	    Q.SUM_ROWS_SENT,
-	    Q.SUM_ROWS_EXAMINED,
-	    Q.SUM_CREATED_TMP_DISK_TABLES,
-	    Q.SUM_CREATED_TMP_TABLES,
-	    Q.SUM_SORT_MERGE_PASSES,
-	    Q.SUM_SORT_ROWS,
-	    Q.SUM_NO_INDEX_USED
+	  WHERE row_number = 1
 	  ORDER BY SUM_TIMER_WAIT DESC
 	  LIMIT %d
 	`

Example with no subquery and simply SUM() the rows:

@@ -3,41 +3,22 @@
 	    ifnull(SCHEMA_NAME, 'NONE') as SCHEMA_NAME,
 	    DIGEST,
 	    LEFT(DIGEST_TEXT, %d) as DIGEST_TEXT,
-	    COUNT_STAR,
-	    SUM_TIMER_WAIT,
-	    SUM_ERRORS,
-	    SUM_WARNINGS,
-	    SUM_ROWS_AFFECTED,
-	    SUM_ROWS_SENT,
-	    SUM_ROWS_EXAMINED,
-	    SUM_CREATED_TMP_DISK_TABLES,
-	    SUM_CREATED_TMP_TABLES,
-	    SUM_SORT_MERGE_PASSES,
-	    SUM_SORT_ROWS,
-	    SUM_NO_INDEX_USED
-	  FROM (
-	    SELECT *
-	    FROM performance_schema.events_statements_summary_by_digest
-	    WHERE SCHEMA_NAME NOT IN ('mysql', 'performance_schema', 'information_schema')
-	      AND LAST_SEEN > DATE_SUB(NOW(), INTERVAL %d SECOND)
-	    ORDER BY LAST_SEEN DESC
-	  )Q
-	  GROUP BY
-	    Q.SCHEMA_NAME,
-	    Q.DIGEST,
-	    Q.DIGEST_TEXT,
-	    Q.COUNT_STAR,
-	    Q.SUM_TIMER_WAIT,
-	    Q.SUM_ERRORS,
-	    Q.SUM_WARNINGS,
-	    Q.SUM_ROWS_AFFECTED,
-	    Q.SUM_ROWS_SENT,
-	    Q.SUM_ROWS_EXAMINED,
-	    Q.SUM_CREATED_TMP_DISK_TABLES,
-	    Q.SUM_CREATED_TMP_TABLES,
-	    Q.SUM_SORT_MERGE_PASSES,
-	    Q.SUM_SORT_ROWS,
-	    Q.SUM_NO_INDEX_USED
+	    SUM(COUNT_STAR) COUNT_STAR,
+	    SUM(SUM_TIMER_WAIT) SUM_TIMER_WAIT,
+	    SUM(SUM_ERRORS) SUM_ERRORS,
+	    SUM(SUM_WARNINGS) SUM_WARNINGS,
+	    SUM(SUM_ROWS_AFFECTED) SUM_ROWS_AFFECTED,
+	    SUM(SUM_ROWS_SENT) SUM_ROWS_SENT,
+	    SUM(SUM_ROWS_EXAMINED) SUM_ROWS_EXAMINED,
+	    SUM(SUM_CREATED_TMP_DISK_TABLES) SUM_CREATED_TMP_DISK_TABLES,
+	    SUM(SUM_CREATED_TMP_TABLES) SUM_CREATED_TMP_TABLES,
+	    SUM(SUM_SORT_MERGE_PASSES) SUM_SORT_MERGE_PASSES,
+	    SUM(SUM_SORT_ROWS) SUM_SORT_ROWS,
+	    SUM(SUM_NO_INDEX_USED) SUM_NO_INDEX_USED
+	  FROM performance_schema.events_statements_summary_by_digest
+	  WHERE SCHEMA_NAME NOT IN ('mysql', 'performance_schema', 'information_schema')
+	    AND LAST_SEEN > DATE_SUB(NOW(), INTERVAL %d SECOND)
+	  GROUP BY SCHEMA_NAME, DIGEST, DIGEST_TEXT
 	  ORDER BY SUM_TIMER_WAIT DESC
 	  LIMIT %d
 	`

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.

4 participants