]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/cephadm: adding loki and promtail monitoring services testing
authorAvan Thakkar <athakkar@redhat.com>
Thu, 10 Feb 2022 10:29:03 +0000 (15:59 +0530)
committerAdam King <adking@redhat.com>
Tue, 3 May 2022 00:48:34 +0000 (20:48 -0400)
Signed-off-by: Avan Thakkar <athakkar@redhat.com>
(cherry picked from commit cf2734a74cde261d7c44830c8668622901ed18cc)

src/pybind/mgr/cephadm/tests/test_cephadm.py
src/pybind/mgr/cephadm/tests/test_services.py

index 4d60e6611b25bc8529635d6e18f23702afc54cf3..ce588791ef965b4f28ef6cc10dd3cc540a896115 100644 (file)
@@ -1033,6 +1033,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'),
@@ -1247,6 +1249,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),
index 9a5ea64b4765bf2f9cfd9fd7b3e851f3fd8d9bf4..765e0c659939a4d7244d70e619f80ca2bbe299c7 100644 (file)
@@ -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")
@@ -324,6 +328,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')