Skip to content
Draft
Show file tree
Hide file tree
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
66 changes: 59 additions & 7 deletions docs/config/fault-manager.rst
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,8 @@ Capture continuous rosbag recordings around fault events.
for a fault whose cap is exactly ``1`` (its rule's ``max_bags``, else
``max_bags_per_fault``): a history someone configured must not be what
an acknowledgement takes away, so the cap governs retention there instead.
A retention rule's ``on_cleared`` replaces it for the fault codes the rule
covers (see Rosbag Retention Rules below).

.. note::

Expand Down Expand Up @@ -789,7 +791,8 @@ Rosbag Retention Rules
~~~~~~~~~~~~~~~~~~~~~~

The parameters under ``snapshots.rosbag.retention.`` set a rule per fault: a ``priority``, an
``over_quota`` choice, a ``max_bags`` cap and ``keep_first``. They are read at startup, validated and
``over_quota`` choice, a ``max_bags`` cap, ``keep_first``, and what happens to the fault's recordings
when it heals (``on_healed``) or is cleared (``on_cleared``). They are read at startup, validated and
logged. They are read only while
rosbag capture is on (``snapshots.rosbag.enabled: true``); with it off, the fault manager warns once
and ignores them. Without any ``snapshots.rosbag.retention.*`` parameter the fault manager behaves as
Expand All @@ -805,6 +808,8 @@ before. An example file is ``config/rosbag_retention.example.yaml``.
defaults:
priority: 10
severity:
INFO:
on_healed: delete
ERROR:
priority: 50
fault_codes:
Expand All @@ -816,6 +821,7 @@ before. An example file is ``config/rosbag_retention.example.yaml``.
gnss_fix:
match: 'GNSS\.FIX_LOST'
priority: 300
on_cleared: delete
pattern_order: [gnss_fix]

Grammar, relative to ``snapshots.rosbag.retention.``:
Expand Down Expand Up @@ -861,6 +867,14 @@ Fields:
- ``true`` or ``false`` (default)
- With a ``max_bags`` of 2 or more, keep the first recording plus the ``max_bags - 1`` newest.
Ignored with a warning when ``max_bags`` is below 2.
* - ``on_healed``
- ``keep`` (default) or ``delete``
- What happens to the fault's recordings when it becomes HEALED. HEALED needs
``healing_enabled: true`` (default ``false``).
* - ``on_cleared``
- ``keep`` or ``delete``; default ``delete`` when ``rosbag.auto_cleanup`` is true and the fault's
``max_bags`` is 1, else ``keep``
- What happens to the fault's recordings when it becomes CLEARED.

**The cap per fault code.** When a recording is stored, each of its fault codes keeps at most its rule's
``max_bags`` recordings, resolved with the fault's severity as it is stored now. Over the cap the
Expand All @@ -872,9 +886,41 @@ store of that fault code logs a warning. A fault that cannot be read when a reco
all its recordings in that store, with a warning; the next store decides again. A fault that is
reported again at a higher severity takes the cap of the higher severity.

**The clear.** With ``rosbag.auto_cleanup: true`` a clear deletes the fault's recordings only when its
``max_bags`` is 1. ``max_bags: 3`` on a rule keeps the history of that fault also when
``max_bags_per_fault`` is 1, and ``max_bags: 1`` deletes it also when ``max_bags_per_fault`` is 3.
**The clear.** A clear deletes the fault's recordings when its rule says ``on_cleared: delete``, and
keeps them with ``on_cleared: keep``, whatever ``rosbag.auto_cleanup`` and the cap are. Without
``on_cleared`` the default applies: with ``rosbag.auto_cleanup: true`` a clear deletes the fault's
recordings only when its ``max_bags`` is 1. ``max_bags: 3`` on a rule keeps the history of that fault
also when ``max_bags_per_fault`` is 1, and ``max_bags: 1`` deletes it also when ``max_bags_per_fault``
is 3.

**The heal.** A fault that becomes HEALED loses its recordings when its rule says
``on_healed: delete``. That holds for every status the fault heals from, PREFAILED included, and also
removes the recordings of earlier episodes of the code. Without ``on_healed`` the recordings stay.

Both actions run at the status change, resolved with the fault's severity at that moment. A recording
shared by a burst loses only the link of the fault that healed or was cleared; the directory is
removed with the last link. Each removed recording is logged as ``Recording removed: <id> (fault
healed)`` or ``(fault cleared)``, after its directory is gone.

**A recording made before a delete action never survives it.** Each fault code joins a recording when
the recording opens or when the fault confirms inside its post-fault window. A fault that heals or is
cleared with delete inside the window gets no row in that recording; a recording no fault keeps a row
in is discarded when it is stored. A recording that is closed but not stored yet when its fault heals
or is cleared with delete is not stored for that fault, also when the fault fails again before the
store. A fault that joins after the delete action keeps its row, unless it is still HEALED or
CLEARED with delete when the recording is stored: a confirmation whose capture runs only after the
fault healed or was cleared with delete stores no row.

**Startup reclassification.** A fault that is HEALED at startup while healing is now disabled for its
code becomes CLEARED. Its recordings are deleted only when its rule says ``on_cleared: delete``
explicitly; the default of ``on_cleared`` does not apply there. A restart with healing turned off thus
deletes nothing that no rule asks to delete.

With ``audit_log.fail_closed: true``, a failed audit append stops the status actions that follow it:
a heal stops before its ``on_healed``, a startup reclassification before its ``on_cleared``, and a
symptom auto-cleared with its root cause stops its own ``on_cleared`` and that of the root cause. The
stored recordings stay until a space limit or a later status change removes them; a recording stored
after the failed append follows the fault's status like any store.

**What the rules do.** A new recording evicts only recordings whose priority is less than or equal to
its own, and evicts them in this order: lowest ``priority`` first, then the recordings whose faults are
Expand Down Expand Up @@ -914,7 +960,7 @@ it in its post-fault window is dropped when it is stored.
new recordings: a recording that does not fit after the per-fault cap is dropped, and nothing is
evicted for the quota. The open-time check runs for every fault. The per-fault cap and the removal of
a cleared fault's recording (``auto_cleanup``) work as without rules, with ``max_bags_per_fault`` for
every fault code.
every fault code. A heal keeps the recordings (``on_healed`` is ``keep``).

A failed attempt to open a recording keeps the ring buffer, so the next fault within ``duration_sec``
still gets its history.
Expand Down Expand Up @@ -947,7 +993,8 @@ A file the fault manager cannot read is reported with a warning and skipped.

- a value of the wrong type (``priority: 5.0`` is a double, not an integer, ``max_bags: "3"`` is a
string, ``keep_first: "yes"`` is a string, not a boolean), ``priority`` outside 0-1000, ``max_bags``
below 0, ``over_quota`` other than ``keep`` or ``drop``;
below 0, ``over_quota`` other than ``keep`` or ``drop``, ``on_healed`` or ``on_cleared`` other than
``keep`` or ``delete`` (``on_cleared: 1`` is an integer);
- an unknown severity name, an unknown field or an unknown key under the prefix;
- ``match`` outside ``patterns``, a pattern without ``match``, a ``match`` that is not a valid regular expression;
- a pattern missing from ``pattern_order``, a label in ``pattern_order`` that names no pattern, or twice.
Expand Down Expand Up @@ -1018,7 +1065,12 @@ by default: with it off there is no table, no file and no write cost.
already committed to the separate fault-store database and the two
databases cannot be made atomic. It signals a broken audit chain so an
operator has to act. Off by default so the audit can never block fault
processing.
processing. A heal, a startup reclassification, or a symptom auto-cleared
with its root cause whose append fails does not run the rosbag status
actions that follow it (``on_healed``, ``on_cleared``; for the symptom also
the root cause's ``on_cleared``): the stored recordings stay until a space
limit or a later status change removes them, and a recording stored after
the failed append follows the fault's status like any store.
* - ``audit_log.database_path``
- ``""``
- Where the audit database lives. Empty puts it beside the fault database,
Expand Down
27 changes: 17 additions & 10 deletions docs/tutorials/snapshots.rst
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,16 @@ configuration always overrides the zero-config fallback when present.
of that code's leftover HEALED rows as it reclassifies them, without a clear
at all. ``snapshots.retain_on_clear: true`` keeps the value snapshots
across all of it, and only those. The rosbag recording is not covered by that
setting. A clear deletes the recording under
setting. A clear removes the fault's link to each of its recordings under
``snapshots.rosbag.auto_cleanup``, unless that is off or
``snapshots.rosbag.max_bags_per_fault`` keeps a history. A retention rule's
``max_bags`` replaces ``max_bags_per_fault`` for the faults it covers. The cap
``snapshots.rosbag.max_bags_per_fault`` keeps a history; a recording is
deleted with its last link. A retention rule's ``max_bags`` replaces
``max_bags_per_fault`` for the faults it covers. The cap
then governs retention, except at ``0`` (unlimited), where only
``snapshots.rosbag.max_total_storage_mb`` bounds it.
``snapshots.rosbag.max_total_storage_mb`` bounds it. A retention rule's
``on_cleared`` (``keep`` or ``delete``) overrides all of this for the faults it
covers, and its ``on_healed: delete`` removes the fault's links when the
fault heals.

Quick Start
-----------
Expand Down Expand Up @@ -503,11 +507,13 @@ Rosbag Capture (Time-Window Recording)

In addition to JSON snapshots, you can enable **rosbag capture** for "black box"
style recording. This continuously buffers messages in memory and flushes them
to a bag file when a fault is confirmed. The recording is deleted when the fault
is cleared, unless ``snapshots.rosbag.auto_cleanup`` is off or
``snapshots.rosbag.max_bags_per_fault`` keeps a history, which takes over the
retention decision. A retention rule's ``max_bags`` replaces
``max_bags_per_fault`` for the faults it covers.
to a bag file when a fault is confirmed. When the fault is cleared, its link to
each of its recordings is removed, unless ``snapshots.rosbag.auto_cleanup`` is
off or ``snapshots.rosbag.max_bags_per_fault`` keeps a history, which takes over
the retention decision. A recording is deleted with its last link. A retention
rule's ``max_bags`` replaces ``max_bags_per_fault`` for the faults it covers, and
its ``on_cleared`` (``keep`` or ``delete``) overrides the clear decision. A rule's
``on_healed: delete`` removes the fault's links when the fault heals.

**Key differences from JSON snapshots:**

Expand Down Expand Up @@ -651,7 +657,8 @@ Rosbag Configuration Options
effect for a fault whose cap is anything other than ``1`` (its retention
rule's ``max_bags``, else ``max_bags_per_fault``): a history someone
configured must not be what an acknowledgement takes away, so the cap
governs retention there instead.
governs retention there instead. A retention rule's ``on_cleared``
(``keep`` or ``delete``) overrides it for the faults the rule covers.
* - ``snapshots.rosbag.lazy_start``
- ``false``
- Controls when the ring buffer starts recording. See diagram below.
Expand Down
5 changes: 5 additions & 0 deletions src/ros2_medkit_fault_manager/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,11 @@ endif()
medkit_add_launch_test(test_rosbag_max_bags test/integration/test_rosbag_max_bags.test.py TIMEOUT 600
LABELS "integration")

# on_healed and on_cleared per retention rule: the heal, the clear, the delete generation and the
# startup reclassification.
medkit_add_launch_test(test_rosbag_status_actions test/integration/test_rosbag_status_actions.test.py
TIMEOUT 600 LABELS "integration")

if(POSTGRES_SUPPORT)
medkit_add_launch_test(test_rosbag_quota_pg test/integration/test_rosbag_quota_pg.test.py TIMEOUT 300
LABELS "integration")
Expand Down
18 changes: 12 additions & 6 deletions src/ros2_medkit_fault_manager/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,17 @@ parameter list and recording lifecycle.
#### Rosbag Retention Rules

`snapshots.rosbag.retention.*` sets a `priority` (0-1000), an `over_quota` choice (`keep` or `drop`), a
`max_bags` cap and `keep_first` per fault, from four levels: fault code, the first matching pattern of
`max_bags` cap, `keep_first`, `on_healed` and `on_cleared` (`keep` or `delete`) per fault, from four levels: fault code, the first matching pattern of
`pattern_order`, severity, defaults. They are read at startup and validated. Each fault code keeps at most its
rule's `max_bags` recordings (`max_bags_per_fault` when no level sets it, `0` = no cap); with `keep_first` and a
`max_bags` of 2 or more the first recording stays and the second oldest goes. "First" is the oldest recording of
the fault code still stored. With `auto_cleanup`, a clear deletes a fault's recordings only when its `max_bags`
is 1. A new recording evicts only recordings of equal or lower priority, lowest priority first, then cleared
the fault code still stored. A heal deletes a fault's recordings with `on_healed: delete` (default `keep`; HEALED
needs `healing_enabled: true`). A clear deletes them with `on_cleared: delete` and keeps them with
`on_cleared: keep`; without `on_cleared`, a clear with `auto_cleanup` deletes them only when the fault's `max_bags`
is 1. A fault the startup turns from HEALED into CLEARED, because healing is now disabled, loses its recordings
only with an explicit `on_cleared: delete`. A recording made before such a delete never survives it, also when
the fault fails again before the recording is stored; a burst's shared recording loses only that fault's link.
A new recording evicts only recordings of equal or lower priority, lowest priority first, then cleared
before healed before active, then a recording `keep_first` protects after the others, then oldest. A recording
that still does not fit follows `over_quota`: `keep` (default) stores it over the quota, `drop` drops it and
deletes nothing.
Expand Down Expand Up @@ -593,19 +598,20 @@ and some of them build an `rclcpp::Clock`.
the clamps and fallbacks and returns the lines to log as `ConfigNotice` values;
- `core::build_core_parts()`: opens the storage and the audit log, loads the threshold and
correlation files. It throws when the storage or the audit log cannot be opened.
`core::reclassify_stale_healed()` is the startup pass for stale HEALED rows;
`core::reclassify_stale_healed()` is the startup pass for stale HEALED rows and returns the codes it changed;
- `core::FaultManagerCore`: `report`, `clear`, `list`, `get`, `list_for_entity`, `record_transition`
and `tick`. These calls run under one internal mutex.
- `core::RosbagRetention`: every rosbag retention decision (the per-fault cap, the storage quota with
the retention rules, the open-time quota check, the clear and the stale-row cleanup) on top of `FaultStorage::apply_rosbag_changes`. It returns
the retention rules, the open-time quota check, the clear, the heal, the startup reclassification and the
stale-row cleanup) on top of `FaultStorage::apply_rosbag_changes`. It returns
the directories to remove and never removes one itself.

