Skip to content

edac: Fix printf-style formatting in slog call - #3759

Merged
ArthurSens merged 1 commit into
prometheus:masterfrom
at-blacknight:fix-edac-slog
Aug 21, 2026
Merged

ArthurSens merged 1 commit into
prometheus:masterfrom
at-blacknight:fix-edac-slog

Conversation

@at-blacknight

Copy link
Copy Markdown
Contributor

@SuperQ — small follow-up to #3734.

That PR converted the ch*_ue_count error return into a debug log, and the fmt.Errorf format string came across with it. slog does no formatting, so the verbs are logged literally and the arguments after the message are consumed as key/value pairs:

level=DEBUG source=edac_linux.go:204 msg="couldn't get ue_count for controller/csrow/channel %s/%s/%s: %w" collector=edac 0=2 0="open /sys/devices/system/edac/mc/mc0/csrow2/ch0_ue_count: no such file or directory"

controllerNumber became a key with csrowNumber as its value, and channelNumber became a second key with the error as its value, so the controller/csrow/channel the message meant to report are no longer readable and the record carries 0 twice. Where the controller and channel numbers differ the second key is named after the channel instead, so the key set changes from one iteration to the next. Under --log.format=json that is an object with a repeated key, and parsers silently drop one of the values.

%w compounds it: that is an fmt.Errorf directive, not a valid Printf verb.

After:

level=DEBUG source=edac_linux.go:204 msg="couldn't get ue_count" collector=edac controller=0 csrow=2 channel=0 err="open /sys/devices/system/edac/mc/mc0/csrow2/ch0_ue_count: no such file or directory"

Reproduces on the existing fixtures: mc0/csrow2 has ch0_ce_count but no ch0_ue_count, so running with --log.level=debug against collector/fixtures/sys hits the branch. Present in v1.12.1 and on master. Metric output is unchanged — 20 node_edac series before and after, identical — and gofmt, go vet and end-to-end-test.sh are clean.

On why CI didn't catch it, in case it's useful: go vet's slog analyzer only fires when a key-position argument isn't a string or the arguments don't pair up, and here the count is even and all three are strings, so the call looks well formed to it. The e2e test does execute this line with debug logging enabled, but only diffs the metrics output. I have a small go/ast test that rejects Printf verbs in slog messages across the collector package — happy to raise it separately if you'd want it, equally happy to leave it.

The Debug call added in prometheus#3734 passes printf verbs and positional arguments to
slog, which does not format them. The format string is logged verbatim and the
arguments are consumed as key/value pairs, so controller and channel numbers
become attribute keys: a duplicate key when the two are equal, and otherwise a
key whose name changes on every iteration. Under --log.format=json that is an
object with a repeated key, and parsers silently drop one of the values. The
csrow number and the error, the two things worth reading, are the only parts
that survive, and they appear as values of meaningless keys.

%w compounds it: that is an fmt.Errorf directive and not a valid Printf verb,
left behind when the error return this replaced was converted to a log line.

Pass the values as named attributes instead. Metric output is unchanged.

Signed-off-by: Adam Butler <[email protected]>
@ArthurSens

Copy link
Copy Markdown
Member

/workflow-approve

@ArthurSens ArthurSens left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@ArthurSens
ArthurSens enabled auto-merge (squash) August 21, 2026 14:29
@ArthurSens
ArthurSens merged commit 6de91da into prometheus:master Aug 21, 2026
17 checks passed
@SuperQ SuperQ mentioned this pull request Nov 18, 2026
SuperQ added a commit that referenced this pull request Nov 18, 2026
The behavior of `node_cpu_frequency_hertz` has changed. There are two different sources
of data for this metric. One from the `cpu` collector, one from the `cpufreq` collector.
Due to historical feature migrations the `cpufreq` collector shares the same subsystem
as the `cpu` collector. This caused conflicting data behavior. An attempt to fix this
was introduced in #3318. This behavior has been reverted to the previous behavior in #3795.

A new flag (`--collector.cpufreq.enable-cpufreq-prefix`) has been introduced that gives
the `cpufreq` a dedicated metric name subsystem (`node_cpufreq_...`). This will likely
be the default in v2.

* [CHANGE] netstat: Use procfs parsers for netstat, snmp and snmp6 #3796
* [CHANGE] edac: Fix no data results #3863
* [CHANGE] nvme: Deprecate metric nvme_namespace_capacity_bytes #3899
* [FEATURE] Add tainted collector for /proc/sys/kernel/tainted #3745
* [FEATURE] Add resctrl collector #3797
* [ENHANCEMENT] netstat: Add new FreeBSD metrics #3334
* [ENHANCEMENT] Add `chip` label to DRM metrics #3572
* [ENHANCEMENT] diskstats: add device-mapper backing device info metric #3676
* [ENHANCEMENT] textfile: support UTF-8 metric and label names #3729
* [ENHANCEMENT] ksmd: add general_profit metric #3778 #3894
* [BUGFIX] edac: Fix printf-style formatting in slog call #3759
* [BUGFIX] fibre_channel: fix crash when attempting to dereference invalid counters #3573
* [BUGFIX] thermal: Fix collecting Darwin temperatures without CPU power status #3767
* [BUGFIX] fibrechannel: Fix for ppc64le #3769
* [BUGFIX] cpu: Revert dup cpu frequency, add node_cpufreq flag #3795
* [BUGFIX] infiniband: skip sysfs reads for excluded devices #3824
* [BUGFIX] bcache: Fix btree_read_average_duration_seconds unit #3828

Signed-off-by: Ben Kochie <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants