2 Commits
Author SHA1 Message Date
bvandeusenandClaude Opus 5.5 263560cc94 fix(migrations): 0035's revision id fits alembic_version (32 chars) (#5374)
CI / unit (push) Successful in 1m35s
CI / lint (push) Successful in 3s
CI / integration (push) Successful in 1m17s
CI / publish (push) Successful in 1m25s
"0035_drop_plugin_catalog_settings" is 33 characters, and
alembic_version.version_num is VARCHAR(32), so the upgrade failed with
"value too long" (CI run 8800, integration). Renamed to
0035_drop_plugin_catalog. tests/test_migration_ids.py now checks every core
and plugin revision id fits, in the unit lane, which never migrates.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-08 13:20:11 -04:00
bvandeusenandClaude Opus 5.5 f035a3b14a fix(snmp): a UPS on mains reads "On battery: No, on mains", not "0s" (#5214)
UPS-MIB upsSecondsOnBattery is zero whenever the UPS is on mains power, so
"On battery for 0s" read as a timer that had just started. The reading gets
its own unit, battery_seconds: zero says "No, on mains", anything else
"for <span>". The metric key stays on_battery_for, so stored history keeps.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-08 13:16:24 -04:00
4 changed files with 38 additions and 3 deletions
+5 -1
View File
@@ -69,7 +69,7 @@ PRESETS: dict[str, tuple[str, str, tuple[Reading, ...]]] = {
Reading("1.3.6.1.2.1.33.1.2.3.0", "runtime_left", "Runtime left", "minutes"), Reading("1.3.6.1.2.1.33.1.2.3.0", "runtime_left", "Runtime left", "minutes"),
Reading("1.3.6.1.2.1.33.1.4.4.1.5.1", "load", "Load", "percent"), Reading("1.3.6.1.2.1.33.1.4.4.1.5.1", "load", "Load", "percent"),
Reading("1.3.6.1.2.1.33.1.3.3.1.3.1", "input_voltage", "Input", "volts"), Reading("1.3.6.1.2.1.33.1.3.3.1.3.1", "input_voltage", "Input", "volts"),
Reading("1.3.6.1.2.1.33.1.2.2.0", "on_battery_for", "On battery for", "seconds"))), Reading("1.3.6.1.2.1.33.1.2.2.0", "on_battery_for", "On battery", "battery_seconds"))),
"linux": ("Linux server", "CPU, memory and load from net-snmp (snmpd's UCD-SNMP-MIB).", "linux": ("Linux server", "CPU, memory and load from net-snmp (snmpd's UCD-SNMP-MIB).",
(Reading("1.3.6.1.4.1.2021.11.11.0", "cpu_used", "CPU used", "percent", scale=-1.0, offset=100.0), (Reading("1.3.6.1.4.1.2021.11.11.0", "cpu_used", "CPU used", "percent", scale=-1.0, offset=100.0),
Reading("1.3.6.1.4.1.2021.10.1.5.1", "load_1m", "Load (1m)", "number", scale=0.01), Reading("1.3.6.1.4.1.2021.10.1.5.1", "load_1m", "Load (1m)", "number", scale=0.01),
@@ -183,6 +183,9 @@ def format_value(unit: str, value: float | None) -> str:
return human_duration(value / 100) return human_duration(value / 100)
if unit == "seconds": if unit == "seconds":
return human_duration(value) return human_duration(value)
if unit == "battery_seconds":
# UPS-MIB upsSecondsOnBattery: zero whenever the UPS is on mains power.
return f"for {human_duration(value)}" if value > 0 else "No, on mains"
if unit == "minutes": if unit == "minutes":
return human_duration(value * 60) return human_duration(value * 60)
if unit == "percent": if unit == "percent":
@@ -207,6 +210,7 @@ def format_value(unit: str, value: float | None) -> str:
# What a chart's axis says for a stored unit, and how its values scale for it. # What a chart's axis says for a stored unit, and how its values scale for it.
def chart_axis(unit: str) -> tuple[str, float]: def chart_axis(unit: str) -> tuple[str, float]:
return {"centiseconds": ("days", 1 / 8_640_000), "seconds": ("seconds", 1.0), return {"centiseconds": ("days", 1 / 8_640_000), "seconds": ("seconds", 1.0),
"battery_seconds": ("seconds on battery", 1.0),
"minutes": ("minutes", 1.0), "percent": ("%", 1.0), "celsius": ("°C", 1.0), "minutes": ("minutes", 1.0), "percent": ("%", 1.0), "celsius": ("°C", 1.0),
"volts": ("V", 1.0), "decivolts": ("V", 0.1), "bytes": ("MiB", 1 / 1_048_576), "volts": ("V", 1.0), "decivolts": ("V", 0.1), "bytes": ("MiB", 1 / 1_048_576),
"kilobytes": ("MiB", 1 / 1024), "bits_per_second": ("Mbit/s", 1e-6), "kilobytes": ("MiB", 1 / 1024), "bits_per_second": ("Mbit/s", 1e-6),
@@ -5,7 +5,7 @@ image and a third-party plugin is a folder the operator mounts, so nothing reads
`plugins.index_url` or `plugins.repositories` any more. The removed feature `plugins.index_url` or `plugins.repositories` any more. The removed feature
takes its rows with it, as 0025 did for the http plugin. takes its rows with it, as 0025 did for the http plugin.
Revision ID: 0035_drop_plugin_catalog_settings Revision ID: 0035_drop_plugin_catalog
Revises: 0034_user_time_zone Revises: 0034_user_time_zone
Create Date: 2026-10-08 Create Date: 2026-10-08
""" """
@@ -13,7 +13,7 @@ from typing import Sequence, Union
from alembic import op from alembic import op
import sqlalchemy as sa import sqlalchemy as sa
revision: str = "0035_drop_plugin_catalog_settings" revision: str = "0035_drop_plugin_catalog"
down_revision: Union[str, None] = "0034_user_time_zone" down_revision: Union[str, None] = "0034_user_time_zone"
branch_labels: Union[str, Sequence[str], None] = None branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None depends_on: Union[str, Sequence[str], None] = None
+2
View File
@@ -54,6 +54,8 @@ def test_presets_come_in_order_and_names_may_not_repeat():
("volts", 121.0, "121 V"), ("volts", 121.0, "121 V"),
("decivolts", 1203, "120.3 V"), ("decivolts", 1203, "120.3 V"),
("minutes", 45, "45m"), ("minutes", 45, "45m"),
("battery_seconds", 0, "No, on mains"),
("battery_seconds", 300, "for 5m"),
("kilobytes", 2048, "2.0 MiB"), ("kilobytes", 2048, "2.0 MiB"),
("bits_per_second", 12_345_678, "12.3 Mbit/s"), ("bits_per_second", 12_345_678, "12.3 Mbit/s"),
("bits_per_second", 950, "950 bit/s"), ("bits_per_second", 950, "950 bit/s"),
+29
View File
@@ -0,0 +1,29 @@
"""Every Alembic revision id fits alembic_version.version_num, a VARCHAR(32).
A longer id passes every unit test and fails only when the upgrade writes it:
"value too long for type character varying(32)", and the app does not boot
(0035, #5374). The unit lane never migrates, so this reads the files.
"""
import pathlib
import re
REPO = pathlib.Path(__file__).resolve().parents[1]
_REVISION = re.compile(r'^revision(?::[^=]*)?=\s*["\']([^"\']+)["\']', re.M)
def revision_ids() -> dict[str, str]:
files = [*(REPO / "steward/migrations/versions").glob("*.py"),
*(REPO / "plugins").glob("*/migrations/versions/*.py")]
found = {}
for path in files:
m = _REVISION.search(path.read_text())
if m:
found[str(path.relative_to(REPO))] = m.group(1)
return found
def test_every_revision_id_fits_version_num():
ids = revision_ids()
assert len(ids) >= 30, ids # core and plugin migrations were found, so the check is real
too_long = {path: rev for path, rev in ids.items() if len(rev) > 32}
assert not too_long, f"alembic_version.version_num is VARCHAR(32): {too_long}"