Skip to content

Add prometheus-lwt as a forward-compatible Lwt interface - #66

Merged
talex5 merged 1 commit into
mirage:masterfrom
avsm:fwd-lwt-iface
Aug 6, 2026
Merged

Add prometheus-lwt as a forward-compatible Lwt interface#66
talex5 merged 1 commit into
mirage:masterfrom
avsm:fwd-lwt-iface

Conversation

@avsm

@avsm avsm commented Aug 6, 2026

Copy link
Copy Markdown
Member

Introduce the prometheus-lwt package with the API that the core will keep once its Lwt dependency is removed (#60 #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 #65.

avsm added a commit to avsm/prometheus that referenced this pull request Aug 6, 2026
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>
@talex5

talex5 commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

I've pushed a commit with some changes:

We'd like people to stop using the old names soon so we can remove the Lwt dependency, so I marked the old functions as deprecated now.

API changes:

  • Remove the _lwt suffix from functions in Prometheus_lwt as redundant (an alternative would be to include the main API here, in which case keeping the suffix would make sense, but I think it's better to avoid using the Lwt package when you don't need it).

  • The new name for Gauge.time is now set_time and it sets the time instead of incrementing it (this is what it was supposed to do; see https://prometheus.io/docs/instrumenting/writing_clientlibs/).

  • The replacement for track_inprogress is now track_in_progress.

  • Summary.time becomes Summary.observe_time, and the same for histograms.

This should mean we end up with a nicer API after removing the old names I think.

All functions in prometheus.mli that mention Lwt are now deprecated, except for collect (which isn't used by libraries, so doesn't matter).

@avsm

avsm commented Aug 6, 2026

Copy link
Copy Markdown
Member Author

Looks good, I was in two minds about the deprecated tags since I really dislike build time spam, but these are all actionable tags with instructions on what to do for the user!

@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.

Looks good to me.

I pushed some more minor changes, updating the changelog and README a bit, and removing the (wrapped false) (didn't look like it was needed).

Comment thread src/prometheus.ml
include METRIC
val observe : t -> float -> unit
val time : t -> (unit -> float) -> (unit -> 'a Lwt.t) -> 'a Lwt.t
val time : t -> (unit -> float) -> (unit -> 'a Lwt.t) -> 'a Lwt.t [@@deprecated]

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This is a minor thing, but is the deprecated tag needed outside of the mli?

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.

It wouldn't build without it for some reason (the error is pretty confusing):

File "src/prometheus.ml", line 1:   
Error (alert deprecated): time
Use observe_time instead if you don't need Lwt here, or Prometheus_lwt.HISTOGRAM.observe_time if you do.
File "src/prometheus.mli", lines 233-234, characters 2-123:
  Definition
File "src/prometheus.ml", line 367, characters 2-67:
367 |   val time : t -> (unit -> float) -> (unit -> 'a Lwt.t) -> 'a Lwt.t
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  Expected signature

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Interesting, it doesn't fire an error when using let bindings and val signatures, only when module types are involved.

Comment thread CHANGES.md Outdated
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>
@talex5
talex5 merged commit 30da687 into mirage:master Aug 6, 2026
1 check was pending
@avsm
avsm deleted the fwd-lwt-iface branch August 6, 2026 12:16
avsm added a commit to avsm/prometheus that referenced this pull request Aug 6, 2026
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