Skip to content

Commit

Permalink
Fix condition for replication status (#8475)
Browse files Browse the repository at this point in the history
* Fix condition for replication status

* Add unit test
  • Loading branch information
coignetp authored and ofek committed Jan 29, 2021
1 parent 02d4898 commit 91c62aa
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion mysql/datadog_checks/mysql/mysql.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ def _check_replication_status(self, results):
if not slave_io_running and not slave_sql_running:
self.log.debug("Slave_IO_Running and Slave_SQL_Running are not ok")
slave_running_status = AgentCheck.CRITICAL
if not slave_io_running or not slave_sql_running:
elif not slave_io_running or not slave_sql_running:
self.log.debug("Either Slave_IO_Running or Slave_SQL_Running are not ok")
slave_running_status = AgentCheck.WARNING

Expand Down
25 changes: 25 additions & 0 deletions mysql/tests/test_mysql.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,31 @@ def cursor(self):
assert v.build == 'log'


@pytest.mark.unit
@pytest.mark.parametrize(
'slave_io_running, slave_sql_running, check_status',
[
pytest.param({}, {}, MySql.CRITICAL),
pytest.param({'stuff': 'yes'}, {}, MySql.WARNING),
pytest.param({}, {'stuff': 'yes'}, MySql.WARNING),
pytest.param({'stuff': 'yes'}, {'stuff': 'yes'}, MySql.OK),
],
)
def test_replication_check_status(slave_io_running, slave_sql_running, check_status, instance_basic, aggregator):
mysql_check = MySql(common.CHECK_NAME, {}, instances=[instance_basic])
mysql_check.service_check_tags = ['foo:bar']
mocked_results = {
'Slaves_connected': 1,
'Binlog_enabled': True,
'Slave_IO_Running': slave_io_running,
'Slave_SQL_Running': slave_sql_running,
}

mysql_check._check_replication_status(mocked_results)

aggregator.assert_service_check('mysql.replication.slave_running', check_status, tags=['foo:bar'], count=1)


@pytest.mark.integration
@pytest.mark.usefixtures('dd_environment')
def test_version_metadata(instance_basic, datadog_agent, version_metadata):
Expand Down

0 comments on commit 91c62aa

Please sign in to comment.