@cherrypy.expose
def index(self) -> str:
- return '''<!DOCTYPE html>
+ return self.mgr.get_store('service_discovery/index') or '''<!DOCTYPE html>
<html>
<head><title>Cephadm HTTP Endpoint</title></head>
<body>
return self.nfs_sd_config()
elif service == 'smb':
return self.smb_sd_config()
+ elif service.startswith("container"):
+ return self.container_sd_config(service)
else:
return []
})
return srv_entries
+ def container_sd_config(self, service: str) -> List[Dict[str, Collection[str]]]:
+ """Return <http_sd_config> compatible prometheus config for a container service."""
+ srv_entries = []
+ for dd in self.mgr.cache.get_daemons_by_service(service):
+ assert dd.hostname is not None
+ addr = dd.ip if dd.ip else self.mgr.inventory.get_addr(dd.hostname)
+ if not dd.ports:
+ continue
+ port = dd.ports[0]
+ srv_entries.append({
+ 'targets': [build_url(host=addr, port=port).lstrip('/')],
+ 'labels': {'instance': dd.hostname}
+ })
+ return srv_entries
+
@cherrypy.expose(alias='prometheus/rules')
def get_prometheus_rules(self) -> str:
"""Return currently configured prometheus rules as Yaml."""
return [FakeDaemonDescription('1.2.3.4', [9922], 'node0'),
FakeDaemonDescription('1.2.3.5', [9922], 'node1')]
+ if service_type == 'container.custom-container':
+ return [FakeDaemonDescription('1.2.3.4', [9123], 'node0'),
+ FakeDaemonDescription('1.2.3.5', [9123], 'node1')]
+
return [FakeDaemonDescription('1.2.3.4', [9100], 'node0'),
FakeDaemonDescription('1.2.3.5', [9200], 'node1')]
# check content
assert cfg[0]['targets'] == ['1.2.3.4:9922']
+ def test_get_sd_config_custom_container(self):
+ mgr = FakeMgr()
+ root = Root(mgr, 5000, '0.0.0.0')
+ cfg = root.get_sd_config('container.custom-container')
+
+ # check response structure
+ assert cfg
+ for entry in cfg:
+ assert 'labels' in entry
+ assert 'targets' in entry
+
+ # check content
+ assert cfg[0]['targets'] == ['1.2.3.4:9123']
+
def test_get_sd_config_invalid_service(self):
mgr = FakeMgr()
root = Root(mgr, 5000, '0.0.0.0')