Search in sources :

Example 1 with PostRequestMetricsSupport

use of io.helidon.metrics.serviceapi.PostRequestMetricsSupport in project helidon by oracle.

the class MetricsSupport method configureVendorMetrics.

/**
 * Configure vendor metrics on the provided routing. This method is
 * exclusive to {@link #update(io.helidon.webserver.Routing.Rules)} (e.g.
 * you should not use both, as otherwise you would duplicate the metrics)
 *
 * @param routingName name of the routing (may be null)
 * @param rules routing builder or routing rules
 */
@Override
public void configureVendorMetrics(String routingName, Routing.Rules rules) {
    String metricPrefix = metricsNamePrefix(routingName);
    KeyPerformanceIndicatorSupport.Metrics kpiMetrics = KeyPerformanceIndicatorMetricsImpls.get(metricPrefix, metricsSettings.keyPerformanceIndicatorSettings());
    rules.any((req, res) -> {
        KeyPerformanceIndicatorSupport.Context kpiContext = kpiContext(req);
        PostRequestMetricsSupport prms = PostRequestMetricsSupport.create();
        req.context().register(prms);
        kpiContext.requestHandlingStarted(kpiMetrics);
        res.whenSent().thenAccept(r -> postRequestProcessing(prms, req, r, null, kpiContext)).exceptionallyAccept(t -> postRequestProcessing(prms, req, res, t, kpiContext));
        Exception exception = null;
        try {
            req.next();
        } catch (Exception e) {
            exception = e;
            throw e;
        } finally {
            // Perform updates which depend on completion of request *handling* (after the server has begun request
            // *processing* but, in the case of async requests, possibly before processing has finished).
            kpiContext.requestHandlingCompleted(exception == null);
        }
    });
}
Also used : Arrays(java.util.Arrays) JsonValue(jakarta.json.JsonValue) KeyPerformanceIndicatorSupport(io.helidon.webserver.KeyPerformanceIndicatorSupport) HelidonRestServiceSupport(io.helidon.servicecommon.rest.HelidonRestServiceSupport) DeprecatedConfig(io.helidon.config.DeprecatedConfig) MediaType(io.helidon.common.http.MediaType) BigDecimal(java.math.BigDecimal) PostRequestMetricsSupport(io.helidon.metrics.serviceapi.PostRequestMetricsSupport) Map(java.util.Map) JsonObject(jakarta.json.JsonObject) BigInteger(java.math.BigInteger) RestServiceSettings(io.helidon.servicecommon.rest.RestServiceSettings) JsonArrayBuilder(jakarta.json.JsonArrayBuilder) Set(java.util.Set) Logger(java.util.logging.Logger) MetricID(org.eclipse.microprofile.metrics.MetricID) Collectors(java.util.stream.Collectors) MetricsSettings(io.helidon.metrics.api.MetricsSettings) ServerRequest(io.helidon.webserver.ServerRequest) Objects(java.util.Objects) List(java.util.List) Stream(java.util.stream.Stream) Handler(io.helidon.webserver.Handler) Optional(java.util.Optional) MetricRegistry(org.eclipse.microprofile.metrics.MetricRegistry) JsonArray(jakarta.json.JsonArray) JsonBuilderFactory(jakarta.json.JsonBuilderFactory) Metric(org.eclipse.microprofile.metrics.Metric) HashMap(java.util.HashMap) Function(java.util.function.Function) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) JsonpSupport(io.helidon.media.jsonp.JsonpSupport) JsonStructure(jakarta.json.JsonStructure) BiConsumer(java.util.function.BiConsumer) ServerResponse(io.helidon.webserver.ServerResponse) Http(io.helidon.common.http.Http) MessageBodyWriter(io.helidon.media.common.MessageBodyWriter) Config(io.helidon.config.Config) MinimalMetricsSupport(io.helidon.metrics.serviceapi.MinimalMetricsSupport) RequestHeaders(io.helidon.webserver.RequestHeaders) Json(jakarta.json.Json) JsonObjectBuilder(jakarta.json.JsonObjectBuilder) KeyPerformanceIndicatorMetricsSettings(io.helidon.metrics.api.KeyPerformanceIndicatorMetricsSettings) RegistryFactory(io.helidon.metrics.api.RegistryFactory) SystemTagsManager(io.helidon.metrics.api.SystemTagsManager) Comparator(java.util.Comparator) Routing(io.helidon.webserver.Routing) Collections(java.util.Collections) KeyPerformanceIndicatorSupport(io.helidon.webserver.KeyPerformanceIndicatorSupport) PostRequestMetricsSupport(io.helidon.metrics.serviceapi.PostRequestMetricsSupport)

Aggregations

Http (io.helidon.common.http.Http)1 MediaType (io.helidon.common.http.MediaType)1 Config (io.helidon.config.Config)1 DeprecatedConfig (io.helidon.config.DeprecatedConfig)1 MessageBodyWriter (io.helidon.media.common.MessageBodyWriter)1 JsonpSupport (io.helidon.media.jsonp.JsonpSupport)1 KeyPerformanceIndicatorMetricsSettings (io.helidon.metrics.api.KeyPerformanceIndicatorMetricsSettings)1 MetricsSettings (io.helidon.metrics.api.MetricsSettings)1 RegistryFactory (io.helidon.metrics.api.RegistryFactory)1 SystemTagsManager (io.helidon.metrics.api.SystemTagsManager)1 MinimalMetricsSupport (io.helidon.metrics.serviceapi.MinimalMetricsSupport)1 PostRequestMetricsSupport (io.helidon.metrics.serviceapi.PostRequestMetricsSupport)1 HelidonRestServiceSupport (io.helidon.servicecommon.rest.HelidonRestServiceSupport)1 RestServiceSettings (io.helidon.servicecommon.rest.RestServiceSettings)1 Handler (io.helidon.webserver.Handler)1 KeyPerformanceIndicatorSupport (io.helidon.webserver.KeyPerformanceIndicatorSupport)1 RequestHeaders (io.helidon.webserver.RequestHeaders)1 Routing (io.helidon.webserver.Routing)1 ServerRequest (io.helidon.webserver.ServerRequest)1 ServerResponse (io.helidon.webserver.ServerResponse)1