]> git.apps.os.sepia.ceph.com Git - ceph-ci.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)
committerAvan Thakkar <athakkar@redhat.com>
Thu, 10 Feb 2022 11:06:35 +0000 (16:36 +0530)
Signed-off-by: Avan Thakkar <athakkar@redhat.com>
src/pybind/mgr/cephadm/tests/test_cephadm.py
src/pybind/mgr/cephadm/tests/test_services.py

index afe2c2e34474abb727e8c5a2343a4292d25145ef..742da7a2259477d9d439414dddb1538e398b0d97 100644 (file)
@@ -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),
index 71a1307ac400ab47a673607abc89b92de2f8cf97..30b1ae93bbe4f131e64a1ac8cf98984195ef58b2 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")
@@ -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')