diff --git a/tangostationcontrol/tangostationcontrol/integration_test/default/prometheus/test_tango_prometheus_client.py b/tangostationcontrol/tangostationcontrol/integration_test/default/prometheus/test_tango_prometheus_client.py index 7fe16e3a12bb48fd98a462c26b20a27800630b71..771cd714a94d0f36316a47018059f02f5292810f 100644 --- a/tangostationcontrol/tangostationcontrol/integration_test/default/prometheus/test_tango_prometheus_client.py +++ b/tangostationcontrol/tangostationcontrol/integration_test/default/prometheus/test_tango_prometheus_client.py @@ -13,8 +13,7 @@ from tangostationcontrol.integration_test.device_proxy import TestDeviceProxy from tango import Database import importlib import sys -#sys.path.append('/opt/lofar/tango/docker-compose/tango-prometheus-exporter/code') -#tpc = importlib.import_module('tango-prometheus-client') +import numpy module_name = 'ArchiverPolicy' file_path = '/opt/lofar/tango/docker-compose/tango-prometheus-exporter/code/tango-prometheus-client.py' @@ -80,3 +79,24 @@ class TestPrometheusClient(BaseIntegrationTestCase): for e in exclude: if '*' not in e: # exclude wildcard self.assertNotIn(e, attribute_list) + + def test_collector_metrics(self): + """ Test if the metrics are correctly exposed """ + device_name = 'stat/recv/1' + recv_proxy = self.setup_recv_proxy(device_name) + collector = self.setUp() + expected_attr_values = recv_proxy.ANT_error_R + numpy.testing.assert_equal(expected_attr_values, numpy.array([True] * 96)) + attribute_metrics, scraping_metrics = collector.collect() + metric_samples = attribute_metrics.samples[0:96] # ANT_error_R + # Test attribute metrics + samples_names = [] + samples_values = [] + for s in metric_samples: + samples_names.append(s.labels['name']) + samples_values.append(numpy.bool(s.value)) + numpy.testing.assert_equal(samples_names, ['ANT_error_R'] * 96) + numpy.testing.assert_equal(samples_values, expected_attr_values) + # Test scraping metrics + total_scraping_time = scraping_metrics.samples[-1].value + self.assertLess(total_scraping_time, 10) # Set acceptable scraping time ? diff --git a/tangostationcontrol/tangostationcontrol/test/prometheus/test_archiver_policy.py b/tangostationcontrol/tangostationcontrol/test/prometheus/test_archiver_policy.py index 9baf490c2a54e8d975f1d57004dcda7e565299c0..3bed30a1c6651e58dc46a8ecb9ccb768da3d2bdb 100644 --- a/tangostationcontrol/tangostationcontrol/test/prometheus/test_archiver_policy.py +++ b/tangostationcontrol/tangostationcontrol/test/prometheus/test_archiver_policy.py @@ -8,13 +8,10 @@ # See LICENSE.txt for more info. from tangostationcontrol.test import base -#import importlib import sys -#sys.path.append('/opt/lofar/tango/docker-compose/tango-prometheus-exporter/code') -#tpc = importlib.import_module('tango-prometheus-client') import importlib.util module_name = 'ArchiverPolicy' -file_path = '/tango/docker-compose/tango-prometheus-exporter/code/tango-prometheus-client.py' +file_path = '/opt/lofar/tango/docker-compose/tango-prometheus-exporter/code/tango-prometheus-client.py' spec = importlib.util.spec_from_file_location(module_name, file_path) tpc = importlib.util.module_from_spec(spec) sys.modules[module_name] = tpc @@ -22,7 +19,7 @@ spec.loader.exec_module(tpc) class TestArchiverPolicy(base.TestCase): - CONFIG = tpc.ArchiverPolicy.load_config('/tango/docker-compose/tango-prometheus-exporter/lofar2-policy.json') + CONFIG = tpc.ArchiverPolicy.load_config('/opt/lofar/tango/docker-compose/tango-prometheus-exporter/lofar2-policy.json') def test_config_file(self): """ Test if policy config file is correctly retrieved """