Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make sure the oldest boot ID is included in the boot list #5591

Merged
merged 1 commit into from
Jan 31, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 23 additions & 19 deletions supervisor/host/logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,25 +111,29 @@ async def get_boot_ids(self) -> list[str]:
_LOGGER.error,
) from err

# If a system has not been rebooted in a long time query can come back with zero results
# Fallback is to get latest log line and its boot ID so we always have at least one.
if not text:
try:
async with self.journald_logs(
range_header="entries=:-1:1",
accept=LogFormat.JSON,
timeout=ClientTimeout(total=20),
) as resp:
text = await resp.text()
except (ClientError, TimeoutError) as err:
raise HostLogError(
"Could not get a list of boot IDs from systemd-journal-gatewayd",
_LOGGER.error,
) from err

self._boot_ids = [
json.loads(entry)[PARAM_BOOT_ID] for entry in text.split("\n") if entry
]
# Get the oldest log entry. This makes sure that its ID is included
# if the start of the oldest boot was rotated out of the journal.
try:
async with self.journald_logs(
range_header="entries=:0:1",
accept=LogFormat.JSON,
timeout=ClientTimeout(total=20),
) as resp:
text = await resp.text() + text
except (ClientError, TimeoutError) as err:
raise HostLogError(
"Could not get a list of boot IDs from systemd-journal-gatewayd",
_LOGGER.error,
) from err

self._boot_ids = []
for entry in text.split("\n"):
if (
entry
and (boot_id := json.loads(entry)[PARAM_BOOT_ID]) not in self._boot_ids
):
self._boot_ids.append(boot_id)

return self._boot_ids

async def get_identifiers(self) -> list[str]:
Expand Down