From c6209cf6d518b457ae8a0ba701d7fab251f1ea53 Mon Sep 17 00:00:00 2001 From: Adam King Date: Tue, 26 Mar 2024 15:10:31 -0400 Subject: [PATCH] cephadm: allow passing custom prometheus alerts to bootstrap This can't be done with the --config flag as the thing that needs to be changed is in the config-key store rather than being a config option. I don't think we have any option other than a new flag here. Makes use of the `ceph orch prometheus set-custom-alerts` command being added in another commit Signed-off-by: Adam King (cherry picked from commit e4883a30f37b6331359b6aa2d9e8bbe161106388) --- src/cephadm/cephadm.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/cephadm/cephadm.py b/src/cephadm/cephadm.py index 0a8292c5f00bc..3cab1644f1883 100755 --- a/src/cephadm/cephadm.py +++ b/src/cephadm/cephadm.py @@ -2776,6 +2776,11 @@ def command_bootstrap(ctx): except PermissionError: raise Error(f'Unable to create {dirname} due to permissions failure. Retry with root, or sudo or preallocate the directory.') + if getattr(ctx, 'custom_prometheus_alerts', None): + ctx.custom_prometheus_alerts = os.path.abspath(ctx.custom_prometheus_alerts) + if not os.path.isfile(ctx.custom_prometheus_alerts): + raise Error(f'No custom prometheus alerts file found at {ctx.custom_prometheus_alerts}') + (user_conf, _) = get_config_and_keyring(ctx) if ctx.ssh_user != 'root': @@ -2848,6 +2853,8 @@ def command_bootstrap(ctx): admin_keyring.name: '/etc/ceph/ceph.client.admin.keyring:z', tmp_config.name: '/etc/ceph/ceph.conf:z', } + if getattr(ctx, 'custom_prometheus_alerts', None): + mounts[ctx.custom_prometheus_alerts] = '/etc/ceph/custom_alerts.yml:z' for k, v in extra_mounts.items(): mounts[k] = v timeout = timeout or ctx.timeout @@ -2992,6 +2999,9 @@ def command_bootstrap(ctx): if getattr(ctx, 'deploy_cephadm_agent', None): cli(['config', 'set', 'mgr', 'mgr/cephadm/use_agent', 'true']) + if getattr(ctx, 'custom_prometheus_alerts', None): + cli(['orch', 'prometheus', 'set-custom-alerts', '-i', '/etc/ceph/custom_alerts.yml']) + return ctx.error_code ################################## @@ -5394,6 +5404,9 @@ def _get_parser(): '--deploy-cephadm-agent', action='store_true', help='deploy the cephadm-agent') + parser_bootstrap.add_argument( + '--custom-prometheus-alerts', + help='provide a file with custom prometheus alerts') parser_deploy = subparsers.add_parser( 'deploy', help='deploy a daemon') -- 2.39.5