Class AbstractMetricCollectingInterceptor

java.lang.Object
io.micrometer.core.instrument.binder.grpc.AbstractMetricCollectingInterceptor
Direct Known Subclasses:
MetricCollectingClientInterceptor, MetricCollectingServerInterceptor

public abstract class AbstractMetricCollectingInterceptor extends Object
An abstract gRPC interceptor that will collect metrics.
Since:
1.7.0
  • Field Details

  • Constructor Details

    • AbstractMetricCollectingInterceptor

      protected AbstractMetricCollectingInterceptor(MeterRegistry registry)
      Creates a new gRPC interceptor that will collect metrics into the given MeterRegistry. This method won't use any customizers and will only initialize the OK status.
      Parameters:
      registry - The registry to use.
    • AbstractMetricCollectingInterceptor

      protected AbstractMetricCollectingInterceptor(MeterRegistry registry, UnaryOperator<Counter.Builder> counterCustomizer, UnaryOperator<Timer.Builder> timerCustomizer, io.grpc.Status.Code... eagerInitializedCodes)
      Creates a new gRPC interceptor that will collect metrics into the given MeterRegistry and uses the given customizers to configure the Counters and Timers.
      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, String name, 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, String name, 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

      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 a AbstractMetricCollectingInterceptor.MetricSet for 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

      protected AbstractMetricCollectingInterceptor.MetricSet newMetricsFor(io.grpc.MethodDescriptor<?,?> method)
      Creates a AbstractMetricCollectingInterceptor.MetricSet for 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

      protected abstract Counter newRequestCounterFor(io.grpc.MethodDescriptor<?,?> method)
      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

      protected abstract Counter newResponseCounterFor(io.grpc.MethodDescriptor<?,?> method)
      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 Function<io.grpc.Status.Code,Timer> asTimerFunction(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 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.