Search in sources :

Example 1 with JsonExporter

use of org.wildfly.swarm.microprofile.metrics.runtime.exporters.JsonExporter in project wildfly-swarm by wildfly-swarm.

the class MetricsHttpHandler method obtainExporter.

/**
 * Determine which exporter we want.
 * @param exchange The http exchange coming in
 * @return An exporter instance or null in case no matching exporter existed.
 */
private Exporter obtainExporter(HttpServerExchange exchange) {
    HeaderValues acceptHeaders = exchange.getRequestHeaders().get(Headers.ACCEPT);
    Exporter exporter;
    String method = exchange.getRequestMethod().toString();
    if (acceptHeaders == null) {
        if (method.equals("GET")) {
            exporter = new PrometheusExporter();
        } else {
            return null;
        }
    } else {
        // Header can look like "application/json, text/plain, */*"
        if (acceptHeaders.getFirst() != null && acceptHeaders.getFirst().startsWith("application/json")) {
            if (method.equals("GET")) {
                exporter = new JsonExporter();
            } else if (method.equals("OPTIONS")) {
                exporter = new JsonMetadataExporter();
            } else {
                return null;
            }
        } else {
            // This is the fallback, but only for GET, as Prometheus does not support OPTIONS
            if (method.equals("GET")) {
                exporter = new PrometheusExporter();
            } else {
                return null;
            }
        }
    }
    return exporter;
}
Also used : PrometheusExporter(org.wildfly.swarm.microprofile.metrics.runtime.exporters.PrometheusExporter) HeaderValues(io.undertow.util.HeaderValues) JsonExporter(org.wildfly.swarm.microprofile.metrics.runtime.exporters.JsonExporter) HttpString(io.undertow.util.HttpString) JsonExporter(org.wildfly.swarm.microprofile.metrics.runtime.exporters.JsonExporter) JsonMetadataExporter(org.wildfly.swarm.microprofile.metrics.runtime.exporters.JsonMetadataExporter) Exporter(org.wildfly.swarm.microprofile.metrics.runtime.exporters.Exporter) PrometheusExporter(org.wildfly.swarm.microprofile.metrics.runtime.exporters.PrometheusExporter) JsonMetadataExporter(org.wildfly.swarm.microprofile.metrics.runtime.exporters.JsonMetadataExporter)

Aggregations

HeaderValues (io.undertow.util.HeaderValues)1 HttpString (io.undertow.util.HttpString)1 Exporter (org.wildfly.swarm.microprofile.metrics.runtime.exporters.Exporter)1 JsonExporter (org.wildfly.swarm.microprofile.metrics.runtime.exporters.JsonExporter)1 JsonMetadataExporter (org.wildfly.swarm.microprofile.metrics.runtime.exporters.JsonMetadataExporter)1 PrometheusExporter (org.wildfly.swarm.microprofile.metrics.runtime.exporters.PrometheusExporter)1