pkg/monitor: fix activity units and document Prometheus naming before release - #209
Conversation
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
No unresolved blocking issues were identified.
Review effort: Lite
Findings: None
What changed in this PR
Updates pkg/monitor for correct AET activity units, explicit Prometheus naming, quieter logging, and release documentation.
Changes:
- Converts kernel nanofarad activity values to farads for OTel export.
- Documents/tests Prometheus naming strategies and configures
cmd/rdtexplicitly. - Updates logging, teardown guidance, dependencies, and OTel documentation.
| File | Summary |
|---|---|
pkg/monitor/reading.go |
Updates activity units and OTel scaling. |
pkg/monitor/reading_test.go |
Tests raw activity values and units. |
pkg/monitor/otel.go |
Applies scaling, warning behavior, and naming documentation. |
pkg/monitor/otel_test.go |
Tests exports, warnings, and Prometheus names. |
pkg/monitor/monitor.go |
Lowers routine lifecycle logs to debug. |
go.mod |
Promotes otlptranslator to a direct dependency. |
doc/resctrl-mon.md |
Documents teardown and OTel/Prometheus behavior. |
cmd/rdt/main.go |
Selects an explicit Prometheus translation strategy. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
marquiz
left a comment
There was a problem hiding this comment.
Thanks @cmcantalupo for the update. Some comments/nits below.
After we get this in we should tag a new release.
| otelprom.WithNamespace(""), | ||
| otelprom.WithoutScopeInfo(), | ||
| otelprom.WithoutTargetInfo(), | ||
| otelprom.WithTranslationStrategy(otlptranslator.UnderscoreEscapingWithSuffixes), |
| cfg: cfg, | ||
| meter: meter, | ||
| instrs: make(map[string]metric.Observable), | ||
| warned: make(map[string]struct{}), |
There was a problem hiding this comment.
I'd suggest to change this to map[string]bool, makes the code using this more fluent and readable
| warned: make(map[string]struct{}), | |
| warned: make(map[string]bool), |
There was a problem hiding this comment.
Made the change, thanks for the suggestion.
| want map[string]string | ||
| }{ | ||
| { | ||
| strategy: otlptranslator.UnderscoreEscapingWithSuffixes, |
There was a problem hiding this comment.
Do we need/want to test every strategy, is it configurable?
There was a problem hiding this comment.
Not configurable in pkg/monitor, since the strategy belongs to the consumer's exporter. Dropped the test; the docs still describe both renderings.
| assert.Equal(t, int32(1), h.n.Load()) | ||
| } | ||
|
|
||
| func TestObserve_ActivityExportedInFarads(t *testing.T) { |
There was a problem hiding this comment.
nit: The new unit tests feel like a bit too much AI verifying it's specific output. The warn counter thingie feels like yeah, maybe ok but a lot of stuff for a human reader to read through. The farad thingie like if we do this could it be a bit more generic testing the general otelExport scaling concept. Thoughts?
There was a problem hiding this comment.
Agreed. Removed the warn-counter and fixture tests and added a small generic TestMetaOTel for the otelExport override/passthrough.
The kernel reports the AET "activity" counter in nanofarads, not farads as the resctrl documentation currently states (a documentation fix is in progress). Reading.Unit for activity was "farads", mislabeling the raw value by a factor of 1e9. Record the raw unit as UCUM "nF" so ReadCounters stays faithful to the kernel value. For OTel export, convert to the base unit: the perf.activity instrument keeps unit "farads" (otlptranslator has no suffix mapping for UCUM "F", so "farads" keeps the Prometheus name perf_activity_farads_total) and observed values are scaled by 1e-9. Scaling is applied after the monotonic accumulator so its state stays in kernel units. Signed-off-by: Christopher M. Cantalupo <christopher.m.cantalupo@intel.com>
The InstrumentName documentation claimed that keeping the _bytes suffix makes the OTel Prometheus bridge render mbm_total_bytes as l3_mbm_total_bytes_total, and that pkg/rdt's l3.mbm.total renders incorrectly as l3_mbm_bytes_total. The rendered name is actually chosen by the consumer's exporter translation strategy: UnderscoreEscapingWithSuffixes -> l3_mbm_bytes_total NoUTF8EscapingWithSuffixes -> l3.mbm.total.bytes_total The underscore strategy removes every "total" word from a counter name before appending _total, so pkg/rdt's name renders identically. Older exporter releases derived their default strategy from model.NameValidationScheme (UTF-8, hence the NoUTF8 form, which a legacy scrape escapes to l3_mbm_total_bytes_total); newer releases default to the underscore strategy. Rewrite the documentation to describe the mechanical file-to-instrument mapping and the strategy-dependent rendering, and recommend that consumers select a strategy explicitly. Signed-off-by: Christopher M. Cantalupo <christopher.m.cantalupo@intel.com>
observe logged a warning for every reading of a counter that was not discovered at registration, i.e. once per group per collection. With frequent Prometheus scrapes and many groups this floods the log. Warn the first time an undiscovered instrument name is seen and log subsequent occurrences at debug level. Signed-off-by: Christopher M. Cantalupo <christopher.m.cantalupo@intel.com>
RegisterOTelInstruments silently returned a no-op Registration when the resctrl root had no readable mon_data counters (for example when resctrl is mounted without monitoring support), leaving the consumer exporting nothing with no indication why. Log a warning naming the scanned mon_data path. The call still succeeds and returns a no-op Registration, so the behavior stays compatible. Signed-off-by: Christopher M. Cantalupo <christopher.m.cantalupo@intel.com>
Creating a group, assigning a PID and removing a group are routine per-workload operations that consumers already log in their own terms (for example per pod). Logging them at info level in the library duplicates that output and ignores the consumer's chosen verbosity. Log these three events at debug level. Adopting a pre-existing group and reaping an orphan in Reconcile stay at info level, and all warnings are unchanged. Signed-off-by: Christopher M. Cantalupo <christopher.m.cantalupo@intel.com>
- Teardown: remove a pod's group only when its last sandbox is gone. Kubelet can create a new sandbox for the same pod UID and garbage-collect the old one while the pod keeps running, so removing the group on every sandbox removal would delete a live group. - Add an OpenTelemetry Export section listing each counter's instrument name, kind, exported unit and value (activity is exported in farads, scaled from the kernel's nanofarads). - Document the Prometheus names under both exporter translation strategies and recommend selecting a strategy explicitly. Signed-off-by: Christopher M. Cantalupo <christopher.m.cantalupo@intel.com>
d3f316c to
57ea66f
Compare
|
Thanks for the quick feedback @marquiz. I think I have addressed your comments. |
marquiz
left a comment
There was a problem hiding this comment.
Thanks @cmcantalupo, looks nice and clean to me now 👍
LGTM
Description
Follow-up to #192. This PR has fixes and documentation for
pkg/monitorthat came up while integrating it into the nri-pluginsresctrl-monplugin (containers/nri-plugins#757). They should land before the first tagged release that includespkg/monitor, because one of them changes exported values.Changes
activityunits (pkg/monitor: report AET activity in nanofarads)activityin nanofarads, not farads asDocumentation/filesystems/resctrl.rstcurrently states. A kernel documentation fix is in progress.Reading.Unitforactivityis now UCUMnF, andReadCountersstill returns the raw kernel value.perf.activitykeeps unitfaradsand observed values are scaled by 1e-9, so the Prometheus name staysperf_activity_farads_total.otelExporttable;TestMetaOTelcovers the override and passthrough behavior.pkg/monitor: correct Prometheus naming documentation)InstrumentNamedoc claimed that keeping_bytesmakesmbm_total_bytesrender asl3_mbm_total_bytes_total, and that pkg/rdt'sl3.mbm.totalrenders incorrectly.UnderscoreEscapingWithSuffixesgivesl3_mbm_bytes_total. This strategy drops everytotalword from a counter name, so pkg/rdt's name renders the same way.NoUTF8EscapingWithSuffixesgivesl3.mbm.total.bytes_total.RegisterOTelInstrumentsnow warns when it discovers no counters. It still returns a no-opRegistrationand a nil error.doc/resctrl-mon.md)Changes since the first revision
main.cmd/rdttranslation-strategy pin. go.mod: bump otel/prometheus deps #210 bumps the exporter to v0.68.0, whose default is alreadyUnderscoreEscapingWithSuffixes.warnedis now amap[string]bool.TestPrometheusNameswas dropped because the strategy is not configurable inpkg/monitor, and with it the directotlptranslatordependency. The log-counting and OTel fixture tests were dropped too.TestMetaOTelis added.Compatibility notes
perf.activityvalues are now 1e9 times smaller: they are correct farads, where previously they were nanofarads labelled as farads. The metric name is unchanged.go.modare unchanged.Testing
go build ./...,go vet ./...,gofmt,golangci-lint run(0 issues), andgo test -race ./....resctrl-montests pass against this branch.