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
13 changes: 13 additions & 0 deletions docs/api/rest.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1481,8 +1481,21 @@ Manage ROS 2 node parameters.
- **400:** Invalid value - the node rejected it, or it cannot be converted to
the parameter's type at all (e.g. a mixed-type array). Both are the
caller's body, so both are ``400``, never ``500``.
- **403:** The parameter is read-only
- **404:** Parameter not found

The gateway reads the parameter's current value and its descriptor before the
write. The JSON value is converted to the current value's type (``1.5`` to the
integer ``1``, a string other than ``"true"`` or ``"1"`` to ``false``, any value
to a string when the current value is one), except for a parameter whose
descriptor allows dynamic typing: that one is sent with the JSON's own type
(``1.5`` as a double, a ``null`` as the string ``"null"``), so the node checks
what the client sent. A rejection answers ``403`` when the descriptor says the
parameter is read-only, and ``400`` otherwise, whatever the node's reason says.
When the descriptor cannot be read, a reason that contains "read-only" or
"read only" answers ``403``. The gateway's own parameters follow the same
rule, for example the read-only ``plugins.<name>.path``.

**Example:**

.. code-block:: bash
Expand Down
84 changes: 74 additions & 10 deletions docs/config/fault-manager.rst
Original file line number Diff line number Diff line change
Expand Up @@ -649,10 +649,13 @@ Capture continuous rosbag recordings around fault events.
- ``500``
- Maximum total storage for all rosbags (MB). A recording shared by a
burst of faults counts once towards the total, and eviction removes a
whole burst's bag at a time (oldest first). The recording that was just
stored is never evicted by its own sweep. If it alone is larger than the
limit it is kept, a warning is logged, and the storage stays over the
limit until a newer recording replaces it.
whole burst's bag at a time. Without retention rules eviction goes
oldest first and the recording that was just stored is never evicted by
its own sweep: if it alone is larger than the limit it is kept, a
warning is logged, and the storage stays over the limit until a newer
recording replaces it. With retention rules eviction follows their
ranked order and ``over_quota: drop`` can drop the new recording, see
:ref:`rosbag-retention-rules`.
* - ``rosbag.max_bags_per_fault``
- ``1``
- How many recordings one fault code keeps. Past the cap the oldest is
Expand Down Expand Up @@ -827,15 +830,17 @@ messages before everything stopped. Note the condition: a single captured topic
goes quiet while others keep publishing is pruned like anything else, because each
arrival prunes the whole buffer by age.

.. _rosbag-retention-rules:

Rosbag Retention Rules
~~~~~~~~~~~~~~~~~~~~~~

The parameters under ``snapshots.rosbag.retention.`` set a rule per fault: a ``priority``, an
``over_quota`` choice, a ``max_bags`` cap, ``keep_first``, what happens to the fault's recordings
when it heals (``on_healed``) or is cleared (``on_cleared``), how long they are kept in each status
(``max_age_sec``), and how much free space stays on the disk (``min_free_disk_mb``). They are read at
startup, validated and
logged. They are read only while
startup, validated and logged, and each one given at startup can be changed while the node runs (see
Changes While the Node Runs below). They are used 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
before. An example file is ``config/rosbag_retention.example.yaml``.
Expand Down Expand Up @@ -1050,7 +1055,7 @@ deletion frees. Each removed recording is logged as ``Recording removed: <id> (m
Every pass ends with one DEBUG line ``floor pass: removed=<n> free=<bytes> floor=<bytes>
met=<true|false> source=<filesystem|test-capacity>``.

A pass runs at two moments, and one pass runs at a time, on the retention worker thread:
A pass runs at three moments, and one pass runs at a time, on the retention worker thread:

- after each store that kept the new recording, at its priority. A store whose per-fault cap removed
every new row kept nothing and runs no pass. It never deletes a recording
Expand All @@ -1059,6 +1064,8 @@ A pass runs at two moments, and one pass runs at a time, on the retention worker
``over_quota: keep`` does not keep a recording that leaves the free space below the floor.
- in the periodic job, after the age sweep, with no priority limit: other data that fills the disk
can then delete any recording, the highest priority last.
- once in the job of a change of ``min_free_disk_mb``, ``sweep_interval_sec`` or a max age while the
node runs, also with no priority limit (see Changes While the Node Runs below).

The floor is a target, not a reservation: other writers can change the free space between two
measurements. When PostgreSQL shares the disk (``storage_type: postgres``), ``min_free_disk_mb`` is
Expand Down Expand Up @@ -1183,9 +1190,66 @@ the configuration: the next fault that confirms reports it again. A start with a
(or none) clears it. If the fault storage is unreachable at start, the report or the clear is retried
every second until the storage accepts it.

The retention parameters are read only: a ``SetParameters`` request for one is refused. At startup the
fault manager also warns once, listing every parameter override that no declaration consumed, so a
misspelled key does not pass unnoticed.
At startup the fault manager also warns once, listing every parameter override that no declaration
consumed, so a misspelled key does not pass unnoticed.

**Changes While the Node Runs.** Each retention parameter given at startup can be changed while the
fault manager runs, for example through the gateway:

.. code-block:: bash

curl -X PUT \
http://localhost:8080/api/v1/apps/fault_manager/configurations/snapshots.rosbag.retention.fault_codes.MOTOR_OVERHEAT.priority \
-H 'Content-Type: application/json' -d '{"data": 900}'

- Only the parameters given at startup exist. ``min_free_disk_mb`` (``0``) and ``sweep_interval_sec``
(``60``) always exist, so they can be changed also when not given; that declaration alone does not
configure the retention, the rules follow the parameters given at startup or changed since. A first
change on a fault manager started without retention parameters makes the retention configured
(every priority ``0``). Adding or removing a rule needs a restart: a key not given at startup answers
HTTP 400 with ``parameter '<name>' cannot be set because it was not declared``.
- A change is validated as the whole configuration with the change applied, by the same parser as at
startup. It is refused when it adds an error the current configuration does not have: HTTP 400, the
reason names each new error with its full parameter name, and nothing changes. A retention parameter
cannot be unset: a ``PARAMETER_NOT_SET`` value is refused (the gateway sends a JSON ``null`` as the
string ``"null"``, which the parser refuses as the wrong type). A set that holds retention
parameters and other parameters at once (``set_parameters_atomically``) is refused: set the retention
parameters on their own. The gateway sets one parameter per request.
- An accepted change of a valid configuration becomes the rules at once and logs one INFO line
``Rosbag retention rules changed (configured): <rules>``. A job on the retention worker then applies
it to the stored recordings and ends with one INFO line ``Rosbag retention change applied: ...``:

- ``priority`` and ``over_quota``: the next decision and the next listing use them; nothing is
removed, and no age or floor pass runs.
- A lower ``max_bags`` for a fault code with stored recordings, also when a changed ``match`` or
``pattern_order`` moves the code to another rule: the cap applies to its recordings at once, each
removal logged as ``Recording removed: <recording_id> (its max_bags)``.
- ``on_cleared`` or ``on_healed`` becoming ``delete`` (also through the clear default): the
recordings of faults already CLEARED or HEALED go, logged with ``(fault cleared)`` or
``(fault healed)``. A fault that failed again before the job reached it keeps them.
- ``max_age_sec``, ``min_free_disk_mb`` and ``sweep_interval_sec``, and a ``match`` or
``pattern_order`` change when a pattern sets a max age: the periodic job takes the new interval (its
next pass one interval after the change), and the age pass (when a max age is set) and the floor
pass (when the floor is above 0) run at once. With no max age and the floor at 0 the periodic job is
off and no pass runs. Only these changes run a pass. The INFO line ends with
``passes run: <age sweep, floor pass, or none>; periodic job <every <n> s, off, or unchanged>``.

- A failure in the job logs WARN lines: a failing age or floor pass logs its own WARN, as in the
periodic job, and the change then logs one summary WARN ``Rosbag retention change not applied:
<caps, status actions, sweep, floor> failed: <error>``, the error of a failed storage read for the
caps and the status actions. The PostgreSQL storage logs its reconnection attempts under its own
logger, ``postgres_fault_storage``. The parameter keeps its new value. A set of any retention
parameter, the same value included, runs the job again: it compares the rules with the rules it last
applied in full.
- In degrade each invalid value can be repaired on its own: a change that leaves only errors the
configuration already had is accepted, the node stays degraded and logs
``Rosbag retention rules changed (degraded): ...``. The change that leaves no error ends degrade: the
rules apply as above and ``ROSBAG_RETENTION_CONFIG_INVALID`` is cleared.
- With rosbag capture off a change is validated the same way and logs that the rules are not used.
- A change is lost at restart: the parameters file wins.

A refused change answers 400, not 403, also when the parameter name contains "read-only": the gateway
decides 403 from the parameter's descriptor (see :doc:`/api/rest`).

.. seealso::

Expand Down
15 changes: 9 additions & 6 deletions docs/tutorials/snapshots.rst
Original file line number Diff line number Diff line change
Expand Up @@ -675,12 +675,15 @@ Rosbag Configuration Options
file, see :ref:`below <tutorial-split-recording>`.
* - ``snapshots.rosbag.max_total_storage_mb``
- ``500``
- Total storage limit for all bag files. Oldest bags are automatically
deleted when this limit is exceeded. The recording that was just written
is never one of them: when it alone is over the limit it is kept, a
warning is logged, and every older bag is deleted. A recording shared by a burst of
faults counts once towards the total, and eviction removes a whole
burst's bag at a time.
- Total storage limit for all bag files. Without retention rules the
oldest bags are deleted when this limit is exceeded, and the recording
that was just written is never one of them: when it alone is over the
limit it is kept, a warning is logged, and every older bag is deleted.
With retention rules the bags go in their ranked order and
``over_quota: drop`` can drop the new recording, see
:ref:`rosbag-retention-rules`. A recording shared by a burst of faults
counts once towards the total, and eviction removes a whole burst's bag
at a time.
* - ``snapshots.rosbag.max_bags_per_fault``
- ``1``
- Recordings kept per fault code; ``0`` means unlimited. Past the cap the
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 @@ -337,6 +337,11 @@ endif()
# A connection lost during the rosbag store transaction, cut by a protocol-aware proxy.
medkit_add_launch_test(test_rosbag_commit_in_doubt_pg test/integration/test_rosbag_commit_in_doubt_pg.test.py
TIMEOUT 300 LABELS "integration")

# A runtime retention change whose apply fails while the server is unreachable, and the same value set
# again once it answers.
medkit_add_launch_test(test_retention_runtime_pg test/integration/test_retention_runtime_pg.test.py
TIMEOUT 300 LABELS "integration")
endif()

# Launches without snapshots.rosbag.format, so the parameter default (mcap)
Expand Down
18 changes: 17 additions & 1 deletion src/ros2_medkit_fault_manager/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,8 @@ There is no marker file: a disk that is not mounted while no recording is stored
`snapshots.rosbag.retention.*` sets a `priority` (0-1000), an `over_quota` choice (`keep` or `drop`), a
`max_bags` cap, `keep_first`, `on_healed` and `on_cleared` (`keep` or `delete`) and `max_age_sec` (`active`,
`healed`, `cleared`) 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
`pattern_order`, severity, defaults. They are read at startup and validated, and each one given at startup can be
changed while the node runs (see below). 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. A heal deletes a fault's recordings with `on_healed: delete` (default `keep`; HEALED
Expand Down Expand Up @@ -189,6 +190,21 @@ A parameter the ROS YAML loader moved (found by reading each parameters file a s
running without the rules, with the quota as a hard stop for new recordings, and reports the fault `ROSBAG_RETENTION_CONFIG_INVALID`. See
`config/rosbag_retention.example.yaml` and `docs/config/fault-manager.rst`.

A retention parameter given at startup can be set while the node runs, for example with
`PUT /api/v1/apps/fault_manager/configurations/snapshots.rosbag.retention.fault_codes.MOTOR_OVERHEAT.priority` on
the gateway. `min_free_disk_mb` and `sweep_interval_sec` always exist (defaults 0 and 60); the rules follow the
parameters given at startup or changed since. Adding or removing a rule needs a restart: another key is not
declared (400). A change is validated as the whole configuration with the same parser as at startup and refused
(400, the reason names each new error) when it adds an error; nothing changes then. An accepted valid change is used
at once and a job on the retention worker applies it to the stored recordings: a lower `max_bags` trims the code's
recordings, an `on_cleared` or `on_healed` that became `delete` removes the recordings of faults already CLEARED or
HEALED, and a changed max age, floor or interval sets the periodic job and runs the passes that are on: the age pass
when a max age is set, the floor pass when the floor is above 0; no other change runs a pass. The job ends with `Rosbag retention change applied` (INFO). After a failure a failing pass logs its
own WARN and the job one summary WARN naming what was not applied; the parameter keeps its value, and setting it again
retries. In degrade each invalid value can be repaired on its own; the change that leaves no error ends degrade and
clears `ROSBAG_RETENTION_CONFIG_INVALID`. With rosbag capture off a change is validated and not used. A value cannot
be unset, a set that also holds other parameters is refused, and a change is lost at restart.

### Storage Backends

This is the persisted fault store (`storage_type`), separate from the rosbag storage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@
# With drop, a recording predicted not to fit is not started.
# Any other key under retention is an error: the fault manager keeps running without the rules, the
# quota becomes a hard stop for new recordings (nothing is evicted for it) and it reports the fault
# ROSBAG_RETENTION_CONFIG_INVALID. Retention values are read-only at runtime.
# ROSBAG_RETENTION_CONFIG_INVALID. A value given here can be changed while the node runs (for example
# with a PUT on the gateway's configurations of the fault manager app) and applies at once; another
# key, or removing one, needs a restart. A change is lost at restart.
#
# Use with: ros2 run ros2_medkit_fault_manager fault_manager_node --ros-args --params-file <this file>
# The rules are read only when snapshots.rosbag.enabled is true.
Expand Down
Loading
Loading