Skip to content

Simplify the logical meter's formula plumbing - #64

Merged
shsms merged 9 commits into
frequenz-floss:v0.x.xfrom
shsms:logical-meter-formula-plumbing
Oct 9, 2026
Merged

shsms merged 9 commits into
frequenz-floss:v0.x.xfrom
shsms:logical-meter-formula-plumbing

Conversation

@shsms

@shsms shsms commented Oct 6, 2026 •

Copy link
Copy Markdown
Collaborator

Prepares the logical meter for evaluating composed formulas in the actor (#60, now split into a stack of three PRs; this is the first). It moves to formula engine 0.2 and component graph 0.6.3, picks graph formulas by a crate-private metric kind instead of per-kind provider impls, and replaces the actor's per-quantity maps and downcast response channel with per-subscriber sinks.

Changes

  • Depend on formula engine 0.2: missing components now read as unknown; NaN and infinity become missing data.
  • The handle picks the graph method from (FormulaKind, FormulaTarget) in one match, replacing GraphFormulaProvider and its macros.
  • The actor keeps one entry per distinct formula with a sink per subscriber, and prunes formulas and resamplers nobody reads on every tick. subscribe() no longer waits for the actor.
  • The handle parses graph formulas, so a formula the engine rejects (e.g. over its operator limit) fails in the handle method with FormulaEngineError, instead of failing subscribe().
  • Requires component graph 0.6.3, whose consumer and producer formulas are no longer clamped at zero. Without a lock file, ^0.6.2 already resolved to it.
  • Focused tests for sink pruning and resampler dropping, the full kind-by-target dispatch table, and the engine's rejection of an oversized consumer formula.

Breaking

Metric::FormulaType and ErrorKind::DroppedUnusedFormulas are removed, Quantity is sealed, and formula values change for NaN/infinite inputs, oversized graph formulas, and the no-longer-clamped consumer and producer formulas. See ## Upgrading in RELEASE_NOTES.md.

Signed-off-by: Sahas Subramanian <sahas.subramanian@proton.me>
@shsms
shsms force-pushed the logical-meter-formula-plumbing branch from 6b34c04 to 803ac5c Compare October 6, 2026 16:02

@Marenz Marenz left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Looks good overall, a few small things.

Comment thread RELEASE_NOTES.md Outdated
Comment thread Cargo.toml
Comment thread src/logical_meter/logical_meter_actor.rs
shsms added 8 commits October 8, 2026 16:27
Without a lock file, `^0.6.2` already resolves to 0.6.3, which no longer
clamps the consumer and producer formulas, so the producer display test
failed. Require 0.6.3 and pin the unclamped formulas in the tests.

Signed-off-by: Sahas Subramanian <sahas.subramanian@proton.me>
The following commits build on engine 0.2's `Formula` type. Users see
two changes: NaN and infinite values now count as missing data, and
formulas past the engine's operator limit are rejected.

The actor's `calculate` call becomes `evaluate`; a missing key now reads
`Unknown`, which the actor maps to `None`.

Signed-off-by: Sahas Subramanian <sahas.subramanian@proton.me>
Use let-else in `push_to_resampler`, and make the test helper
`next_sample` generic so the frequency test can reuse it.

Signed-off-by: Sahas Subramanian <sahas.subramanian@proton.me>
Metrics now state their graph formula kind as a crate-private const
instead of the public `Metric::FormulaType`. One match in the handle
picks the graph method from that kind and the formula target, which
removes the provider trait, its macros and the kind parameter on
`GraphFormula`.

Signed-off-by: Sahas Subramanian <sahas.subramanian@proton.me>
The formula engine works in f32 base units, and `BaseValue` builds typed
quantities from them. As a crate-private supertrait of `Quantity` it
stays hidden, but `Quantity` can no longer be implemented downstream.
Used in the next commit.

Signed-off-by: Sahas Subramanian <sahas.subramanian@proton.me>
The actor keeps one entry per distinct formula with a sink per
subscriber, replacing the per-quantity maps and the downcast of the
response channel. Formulas and resamplers nobody listens to are pruned
on every tick.

Each subscriber gets its own channel, so `subscribe()` no longer waits
for the actor to reply. The handle now parses the graph formula, so a
formula the engine rejects fails the handle method with
`FormulaEngineError` instead of failing `subscribe()` with
`ConnectionFailure`. A formula whose telemetry cannot be started is not
registered, so its subscriber's stream closes.

Signed-off-by: Sahas Subramanian <sahas.subramanian@proton.me>
The actor's per-tick bookkeeping had no coverage. Its methods are
exercised directly with stub sinks, so the tests do not depend on the
mock's stream tracking. A test-only disconnected client handle covers a
subscription whose telemetry cannot be started.

Signed-off-by: Sahas Subramanian <sahas.subramanian@proton.me>
Signed-off-by: Sahas Subramanian <sahas.subramanian@proton.me>
@shsms
shsms force-pushed the logical-meter-formula-plumbing branch from 803ac5c to d449942 Compare October 8, 2026 14:27
@shsms
shsms requested a review from Marenz October 8, 2026 14:29

@Marenz Marenz left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

All three addressed, thanks. Verified locally on 1.99 (what CI uses): fmt, clippy --no-deps -D warnings, and clippy --all-targets -D warnings clean, 164 tests pass, and every commit from 19a6e1c on is green.

One non-blocking thing for later: drop_unused_resamplers runs every tick and recomputes engine_formula.components() per formula, which is a full tree walk plus a fresh HashSet each time. The set never changes, so it could live in SubscribedFormula, and the sweep only needs to run when evaluate_formulas actually dropped something.

@shsms
shsms added this pull request to the merge queue Oct 9, 2026
Merged via the queue into frequenz-floss:v0.x.x with commit b9877e6 Oct 9, 2026
3 checks passed
@shsms
shsms deleted the logical-meter-formula-plumbing branch October 9, 2026 09:46
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