Skip to content

Skip registering Hazelcast meters when statistics are not enabled#7568

Open
jewoodev wants to merge 1 commit into
micrometer-metrics:mainfrom
jewoodev:fix/5066-hazelcast-skip-meters-when-stats-disabled
Open

Skip registering Hazelcast meters when statistics are not enabled#7568
jewoodev wants to merge 1 commit into
micrometer-metrics:mainfrom
jewoodev:fix/5066-hazelcast-skip-meters-when-stats-disabled

Conversation

@jewoodev

@jewoodev jewoodev commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

Summary

Follow-up to gh-5402, gh-5409, and gh-7562 for HazelcastCacheMetrics. See gh-5066.

When a Hazelcast IMap is bound without statistics enabled, the registered meters silently report zero, which is hard to diagnose. This change mirrors the JCache pattern from gh-7562: detect the stats-disabled state via MapConfig#isStatisticsEnabled(), log a warning explaining how to enable statistics, and skip registering the stats-dependent meters (cache.size, cache.gets, cache.puts, cache.entries, cache.entry.memory, cache.partition.gets, the near-cache gauges, and the cache.gets.latency/cache.puts.latency/cache.removals.latency timers). cache.size is included because it reads LocalMapStats#getOwnedEntryCount(), which is meaningless once statistics are disabled.

HazelcastCacheMetrics accesses the cache through reflection via HazelcastIMapAdapter, so the new check is added as a reflection chain on the same adapter: AbstractDistributedObject#getNodeEngineNodeEngine#getConfigConfig#getMapConfig(name)MapConfig#isStatisticsEnabled. The first two classes are internal types whose package changed between Hazelcast 3.x (com.hazelcast.spi) and 4.x+ (com.hazelcast.spi.impl), so the adapter tries both variants in the same resolveOneOf style that the existing IMap/LocalMapStats/NearCacheStats resolution already uses. The check was verified against Hazelcast 5.3.8, the pinned optionalApi version. If any class or method in the chain cannot be resolved, or the chain throws at runtime, this assumes statistics are enabled to avoid a false-positive warning. This also keeps existing mock-based callers unaffected.

Status of other cache binders

Testing

  • New test HazelcastCacheMetricsTest#doNotReportMetricsWhenStatisticsAreDisabled registers a MapConfig with statistics disabled at instance startup, binds metrics to that IMap, and asserts both the warning is emitted and that cache.size, cache.gets, cache.puts, cache.entries, cache.entry.memory, cache.partition.gets, and the three latency timers are not registered. This is also what exercises the reflection chain on Hazelcast 5.3.8 end-to-end — the existing tests use default (enabled) statistics, where the chain returning true is indistinguishable from the fail-safe fallback.
  • Existing tests continue to pass without changes: they bind a Hazelcast IMap with default (enabled) statistics, so meters register as before.
  • ./gradlew :micrometer-core:check passes locally.

Follow-up to micrometer-metricsgh-5402, micrometer-metricsgh-5409, and micrometer-metricsgh-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.

The check is added as a reflection chain on `HazelcastIMapAdapter`
(`AbstractDistributedObject#getNodeEngine` -> `NodeEngine#getConfig`
-> `Config#getMapConfig(name)` -> `MapConfig#isStatisticsEnabled`).
The first two classes moved from `com.hazelcast.spi` (3.x) to
`com.hazelcast.spi.impl` (4.x+), so the adapter tries both variants
in the same `resolveOneOf` style already used for `IMap`,
`LocalMapStats`, and `NearCacheStats`. Verified against Hazelcast
5.3.8, the pinned `optionalApi` version. If any class or method
cannot be resolved or the chain throws at runtime, statistics are
assumed enabled to avoid false-positive warnings and to keep existing
mock-based callers unaffected.

See micrometer-metricsgh-5066

Signed-off-by: jewoodev <jewoos15@naver.com>
@shakuzen shakuzen added the blocked An issue that's blocked on an external project change label Jun 4, 2026
@shakuzen

shakuzen commented Jun 4, 2026

Copy link
Copy Markdown
Member

Thanks for the PR. We'll follow-up once we start merging things for 1.18

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

blocked An issue that's blocked on an external project change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Log a warning when instrumenting a cache that is not recording stats

2 participants