Skip to content

Commit

Permalink
Improve piggyback processing performance
Browse files Browse the repository at this point in the history
A call to get_piggybacked_hosts_time_settings with a given piggybacked_hostname
processed all piggyback data needlessly, leading to a huge performance
impact.

This change propagates the piggybacked_hostname further to reduce the
overhead in the called helpers.

We'll have to see if this is enough. If not, we will need to make more
drastic changes ;).

CMK-21777

Change-Id: I78d72f13518c65acdba72b99cab0c7ec38d3cb23
  • Loading branch information
LarsMichelsen committed Feb 13, 2025
1 parent dce0d28 commit 9657918
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
4 changes: 3 additions & 1 deletion cmk/base/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3951,7 +3951,9 @@ def get_clustered_service_configuration(
def get_piggybacked_hosts_time_settings(
self, piggybacked_hostname: HostName | None = None
) -> Sequence[tuple[str | None, str, int]]:
all_sources = piggyback_backend.get_piggybacked_host_with_sources(cmk.utils.paths.omd_root)
all_sources = piggyback_backend.get_piggybacked_host_with_sources(
cmk.utils.paths.omd_root, piggybacked_hostname
)
used_sources = (
{m.source for sources in all_sources.values() for m in sources}
if piggybacked_hostname is None
Expand Down
8 changes: 6 additions & 2 deletions cmk/piggyback/backend/_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,16 @@ def get_messages_for(


def get_piggybacked_host_with_sources(
omd_root: Path,
omd_root: Path, piggybacked_hostname: HostName | None = None
) -> Mapping[HostAddress, Sequence[PiggybackMetaData]]:
"""Generates all piggyback pig/piggybacked host pairs"""
return {
piggybacked_host: _get_payload_meta_data(piggybacked_host, omd_root)
for piggybacked_host_folder in _get_piggybacked_host_folders(omd_root)
for piggybacked_host_folder in (
[d for d in [payload_dir(omd_root) / piggybacked_hostname] if d.exists()]
if piggybacked_hostname
else _get_piggybacked_host_folders(omd_root)
)
if (piggybacked_host := HostAddress(piggybacked_host_folder.name))
}

Expand Down

0 comments on commit 9657918

Please sign in to comment.