Commit 55f6f4d
authored
feat(device): add
* feat(device): promote `PowerMeter` interface
Promote the unexported `powerMeter` interface in
`internal/device/power_meter.go` to an exported `PowerMeter` requiring
`Name` and `Init` (via `service.Service` and `service.Initializer`).
Backends with resources can opt into cleanup by implementing
`service.Shutdowner`; the run framework already type-asserts it.
`device.CPUPowerMeter` embeds `PowerMeter`. The fake CPU meter and
`MockCPUPowerMeter` gain a no-op `Init()` to satisfy the interface;
no behaviour change.
Signed-off-by: nikimanoledaki <niki.manoledaki@grafana.com>
* feat(device): add `cpu.meters` config and switch-based CPU meter selection
`createCPUMeter` in `cmd/kepler/main.go` hardcoded the RAPL → hwmon
fallback chain. This commit replaces it with a config-driven switch:
- New `cfg.Cpu.Meters` config (default `["rapl", "hwmon"]`) lets operators
reorder backend priority without forking.
- New `device.CreateCPUMeter` walks the list, builds each backend, runs
`Init()`, and returns the first that reports zones. Real failures
aggregate via `errors.Join`; empty zones are a soft skip.
- New `buildCPUMeter` is a switch over backend names — adding a new
backend means adding one case and one constructor.
- `cmd/kepler/main.go` calls `device.CreateCPUMeter` and drops the old
`createCPUMeter` / `createHwmonMeter` helpers (~70 lines deleted).
Two legacy keys translate to `cpu.meters` at startup with a deprecation
warning, preserving operator behaviour:
- `dev.fake-cpu-meter.enabled: true` → `cpu.meters: ["fake"]`
- `experimental.hwmon.forceEnabled: true` → `cpu.meters: ["hwmon"]`
Sample configs (`hack/config.yaml`, helm values, k8s configmap, dev
compose) and `docs/user/configuration.md` updated.
No behaviour change for healthy systems running default config.
Signed-off-by: nikimanoledaki <niki.manoledaki@grafana.com>
* fix(ci): unbreak yaml lint and fake-cpu-meter sed target
Three CI fixes for PR #2468:
- `yamllint`: drop redundant double-quotes in `meters: [rapl, hwmon]`
across `hack/config.yaml`, `compose/dev/kepler-dev/etc/kepler/config.yaml`,
and `manifests/helm/kepler/values.yaml`. Project's `.yamllint.yaml`
enforces `quoted-strings: required: only-when-needed`.
- `compose-deploy` / `build-and-deploy`: the CI runs
`sed -i '/fake-cpu-meter:/{n;s/enabled: false/enabled: true/}'` to flip
the fake meter on for tests. The previous commit added a multi-line
deprecation comment between `fake-cpu-meter:` and `enabled: false`,
which broke the sed (`n` jumped to the comment instead of `enabled:`).
Move the deprecation note to a trailing comment on the same line as
`enabled: false` in all four affected files.
- `codecov/patch`: add `internal/device/cpu_power_meter_test.go`
covering `CreateCPUMeter` and `buildCPUMeter` (success, unknown name,
fallthrough, empty meters).
Signed-off-by: nikimanoledaki <niki.manoledaki@grafana.com>
* test(device): cover rapl/hwmon paths and error branches in CreateCPUMeter
Extends `cpu_power_meter_test.go` to exercise the previously-uncovered
new lines flagged by codecov/patch:
- `buildCPUMeter` "rapl" case (with `cfg.Rapl.Zones` filter logging).
- `buildCPUMeter` "hwmon" case with experimental config (zones + chipRules).
- `buildCPUMeter` "hwmon" case with nil experimental config.
- `CreateCPUMeter` factory-error path (rapl with bogus sysfs).
- `CreateCPUMeter` Init-error path (hwmon with bogus sysfs).
- `CreateCPUMeter` aggregated-error path (rapl + hwmon both fail).
Tests use `/nonexistent/sysfs/path` to force factory or Init failures
without requiring real hardware.
Signed-off-by: nikimanoledaki <niki.manoledaki@grafana.com>
* refactor(cpu): switch dispatch, structured logging, table tests
Three polish changes on top of the switch-based design:
- `ApplyCpuMeterDeprecations` rewritten as a `switch` for symmetry. The
previous `if { ...; return } if { ... }` shape had a load-bearing early
return that read as asymmetric.
- `cpu_power_meter.go` logging uses static messages with a `"meter"` attr
instead of `fmt.Sprintf`-baked dynamic strings. Mirrors the existing
convention in `gpu/registry.go` and the rest of `internal/device/`,
and gives operators a queryable `"meter"` attr that didn't exist before.
- `config_cpu_test.go` collapses `TestCpuMetersDefault` and
`TestApplyCpuMeterDeprecations` into a single `TestCpuMeters` table.
The default case is one row where `setup` is a no-op. Drops the
`io.Discard` boilerplate for `slog.DiscardHandler` (Go 1.24+).
Signed-off-by: nikimanoledaki <niki.manoledaki@grafana.com>
* fix(device): aggregate empty-zone soft-skips in CreateCPUMeter
When all configured backends in `cpu.Meters` returned empty zones, the
soft-skip path discarded that signal and the function returned a misleading
"cpu.meters is empty" error. Append to `errs` on the empty-zones path so
the joined error reports each skipped backend by name. Handle the truly
empty-config case with an early return at the top of the function.
Addresses review feedback on #2468.
Signed-off-by: nikimanoledaki <niki.manoledaki@grafana.com>
* feat(config): hard-fail on unknown `cpu.meters` entries
Validate `cpu.meters` against the set of known backends in
`Config.Validate` and return an explicit error listing the valid names.
A typo such as `["rappl", "hwmon"]` is now caught at startup
instead of silently falling through to the next backend. The `Warn` in
`CreateCPUMeter` stays as defense-in-depth for callers that skip
validation.
Addresses review feedback on #2468.
Signed-off-by: nikimanoledaki <niki.manoledaki@grafana.com>
* chore(cpu): use `slog.DiscardHandler` and clarify legacy precedence
- Switch `discardLogger()` in `cpu_power_meter_test.go` to
`slog.New(slog.DiscardHandler)` to match `config_cpu_test.go`.
Drops the unused `io` import.
- Note in `ApplyCpuMeterDeprecations` that `fake` takes precedence
over `hwmon` when both legacy keys are set.
Addresses review feedback on #2468.
Signed-off-by: nikimanoledaki <niki.manoledaki@grafana.com>
---------
Signed-off-by: nikimanoledaki <niki.manoledaki@grafana.com>cpu.meters config and switch-based CPU meter selection (#2468)1 parent bab38cb commit 55f6f4d
13 files changed
Lines changed: 567 additions & 95 deletions
File tree
- cmd/kepler
- compose/dev/kepler-dev/etc/kepler
- config
- docs/user
- hack
- internal
- device
- monitor
- manifests
- helm/kepler
- k8s
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
| 48 | + | |
| 49 | + | |
48 | 50 | | |
49 | 51 | | |
50 | 52 | | |
| |||
127 | 129 | | |
128 | 130 | | |
129 | 131 | | |
130 | | - | |
| 132 | + | |
131 | 133 | | |
132 | 134 | | |
133 | 135 | | |
| |||
309 | 311 | | |
310 | 312 | | |
311 | 313 | | |
312 | | - | |
313 | | - | |
314 | | - | |
315 | | - | |
316 | | - | |
317 | | - | |
318 | | - | |
319 | | - | |
320 | | - | |
321 | | - | |
322 | | - | |
323 | | - | |
324 | | - | |
325 | | - | |
326 | | - | |
327 | | - | |
328 | | - | |
329 | | - | |
330 | | - | |
331 | | - | |
332 | | - | |
333 | | - | |
334 | | - | |
335 | | - | |
336 | | - | |
337 | | - | |
338 | | - | |
339 | | - | |
340 | | - | |
341 | | - | |
342 | | - | |
343 | | - | |
344 | | - | |
345 | | - | |
346 | | - | |
347 | | - | |
348 | | - | |
349 | | - | |
350 | | - | |
351 | | - | |
352 | | - | |
353 | | - | |
354 | | - | |
355 | | - | |
356 | | - | |
357 | | - | |
358 | | - | |
359 | | - | |
360 | | - | |
361 | | - | |
362 | | - | |
363 | | - | |
364 | | - | |
365 | | - | |
366 | | - | |
367 | | - | |
368 | | - | |
369 | | - | |
370 | | - | |
371 | | - | |
372 | | - | |
373 | | - | |
374 | | - | |
375 | | - | |
376 | | - | |
377 | | - | |
378 | | - | |
379 | | - | |
380 | | - | |
381 | | - | |
382 | | - | |
383 | | - | |
384 | | - | |
385 | 314 | | |
386 | 315 | | |
387 | 316 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
35 | 41 | | |
36 | 42 | | |
37 | 43 | | |
| |||
71 | 77 | | |
72 | 78 | | |
73 | 79 | | |
74 | | - | |
| 80 | + | |
75 | 81 | | |
76 | 82 | | |
77 | 83 | | |
| |||
84 | 90 | | |
85 | 91 | | |
86 | 92 | | |
87 | | - | |
| 93 | + | |
88 | 94 | | |
89 | 95 | | |
90 | 96 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
| |||
53 | 54 | | |
54 | 55 | | |
55 | 56 | | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
56 | 64 | | |
57 | 65 | | |
58 | 66 | | |
| |||
192 | 200 | | |
193 | 201 | | |
194 | 202 | | |
| 203 | + | |
195 | 204 | | |
196 | 205 | | |
197 | 206 | | |
| |||
264 | 273 | | |
265 | 274 | | |
266 | 275 | | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
267 | 279 | | |
268 | 280 | | |
269 | 281 | | |
| |||
313 | 325 | | |
314 | 326 | | |
315 | 327 | | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
316 | 331 | | |
317 | 332 | | |
318 | 333 | | |
| |||
358 | 373 | | |
359 | 374 | | |
360 | 375 | | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
361 | 398 | | |
362 | 399 | | |
363 | 400 | | |
| |||
786 | 823 | | |
787 | 824 | | |
788 | 825 | | |
| 826 | + | |
| 827 | + | |
| 828 | + | |
| 829 | + | |
789 | 830 | | |
790 | 831 | | |
791 | 832 | | |
| |||
875 | 916 | | |
876 | 917 | | |
877 | 918 | | |
| 919 | + | |
| 920 | + | |
| 921 | + | |
| 922 | + | |
| 923 | + | |
| 924 | + | |
| 925 | + | |
| 926 | + | |
| 927 | + | |
| 928 | + | |
| 929 | + | |
| 930 | + | |
| 931 | + | |
878 | 932 | | |
879 | 933 | | |
880 | 934 | | |
| |||
1076 | 1130 | | |
1077 | 1131 | | |
1078 | 1132 | | |
| 1133 | + | |
1079 | 1134 | | |
1080 | 1135 | | |
1081 | 1136 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
0 commit comments