Port from Lwt to Eio#59
Open
mtelvers wants to merge 3 commits into
Open
Conversation
Replaces the Lwt dependency throughout with direct-style Eio. As flagged in the v1.2 CHANGES entry, the Lwt collectors were a temporary shim for pre-5.0 OCaml; with OCaml 5 and effects they can go away entirely. - CollectorRegistry.collect is now synchronous. Collectors may still perform IO via effects (e.g. Eio operations). - Drop register_lwt / register_pre_collect_lwt and the separate metrics_lwt / pre_collect_lwt state; a single register / register_pre_collect pair serves both sync and effectful collectors. - Gauge.track_inprogress and the *.time helpers take (unit -> 'a) -> 'a and use Fun.protect, so the gauge/observation is updated even when the inner function raises. - Prometheus_app: the Cohttp(Server) functor becomes a top-level callback suitable for Cohttp_eio.Server.make. - Prometheus_unix.serve takes ~sw and ~net explicitly and forks the server onto the caller's switch. - Bump ocaml lower bound to 5.0. Drop lwt, cohttp-lwt, cohttp-lwt-unix, alcotest-lwt. Add eio, cohttp-eio, eio_main (tests/example).
- Prometheus_unix.serve now returns a (unit -> unit) list and creates its own switch internally; callers compose with Eio.Fiber.all/fork rather than passing ~sw. - Expose ?backlog and ?addr on serve so users can bind to IPv6/dual stack or tune the listen queue. - Example uses while-loop counter, idiomatic Term.(const $ ...) cmdliner spelling, and Eio.Fiber.all to express concurrency at the call site. - Fix cohttp-eio log source name: 'cohttp.eio' -> 'cohttp.eio.io'. - Relax prometheus.opam ocaml floor from >= 5.0 to >= 4.08 (Fun.protect is the only stdlib-version-sensitive call; the core no longer needs Eio).
Eliminate the two remaining Unix.gettimeofday calls in
Prometheus_unix:
- process_start_time_seconds was captured at module-init time. It
now comes from Eio.Time.now clock, captured the first time
Prometheus_unix.init ~clock () is called. The metric is no longer
auto-registered at module load.
- The Logs reporter installed by Logging.init used to call
Unix.gettimeofday for every log line; it now closes over a clock
and calls Eio.Time.now.
Both Logging.init and the new top-level init require ~clock and must
be called from inside Eio_main.run, where a clock capability is
available. This matches the Eio idiom (capabilities passed
explicitly, no global resources) and matches feedback talex5 gave on
the obuilder Eio port: 'plumb a clock through; useful for tests
anyway.'
Migration for downstream callers is mechanical: move the toplevel
Prometheus_unix.Logging.init () into the body of Eio_main.run, add
~clock, and follow with Prometheus_unix.init ~clock ().
Member
|
I'm not sure that replacing As for the library, this would therefore involve abstracting the monad so as to retain support for Finally, as for the application, I’m not sure it's fundamentally necessary to use |
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.
Replaces the Lwt-based runtime with direct-style Eio. The bulk of the diff is removing Lwt.t from every signature, but a few things are worth noting.
API changes:
CollectorRegistry.collectnow returns asnapshotdirectly rather than asnapshot Lwt.t. Collectors and pre-collect hooks may perform IO via effects, so the parallel_lwt-suffixed API is gone:register_lwt,register_pre_collect_lwtand the internalmetrics_lwt/pre_collect_lwtfields are all removed.Gauge.track_inprogress,Gauge.time,Summary.timeandHistogram.timetake a plain (unit -> 'a) and return 'a. Internally they useFun.protectso the gauge/observation is still updated if the inner function raises. This is covered in a new regression test.Prometheus_app.Cohttpfunctor is replaced by a single top-levelPrometheus_app.callbackforcohttp-eio(no transport parameterisation needed).Prometheus_unix.servereturns a (unit -> unit) list of fiber bodies. The caller composes them withEio.Fiber.all/Fiber.forkrather than passing a switch. Each fiber manages its own listening socket via an internal switch and shuts down cleanly on cancellation. New optional?backlogand?addrparameters let callers tune the listen queue or bind to IPv6.Prometheus_unix.Logging.initnow requires~clock:_ Eio.Time.clock. The Logs reporter sources timestamps fromEio.Time.nowinstead ofUnix.gettimeofday, so it must be called from insideEio_main.run.Prometheus_unix.init ~clock ()replaces the implicit module-init registration ofprocess_start_time_seconds. The metric's value is captured from the supplied clock wheninitis called. Callers must invoke this once, insideEio_main.run.Package deps and constraints:
Fun.protect.cohttp-eioandeioinstead ofcohttp-lwt/cohttp-lwt-unix/lwt;alcotest-lwtdropped from test deps.Tests:
Eio.Fiber.yield ()in place ofLwt.pause ()to exercise a collector that suspends.Fun.protect-based implementation.Example:
examples/example.mluses a while-loop counter, callsEio.Fiber.alloverPrometheus_unix.serve.The interpretation of "thread-safe" in the docs is qualified: safe under OCaml 5 effect-based schedulers running on a single domain, NOT under multi-domain parallelism.