pcp.py: Unhandled PM_ERR_INST_LOG exception crashes metrics channel on archives with transient instances
Explain what happens
In Overview > Metrics & History, the metrics view crashes and displays:
"Metrics history could not be loaded: pmlogger.service is failing to collect data"
In the browser developer console:
cockpit.js:6 PM_ERR_INST_LOG Instance identifier not defined in the PCP archiveThis explains the intermittent "Heisenbug" previously reported and discussed in #22278:
- In the morning or upon initial load, Cockpit reads the active day's archive (
pmlogger/$(hostname)/YYYYMMDD.HH.MM), which is typically healthy. - As the user scrolls back, paginates, or when Cockpit fetches historical archives in the background, it accesses archives from previous days where transient network interfaces (e.g. Podman / Docker container
vethinterfaces) were created and destroyed. - The entire metrics channel immediately crashes, showing the false-positive error that
pmlogger.serviceis failing to collect data.
Root Cause Analysis
In src/cockpit/channels/pcp.py, inside send_meta:
if metric_desc.instanced:
insts: List[str] = []
for i in range(results.contents.numpmid):
pmid = results.contents.get_pmid(i)
if metric_desc.pmid != pmid:
continue
for j in range(results.contents.get_numval(i)):
value = results.contents.get_vlist(i, j)
instance_desc = context.pmNameInDom(metric_desc.desc, value.inst)
insts.append(instance_desc)
desc['instances'] = instsWhen pmlogger records archives on systems running containers or VMs, network interface instance domains change dynamically. When Cockpit reads these archives using context.pmSetMode(c_api.PM_MODE_INTERP, ...), context.pmFetch() samples values for instance IDs at timestamps where the instance is no longer defined in the archive's InDom.
When context.pmNameInDom(metric_desc.desc, value.inst) is invoked for that instance ID, PCP raises:
pmapi.pmErr: PM_ERR_INST_LOG Instance identifier not defined in the PCP archiveBecause line 368 has no exception handling, this error propagates out of send_meta, aborts the async PCP channel (pcp-archive), and closes the websocket with an internal-error.
Proposed Fix
Handle pmapi.pmErr on pmNameInDom gracefully by falling back to a stringified instance identifier (e.g. f"[{value.inst}]") rather than crashing the channel:
for j in range(results.contents.get_numval(i)):
value = results.contents.get_vlist(i, j)
try:
instance_desc = context.pmNameInDom(metric_desc.desc, value.inst)
except pmapi.pmErr:
instance_desc = f"[{value.inst}]"
insts.append(instance_desc)With this fallback, Cockpit continues replaying archive history cleanly without dropping the channel or alarming the user with false-positive service failure banners.
Cockpit Version
Cockpit 367+ / git main
Where is the problem in Cockpit?
Overview > Metrics & History
Server operating system
Fedora (Kinoite / Silverblue / Bazzite 44) & Ubuntu / Debian (as reported in #22278)
Source: cockpit-project/cockpit