Skip to content

Commit

Permalink
Change metric type of LocalCacheState from counter to gauge
Browse files Browse the repository at this point in the history
### What changes are proposed in this pull request?

Change metric type of LocalCacheState from counter to gauge.

### Why are the changes needed?

The type of LocalCacheState metric is not reasonable since the value of this metric is a enum type not an increasable value

### Does this PR introduce any user facing changes?

No

			pr-link: #18070
			change-id: cid-61037d3580e2f25f782e1c876ced0ecad5b312a4
  • Loading branch information
maobaolong authored Sep 8, 2023
1 parent 3d2eb7e commit 6a0e1c5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,8 @@ public static LocalCacheManager create(CacheManagerOptions options,
} else {
mTtlEnforcerExecutor = Optional.empty();
}
Metrics.registerGauges(mCacheSize, mPageMetaStore);
Metrics.registerGauges(mCacheSize, mPageMetaStore, mState);
mState.set(READ_ONLY);
Metrics.STATE.inc();
}

@Override
Expand Down Expand Up @@ -751,14 +750,12 @@ private void restoreOrInit(List<PageStoreDir> pageStoreDirs) throws IOException
} catch (IOException e) {
LOG.error("Cache is in NOT_IN_USE.");
mState.set(NOT_IN_USE);
Metrics.STATE.dec();
throw e;
}
}
}
LOG.info("Cache is in READ_WRITE.");
mState.set(READ_WRITE);
Metrics.STATE.inc();
}

private boolean restore(PageStoreDir pageStoreDir) {
Expand Down Expand Up @@ -1055,19 +1052,18 @@ private static final class Metrics {
*/
private static final Counter PUT_STORE_WRITE_NO_SPACE_ERRORS =
MetricsSystem.counter(MetricKey.CLIENT_CACHE_PUT_STORE_WRITE_NO_SPACE_ERRORS.getName());
/**
* State of the cache.
*/
private static final Counter STATE =
MetricsSystem.counter(MetricKey.CLIENT_CACHE_STATE.getName());

private static void registerGauges(long cacheSize, PageMetaStore pageMetaStore) {
private static void registerGauges(long cacheSize, PageMetaStore pageMetaStore,
AtomicReference<State> state) {
MetricsSystem.registerGaugeIfAbsent(
MetricsSystem.getMetricName(MetricKey.CLIENT_CACHE_SPACE_AVAILABLE.getName()),
() -> cacheSize - pageMetaStore.bytes());
MetricsSystem.registerGaugeIfAbsent(
MetricsSystem.getMetricName(MetricKey.CLIENT_CACHE_SPACE_USED.getName()),
pageMetaStore::bytes);
MetricsSystem.registerGaugeIfAbsent(
MetricsSystem.getMetricName(MetricKey.CLIENT_CACHE_STATE.getName()),
() -> state.get().getValue());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2531,7 +2531,7 @@ public static String getSyncMetricName(long mountId) {
public static final MetricKey CLIENT_CACHE_STATE =
new Builder("Client.CacheState")
.setDescription("State of the cache: 0 (NOT_IN_USE), 1 (READ_ONLY) and 2 (READ_WRITE)")
.setMetricType(MetricType.COUNTER)
.setMetricType(MetricType.GAUGE)
.setIsClusterAggregated(false)
.build();
public static final MetricKey CLIENT_META_DATA_CACHE_SIZE =
Expand Down

0 comments on commit 6a0e1c5

Please sign in to comment.