]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/telemetry: add commands to enable/disable channels
authorYaarit Hatuka <yaarit@redhat.com>
Tue, 23 Nov 2021 00:12:10 +0000 (00:12 +0000)
committerYaarit Hatuka <yaarit@redhat.com>
Thu, 13 Jan 2022 21:53:47 +0000 (21:53 +0000)
Currently we enable/disable a telemetry channel via CLI with:
  `ceph config set mgr mgr/telemetry/channel_basic true`
  `ceph config set mgr mgr/telemetry/channel_crash false`

We can now do this with:
  `ceph telemetry enable channel basic`
  `ceph telemetry disable channel crash`

We allow enabling / disabling lists of channels:
  `ceph telemetry enable channel basic device crash perf`
  `ceph telemetry disable channel basic device crash perf`

Please note, telemetry should be on for these commands to take effect.

Signed-off-by: Yaarit Hatuka <yaarit@redhat.com>
src/pybind/mgr/telemetry/module.py

index c34239dedbe2656c59e1855fcae93243d306be5b..e0b09dc4b3793a59987980d689262638e1177a7d 100644 (file)
@@ -1291,6 +1291,34 @@ class Module(MgrModule):
             # histograms.
             pass
 
+    def toggle_channel(self, action, channels: Optional[List[str]] = None) -> Tuple[int, str, str]:
+        '''
+        Enable or disable a list of channels
+        '''
+        if not self.enabled:
+            # telemetry should be on for channels to be toggled
+            msg = 'Telemetry is off. Please consider opting-in with `ceph telemetry on`.\n' \
+                  'Preview sample reports with `ceph telemetry preview`.'
+            return 0, msg, ''
+
+        if channels is None:
+            msg = f'Please provide a channel name. Available channels: {ALL_CHANNELS}.'
+            return 0, msg, ''
+
+        state = action == 'enable'
+        msg = ''
+        for c in channels:
+            if c not in ALL_CHANNELS:
+                msg = f"{msg}{c} is not a valid channel name. "\
+                        f"Available channels: {ALL_CHANNELS}.\n"
+            else:
+                self.set_module_option(f"channel_{c}", state)
+                setattr(self,
+                        f"channel_{c}",
+                        state)
+                msg = f"{msg}channel_{c} is {action}d\n"
+
+        return 0, msg, ''
 
     def restore_default_opt_setting(self, opt_name) -> None:
         for o in self.MODULE_OPTIONS:
@@ -1397,6 +1425,20 @@ To enable, add '--license {LICENSE}' to the 'ceph telemetry on' command.'''
         msg = 'Telemetry is now disabled. Channels settings are restored to default.'
         return 0, msg, ''
 
+    @CLIReadCommand('telemetry enable channel')
+    def enable_channel(self, channels: Optional[List[str]] = None) -> Tuple[int, str, str]:
+        '''
+        Enable a list of channels
+        '''
+        return self.toggle_channel('enable', channels)
+
+    @CLIReadCommand('telemetry disable channel')
+    def disable_channel(self, channels: Optional[List[str]] = None) -> Tuple[int, str, str]:
+        '''
+        Disable a list of channels
+        '''
+        return self.toggle_channel('disable', channels)
+
     @CLICommand('telemetry send')
     def do_send(self,
                 endpoint: Optional[List[EndPoint]] = None,