Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add MP metrics annotation support to MP REST clients #9534

Merged
merged 6 commits into from
Dec 2, 2024

Conversation

tjquinno
Copy link
Member

@tjquinno tjquinno commented Nov 26, 2024

Description

Resolves #6057

This PR allows users to use the MicroProfile metrics @Counted and @Timed annotations on MicroProfile REST client interfaces and interface methods by adding a dependency in their project on a new Helidon component.

Note that Helidon registers the metrics for a given REST client only once Helidon becomes aware of it which happens either when CDI produces that REST client or when an instance is created explicitly using the REST client builder approach. The metric registration can therefore occur after the app has started depending on how the app code is written to refer to REST clients.

Details

The PR adds a new Helidon component helidon-rest-client-metrics.

The CDI extension does these basic tasks:

  • Prepares the metrics registrations derived from the developer-provided annotations on REST client interfaces.
  • Registers the metrics for a given interface when that interface becomes known to Helidon as a REST client.
  • Encapsulates the metrics-related work required for each such metric before and after each outbound request through a REST client method.

The annotation scanning is pretty straightforward. It saves information about the metrics that will be needed for each REST client interface.

At runtime, when user code or CDI production creates a new REST client from an interface, the MP REST Client implementation calls back to a listener added in this PR. The listener:

  • registers the metrics associated with that interface in the MP MetricRegistry,
  • prepares a data structure containing "before" invocation and "after" invocation work which updates the metrics, and
  • adds a filter (also in this PR) to the REST client builder so the filter will be invoked whenever methods on that REST client are invoked.

When the filter is invoked, it basically delegates back to the CDI extension to perform the pre- and post-invocation metrics updating work.

Documentation

The PR includes extensive doc updates.

The existing REST client doc page is moved into a new restclient directory which is also where the new REST client metrics page now lives. Several pages with cross-references to the existing REST client page needed to be updated as well. Snippets moved as well.

The new REST client metrics page also has an extensive example discussion. There is no existing REST client example app and I have not at this point created one for REST client metrics. That would be a separate PR for the examples repo anyway.

@tjquinno tjquinno self-assigned this Nov 26, 2024
@oracle-contributor-agreement oracle-contributor-agreement bot added the OCA Verified All contributors have signed the Oracle Contributor Agreement. label Nov 26, 2024
Copy link
Member

@spericas spericas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@tjquinno tjquinno merged commit 42f8ce6 into helidon-io:main Dec 2, 2024
46 checks passed
@tjquinno tjquinno deleted the 4.x-mp-rest-client-metrics branch December 2, 2024 20:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
OCA Verified All contributors have signed the Oracle Contributor Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Helidon does not support MP metrics annotations on MP REST clients
2 participants