All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.palantir.conjure.java.okhttp.ConjureJavaClientQosMetrics Maven / Gradle / Ivy

The newest version!
package com.palantir.conjure.java.okhttp;

import com.codahale.metrics.Meter;
import com.codahale.metrics.Timer;
import com.google.errorprone.annotations.CheckReturnValue;
import com.palantir.logsafe.Preconditions;
import com.palantir.logsafe.Safe;
import com.palantir.tritium.metrics.registry.MetricName;
import com.palantir.tritium.metrics.registry.TaggedMetricRegistry;

/**
 * Conjure okhttp client quality of service metrics.
 */
final class ConjureJavaClientQosMetrics {
    private static final String JAVA_VERSION = System.getProperty("java.version", "unknown");

    private static final String LIBRARY_NAME = "conjure-java-runtime";

    private static final String LIBRARY_VERSION = "8.13.0";

    private static final MetricName requestPermitSlowAcquireMetricName = MetricName.builder()
            .safeName("conjure-java-client.qos.request-permit.slow-acquire")
            .putSafeTags("libraryName", LIBRARY_NAME)
            .putSafeTags("libraryVersion", LIBRARY_VERSION)
            .putSafeTags("javaVersion", JAVA_VERSION)
            .build();

    private static final MetricName requestPermitLeakSuspectedMetricName = MetricName.builder()
            .safeName("conjure-java-client.qos.request-permit.leak-suspected")
            .putSafeTags("libraryName", LIBRARY_NAME)
            .putSafeTags("libraryVersion", LIBRARY_VERSION)
            .putSafeTags("javaVersion", JAVA_VERSION)
            .build();

    private final TaggedMetricRegistry registry;

    private ConjureJavaClientQosMetrics(TaggedMetricRegistry registry) {
        this.registry = registry;
    }

    static ConjureJavaClientQosMetrics of(TaggedMetricRegistry registry) {
        return new ConjureJavaClientQosMetrics(Preconditions.checkNotNull(registry, "TaggedMetricRegistry"));
    }

    /**
     * Timer representing how long it takes to acquire ConcurrencyLimiter permits. (<1ms acquisitions are considered successful, so not included in this 'slow-acquire' timer).
     * 

OkHttpClients acquire a ConcurrencyLimiter permit (scoped to each particular endpoint) to constrain the number of in-flight requests if the server is overloaded. * Any acquire that takes less than a millisecond is considered to be successful - this 'slow-acquire' timer measures any that take longer than a millisecond, * indicating that conjure-java-runtime is trying to avoid overloading a server.

*

See https://github.com/palantir/conjure-java-runtime#quality-of-service-retry-failover-throttling-backpressure

*/ @CheckReturnValue Timer requestPermitSlowAcquire() { return registry.timer(requestPermitSlowAcquireMetricName()); } static MetricName requestPermitSlowAcquireMetricName() { return requestPermitSlowAcquireMetricName; } /** * Meter indicating a client timed out waiting for a ConcurrencyLimiter permit, so the limiter was reset to avoid infinite waiting. * An associated WARN log line includes detailed information about the serviceClass, hostname, method, pathTemplate and timeout. */ @CheckReturnValue Meter requestPermitLeakSuspected() { return registry.meter(requestPermitLeakSuspectedMetricName()); } static MetricName requestPermitLeakSuspectedMetricName() { return requestPermitLeakSuspectedMetricName; } /** * Per serviceClass timer representing how long it takes to acquire ConcurrencyLimiter permits. (<1ms acquisitions are considered successful, so not included in this 'slow-acquire' timer). *

OkHttpClients acquire a ConcurrencyLimiter permit (scoped to each particular endpoint) to constrain the number of in-flight requests if the server is overloaded. * Any acquire that takes less than a millisecond is considered to be successful - this 'slow-acquire' timer measures any that take longer than a millisecond, * indicating that conjure-java-runtime is trying to avoid overloading a server.

*

See https://github.com/palantir/conjure-java-runtime#quality-of-service-retry-failover-throttling-backpressure

*/ @CheckReturnValue Timer requestPermitSlowAcquireTagged(@Safe String serviceClass) { return registry.timer(requestPermitSlowAcquireTaggedMetricName(serviceClass)); } static MetricName requestPermitSlowAcquireTaggedMetricName(@Safe String serviceClass) { return MetricName.builder() .safeName("conjure-java-client.qos.request-permit.slow-acquire-tagged") .putSafeTags("serviceClass", serviceClass) .putSafeTags("libraryName", LIBRARY_NAME) .putSafeTags("libraryVersion", LIBRARY_VERSION) .putSafeTags("javaVersion", JAVA_VERSION) .build(); } @Override public String toString() { return "ConjureJavaClientQosMetrics{registry=" + registry + '}'; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy