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

More carefully handle re-creation of global meter registry #8389

Merged
merged 1 commit into from Feb 22, 2024

Conversation

tjquinno
Copy link
Member

@tjquinno tjquinno commented Feb 15, 2024

Description

Resolves #8382

The global meter registry can be reconfigured with new MetricsConfig even if it has been previously initialized.

This should be rare but can happen. In such cases, the Helidon metrics implementation using Micrometer did not remove previously-registered meters from the Micrometer meter registry. It just cleared out the Helidon data structures.

When Helidon creates a new meter registry, it automatically registers any pre-defined meters (such as the base metrics for various JVM quantities). The warnings reported in the issue resulted when Helidon, as it was registering the predefined meters for the new meter registry, unexpectedly found those meters already registered in the Micrometer meter registry because of the prior initialization of a prior global registry.

This PR does several things:

  1. When the global meter registry is reconfigured, Helidon now removes any previously-registered meters as part of closing the Helidon meter registry. This removes them from the Micrometer meter registry as well so when predefined meters are added again via the Helidon metrics API they do not already exist in the Micrometer registry.

  2. As an optimization, the code skips the reconfiguration of the global registry (and the removal and reregistration of predefined meters) if the MetricsConfig provided for the re-configuration is consistent with the MetricsConfig used when the previous global registry was created.

    As part of this optimization, the config setting for MetricsConfig is now marked as redundant so it is not used in the generated equals or hashCode methods. To decide if the previous and new MetricsConfig objects are consistent we don't care if the configuration objects (if any) are equal--just that the behavior induced by the MetricsConfig settings will be the same. For example, this can happen if one config instance explicitly sets values that happen to be the defaults there are used if the config node is MISSING.

  3. The warning message (and some other related ones not involved in this issue) used the Micrometer Meter.toString() which did not have a helpful implementation. Now those messages log the meter ID which is at least readable.

Documentation

Bug fix; no doc impact

@tjquinno tjquinno self-assigned this Feb 15, 2024
@oracle-contributor-agreement oracle-contributor-agreement bot added the OCA Verified All contributors have signed the Oracle Contributor Agreement. label Feb 15, 2024
@tjquinno tjquinno merged commit fbd5a2f into helidon-io:main Feb 22, 2024
12 checks passed
hrstoyanov pushed a commit to hrstoyanov/helidon that referenced this pull request Feb 23, 2024
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.

4.x: Metrics: WARNING Unexpected discovery of unknown previously-created meter
2 participants