def test_collect_host_metrics(mock_requests, mock_status, aggregator): # type: (Any, Any, AggregatorStub) -> None check = MarklogicCheck('marklogic', {}, [INSTANCE_FILTERS]) # Expected output when there is no exclude list check.resources_to_monitor = { 'forest': [], 'database': [], 'host': [ # Does not exist { 'name': '9aea032c882e', 'id': '17797492400840985949', 'type': 'host', 'uri': '/hosts/9aea032c882e' }, { 'name': 'ff0fef449486', 'id': '3428441913043145991', 'type': 'host', 'uri': 'hosts/ff0fef449486' }, ], 'server': [], } check.collect_per_resource_metrics() expected_tags = COMMON_TAGS + ['marklogic_host_name:ff0fef449486'] for m in HOST_STATUS_METRICS_GENERAL: aggregator.assert_metric(m, tags=expected_tags, count=1) for m in [ 'marklogic.requests.query-count', 'marklogic.requests.total-requests', 'marklogic.requests.update-count' ]: aggregator.assert_metric(m, tags=expected_tags, count=1) aggregator.assert_all_metrics_covered()
def test_bad_resource_storage(mock_requests, aggregator, caplog): # type: (Any, Any, AggregatorStub) -> None caplog.at_level(logging.WARNING) check = MarklogicCheck('marklogic', {}, [INSTANCE_FILTERS]) check.resources_to_monitor = { 'forest': [ { 'id': '4259429487027269237', 'type': 'forest', 'name': 'Documents', 'uri': '/forests/Documents' }, ], 'database': [], 'host': [], 'server': [], } check.collect_per_resource_metrics() # This can happen when the database owning this forest is disabled assert "Status information unavailable for resource {" in caplog.text assert "Storage information unavailable for resource {" in caplog.text