blob: cf758b58980e11e685bc56b0728769b2268bb235 [file] [log] [blame]
// Copyright (C) 2022 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package com.googlesource.gerrit.modules.cache.chroniclemap;
import com.google.gerrit.metrics.Counter0;
import com.google.gerrit.metrics.Description;
import com.google.gerrit.metrics.MetricMaker;
class ChronicleMapStoreMetrics {
private final String sanitizedName;
private final MetricMaker metricMaker;
private final String name;
private final Counter0 storePutFailures;
ChronicleMapStoreMetrics(String name, MetricMaker metricMaker) {
this.name = name;
this.sanitizedName = metricMaker.sanitizeMetricName(name);
this.metricMaker = metricMaker;
this.storePutFailures =
metricMaker.newCounter(
"cache/chroniclemap/store_put_failures_" + sanitizedName,
new Description(
"The number of errors caught when inserting entries in chronicle-map store: "
+ name)
.setCumulative()
.setUnit("errors"));
}
void incrementPutFailures() {
storePutFailures.increment();
}
<K, V> void registerCallBackMetrics(ChronicleMapStore<K, V> store) {
String PERCENTAGE_FREE_SPACE_METRIC =
"cache/chroniclemap/percentage_free_space_" + sanitizedName;
String REMAINING_AUTORESIZES_METRIC =
"cache/chroniclemap/remaining_autoresizes_" + sanitizedName;
String MAX_AUTORESIZES_METRIC = "cache/chroniclemap/max_autoresizes_" + sanitizedName;
metricMaker.newCallbackMetric(
PERCENTAGE_FREE_SPACE_METRIC,
Long.class,
new Description(
String.format("The amount of free space in the %s cache as a percentage", name)),
() -> (long) store.percentageFreeSpace());
metricMaker.newCallbackMetric(
REMAINING_AUTORESIZES_METRIC,
Integer.class,
new Description(
String.format(
"The number of times the %s cache can automatically expand its capacity", name)),
store::remainingAutoResizes);
metricMaker.newConstantMetric(
MAX_AUTORESIZES_METRIC,
store.maxAutoResizes(),
new Description(
String.format(
"The maximum number of times the %s cache can automatically expand its capacity",
name)));
}
}