Add metric for lock life duration

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=177070996
This commit is contained in:
guyben 2017-11-27 14:20:36 -08:00 committed by jianglai
parent 25b49c57cd
commit 38b2cb13bf
4 changed files with 70 additions and 12 deletions

View file

@ -16,30 +16,57 @@ package google.registry.model.server;
import com.google.common.collect.ImmutableSet;
import google.registry.model.server.Lock.LockState;
import google.registry.monitoring.metrics.DistributionFitter;
import google.registry.monitoring.metrics.EventMetric;
import google.registry.monitoring.metrics.ExponentialFitter;
import google.registry.monitoring.metrics.IncrementableMetric;
import google.registry.monitoring.metrics.LabelDescriptor;
import google.registry.monitoring.metrics.MetricRegistryImpl;
import javax.annotation.Nullable;
import org.joda.time.Duration;
/** Metrics for lock contention. */
class LockMetrics {
private static final ImmutableSet<LabelDescriptor> LABEL_DESCRIPTORS =
private static final ImmutableSet<LabelDescriptor> REQUEST_LABEL_DESCRIPTORS =
ImmutableSet.of(
LabelDescriptor.create("tld", "TLD"),
LabelDescriptor.create("resource", "resource name"),
LabelDescriptor.create(
"state", "The existing lock state (before attempting to acquire)."));
private static final ImmutableSet<LabelDescriptor> RELEASE_LABEL_DESCRIPTORS =
ImmutableSet.of(
LabelDescriptor.create("tld", "TLD"),
LabelDescriptor.create("resource", "resource name"));
// Finer-grained fitter than the DEFAULT_FITTER, allows values between 10 and 10*2^20, which
// gives almost 3 hours.
private static final DistributionFitter EXPONENTIAL_FITTER =
ExponentialFitter.create(20, 2.0, 10.0);
private static final IncrementableMetric lockRequestsMetric =
MetricRegistryImpl.getDefault()
.newIncrementableMetric(
"/lock/acquire_lock_requests",
"Count of lock acquisition attempts",
"count",
LABEL_DESCRIPTORS);
REQUEST_LABEL_DESCRIPTORS);
void record(String resourceName, @Nullable String tld, LockState state) {
private static final EventMetric lockLifetimeMetric =
MetricRegistryImpl.getDefault()
.newEventMetric(
"/lock/lock_duration",
"Lock lifetime",
"milliseconds",
RELEASE_LABEL_DESCRIPTORS,
EXPONENTIAL_FITTER);
void recordAcquire(String resourceName, @Nullable String tld, LockState state) {
lockRequestsMetric.increment(String.valueOf(tld), resourceName, state.name());
}
void recordRelease(String resourceName, @Nullable String tld, Duration duration) {
lockLifetimeMetric.record(duration.getMillis(), String.valueOf(tld), resourceName);
}
}