Search code examples
jettyprometheus

Porting from Jetty 11 to Jetty 12. Missing StatisticsHandler methods


I am porting my app from Jetty 11 to Jetty 12.

I noticed that following methods from StatisticsHandler are missing:

- getDispatched
- getDispatchedActive
- getDispatchedActiveMax
- getDispatchedTimeMax
- getDispatchedTimeTotal
- getAsyncRequests
- getAsyncRequestsWaiting
- getAsyncRequestsWaitingMax
- getAsyncDispatches
- getExpires
- getStatsOnMs
- getResponsesBytesTotal

I checked the Jetty repo and found Re-introduce a more complete set of stats in StatisticsHandler #10555

In Jetty 10/11, StatisticsHandler used to expose more of the internals than Jetty 12 currently does. Here is a list of such stats available on 10/11 and absent from 12:

getStatsOnMs()
getDispatchedActive()
getDispatched()
getDispatchedActiveMax()
getDispatchedTimeTotal()
getDispatchedTimeMax()
getDispatchedTimeMean()
getDispatchedTimeStdDev()
getExpires()
getAsyncDispatches()
getAsyncRequestsWaiting()

Those should be re-implemented as they were or eventually revisited if the changes between 10/11 and 12 necessitate slightly different stats.

The issue is closed, but most methods from the list above were not added.

My questions:

  • why are getDispatched*, getAsync*() methods removed (If they do not make sense in Jetty 12, then what are the reasons)
  • are there any replacements?

For more context: I am using JettyStatisticsCollector from io.prometheus:simpleclient_jetty:0.16.0:

@Override
public List<MetricFamilySamples> collect() {
  return Arrays.asList(
          buildCounter("jetty_requests_total", "Number of requests", statisticsHandler.getRequests()),
          buildGauge("jetty_requests_active", "Number of requests currently active", statisticsHandler.getRequestsActive()),
          buildGauge("jetty_requests_active_max", "Maximum number of requests that have been active at once", statisticsHandler.getRequestsActiveMax()),
          buildGauge("jetty_request_time_max_seconds", "Maximum time spent handling requests", statisticsHandler.getRequestTimeMax() / 1000.0),
          buildCounter("jetty_request_time_seconds_total", "Total time spent in all request handling", statisticsHandler.getRequestTimeTotal() / 1000.0),
          buildCounter("jetty_dispatched_total", "Number of dispatches", statisticsHandler.getDispatched()),
          buildGauge("jetty_dispatched_active", "Number of dispatches currently active", statisticsHandler.getDispatchedActive()),
          buildGauge("jetty_dispatched_active_max", "Maximum number of active dispatches being handled", statisticsHandler.getDispatchedActiveMax()),
          buildGauge("jetty_dispatched_time_max", "Maximum time spent in dispatch handling", statisticsHandler.getDispatchedTimeMax()),
          buildCounter("jetty_dispatched_time_seconds_total", "Total time spent in dispatch handling", statisticsHandler.getDispatchedTimeTotal() / 1000.0),
          buildCounter("jetty_async_requests_total", "Total number of async requests", statisticsHandler.getAsyncRequests()),
          buildGauge("jetty_async_requests_waiting", "Currently waiting async requests", statisticsHandler.getAsyncRequestsWaiting()),
          buildGauge("jetty_async_requests_waiting_max", "Maximum number of waiting async requests", statisticsHandler.getAsyncRequestsWaitingMax()),
          buildCounter("jetty_async_dispatches_total", "Number of requested that have been asynchronously dispatched", statisticsHandler.getAsyncDispatches()),
          buildCounter("jetty_expires_total", "Number of async requests requests that have expired", statisticsHandler.getExpires()),
          buildStatusCounter(),
          buildGauge("jetty_stats_seconds", "Time in seconds stats have been collected for", statisticsHandler.getStatsOnMs() / 1000.0),
          buildCounter("jetty_responses_bytes_total", "Total number of bytes across all responses", statisticsHandler.getResponsesBytesTotal())
  );
}

I can probably override this list, but I want full set of stats exposed by Jetty.

Note that io.prometheus:simpleclient_jetty:0.16.0 is end of line, the replacement is io.prometheus:client_java but it has not migrated JettyStatisticsCollector yet:

This is not functional source code. We just keep these files around so we don't loose the Github history once we copy them to the new 1.0.x modules.


Solution

    • why are getDispatched*, getAsync*() methods removed (If they do not make sense in Jetty 12, then what are the reasons)
    • are there any replacements?

    Both of those are tracking Servlet specific behaviors (DispatcherType and AsyncContext use to be specific).

    Jetty 12 core classes have no servlet dependency anymore, that's the reason those specific methods/metrics were dropped.

    There are no replacements at the Jetty Core or StatisticsHandler level.

    Back in Jetty 11 and older, the core of Jetty (and things like StatisticsHandler) was tied to a specific version of Servlet. (for Jetty 11 that was Servlet 5.0)

    Now in Jetty 12, the servlet classes only exist in the individual environments, and you can pick and choose which environment (eg: servlet version) you want to run with.