Configurable meter drivers - #1
Open
tescalada wants to merge 9 commits into
Open
Conversation
tescalada
force-pushed
the
configurable-meter-drivers
branch
3 times, most recently
from
July 19, 2026 15:56
8bf6a10 to
cb2f374
Compare
Diff CoverageDiff: origin/main...HEAD, staged and unstaged changes
Summary
sparkmeter/asgi.pyLines 41-49 41 # When this file is launched via `python -m sparkmeter.asgi`, Python executes it
42 # as `__main__`. Register the canonical module name as an alias to the running
43 # module so in-process helpers don't accidentally import a second copy.
44 if __name__ == "__main__":
! 45 sys.modules.setdefault("sparkmeter.asgi", sys.modules[__name__])
46
47
48 @asynccontextmanager
49 async def app_lifespan(app: FastAPI):sparkmeter/config/configviews.pyLines 152-162 152 provider=provider,
153 )
154
155 if request.method == "POST" and form.validate():
! 156 form.save()
! 157 flash(form.notification_message(), "success")
! 158 return redirect(url_for("config.meter_driver"))
159
160 return form.render(provider=provider)
161 |
tescalada
force-pushed
the
configurable-meter-drivers
branch
2 times, most recently
from
July 21, 2026 03:28
0733849 to
c6f08d9
Compare
tescalada
force-pushed
the
configurable-meter-drivers
branch
from
July 21, 2026 03:50
c6f08d9 to
b2bf3eb
Compare
tescalada
force-pushed
the
configurable-meter-drivers
branch
from
July 31, 2026 12:13
b2bf3eb to
77f73f5
Compare
Coverage report
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Add the metering subsystem — runtime client, command dispatch, event stream, lifespan and reconciliation — talking to a driver over gRPC and HTTP+SSE using the released meter-driver-spec wheel. Delete the vendored sparkmeter/metering/_generated OpenAPI client and the regen-metering-wire.sh script that produced it; the local codegen workflow and its pre-commit and setup.cfg entries go with them.
Delete the `reading create-fake` command and its ReadingGenerator, which synthesized random readings for demo/testing. Drop the now-empty reading CLI group registration and its coverage in the CLI-registration and meter-command tests.
No source path scales readings any longer: slipstream is gone, and the fake-reading generator (its only remaining caller) was just removed. Provider readings arrive in engineering units and are persisted as-is. Drop the apply_meter_scalars parameter from add_reading / save_raw_reading and delete Meter.apply_scalars. Update the reading controller tests to supply realistic engineering-unit values directly instead of raw counts that were scaled down at persist time, and remove the apply_scalars unit test.
…hing Add sparkmeter/metering/runtime_registry.py (set_running_app/get_running_app) as the single source for the running public ASGI app, replacing the sys.modules/__dict__ reflection that located it for the sync-to-async metering bridge. Remove all globals()[...] app-publishing from asgi.py: the registry holds the public app and a private _internal_app caches the internal app, both resolved via __getattr__. Inline the redundant _get_running_public_app wrapper into its one call site.
Drop the _is_ground() wrapper and its SPARKMETER_MODE env fallback, now that main derives ground/cloud from the HEROKU config key. The two lifespan guards call config.is_cloud() directly, and the lifespan tests drive the branch by setting config["HEROKU"] rather than stubbing the removed helper.
The _metering_enabled() helper re-read and re-normalized SM_OFFLINE in an except-fallback, duplicating the SM_-prefix env normalization ConfigDict already does at load time. Replace it with a config.is_offline() method that reads the normalized OFFLINE value, alongside is_ground()/is_cloud(). The two metering guards call config.is_offline() directly, and the tests drive the branch by setting config["OFFLINE"] rather than stubbing the removed helper.
tescalada
force-pushed
the
configurable-meter-drivers
branch
from
July 31, 2026 18:14
77f73f5 to
1f5758a
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Introduces configurable meter drivers and per-provider metering settings, and migrates the metering stack off the vendored OpenAPI/sparknet-http client onto the generic
meter-driver-specpackage (consumed as a released wheel) with runtime driver discovery.Changes
meter.provider_idcolumn, surfaced throughmeter_view(DB migration0.84).meter-driver-specmodels with runtime driver discovery; consume it as a released wheel; bump tov1.3.0and update the gRPC import path.sparknet-httppackage; add a sparknet-http gRPC/SSE runtime client; point imports at thegrpc/httpsubpackages.Notes
0.84migration addsmeter.provider_idand rebuildsmeter_view; its downgrade dropsmeter_viewbefore removing the column and no longer re-runsmeterschema.sqlin-migration (the migration runner rebuilds views after migrations).sparkmeter/config/tests/test_provider_settings.py.