Skip to content

Commit

Permalink
Don't emit any warnings if NO_MSG_AVAILABLE is received (#9452)
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianVeaux committed Jun 1, 2021
1 parent 029b46e commit 13c10d9
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def _submit_channel_status(self, queue_manager, search_channel_name, tags, chann
self.service_check(self.CHANNEL_SERVICE_CHECK, AgentCheck.CRITICAL, search_channel_tags)
if e.comp == pymqi.CMQC.MQCC_FAILED and e.reason == pymqi.CMQCFC.MQRCCF_CHL_STATUS_NOT_FOUND:
self.log.debug("Channel status not found for channel %s: %s", search_channel_name, e)
else:
elif not (e.comp == pymqi.CMQC.MQCC_FAILED and e.reason == pymqi.CMQC.MQRC_NO_MSG_AVAILABLE):
self.log.warning("Error getting CHANNEL status for channel %s: %s", search_channel_name, e)
else:
for channel_info in response:
Expand Down
35 changes: 33 additions & 2 deletions ibm_mq/tests/test_ibm_mq_int.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
# All rights reserved
# Licensed under a 3-clause BSD style license (see LICENSE)
import datetime as dt
import logging
import os

import mock
import pytest
from pymqi import MQMIError
from pymqi.CMQC import MQCC_FAILED, MQRC_NO_MSG_AVAILABLE
from pymqi import MQMIError, PCFExecute
from pymqi.CMQC import MQCC_FAILED, MQRC_BUFFER_ERROR, MQRC_NO_MSG_AVAILABLE
from six import iteritems

from datadog_checks.base import AgentCheck
Expand All @@ -21,6 +22,36 @@
pytestmark = [pytest.mark.usefixtures("dd_environment"), pytest.mark.integration]


def test_no_msg_errors_are_caught(aggregator, instance, caplog):
caplog.set_level(logging.WARNING)
m = mock.MagicMock()
with mock.patch('datadog_checks.ibm_mq.collectors.channel_metric_collector.pymqi.PCFExecute', new=m), mock.patch(
'datadog_checks.ibm_mq.collectors.queue_metric_collector.pymqi.PCFExecute', new=m
), mock.patch('datadog_checks.ibm_mq.collectors.stats_collector.pymqi.PCFExecute', new=m):
error = MQMIError(MQCC_FAILED, MQRC_NO_MSG_AVAILABLE)
m.side_effect = error
m.unpack = PCFExecute.unpack
check = IbmMqCheck('ibm_mq', {}, [instance])
check.check(instance)

assert not caplog.records


def test_errors_are_loogged(aggregator, instance, caplog):
caplog.set_level(logging.WARNING)
m = mock.MagicMock()
with mock.patch('datadog_checks.ibm_mq.collectors.channel_metric_collector.pymqi.PCFExecute', new=m), mock.patch(
'datadog_checks.ibm_mq.collectors.queue_metric_collector.pymqi.PCFExecute', new=m
), mock.patch('datadog_checks.ibm_mq.collectors.stats_collector.pymqi.PCFExecute', new=m):
error = MQMIError(MQCC_FAILED, MQRC_BUFFER_ERROR)
m.side_effect = error
m.unpack = PCFExecute.unpack
check = IbmMqCheck('ibm_mq', {}, [instance])
check.check(instance)

assert caplog.records


def test_check_metrics_and_service_checks(aggregator, instance, seed_data):
instance['mqcd_version'] = os.getenv('IBM_MQ_VERSION')
check = IbmMqCheck('ibm_mq', {}, [instance])
Expand Down

0 comments on commit 13c10d9

Please sign in to comment.