Class AbstractMetricCollectingInterceptor
java.lang.Object
io.micrometer.core.instrument.binder.grpc.AbstractMetricCollectingInterceptor
- Direct Known Subclasses:
MetricCollectingClientInterceptor,MetricCollectingServerInterceptor
public abstract class AbstractMetricCollectingInterceptor
extends java.lang.Object
An abstract gRPC interceptor that will collect metrics.
- Since:
- 1.7.0
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static classAbstractMetricCollectingInterceptor.MetricSetContainer for all metrics of a certain call. -
Field Summary
Fields Modifier and Type Field Description protected java.util.function.UnaryOperator<Counter.Builder>counterCustomizerprotected io.grpc.Status.Code[]eagerInitializedCodesprotected MeterRegistryregistryprotected java.util.function.UnaryOperator<Timer.Builder>timerCustomizer -
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractMetricCollectingInterceptor(MeterRegistry registry)Creates a new gRPC interceptor that will collect metrics into the givenMeterRegistry.protectedAbstractMetricCollectingInterceptor(MeterRegistry registry, java.util.function.UnaryOperator<Counter.Builder> counterCustomizer, java.util.function.UnaryOperator<Timer.Builder> timerCustomizer, io.grpc.Status.Code... eagerInitializedCodes)Creates a new gRPC interceptor that will collect metrics into the givenMeterRegistryand uses the given customizers to configure theCounters andTimers. -
Method Summary
Modifier and Type Method Description protected java.util.function.Function<io.grpc.Status.Code,Timer>asTimerFunction(java.util.function.Supplier<Timer.Builder> timerTemplate)Creates a new timer function using the given template.protected AbstractMetricCollectingInterceptor.MetricSetmetricsFor(io.grpc.MethodDescriptor<?,?> method)Gets or creates aAbstractMetricCollectingInterceptor.MetricSetfor the given gRPC method.protected AbstractMetricCollectingInterceptor.MetricSetnewMetricsFor(io.grpc.MethodDescriptor<?,?> method)Creates aAbstractMetricCollectingInterceptor.MetricSetfor the given gRPC method.protected abstract CounternewRequestCounterFor(io.grpc.MethodDescriptor<?,?> method)Creates a new request counter for the given method.protected abstract CounternewResponseCounterFor(io.grpc.MethodDescriptor<?,?> method)Creates a new response counter for the given method.protected abstract java.util.function.Function<io.grpc.Status.Code,Timer>newTimerFunction(io.grpc.MethodDescriptor<?,?> method)Creates a new function that returns a timer for a given code for the given method.protected static Counter.BuilderprepareCounterFor(io.grpc.MethodDescriptor<?,?> method, java.lang.String name, java.lang.String description)Creates a new counter builder for the given method.protected static Timer.BuilderprepareTimerFor(io.grpc.MethodDescriptor<?,?> method, java.lang.String name, java.lang.String description)Creates a new timer builder for the given method.voidpreregisterMethod(io.grpc.MethodDescriptor<?,?> method)Pre-registers the given method.voidpreregisterService(io.grpc.ServiceDescriptor service)Pre-registers the all methods provided by the given service.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Field Details
-
registry
-
counterCustomizer
-
timerCustomizer
-
eagerInitializedCodes
protected final io.grpc.Status.Code[] eagerInitializedCodes
-
-
Constructor Details
-
AbstractMetricCollectingInterceptor
Creates a new gRPC interceptor that will collect metrics into the givenMeterRegistry. This method won't use any customizers and will only initialize theOKstatus.- Parameters:
registry- The registry to use.
-
AbstractMetricCollectingInterceptor
protected AbstractMetricCollectingInterceptor(MeterRegistry registry, java.util.function.UnaryOperator<Counter.Builder> counterCustomizer, java.util.function.UnaryOperator<Timer.Builder> timerCustomizer, io.grpc.Status.Code... eagerInitializedCodes)Creates a new gRPC interceptor that will collect metrics into the givenMeterRegistryand uses the given customizers to configure theCounters andTimers.- Parameters:
registry- The registry to use.counterCustomizer- The unary function that can be used to customize the created counters.timerCustomizer- The unary function that can be used to customize the created timers.eagerInitializedCodes- The status codes that should be eager initialized.
-
-
Method Details
-
prepareCounterFor
protected static Counter.Builder prepareCounterFor(io.grpc.MethodDescriptor<?,?> method, java.lang.String name, java.lang.String description)Creates a new counter builder for the given method. By default the base unit will be messages.- Parameters:
method- The method the counter will be created for.name- The name of the counter to use.description- The description of the counter to use.- Returns:
- The newly created counter builder.
-
prepareTimerFor
protected static Timer.Builder prepareTimerFor(io.grpc.MethodDescriptor<?,?> method, java.lang.String name, java.lang.String description)Creates a new timer builder for the given method.- Parameters:
method- The method the timer will be created for.name- The name of the timer to use.description- The description of the timer to use.- Returns:
- The newly created timer builder.
-
preregisterService
public void preregisterService(io.grpc.ServiceDescriptor service)Pre-registers the all methods provided by the given service. This will initialize all default counters and timers for those methods.- Parameters:
service- The service to initialize the meters for.- See Also:
preregisterMethod(MethodDescriptor)
-
preregisterMethod
public void preregisterMethod(io.grpc.MethodDescriptor<?,?> method)Pre-registers the given method. This will initialize all default counters and timers for that method.- Parameters:
method- The method to initialize the meters for.
-
metricsFor
protected final AbstractMetricCollectingInterceptor.MetricSet metricsFor(io.grpc.MethodDescriptor<?,?> method)Gets or creates aAbstractMetricCollectingInterceptor.MetricSetfor the given gRPC method. This will initialize all default counters and timers for that method.- Parameters:
method- The method to get the metric set for.- Returns:
- The metric set for the given method.
- See Also:
newMetricsFor(MethodDescriptor)
-
newMetricsFor
protected AbstractMetricCollectingInterceptor.MetricSet newMetricsFor(io.grpc.MethodDescriptor<?,?> method)Creates aAbstractMetricCollectingInterceptor.MetricSetfor the given gRPC method. This will initialize all default counters and timers for that method.- Parameters:
method- The method to get the metric set for.- Returns:
- The newly created metric set for the given method.
-
newRequestCounterFor
Creates a new request counter for the given method.- Parameters:
method- The method to create the counter for.- Returns:
- The newly created request counter.
-
newResponseCounterFor
Creates a new response counter for the given method.- Parameters:
method- The method to create the counter for.- Returns:
- The newly created response counter.
-
asTimerFunction
protected java.util.function.Function<io.grpc.Status.Code,Timer> asTimerFunction(java.util.function.Supplier<Timer.Builder> timerTemplate)Creates a new timer function using the given template. This method initializes the default timers.- Parameters:
timerTemplate- The template to create the instances from.- Returns:
- The newly created function that returns a timer for a given code.
-
newTimerFunction
protected abstract java.util.function.Function<io.grpc.Status.Code,Timer> newTimerFunction(io.grpc.MethodDescriptor<?,?> method)Creates a new function that returns a timer for a given code for the given method.- Parameters:
method- The method to create the timer for.- Returns:
- The newly created function that returns a timer for a given code.
-