def test_metrics(monkeypatch): client = client_mock(monkeypatch) resp = MagicMock() resp.text = 'metrics' client.return_value.session.get.return_value = resp parsed = MagicMock() parsed.samples = [ ('metric-1', {}, 20.17), ('metric-2', {'verb': 'GET'}, 20.16), ('metric-1', {'verb': 'POST'}, 20.18) ] parser = MagicMock() parser.return_value = [parsed] monkeypatch.setattr('zmon_worker_monitor.builtins.plugins.kubernetes.text_string_to_metric_families', parser) k = KubernetesWrapper() metrics = k.metrics() expected = { 'metric-1': [({}, 20.17), ({'verb': 'POST'}, 20.18)], 'metric-2': [({'verb': 'GET'}, 20.16)], } assert metrics == expected parser.assert_called_with(resp.text) client.return_value.session.get.assert_called_with(CLUSTER_URL + '/metrics')
def test_metrics(monkeypatch): client = client_mock(monkeypatch) resp = MagicMock() resp.text = "metrics" client.session.get.return_value = resp parsed = MagicMock() parsed.samples = [ ("metric-1", {}, 20.17), ("metric-2", { "verb": "GET" }, 20.16), ("metric-1", { "verb": "POST" }, 20.18), ] parser = MagicMock() parser.return_value = [parsed] monkeypatch.setattr( "zmon_worker_monitor.builtins.plugins.kubernetes.text_string_to_metric_families", parser, ) k = KubernetesWrapper(check_id='<test>') metrics = k.metrics() expected = { "metric-1": [({}, 20.17), ({ "verb": "POST" }, 20.18)], "metric-2": [({ "verb": "GET" }, 20.16)], } assert metrics == expected parser.assert_called_with(resp.text) client.session.get.assert_called_with(CLUSTER_URL + "/metrics")
def test_metrics(monkeypatch): client = client_mock(monkeypatch) resp = MagicMock() resp.text = 'metrics' client.return_value.session.get.return_value = resp parsed = MagicMock() parsed.samples = [('metric-1', {}, 20.17), ('metric-2', { 'verb': 'GET' }, 20.16), ('metric-1', { 'verb': 'POST' }, 20.18)] parser = MagicMock() parser.return_value = [parsed] monkeypatch.setattr( 'zmon_worker_monitor.builtins.plugins.kubernetes.text_string_to_metric_families', parser) k = KubernetesWrapper() metrics = k.metrics() expected = { 'metric-1': [({}, 20.17), ({ 'verb': 'POST' }, 20.18)], 'metric-2': [({ 'verb': 'GET' }, 20.16)], } assert metrics == expected parser.assert_called_with(resp.text) client.return_value.session.get.assert_called_with(CLUSTER_URL + '/metrics')