mirror of
https://github.com/google/nomulus.git
synced 2025-05-13 16:07:15 +02:00
Add metric for lock life duration
------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=177070996
This commit is contained in:
parent
25b49c57cd
commit
38b2cb13bf
4 changed files with 70 additions and 12 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue