Skip to content

Commit 08a2dc1

Browse files
committed
use existing cache metrics for cache size
1 parent 0c3503a commit 08a2dc1

10 files changed

Lines changed: 78 additions & 23 deletions

File tree

core/src/main/java/org/apache/accumulo/core/clientImpl/ClientContext.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1198,18 +1198,19 @@ public MeterRegistry getMeterRegistry() {
11981198
return micrometer;
11991199
}
12001200

1201-
public void setMeterRegistry(MeterRegistry micrometer) {
1201+
public synchronized void setMeterRegistry(MeterRegistry micrometer) {
12021202
ensureOpen();
12031203
this.micrometer = micrometer;
1204-
getCaches();
1204+
if (caches != null) {
1205+
caches.registerMetrics(micrometer);
1206+
}
12051207
}
12061208

12071209
public synchronized Caches getCaches() {
12081210
ensureOpen();
12091211
if (caches == null) {
12101212
caches = Caches.getInstance();
1211-
if (micrometer != null
1212-
&& getConfiguration().getBoolean(Property.GENERAL_MICROMETER_CACHE_METRICS_ENABLED)) {
1213+
if (micrometer != null) {
12131214
caches.registerMetrics(micrometer);
12141215
}
12151216
}

core/src/main/java/org/apache/accumulo/core/conf/Property.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -352,9 +352,6 @@ temporary files (for example, when creating a pre-split table). \
352352
PropertyType.TIMEDURATION,
353353
"The maximum amount of time that a Scanner should wait before retrying a failed RPC.",
354354
"1.7.3"),
355-
GENERAL_MICROMETER_CACHE_METRICS_ENABLED("general.micrometer.cache.metrics.enabled", "false",
356-
PropertyType.BOOLEAN, "Enables Caffeine Cache metrics functionality using Micrometer.",
357-
"4.0.0"),
358355
GENERAL_MICROMETER_ENABLED("general.micrometer.enabled", "false", PropertyType.BOOLEAN,
359356
"Enables metrics collection and reporting functionality using Micrometer.", "2.1.0"),
360357
GENERAL_MICROMETER_JVM_METRICS_ENABLED("general.micrometer.jvm.metrics.enabled", "false",
@@ -1688,8 +1685,7 @@ public static boolean isValidTablePropertyKey(String key) {
16881685
GENERAL_IDLE_PROCESS_INTERVAL, GENERAL_MICROMETER_ENABLED,
16891686
GENERAL_MICROMETER_JVM_METRICS_ENABLED, GENERAL_MICROMETER_LOG_METRICS,
16901687
GENERAL_MICROMETER_FACTORY, GENERAL_SERVER_LOCK_VERIFICATION_INTERVAL,
1691-
GENERAL_CACHE_MANAGER_IMPL, GENERAL_MICROMETER_CACHE_METRICS_ENABLED,
1692-
GENERAL_LOW_MEM_DETECTOR_INTERVAL,
1688+
GENERAL_CACHE_MANAGER_IMPL, GENERAL_LOW_MEM_DETECTOR_INTERVAL,
16931689

16941690
// MANAGER options
16951691
MANAGER_THREADCHECK, MANAGER_FATE_METRICS_MIN_UPDATE_INTERVAL, MANAGER_METADATA_SUSPENDABLE,

core/src/main/java/org/apache/accumulo/core/metrics/Metric.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -258,9 +258,6 @@ public enum Metric {
258258
SCAN_BUSY_TIMEOUT_COUNT("accumulo.scan.busy.timeout.count", MetricType.FUNCTION_COUNTER,
259259
"Count of the scans where a busy timeout happened.", MetricDocSection.SCAN, "Scan Busy Count",
260260
null, NUMBER),
261-
SCAN_TABLETS_CACHED("accumulo.scan.tablet.cached", MetricType.GAUGE,
262-
"The number of tablets for which a scan server has cached metadata.", MetricDocSection.SCAN,
263-
"Tablets Cached", null, NUMBER),
264261

265262
// Scan Metrics
266263
SCAN_TIMES("accumulo.scan.times", MetricType.TIMER, "Scan session lifetime (creation to close).",
@@ -405,7 +402,11 @@ public enum Metric {
405402
MetricDocSection.GENERAL_SERVER, "Completed task", null, NUMBER),
406403
EXECUTOR_QUEUED("executor.queued", MetricType.GAUGE,
407404
"Task queued for a thread pool. Each thread pool emits this metric w/ a different tag.",
408-
MetricDocSection.GENERAL_SERVER, "Queued task", null, NUMBER);
405+
MetricDocSection.GENERAL_SERVER, "Queued task", null, NUMBER),
406+
407+
// Cache metrics
408+
CACHE_SIZE("cache.size", MetricType.GAUGE, "The current number of entries a cache has.",
409+
MetricDocSection.GENERAL_SERVER, "Cache size", null, NUMBER);
409410

410411
public enum MonitorCssClass {
411412
BYTES("big-size"),

server/base/src/main/java/org/apache/accumulo/server/AbstractServer.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,8 @@ public MetricResponse getMetrics(TInfo tinfo, TCredentials credentials) throws T
410410
registry.getMeters().forEach(m -> {
411411
if (m.getId().getName().startsWith("accumulo.")
412412
|| m.getId().getName().equals(Metric.EXECUTOR_COMPLETED.getName())
413-
|| m.getId().getName().equals(Metric.EXECUTOR_QUEUED.getName())) {
413+
|| m.getId().getName().equals(Metric.EXECUTOR_QUEUED.getName())
414+
|| m.getId().getName().equals(Metric.CACHE_SIZE.getName())) {
414415
if (!this.monitorMetricExclusions.contains(m.getId().getName())) {
415416
m.match(response::writeMeter, response::writeMeter, response::writeTimer,
416417
response::writeDistributionSummary, response::writeLongTaskTimer,
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* https://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.accumulo.monitor.next.views;
20+
21+
import java.util.List;
22+
import java.util.Map;
23+
24+
import com.google.common.base.Preconditions;
25+
import org.apache.accumulo.core.client.admin.servers.ServerId;
26+
import org.apache.accumulo.core.metrics.Metric;
27+
import org.apache.accumulo.core.metrics.flatbuffers.FMetric;
28+
import org.apache.accumulo.core.metrics.flatbuffers.FTag;
29+
import org.apache.accumulo.core.process.thrift.MetricResponse;
30+
import org.apache.accumulo.monitor.next.SystemInformation;
31+
32+
public class CacheSizeColumnFactory implements ColumnFactory {
33+
34+
private final String cacheName;
35+
private final TableData.Column column;
36+
37+
CacheSizeColumnFactory(String cacheName, String colHeader, String description) {
38+
this.cacheName = cacheName;
39+
Preconditions.checkState(Metric.CACHE_SIZE.getColumnClasses().length == 1);
40+
this.column = new TableData.Column(Metric.CACHE_SIZE.getName() + "_" + cacheName, colHeader,
41+
description, Metric.CACHE_SIZE.getColumnClasses()[0].getCssClass());
42+
}
43+
44+
@Override
45+
public TableData.Column getColumn() {
46+
return column;
47+
}
48+
49+
@Override
50+
public Object getRowData(ServerId sid, MetricResponse mr,
51+
Map<String,List<FMetric>> serverMetrics) {
52+
var tag = new FTag();
53+
for (var metric : serverMetrics.getOrDefault(Metric.CACHE_SIZE.getName(), List.of())) {
54+
for (int i = 0; i < metric.tagsLength(); i++) {
55+
metric.tags(tag, i);
56+
if ("cache".equals(tag.key()) && cacheName.equals(tag.value())) {
57+
return SystemInformation.getMetricValue(metric);
58+
}
59+
}
60+
}
61+
return null;
62+
}
63+
}

server/monitor/src/main/java/org/apache/accumulo/monitor/next/views/TableDataFactory.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,8 @@ private static void scanColumns(List<ColumnFactory> cols) {
266266
private static void scanServerColumns(List<ColumnFactory> cols) {
267267
commonColumns(cols);
268268
scanColumns(cols);
269-
cols.add(new MetricColumnFactory(Metric.SCAN_TABLETS_CACHED));
269+
cols.add(new CacheSizeColumnFactory(Metric.SCAN_TABLET_METADATA_CACHE.getName(),
270+
"Tablets Cached", "The number of tablets for which a scan server has cached metadata."));
270271
cols.add(new MetricColumnFactory(Metric.SCAN_RESERVATION_FILES));
271272
cols.add(new MetricColumnFactory(Metric.SCAN_BUSY_TIMEOUT_COUNT));
272273
cols.add(new TimerColumnFactory(Metric.SCAN_RESERVATION_TOTAL_TIMER));

server/tserver/src/main/java/org/apache/accumulo/tserver/ScanServerMetrics.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import static org.apache.accumulo.core.metrics.Metric.SCAN_RESERVATION_FILES;
2424
import static org.apache.accumulo.core.metrics.Metric.SCAN_RESERVATION_TOTAL_TIMER;
2525
import static org.apache.accumulo.core.metrics.Metric.SCAN_RESERVATION_WRITEOUT_TIMER;
26-
import static org.apache.accumulo.core.metrics.Metric.SCAN_TABLETS_CACHED;
2726
import static org.apache.accumulo.core.metrics.Metric.SCAN_TABLET_METADATA_CACHE;
2827

2928
import java.time.Duration;
@@ -76,10 +75,6 @@ public void registerMetrics(MeterRegistry registry) {
7675
.description(SCAN_RESERVATION_FILES.getDescription()).register(registry);
7776

7877
if (tabletMetadataCache != null) {
79-
Gauge
80-
.builder(SCAN_TABLETS_CACHED.getName(),
81-
() -> (double) tabletMetadataCache.estimatedSize())
82-
.description(SCAN_TABLETS_CACHED.getDescription()).register(registry);
8378
Preconditions.checkState(tabletMetadataCache.policy().isRecordingStats(),
8479
"Attempted to instrument cache that is not recording stats.");
8580
CaffeineCacheMetrics.monitor(registry, tabletMetadataCache,

test/src/main/java/org/apache/accumulo/test/compaction/BadCompactionServiceConfigIT.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@ public void configureMiniCluster(MiniAccumuloConfigImpl cfg, Configuration hadoo
9999
// that will be configured to push all metrics to the sink we started.
100100
cfg.setProperty(Property.GENERAL_MICROMETER_ENABLED, "true");
101101
cfg.setProperty(Property.GENERAL_MICROMETER_USER_TAGS, "tag1=value1,tag2=value2");
102-
cfg.setProperty(Property.GENERAL_MICROMETER_CACHE_METRICS_ENABLED, "true");
103102
cfg.setProperty(Property.GENERAL_MICROMETER_JVM_METRICS_ENABLED, "true");
104103
cfg.setProperty("general.custom.metrics.opts.logging.step", "10s");
105104
String clazzList = LoggingMeterRegistryFactory.class.getName() + ","

test/src/main/java/org/apache/accumulo/test/metrics/MetricsIT.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,6 @@ protected void configure(MiniAccumuloConfigImpl cfg, Configuration hadoopCoreSit
126126
// that will be configured to push all metrics to the sink we started.
127127
cfg.setProperty(Property.GENERAL_MICROMETER_ENABLED, "true");
128128
cfg.setProperty(Property.GENERAL_MICROMETER_USER_TAGS, "tag1=value1,tag2=value2");
129-
cfg.setProperty(Property.GENERAL_MICROMETER_CACHE_METRICS_ENABLED, "true");
130129
cfg.setProperty(Property.GENERAL_MICROMETER_JVM_METRICS_ENABLED, "true");
131130
cfg.setProperty("general.custom.metrics.opts.logging.step", "10s");
132131
String clazzList = LoggingMeterRegistryFactory.class.getName() + ","

test/src/main/java/org/apache/accumulo/test/metrics/MetricsThriftRpcIT.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ protected void configure(MiniAccumuloConfigImpl cfg, Configuration hadoopCoreSit
7171
cfg.setProperty(Property.MANAGER_FATE_METRICS_MIN_UPDATE_INTERVAL, "1s");
7272
cfg.setProperty(Property.GENERAL_MICROMETER_ENABLED, "true");
7373
cfg.setProperty(Property.GENERAL_MICROMETER_USER_TAGS, "tag1=value1,tag2=value2");
74-
cfg.setProperty(Property.GENERAL_MICROMETER_CACHE_METRICS_ENABLED, "true");
7574
cfg.setProperty(Property.GENERAL_MICROMETER_JVM_METRICS_ENABLED, "true");
7675
cfg.getClusterServerConfiguration().setNumDefaultCompactors(1);
7776
cfg.getClusterServerConfiguration().setNumDefaultScanServers(1);

0 commit comments

Comments
 (0)