From 6cf495fbc4fdeb5e263f6005530469cef71fe196 Mon Sep 17 00:00:00 2001 From: Patrick Donnelly Date: Fri, 19 Apr 2024 14:31:09 -0400 Subject: [PATCH] mgr: allow specifying module option level Some are for development purposes and should be filtered out by the dashboard. Signed-off-by: Patrick Donnelly (cherry picked from commit 0d94eebb0dd1b3e2afdde92e1c1051affded46f2) --- qa/tasks/mgr/dashboard/test_mgr_module.py | 1 + src/common/options.h | 12 ++++++++++++ src/mgr/PyModule.cc | 7 +++++++ src/pybind/mgr/mgr_module.py | 6 ++++++ 4 files changed, 26 insertions(+) diff --git a/qa/tasks/mgr/dashboard/test_mgr_module.py b/qa/tasks/mgr/dashboard/test_mgr_module.py index c196c71240140..2b8b672f28400 100644 --- a/qa/tasks/mgr/dashboard/test_mgr_module.py +++ b/qa/tasks/mgr/dashboard/test_mgr_module.py @@ -112,6 +112,7 @@ class MgrModuleTest(MgrModuleTestCase): 'last_opt_revision': module_options_object_schema, 'leaderboard': module_options_object_schema, 'leaderboard_description': module_options_object_schema, + 'sqlite3_killpoint': module_options_object_schema, 'log_level': module_options_object_schema, 'log_to_cluster': module_options_object_schema, 'log_to_cluster_level': module_options_object_schema, diff --git a/src/common/options.h b/src/common/options.h index e1d4ec16ed704..ad39936d43ae5 100644 --- a/src/common/options.h +++ b/src/common/options.h @@ -116,6 +116,18 @@ struct Option { } } + static level_t str_to_level(std::string_view s) { + if (s == "basic") { + return LEVEL_BASIC; + } else if (s == "advanced") { + return LEVEL_ADVANCED; + } else if (s == "dev") { + return LEVEL_DEV; + } else { + return LEVEL_UNKNOWN; + } + } + enum flag_t { FLAG_RUNTIME = 0x1, ///< option can be changed at runtime FLAG_NO_MON_UPDATE = 0x2, ///< option cannot be changed via mon config diff --git a/src/mgr/PyModule.cc b/src/mgr/PyModule.cc index 084cf3ffc1eac..20234ec57682e 100644 --- a/src/mgr/PyModule.cc +++ b/src/mgr/PyModule.cc @@ -609,6 +609,13 @@ int PyModule::load_options() option.type = t; } } + p = PyDict_GetItemString(pOption, "level"); + if (p && PyLong_Check(p)) { + long v = PyLong_AsLong(p); + option.level = static_cast(v); + } else { + option.level = Option::level_t::LEVEL_ADVANCED; + } p = PyDict_GetItemString(pOption, "desc"); if (p && PyObject_TypeCheck(p, &PyUnicode_Type)) { option.desc = PyUnicode_AsUTF8(p); diff --git a/src/pybind/mgr/mgr_module.py b/src/pybind/mgr/mgr_module.py index 3fefd79b99419..15939a2628009 100644 --- a/src/pybind/mgr/mgr_module.py +++ b/src/pybind/mgr/mgr_module.py @@ -558,6 +558,11 @@ if TYPE_CHECKING: # common/options.h: value_t OptionValue = Optional[Union[bool, int, float, str]] +class OptionLevel(IntEnum): + BASIC = 0 + ADVANCED = 1 + DEV = 2 + UNKNOWN = 3 class Option(Dict): """ @@ -568,6 +573,7 @@ class Option(Dict): def __init__( self, name: str, + level: OptionLevel = OptionLevel.ADVANCED, default: OptionValue = None, type: 'OptionTypeLabel' = 'str', desc: Optional[str] = None, -- 2.39.5