Skip to content

Skip registering Caffeine meters when statistics are not enabled - #5409

Merged
shakuzen merged 1 commit into
micrometer-metrics:mainfrom
izeye:gh-5408
Aug 30, 2024
Merged

shakuzen merged 1 commit into
micrometer-metrics:mainfrom
izeye:gh-5408

Conversation

@izeye

@izeye izeye commented Aug 29, 2024

Copy link
Copy Markdown
Contributor

This PR changes to skip registering Caffeine meters when statistics are not enabled.

This PR also fixes and improves GuavaCacheMetricsTest and CaffeineCacheMetricsTest.

Closes gh-5408

This commit also fixes and improves GuavaCacheMetricsTest and CaffeineCacheMetricsTest.

Closes micrometer-metricsgh-5408

private static final String DESCRIPTION_CACHE_GETS = "The number of times cache lookup methods have returned a cached (hit) or uncached (newly loaded or null) value (miss).";

static final long UNSUPPORTED = -1L;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'm not happy with this magic number to express an unsupported meter for the long primitive type but couldn't find a better way without breaking changes.

@shakuzen
shakuzen merged commit d14eac7 into micrometer-metrics:main Aug 30, 2024
@shakuzen shakuzen added enhancement A general enhancement module: micrometer-core An issue that is related to our core module instrumentation An issue that is related to instrumenting a component labels Aug 30, 2024
@shakuzen shakuzen added this to the 1.14.0-M3 milestone Aug 30, 2024
@izeye
izeye deleted the gh-5408 branch August 30, 2024 01:42
shakuzen pushed a commit that referenced this pull request Aug 10, 2026
* Skip registering JCache meters when statistics are not enabled

When a JCache cache is bound without statistics enabled, the registered
meters silently report zero, which is hard to diagnose. Detect this case
via CompleteConfiguration#isStatisticsEnabled() and skip registering the
stats-dependent meters; log a warning explaining how to enable
statistics. This mirrors what was done for Caffeine in gh-5402 and
gh-5409.

If the JCache provider does not expose CompleteConfiguration (the
configuration is null or getConfiguration() throws
IllegalArgumentException), assume statistics are enabled to avoid a
false-positive warning.

See gh-5066.

Signed-off-by: jewoodev <jewoos15@naver.com>

* Document that JCache statistics toggles are not tracked

JCacheMetrics checks whether statistics are enabled at construction time.
Runtime toggles via CacheManager#enableStatistics(...) are intentionally
not tracked, so metrics need to be rebound if statistics are enabled later.

Signed-off-by: jewoodev <jewoos15@naver.com>

---------

Signed-off-by: jewoodev <jewoos15@naver.com>
shakuzen pushed a commit that referenced this pull request Aug 24, 2026
)

Follow-up to gh-5402, gh-5409, and gh-7562 for HazelcastCacheMetrics.
When a Hazelcast `IMap` is bound without statistics enabled, the
registered meters silently report zero, which is hard to diagnose.
This change detects the stats-disabled state via
`MapConfig#isStatisticsEnabled()`, logs a warning explaining how to
enable statistics, and skips registering every stats-dependent meter,
including `cache.size` because it reads
`LocalMapStats#getOwnedEntryCount()` and is meaningless once
statistics are disabled.

See gh-5066

* Use Hazelcast `Config` to detect statistics

Avoid relying on Hazelcast internal SPI classes to inspect map
configuration. Add `Config`-based overloads that use the public API while
preserving the behavior of existing overloads.

---------

Signed-off-by: jewoodev <jewoos15@naver.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement A general enhancement instrumentation An issue that is related to instrumenting a component module: micrometer-core An issue that is related to our core module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Skip registering Caffeine meters when statistics are not enabled

2 participants