com.github.mwiede:metrics-feign

A decorator wrapping Feign client method handlers in order to provide metrics of calls to feign target interfaces.

License

License

Categories

Categories

Feign Net HTTP Clients Metrics Application Testing & Monitoring Monitoring
GroupId

GroupId

com.github.mwiede
ArtifactId

ArtifactId

metrics-feign
Last Version

Last Version

3.0
Release Date

Release Date

Type

Type

jar
Description

Description

com.github.mwiede:metrics-feign
A decorator wrapping Feign client method handlers in order to provide metrics of calls to feign target interfaces.
Project URL

Project URL

https://github.com/mwiede/metrics-feign
Source Code Management

Source Code Management

https://github.com/mwiede/metrics-feign

Download metrics-feign

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.mwiede/metrics-feign/ -->
<dependency>
    <groupId>com.github.mwiede</groupId>
    <artifactId>metrics-feign</artifactId>
    <version>3.0</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.mwiede/metrics-feign/
implementation 'com.github.mwiede:metrics-feign:3.0'
// https://jarcasting.com/artifacts/com.github.mwiede/metrics-feign/
implementation ("com.github.mwiede:metrics-feign:3.0")
'com.github.mwiede:metrics-feign:jar:3.0'
<dependency org="com.github.mwiede" name="metrics-feign" rev="3.0">
  <artifact name="metrics-feign" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.mwiede', module='metrics-feign', version='3.0')
)
libraryDependencies += "com.github.mwiede" % "metrics-feign" % "3.0"
[com.github.mwiede/metrics-feign "3.0"]

Dependencies

compile (3)

Group / Artifact Type Version
io.dropwizard.metrics : metrics-core jar 4.1.2
io.dropwizard.metrics : metrics-annotation jar 4.1.2
io.github.openfeign : feign-core jar 10.12

test (4)

Group / Artifact Type Version
junit : junit jar 4.13.1
org.mockito : mockito-core jar 2.27.0
com.github.tomakehurst : wiremock jar 2.23.2
io.github.openfeign : feign-gson jar 10.12

Project Modules

There are no modules declared in this project.

metrics-feign travis status Maven Central

A decorator wrapping Feign client method handlers in order to provide Dropwizard Metrics of calls to feign target interfaces.

Usage with Feign 10

Feign offers Metrics4Capability, which gives basic metrics, but in order to use metric annotations, add com.github.mwiede.metrics.feign.AnnotionMetricsCapability like this:

  @Timed
  @Metered
  @ExceptionMetered
  @ResponseMetered
  interface GitHub {
    @RequestLine("GET /repos/{owner}/{repo}/contributors")
    List<Contributor> contributors(@Param("owner") String owner, @Param("repo") String repo);
  }

  static class Contributor {
    String login;
    int contributions;
  }

  public static void main(final String... args) {

    final MetricRegistry metricRegistry = SharedMetricRegistries.getOrCreate("feign");

    final ConsoleReporter reporter =
        ConsoleReporter.forRegistry(metricRegistry).convertRatesTo(TimeUnit.SECONDS)
            .convertDurationsTo(TimeUnit.MILLISECONDS).build();

    final GitHub github =
        Feign.builder().decoder(new GsonDecoder())
                .addCapability(new AnnotionMetricsCapability(metricRegistry))
            .target(GitHub.class, "https://api.github.com");
    try {
      // Fetch and print a list of the contributors to this library.
      final List<Contributor> contributors = github.contributors("mwiede", "metrics-feign");
      for (final Contributor contributor : contributors) {
        System.out.println(contributor.login + " (" + contributor.contributions + ")");
      }
    } finally {
      reporter.report();
    }
  }

Usage with Feign < 10.11

Basically you only have to replace Feign.builder() with FeignWithMetrics.builder(metricRegistry).

  @Timed
  @Metered
  @ExceptionMetered
  @ResponseMetered
  interface GitHub {
    @RequestLine("GET /repos/{owner}/{repo}/contributors")
    List<Contributor> contributors(@Param("owner") String owner, @Param("repo") String repo);
  }

  static class Contributor {
    String login;
    int contributions;
  }

  public static void main(final String... args) {

    final MetricRegistry metricRegistry = new MetricRegistry();

    final ConsoleReporter reporter =
        ConsoleReporter.forRegistry(metricRegistry).convertRatesTo(TimeUnit.SECONDS)
            .convertDurationsTo(TimeUnit.MILLISECONDS).build();

    final GitHub github =
        FeignWithMetrics.builder(metricRegistry).decoder(new GsonDecoder())
            .target(GitHub.class, "https://api.github.com");
    try {
      // Fetch and print a list of the contributors to this library.
      final List<Contributor> contributors = github.contributors("mwiede", "metrics-feign");
      for (final Contributor contributor : contributors) {
        System.out.println(contributor.login + " (" + contributor.contributions + ")");
      }
    } finally {
      reporter.report();
    }
  }

List of provided metrics

Based of the example above, the following metrics were registered and reported:

Meters

  • com.github.mwiede.metrics.example.Example$GitHub.contributors.1xx-responses
  • com.github.mwiede.metrics.example.Example$GitHub.contributors.2xx-responses
  • com.github.mwiede.metrics.example.Example$GitHub.contributors.3xx-responses
  • com.github.mwiede.metrics.example.Example$GitHub.contributors.4xx-responses
  • com.github.mwiede.metrics.example.Example$GitHub.contributors.5xx-responses
  • com.github.mwiede.metrics.example.Example$GitHub.contributors.Metered
  • com.github.mwiede.metrics.example.Example$GitHub.contributors.exceptions
  • com.github.mwiede.metrics.example.Example$GitHub.contributors.reAttempts.Metered
  • com.github.mwiede.metrics.example.Example$GitHub.contributors.retryExhausted.Metered

Timers

com.github.mwiede.metrics.example.Example$GitHub.contributors.Timed

Download

You can use this library via maven:

<dependency>
  <groupId>com.github.mwiede</groupId>
  <artifactId>metrics-feign</artifactId>
  <version>3.0</version>
</dependency>

Versions

Version
3.0
2.0
1.0