The core reaches the outside through four interfaces. The ROS adapter implements them.

| Interface | Role |
| --- | --- |
| `core::EventSink` | `publish()` receives every fault event the core emits. |
| `core::CaptureHooks` | `capture_now()` queues the snapshot and rosbag capture of a fault code. The core has already applied the recapture cooldown. `on_prefailed()` and `on_cleared()` notify the capture side. |
| `core::CaptureHooks` | `capture_now()` queues the snapshot and rosbag capture of a fault code. The core has already applied the recapture cooldown. `on_prefailed()`, `on_cleared()` and `on_healed()` notify the capture side. |
| `core::WallClock` | `now_ns()` returns nanoseconds since the Unix epoch. |
| `core::LogSink` | `log()` receives the log lines. |

Expand Down
16 changes: 12 additions & 4 deletions src/ros2_medkit_fault_manager/config/rosbag_retention.example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,18 @@
# fault_codes.<CODE>, then the first label of pattern_order whose match covers the whole
# fault code, then severity.<SEVERITY> of the fault, then defaults, then the built-in value.
# Fields: priority (integer 0-1000, built-in 0), over_quota (keep or drop, built-in keep),
# max_bags (integer 0 or more, built-in snapshots.rosbag.max_bags_per_fault) and keep_first (true or
# false, built-in false).
# max_bags (integer 0 or more, built-in snapshots.rosbag.max_bags_per_fault), keep_first (true or
# false, built-in false), on_healed (keep or delete, built-in keep) and on_cleared (keep or delete,
# built-in: the clear default below).
# max_bags is the number of recordings kept per fault code, 0 = no cap. Over the cap the oldest
# recording goes; with keep_first and a max_bags of 2 or more the first recording stays and the
# second oldest goes. "First" is the oldest recording of the fault code still stored. keep_first
# with a max_bags below 2 is ignored with a warning. A clear deletes the fault's recordings when
# snapshots.rosbag.auto_cleanup is true and its max_bags is 1.
# with a max_bags below 2 is ignored with a warning.
# on_healed and on_cleared run when the fault becomes HEALED or CLEARED. HEALED needs
# healing_enabled: true. Without on_cleared a clear deletes the fault's recordings when
# snapshots.rosbag.auto_cleanup is true and its max_bags is 1. A fault turned from HEALED into
# CLEARED at startup, because healing is now disabled, loses its recordings only with an explicit
# on_cleared: delete. A recording shared by a burst loses only the link of that fault.
# A new recording evicts only recordings of equal or lower priority: lowest priority first, then
# cleared, healed, active; inside that, a recording kept by keep_first after the others, then
# oldest first. If it still does not fit, keep stores it over the quota and drop discards it alone.
Expand All @@ -31,6 +36,8 @@ fault_manager:
over_quota: keep
severity:
# Severity names: INFO, WARN, ERROR, CRITICAL.
INFO:
on_healed: delete
ERROR:
priority: 50
CRITICAL:
Expand All @@ -46,6 +53,7 @@ fault_manager:
DEBUG_NOISE:
priority: 0
over_quota: drop
on_cleared: delete
patterns:
# A dotted fault code goes through a pattern whose match escapes the dot.
# The match covers the whole fault code (ECMAScript regular expression).
Expand Down
1 change: 1 addition & 0 deletions src/ros2_medkit_fault_manager/config/snapshots.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ rosbag:
# No effect for a fault whose cap is anything other than 1 (its retention rule's
# max_bags, else max_bags_per_fault): a configured history governs retention
# instead, and an acknowledgement leaves it alone
# A retention rule's on_cleared (keep or delete) replaces it for the faults it covers
auto_cleanup: true

# =============================================================================
Expand Down
1 change: 1 addition & 0 deletions src/ros2_medkit_fault_manager/design/architecture.puml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ package "ros2_medkit_fault_manager" {
+ capture_now(code): CaptureResult
+ on_prefailed(code): void
+ on_cleared(code): void
+ on_healed(code): void
}

class WallClock <<interface>> {
Expand Down
Loading
Loading