Skip to content

Move the Lwt logic out of the prometheus core - #65

Open
avsm wants to merge 1 commit into
mirage:masterfrom
avsm:split-lwt
Open

Move the Lwt logic out of the prometheus core#65
avsm wants to merge 1 commit into
mirage:masterfrom
avsm:split-lwt

Conversation

@avsm

@avsm avsm commented Aug 5, 2026

Copy link
Copy Markdown
Member

Split off the Lwt-specific parts of the library so that defining and recording metrics no longer pulls in a concurrency library. Metric recording is synchronous anyway (it updates an in-memory scoreboard) so the core does not need Lwt.

This is the first half of #60, so that the interface-breaking move can be reviewed separately.

@avsm

avsm commented Aug 5, 2026

Copy link
Copy Markdown
Member Author

Since we're breaking interfaces here, I intend to look at #46 after as well to get the prometheus-reporter changes in. Once that's done, it should be straightforward to add eio, miou, or any other concurrency library as additions. This'll need testing in a unikernel to be sure it works; I've only done that by inspection of dependencies.

@talex5 talex5 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

One problem here is that you need to upgrade all libraries using prometheus at once, which could be a problem.

An alternative would be to add the separate lwt package first with the new API, but have it simply call the corresponding functions in the main prometheus package (which would still be using lwt).

Then libraries can be updated incrementally to the new API without breaking compatibility. Then we can break the original API in another release.

One annoyance is that we'd want to provide the new synchronous functions at the same time (so people upgrading can decide whether they need the Lwt version or not), but the old recording functions don't have _lwt in their names. But maybe we just need to be creative about names (e.g. replace time with time_fn or something).

On the other hand, maybe not that many people are using the library and it doesn't matter?

Comment thread lwt/prometheus_lwt.mli Outdated
Comment on lines +46 to +52
module Cohttp (S : Cohttp_lwt.S.Server) : sig
val callback :
S.conn ->
Cohttp.Request.t ->
Cohttp_lwt.Body.t -> (Cohttp.Response.t * Cohttp_lwt.Body.t) Lwt.t
end
(** A Cohttp callback that serves {!CollectorRegistry.default} at [/metrics]. *)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Having the server here is bad - anything that wants to report Lwt metrics will pull in a cohttp dependency, even if the metrics aren't being used.

avsm added a commit to avsm/prometheus that referenced this pull request Aug 6, 2026
Introduce the `prometheus-lwt` package with the API that the core will keep
once its Lwt dependency is removed (mirage#60 mirage#65), but implemented for now via Lwt
support still present in `prometheus`.

Therefore nothing breaks in this release as existing users can migrate to
`Prometheus_lwt` and also to the new synchronous `_fn` functions at their own
pace. The actual interface break will then happen in a later release without
further source changes for migrated Lwt users.

Also add synchronous variants of the timing helpers to the core since the
existing Lwt-typed functions occupy the unsuffixed names until the break.

Suggested by @talex5 in mirage#65.

Co-authored-by: Mark Elvers <mark.elvers@tunbury.org>
avsm added a commit to avsm/prometheus that referenced this pull request Aug 6, 2026
Introduce the `prometheus-lwt` package with the API that the core will keep
once its Lwt dependency is removed (mirage#60 mirage#65), but implemented for now via Lwt
support still present in `prometheus`.

Therefore nothing breaks in this release as existing users can migrate to
`Prometheus_lwt` and also to the new synchronous `_fn` functions at their own
pace. The actual interface break will then happen in a later release without
further source changes for migrated Lwt users.

Also add synchronous variants of the timing helpers to the core since the
existing Lwt-typed functions occupy the unsuffixed names until the break.

Suggested by @talex5 in mirage#65.

Co-authored-by: Mark Elvers <mark.elvers@tunbury.org>
avsm added a commit to avsm/prometheus that referenced this pull request Aug 6, 2026
Introduce the `prometheus-lwt` package with the API that the core will keep
once its Lwt dependency is removed (mirage#60 mirage#65), but implemented for now via Lwt
support still present in `prometheus`.

Therefore nothing breaks in this release as existing users can migrate to
`Prometheus_lwt` and also to the new synchronous `_fn` functions at their own
pace. The actual interface break will then happen in a later release without
further source changes for migrated Lwt users.

Also add synchronous variants of the timing helpers to the core since the
existing Lwt-typed functions occupy the unsuffixed names until the break.

Suggested by @talex5 in mirage#65.

Co-authored-by: Mark Elvers <mark.elvers@tunbury.org>
@avsm

avsm commented Aug 6, 2026

Copy link
Copy Markdown
Member Author

@talex5 I think your suggestion makes sense; prometheus is pretty deep in the dependency core and so providing a migration path for existing users is a good thing. I've done this in #66; the only slightly fiddly thing is adding a functor for HISTOGRAM for the future Lwt time function.

@avsm

avsm commented Aug 6, 2026

Copy link
Copy Markdown
Member Author

Rebased this over #66 with a801c2a, leaving the cohttp in prometheus-app for now

talex5 added a commit to avsm/prometheus that referenced this pull request Aug 6, 2026
Introduce the `prometheus-lwt` package with the API that the core will keep
once its Lwt dependency is removed (mirage#60 mirage#65), but implemented for now via Lwt
support still present in `prometheus`.

Therefore nothing breaks in this release as existing users can migrate to
`Prometheus_lwt` and also to the new synchronous functions at their own
pace. The actual interface break will then happen in a later release without
further source changes for migrated Lwt users.

Also add synchronous variants of the timing helpers to the core since the
existing Lwt-typed functions occupy the unsuffixed names until the break.

Suggested by @talex5 in mirage#65.

Co-authored-by: Mark Elvers <mark.elvers@tunbury.org>
Co-authored-by: Thomas Leonard <talex5@gmail.com>
Complete the migration started in mirage#66 so the core no longer depends
on Lwt.  Libraries that only define and record metrics no longer need
to pull in a concurrency library.

Review suggestions from @talex5

Co-authored-by: Mark Elvers <mark.elvers@tunbury.org>
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