Skip to content

Revert dup cpu frequency, add node_cpufreq flag - #3795

Merged
SuperQ merged 1 commit into
prometheus:masterfrom
rtreffer:cpufreq-prefix-flag
Aug 28, 2026
Merged

SuperQ merged 1 commit into
prometheus:masterfrom
rtreffer:cpufreq-prefix-flag

Conversation

@rtreffer

Copy link
Copy Markdown
Contributor

Both cpu_linux and cpufreq export cpu frequencies under the same name. This makes the metric mutually exclusive.

A previous PR made it possible to enable both which can cause flapping help texts.

This PR re-introduces mutual-exclusive behavior for the frequencies. A new flag collector.cpufreq.enable-cpufreq-prefix can be used to migrate all cpufreq metrics to node_cpufreq to avoid the collision.

Signed-off-by: René Treffer <treffer@measite.de>

See #3689

Reviewers

AI disclosure: This was written with Claude/Fable.
I did a pass over the outcome (this is under my name).
I couldn't find anything obviously wrong. I would like to highlight a few pieces though....

New flag:

      --[no-]collector.cpufreq.enable-cpufreq-prefix  
                                 Expose cpufreq metrics with the node_cpufreq_
                                 prefix instead of node_cpu_. This avoids a
                                 metric name collision with the cpu collector
                                 and will be the default behavior in 2.x.

This promises a future behavior change. Please check if this is the intended direction.
It might be worth a CHANGELOG entry, too.

The descs pattern used to generalize over the prefix switch is rather unique.
Other collectors use descs or metricDescs as well, but often in an untyped way.
Typed + constructor time looks like a decent trade-off in this context but I would be happy to change it for a more simplistic or different approach.

Code snippets:

type cpuFreqDescs struct {
	hertz           *prometheus.Desc
	avgHertz        *prometheus.Desc
	minHertz        *prometheus.Desc
	maxHertz        *prometheus.Desc
...
}

func newCPUFreqDescs() cpuFreqDescs {
	subsystem := cpuCollectorSubsystem
	if *useCPUFreqPrefix {
		subsystem = cpuFreqCollectorSubsystem
	}
	return cpuFreqDescs{
		hertz: prometheus.NewDesc(
			prometheus.BuildFQName(namespace, subsystem, "frequency_hertz"),
			"Current CPU thread frequency in hertz.",
			[]string{"cpu"}, nil,
		),
....
}

...
	return &cpuFreqCollector{
		fs:     fs,
		descs:  newCPUFreqDescs(),
		logger: logger,
	}, ...

This all leads to a very neat diff in the end:

		if stats.CpuinfoMinimumFrequency != nil {
			ch <- prometheus.MustNewConstMetric(
-				cpuFreqMinDesc,
+				c.descs.minHertz,
				prometheus.GaugeValue,
				float64(*stats.CpuinfoMinimumFrequency)*1000.0,
				stats.Name,
			)
		}

Both cpu_linux and cpufreq export cpu frequencies under the same name.
This makes the metric mutually exclusive.

A previous PR made it possible to enable both which can cause flapping
help texts.

This PR re-introduces mutual-exclusive behavior for the frequencies.
A new flag `collector.cpufreq.enable-cpufreq-prefix` can be used to
migrate all cpufreq metrics to node_cpufreq to avoid the collision.

Signed-off-by: René Treffer <treffer@measite.de>
@SuperQ

SuperQ commented Aug 28, 2026

Copy link
Copy Markdown
Member

I will make a more detailed changelog entry for this behavior change.

@SuperQ
SuperQ merged commit 963cc14 into prometheus:master Aug 28, 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 <superq@gmail.com>
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.

3 participants