HealthRecorder

HealthRecorder derives a device’s healthState and healthReport from the Tango quality factors of a configured set of attributes. This page documents how that derivation works.

Attribute quality

Alongside its value, every Tango attribute carries a quality factor (tango.AttrQuality), which is one of:

  • ATTR_VALID – the value is within its configured normal range.

  • ATTR_WARNING – the value has crossed a configured warning threshold.

  • ATTR_ALARM – the value has crossed a configured alarm threshold.

  • ATTR_INVALID – the value is not currently valid (for example, not yet read from hardware).

For numeric attributes, the thresholds that drive this quality factor are configured on the attribute itself, via the min_alarm, max_alarm, min_warning and max_warning parameters. These are the same parameters returned by DeviceProxy.get_attribute_config_ex, and they can be inspected or changed at runtime using the standard PyTango attribute configuration API. Tango itself is responsible for comparing each new value against these thresholds and computing the resulting quality factor whenever the attribute is updated.

Tracking attribute quality

HealthRecorder is constructed with a device’s trl and a list of attributes to track. It opens a throwaway MccsDeviceProxy to that trl and, once the device is exported and the proxy connected, subscribes to two events per attribute:

  • a CHANGE_EVENT, handled by attribute_value_changed, which records the attribute’s latest (quality, value) pair and triggers re-evaluation of health.

  • an ATTR_CONF_EVENT, handled by _attr_conf_callback – see Attribute configuration changes below.

The most recently observed (quality, value) for each attribute is kept in an internal cache (_attribute_state), keyed by attribute name. This cache is the sole input to health evaluation.

Deriving healthState

healthState is derived by taking the worst quality factor across every tracked attribute, using the severity ordering ALARM < WARNING < INVALID < VALID (QUALITY_SEVERITY), and mapping that quality onto a HealthState (QUALITY_TO_HEALTH):

AttrQuality

HealthState

ATTR_VALID

OK

ATTR_WARNING

DEGRADED

ATTR_ALARM

FAILED

ATTR_INVALID

UNKNOWN

If no attribute has been recorded yet (for example, before any value has been read from hardware), healthState is HealthState.UNKNOWN.

Deriving healthReport

When every tracked attribute is ATTR_VALID, healthReport is the fixed string "Health is OK.". Otherwise, the report is built by selecting every attribute whose quality equals the worst quality identified above, and rendering one line per attribute in the form:

<attribute name> is in <quality> with value <value>

These lines are joined with newlines, so the report always names every attribute currently responsible for the reported healthState, along with the value that triggered it.

Both values are recomputed on every CHANGE_EVENT, and the supplied health_callback is invoked after every evaluation. Successive equal values are still reported; deduplication of events is left to Tango’s native change detection.

Attribute configuration changes

As of PyTango 10.0.2, if an attribute’s alarm/warning thresholds are reconfigured such that its current value would now be alarming, Tango does not recompute the attribute’s quality until the next time a value is pushed for it. The ATTR_CONF_EVENT subscription exists to work around this: on a configuration change, HealthRecorder calls back into the owning device via attr_conf_callback, so the device can push a fresh value for that attribute and have its quality – and therefore healthState/healthReport – re-evaluated immediately, rather than waiting for the next natural hardware poll.

Loss of communication

clear_attribute_state() discards every cached (quality, value) pair and re-evaluates health. This is called by the owning device when a device loses communication with its hardware, since none of its previously recorded attribute values can still be trusted; healthState reverts to HealthState.UNKNOWN until fresh events arrive.