Skip to content

Commit

Permalink
Merge pull request #722 from gbregman/devel
Browse files Browse the repository at this point in the history
Add an id text for update related log messages to identify the component they came from
  • Loading branch information
gbregman authored Jun 19, 2024
2 parents 0bb3919 + c94fe9b commit 5d6ceab
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 21 deletions.
17 changes: 8 additions & 9 deletions control/cephutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,34 +35,33 @@ def execute_ceph_monitor_command(self, cmd):
def get_number_created_gateways(self, pool, group):
now = time.time()
if (now - self.last_sent) < 10 and self.anagroup_list :
self.logger.info(f" Caching response of the monitor: {self.anagroup_list} ")
self.logger.info(f"Caching response of the monitor: {self.anagroup_list}")
return self.anagroup_list
else :
try:
self.anagroup_list = []
self.last_sent = now
str = '{' + f'"prefix":"nvme-gw show", "pool":"{pool}", "group":"{group}"' + '}'
self.logger.info(f"nvme-show string: {str} ")
self.logger.debug(f"nvme-show string: {str}")
rply = self.execute_ceph_monitor_command(str)
self.logger.info(f"reply \"{rply}\"")
self.logger.debug(f"reply \"{rply}\"")
conv_str = rply[1].decode()
pos = conv_str.find("[")
if pos!= -1:
new_str = conv_str[pos+ len("[") :]
if pos != -1:
new_str = conv_str[pos + len("[") :]
pos = new_str.find("]")
new_str = new_str[: pos].strip()
int_str_list = new_str.split(' ')
self.logger.info(f"new_str : {new_str}")
self.logger.debug(f"new_str : {new_str}")
for x in int_str_list:
self.anagroup_list.append(int(x))
self.logger.info(self.anagroup_list)
self.logger.info(f"ANA group list: {self.anagroup_list}")
else:
self.logger.info("Gws not found")
self.logger.warning("GWs not found")

except Exception:
self.logger.exception(f"Failure get number created gateways:")
self.anagroup_list = []
pass

return self.anagroup_list

Expand Down
4 changes: 2 additions & 2 deletions control/discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ def __init__(self, config):
self.version = 1
self.config = config
self.lock = threading.Lock()
self.omap_state = OmapGatewayState(self.config)
self.omap_state = OmapGatewayState(self.config, "discovery")

self.gw_logger_object = GatewayLogger(config)
self.logger = self.gw_logger_object.logger
Expand Down Expand Up @@ -1079,7 +1079,7 @@ def start_service(self):

local_state = LocalGatewayState()
gateway_state = GatewayStateHandler(self.config, local_state,
self.omap_state, self._state_notify_update)
self.omap_state, self._state_notify_update, "discovery")
gateway_state.start_update()

try:
Expand Down
4 changes: 2 additions & 2 deletions control/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def serve(self):
"""Starts gateway server."""
self.logger.info(f"Starting serve, monitor client version: {self._monitor_client_version()}")

omap_state = OmapGatewayState(self.config)
omap_state = OmapGatewayState(self.config, f"gateway-{self.name}")
local_state = LocalGatewayState()
omap_state.check_for_old_format_omap_files()

Expand All @@ -179,7 +179,7 @@ def serve(self):
self._start_discovery_service()

# Register service implementation with server
gateway_state = GatewayStateHandler(self.config, local_state, omap_state, self.gateway_rpc_caller)
gateway_state = GatewayStateHandler(self.config, local_state, omap_state, self.gateway_rpc_caller, f"gateway-{self.name}")
omap_lock = OmapLock(omap_state, gateway_state, self.rpc_lock)
self.gateway_rpc = GatewayService(self.config, gateway_state, self.rpc_lock, omap_lock, self.group_id, self.spdk_rpc_client, self.ceph_utils)
self.server = grpc.server(futures.ThreadPoolExecutor(max_workers=1))
Expand Down
12 changes: 7 additions & 5 deletions control/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,14 +343,15 @@ class OmapGatewayState(GatewayState):

OMAP_VERSION_KEY = "omap_version"

def __init__(self, config):
def __init__(self, config, id_text=""):
self.config = config
self.version = 1
self.logger = GatewayLogger(self.config).logger
self.watch = None
gateway_group = self.config.get("gateway", "group")
self.omap_name = f"nvmeof.{gateway_group}.state" if gateway_group else "nvmeof.state"
self.conn = None
self.id_text = id_text

try:
self.ioctx = self.open_rados_connection(self.config)
Expand Down Expand Up @@ -519,7 +520,7 @@ class GatewayStateHandler:
use_notify: Flag to indicate use of OMAP watch/notify
"""

def __init__(self, config, local, omap, gateway_rpc_caller):
def __init__(self, config, local, omap, gateway_rpc_caller, id_text=""):
self.config = config
self.local = local
self.omap = omap
Expand All @@ -534,6 +535,7 @@ def __init__(self, config, local, omap, gateway_rpc_caller):
self.use_notify = self.config.getboolean("gateway",
"state_update_notify")
self.update_is_active_lock = threading.Lock()
self.id_text = id_text

def add_namespace(self, subsystem_nqn: str, nsid: str, val: str):
"""Adds a namespace to the state data store."""
Expand Down Expand Up @@ -647,7 +649,7 @@ def update(self) -> bool:
local_version = self.omap.get_local_version()

if local_version < omap_version:
self.logger.debug(f"Start update from {local_version} to {omap_version}.")
self.logger.debug(f"Start update from {local_version} to {omap_version} ({self.id_text}).")
local_state_dict = self.local.get_state()
local_state_keys = local_state_dict.keys()
omap_state_keys = omap_state_dict.keys()
Expand All @@ -664,7 +666,7 @@ def update(self) -> bool:
if not self.compare_state_values(local_state_dict[key], omap_state_dict[key])
}
grouped_changed = self._group_by_prefix(changed, prefix_list)

# Find OMAP removals
removed_keys = local_state_keys - omap_state_keys
removed = {key: local_state_dict[key] for key in removed_keys}
Expand All @@ -682,7 +684,7 @@ def update(self) -> bool:
# Update local state and version
self.local.reset(omap_state_dict)
self.omap.set_local_version(omap_version)
self.logger.debug(f"Update complete ({local_version} -> {omap_version}).")
self.logger.debug(f"Update complete ({local_version} -> {omap_version}) ({self.id_text}).")

return True

Expand Down
6 changes: 3 additions & 3 deletions tests/test_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def local_state():
@pytest.fixture
def omap_state(config):
"""Sets up and tears down OMAP state object."""
omap = OmapGatewayState(config)
omap = OmapGatewayState(config, "test")
omap.delete_state()
yield omap
omap.delete_state()
Expand Down Expand Up @@ -75,7 +75,7 @@ def _state_polling_update(update, is_add_req):
version = 1
update_interval_sec = 1
state = GatewayStateHandler(config, local_state, omap_state,
_state_polling_update)
_state_polling_update, "test")
state.update_interval = update_interval_sec
state.use_notify = False
key = "namespace_test"
Expand Down Expand Up @@ -136,7 +136,7 @@ def _state_notify_update(update, is_add_req):
version = 1
update_interval_sec = 10
state = GatewayStateHandler(config, local_state, omap_state,
_state_notify_update)
_state_notify_update, "test")
key = "namespace_test"
state.update_interval = update_interval_sec
state.use_notify = True
Expand Down

0 comments on commit 5d6ceab

Please sign in to comment.