Skip to content

[mysql] Work _get_slave_status in case of performance_schema is dis… #3061

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

hirose31
Copy link

@hirose31 hirose31 commented Dec 6, 2016

What does this PR do?

This PR makes replication: true works correctly in case of MySQL >= 5.5 with performance_schema is disabled and MySQL 5.1.

Detail

_collect_metrics calls _get_slave_status without the nonblocking parameter.

            results.update(self._get_slave_status(db))

_get_slave_status (nonblocking is True implicitly) queries SELECT THREAD_ID, NAME FROM performance_schema.threads WHERE NAME LIKE '%worker'.

    def _get_slave_status(self, db, nonblocking=True):
...
                if nonblocking:
                    cursor.execute("SELECT THREAD_ID, NAME FROM performance_schema.threads WHERE NAME LIKE '%worker'")
                else:
                    cursor.execute("SELECT * FROM INFORMATION_SCHEMA.PROCESSLIST WHERE COMMAND LIKE '%Binlog dump%'")
...

that causes:

  • MySQL >= 5.5 w/ performance_schema = off
    • metrics mysql.replication.slaves_connected is always 0, becuse there is no record in performance_schema.threads
  • MySQL <= 5.1 (does not support performance_schema)
    • raise exception because performance_schema.threads does not exist
2016-12-06 18:33:35 JST | ERROR | dd.collector | checks.mysql(mysql.py:313) | error!
Traceback (most recent call last):
  File "/opt/datadog-agent/agent/checks.d/mysql.py", line 306, in check
    self._collect_metrics(host, db, tags, options, queries)
  File "/opt/datadog-agent/agent/checks.d/mysql.py", line 532, in _collect_metrics
    results.update(self._get_slave_status(db), False)
  File "/opt/datadog-agent/agent/checks.d/mysql.py", line 872, in _get_slave_status
    cursor.execute("SELECT THREAD_ID, NAME FROM performance_schema.threads WHERE NAME LIKE '%worker'")
  File "/opt/datadog-agent/embedded/lib/python2.7/site-packages/pymysql/cursors.py", line 134, in execute
    result = self._query(query)
...
ProgrammingError: (1146, u"Table 'performance_schema.threads' doesn't exist")

Additional Notes

passing performance_schema_enabled to _get_slave_status is dropped on @e614fa0593f449213c5c07982e6b59b785287f2d . I don't know why.

@degemer
Copy link
Member

degemer commented Dec 22, 2016

Thank you for your detailed description @hirose31 !
You're right, this was changed in #2603 (whereas the description states the exact opposite).
I missed it during the review, I'm going to ask @truthbk to have a look, if he remembers why he changed this behaviour.

@degemer degemer requested a review from truthbk December 22, 2016 13:59
@degemer degemer removed their assignment Dec 22, 2016
@truthbk truthbk self-assigned this Jan 31, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants