Skip to content

Commit

Permalink
piggyback: rename
Browse files Browse the repository at this point in the history
Change-Id: I4c541e9a8b7e03d17b41dc99ac5342f1cd5e0a42
  • Loading branch information
mo-ki committed Oct 1, 2024
1 parent 9d884cd commit a2f2bea
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 20 deletions.
4 changes: 1 addition & 3 deletions cmk/base/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3335,9 +3335,7 @@ def _host_has_piggyback_data_right_now(self, host_name: HostAddress) -> bool:
def _is_usable(data: piggyback.PiggybackMessage) -> bool:
return (now - data.meta.last_update) <= piggy_config.max_cache_age(data.meta.source)

return any(
map(_is_usable, piggyback.get_piggyback_raw_data(host_name, cmk.utils.paths.omd_root))
)
return any(map(_is_usable, piggyback.get_messages_for(host_name, cmk.utils.paths.omd_root)))

def _piggybacked_host_files(self, host_name: HostName) -> list[tuple[str | None, str, int]]:
if rules := self.ruleset_matcher.get_host_values(host_name, piggybacked_host_files):
Expand Down
6 changes: 2 additions & 4 deletions cmk/base/errorhandling/_crash.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

from cmk.checkengine.checking import CheckPluginName

from cmk.piggyback import get_piggyback_raw_data
from cmk.piggyback import get_messages_for

CrashReportStore = crash_reporting.CrashReportStore

Expand Down Expand Up @@ -172,9 +172,7 @@ def _read_agent_output(hostname: HostName) -> AgentRawData | None:
pass

# Note: this is not quite what the fetcher does :(
agent_outputs.extend(
r.raw_data for r in get_piggyback_raw_data(hostname, cmk.utils.paths.omd_root)
)
agent_outputs.extend(r.raw_data for r in get_messages_for(hostname, cmk.utils.paths.omd_root))

if agent_outputs:
return AgentRawData(b"\n".join(agent_outputs))
Expand Down
4 changes: 2 additions & 2 deletions cmk/fetchers/_piggyback.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from cmk.utils.log import VERBOSE
from cmk.utils.paths import omd_root

from cmk.piggyback import get_piggyback_raw_data, PiggybackMessage
from cmk.piggyback import get_messages_for, PiggybackMessage
from cmk.piggyback.config import Config as PiggybackConfig

from ._abstract import Fetcher, Mode
Expand Down Expand Up @@ -117,4 +117,4 @@ def _get_source_labels_section(self) -> bytearray | bytes:

@staticmethod
def _raw_data(hostname: HostAddress) -> Sequence[PiggybackMessage]:
return get_piggyback_raw_data(hostname, omd_root)
return get_messages_for(hostname, omd_root)
4 changes: 2 additions & 2 deletions cmk/piggyback/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from . import config
from ._storage import (
cleanup_piggyback_files,
get_piggyback_raw_data,
get_messages_for,
get_piggybacked_host_with_sources,
load_last_distribution_time,
move_for_host_rename,
Expand All @@ -21,7 +21,7 @@
"config",
"cleanup_piggyback_files",
"get_piggybacked_host_with_sources",
"get_piggyback_raw_data",
"get_messages_for",
"PiggybackMetaData",
"PiggybackMessage",
"remove_source_status_file",
Expand Down
2 changes: 1 addition & 1 deletion cmk/piggyback/_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class PiggybackMessage:
# - Path(tmp/check_mk/piggyback_sources/SOURCE).name


def get_piggyback_raw_data(
def get_messages_for(
piggybacked_hostname: HostAddress, omd_root: Path
) -> Sequence[PiggybackMessage]:
"""Returns piggyback messages for the given host"""
Expand Down
4 changes: 2 additions & 2 deletions cmk/piggyback_hub/payload.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

from cmk.messaging import Channel, CMKConnectionError, Connection, DeliveryTag
from cmk.piggyback import (
get_piggyback_raw_data,
get_messages_for,
load_last_distribution_time,
PiggybackMessage,
PiggybackMetaData,
Expand Down Expand Up @@ -85,7 +85,7 @@ def _get_piggyback_raw_data_to_send(
) -> Sequence[PiggybackMessage]:
return [
data
for data in get_piggyback_raw_data(target_host, omd_root)
for data in get_messages_for(target_host, omd_root)
if not _is_message_already_distributed(data.meta, omd_root)
]

Expand Down
4 changes: 2 additions & 2 deletions tests/unit/cmk/piggyback_hub/test_payload.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

from cmk.messaging import DeliveryTag
from cmk.piggyback import (
get_piggyback_raw_data,
get_messages_for,
load_last_distribution_time,
PiggybackMessage,
PiggybackMetaData,
Expand Down Expand Up @@ -55,7 +55,7 @@ def test__on_message() -> None:
raw_data=b"line1\nline2\n",
)
]
actual_payload = get_piggyback_raw_data(HostName("target"), cmk.utils.paths.omd_root)
actual_payload = get_messages_for(HostName("target"), cmk.utils.paths.omd_root)
assert actual_payload == expected_payload


Expand Down
8 changes: 4 additions & 4 deletions tests/unit/cmk/test_piggyback.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@


def _get_only_raw_data_element(host_name: HostAddress) -> piggyback.PiggybackMessage:
first, *other = piggyback.get_piggyback_raw_data(host_name, cmk.utils.paths.omd_root)
first, *other = piggyback.get_messages_for(host_name, cmk.utils.paths.omd_root)
assert not other
return first


def test_get_piggyback_raw_data_no_data() -> None:
assert not piggyback.get_piggyback_raw_data(HostAddress("no-host"), cmk.utils.paths.omd_root)
assert not piggyback.get_messages_for(HostAddress("no-host"), cmk.utils.paths.omd_root)


def test_store_piggyback_raw_data_simple() -> None:
Expand Down Expand Up @@ -112,7 +112,7 @@ def test_store_piggyback_raw_data_second_source() -> None:

raw_data_map = {
rd.meta.source: rd.meta
for rd in piggyback.get_piggyback_raw_data(_TEST_HOST_NAME, cmk.utils.paths.omd_root)
for rd in piggyback.get_messages_for(_TEST_HOST_NAME, cmk.utils.paths.omd_root)
}
assert len(raw_data_map) == 2

Expand All @@ -132,7 +132,7 @@ def test_store_piggyback_raw_data_different_timestamp() -> None:
)
raw_data_map = {
rd.meta.source: rd.meta
for rd in piggyback.get_piggyback_raw_data(_TEST_HOST_NAME, cmk.utils.paths.omd_root)
for rd in piggyback.get_messages_for(_TEST_HOST_NAME, cmk.utils.paths.omd_root)
}

assert (raw1 := raw_data_map[HostAddress("source1")]).last_update == _REF_TIME
Expand Down

0 comments on commit a2f2bea

Please sign in to comment.