From: Avan Thakkar Date: Thu, 10 Feb 2022 10:29:03 +0000 (+0530) Subject: mgr/cephadm: adding loki and promtail monitoring services testing X-Git-Tag: v18.0.0~1249^2~2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=cf2734a74cde261d7c44830c8668622901ed18cc;p=ceph.git mgr/cephadm: adding loki and promtail monitoring services testing Signed-off-by: Avan Thakkar --- diff --git a/src/pybind/mgr/cephadm/tests/test_cephadm.py b/src/pybind/mgr/cephadm/tests/test_cephadm.py index afe2c2e34474..742da7a22594 100644 --- a/src/pybind/mgr/cephadm/tests/test_cephadm.py +++ b/src/pybind/mgr/cephadm/tests/test_cephadm.py @@ -1003,6 +1003,8 @@ class TestCephadm(object): ServiceSpec('grafana'), ServiceSpec('node-exporter'), ServiceSpec('alertmanager'), + ServiceSpec('loki'), + ServiceSpec('promtail'), ServiceSpec('rbd-mirror'), ServiceSpec('cephfs-mirror'), ServiceSpec('mds', service_id='fsname'), @@ -1217,6 +1219,8 @@ class TestCephadm(object): (ServiceSpec('mgr'), CephadmOrchestrator.apply_mgr), (ServiceSpec('crash'), CephadmOrchestrator.apply_crash), (ServiceSpec('prometheus'), CephadmOrchestrator.apply_prometheus), + (ServiceSpec('loki'), CephadmOrchestrator.apply_loki), + (ServiceSpec('promtail'), CephadmOrchestrator.apply_promtail), (ServiceSpec('grafana'), CephadmOrchestrator.apply_grafana), (ServiceSpec('node-exporter'), CephadmOrchestrator.apply_node_exporter), (ServiceSpec('alertmanager'), CephadmOrchestrator.apply_alertmanager), diff --git a/src/pybind/mgr/cephadm/tests/test_services.py b/src/pybind/mgr/cephadm/tests/test_services.py index 71a1307ac400..30b1ae93bbe4 100644 --- a/src/pybind/mgr/cephadm/tests/test_services.py +++ b/src/pybind/mgr/cephadm/tests/test_services.py @@ -13,7 +13,7 @@ from cephadm.services.iscsi import IscsiService from cephadm.services.nfs import NFSService from cephadm.services.osd import OSDService from cephadm.services.monitoring import GrafanaService, AlertmanagerService, PrometheusService, \ - NodeExporterService + NodeExporterService, LokiService, PromtailService from cephadm.module import CephadmOrchestrator from ceph.deployment.service_spec import IscsiServiceSpec, MonitoringSpec, AlertManagerSpec, \ ServiceSpec, RGWSpec, GrafanaSpec, SNMPGatewaySpec, IngressSpec, PlacementSpec @@ -80,6 +80,8 @@ class TestCephadmService: alertmanager_service = AlertmanagerService(mgr) prometheus_service = PrometheusService(mgr) node_exporter_service = NodeExporterService(mgr) + loki_service = LokiService(mgr) + promtail_service = PromtailService(mgr) crash_service = CrashService(mgr) iscsi_service = IscsiService(mgr) cephadm_services = { @@ -94,6 +96,8 @@ class TestCephadmService: 'alertmanager': alertmanager_service, 'prometheus': prometheus_service, 'node-exporter': node_exporter_service, + 'loki': loki_service, + 'promtail': promtail_service, 'crash': crash_service, 'iscsi': iscsi_service, } @@ -135,7 +139,7 @@ class TestCephadmService: # services based on CephadmService shouldn't have get_auth_entity with pytest.raises(AttributeError): - for daemon_type in ['grafana', 'alertmanager', 'prometheus', 'node-exporter']: + for daemon_type in ['grafana', 'alertmanager', 'prometheus', 'node-exporter', 'loki', 'promtail']: cephadm_services[daemon_type].get_auth_entity("id1", "host") cephadm_services[daemon_type].get_auth_entity("id1", "") cephadm_services[daemon_type].get_auth_entity("id1") @@ -321,6 +325,101 @@ class TestMonitoring: ], stdin=json.dumps({"files": {"prometheus.yml": y}}), image='') + + @patch("cephadm.serve.CephadmServe._run_cephadm") + def test_loki_config(self, _run_cephadm, cephadm_module: CephadmOrchestrator): + _run_cephadm.side_effect = async_side_effect(('{}', '', 0)) + + with with_host(cephadm_module, 'test'): + with with_service(cephadm_module, MonitoringSpec('loki')) as _: + + y = dedent(""" + # This file is generated by cephadm. + auth_enabled: false + + server: + http_listen_port: 3100 + grpc_listen_port: 8080 + + common: + path_prefix: /tmp/loki + storage: + filesystem: + chunks_directory: /tmp/loki/chunks + rules_directory: /tmp/loki/rules + replication_factor: 1 + ring: + instance_addr: 127.0.0.1 + kvstore: + store: inmemory + + schema_config: + configs: + - from: 2020-10-24 + store: boltdb-shipper + object_store: filesystem + schema: v11 + index: + prefix: index_ + period: 24h + + """).lstrip() + + _run_cephadm.assert_called_with( + 'test', + 'loki.test', + 'deploy', + [ + '--name', 'loki.test', + '{"service_name": "loki", "ports": [3100], "ip": null, "deployed_by": [], "rank": null, "rank_generation": null, "extra_container_args": null}', + '--config-json', '-', + '--tcp-ports', '3100' + ], + stdin=json.dumps({"files": {"loki.yml": y}}), + image='') + + @patch("cephadm.serve.CephadmServe._run_cephadm") + def test_promtail_config(self, _run_cephadm, cephadm_module: CephadmOrchestrator): + _run_cephadm.side_effect = async_side_effect(('{}', '', 0)) + + with with_host(cephadm_module, 'test'): + with with_service(cephadm_module, MonitoringSpec('promtail')) as _: + + y = dedent(""" + # This file is generated by cephadm. + server: + http_listen_port: 9080 + grpc_listen_port: 0 + + positions: + filename: /tmp/positions.yaml + + clients: + - url: http://192.168.1.1:3100/loki/api/v1/push + + scrape_configs: + - job_name: system + static_configs: + - targets: + - 192.168.1.1 + labels: + job: Cluster Logs + __path__: /var/log/ceph/**/*.log + + """).lstrip() + + _run_cephadm.assert_called_with( + 'test', + 'promtail.test', + 'deploy', + [ + '--name', 'promtail.test', + '{"service_name": "promtail", "ports": [9080], "ip": null, "deployed_by": [], "rank": null, "rank_generation": null, "extra_container_args": null}', + '--config-json', '-', + '--tcp-ports', '9080' + ], + stdin=json.dumps({"files": {"promtail.yml": y}}), + image='') @patch("cephadm.serve.CephadmServe._run_cephadm") @patch("cephadm.module.CephadmOrchestrator.get_mgr_ip", lambda _: '1::4')