From 829c8040749b34e816df0a3e4989c00c3880af42 Mon Sep 17 00:00:00 2001 From: "jinhong.kim" Date: Fri, 24 Jun 2022 14:50:05 +0900 Subject: [PATCH] mgr/cephadm: fix the loki address in grafana, promtail configuration files - Fix to use loki address instead of MGR address(grafana datasource, promtail loki host) - Add a loki dependency on grafana and promtail services Signed-off-by: jinhong.kim --- src/pybind/mgr/cephadm/module.py | 3 ++- src/pybind/mgr/cephadm/services/monitoring.py | 19 +++++++++---------- .../templates/services/promtail.yml.j2 | 8 ++------ src/pybind/mgr/cephadm/tests/test_services.py | 10 ++++------ 4 files changed, 17 insertions(+), 23 deletions(-) diff --git a/src/pybind/mgr/cephadm/module.py b/src/pybind/mgr/cephadm/module.py index d8cf7cee5c1..b9b3ad53dbe 100644 --- a/src/pybind/mgr/cephadm/module.py +++ b/src/pybind/mgr/cephadm/module.py @@ -2325,8 +2325,9 @@ Then run the following: else: need = { 'prometheus': ['mgr', 'alertmanager', 'node-exporter', 'ingress'], - 'grafana': ['prometheus'], + 'grafana': ['prometheus', 'loki'], 'alertmanager': ['mgr', 'alertmanager', 'snmp-gateway'], + 'promtail': ['loki'], } for dep_type in need.get(daemon_type, []): for dd in self.cache.get_daemons_by_type(dep_type): diff --git a/src/pybind/mgr/cephadm/services/monitoring.py b/src/pybind/mgr/cephadm/services/monitoring.py index 246da8e39fd..b66fdc87c6b 100644 --- a/src/pybind/mgr/cephadm/services/monitoring.py +++ b/src/pybind/mgr/cephadm/services/monitoring.py @@ -39,10 +39,9 @@ class GrafanaService(CephadmService): deps.append(dd.name()) - daemons = self.mgr.cache.get_daemons_by_service('mgr') + daemons = self.mgr.cache.get_daemons_by_service('loki') loki_host = '' - assert daemons is not None - if daemons != []: + if daemons: assert daemons[0].hostname is not None addr = daemons[0].ip if daemons[0].ip else self._inventory_get_fqdn(daemons[0].hostname) loki_host = build_url(scheme='http', host=addr, port=3100) @@ -445,14 +444,14 @@ class PromtailService(CephadmService): def generate_config(self, daemon_spec: CephadmDaemonDeploySpec) -> Tuple[Dict[str, Any], List[str]]: assert self.TYPE == daemon_spec.daemon_type deps: List[str] = [] - hostnames: List[str] = [] - for dd in self.mgr.cache.get_daemons_by_service('mgr'): - assert dd.hostname is not None - addr = self.mgr.inventory.get_addr(dd.hostname) - hostnames.append(addr) + daemons = self.mgr.cache.get_daemons_by_service('loki') + loki_host = '' + if daemons: + assert daemons[0].hostname is not None + loki_host = daemons[0].ip or self._inventory_get_fqdn(daemons[0].hostname) + context = { - 'hostnames': hostnames, - 'client_hostname': hostnames[0], + 'client_hostname': loki_host, } yml = self.mgr.template.render('services/promtail.yml.j2', context) diff --git a/src/pybind/mgr/cephadm/templates/services/promtail.yml.j2 b/src/pybind/mgr/cephadm/templates/services/promtail.yml.j2 index f500f5d22ee..5ce7a310352 100644 --- a/src/pybind/mgr/cephadm/templates/services/promtail.yml.j2 +++ b/src/pybind/mgr/cephadm/templates/services/promtail.yml.j2 @@ -12,10 +12,6 @@ clients: scrape_configs: - job_name: system static_configs: - - targets: -{% for url in hostnames %} - - {{ url }} -{% endfor %} - labels: + - labels: job: Cluster Logs - __path__: /var/log/ceph/**/*.log + __path__: /var/log/ceph/**/*.log \ No newline at end of file diff --git a/src/pybind/mgr/cephadm/tests/test_services.py b/src/pybind/mgr/cephadm/tests/test_services.py index 69ee8a9944e..102d6e7cc80 100644 --- a/src/pybind/mgr/cephadm/tests/test_services.py +++ b/src/pybind/mgr/cephadm/tests/test_services.py @@ -498,14 +498,12 @@ class TestMonitoring: filename: /tmp/positions.yaml clients: - - url: http://1::4:3100/loki/api/v1/push + - url: http://:3100/loki/api/v1/push scrape_configs: - job_name: system static_configs: - - targets: - - 1::4 - labels: + - labels: job: Cluster Logs __path__: /var/log/ceph/**/*.log""").lstrip() @@ -583,7 +581,7 @@ class TestMonitoring: type: 'loki' access: 'proxy' orgId: 2 - url: 'http://[1::4]:3100' + url: '' basicAuth: false isDefault: true editable: false""").lstrip(), @@ -651,7 +649,7 @@ class TestMonitoring: " type: 'loki'\n" " access: 'proxy'\n" ' orgId: 2\n' - " url: 'http://[1::4]:3100'\n" + " url: ''\n" ' basicAuth: false\n' ' isDefault: true\n' ' editable: false', -- 2.39.5