Register quota metrics in GCP proxy

When a quota request is rejected, increment the metric counter by one.

Also makes both frontend and backend metrics singleton because all the fields they have a static.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=185146804
This commit is contained in:
jianglai 2018-02-09 08:50:10 -08:00
parent c34e547659
commit ce5baafc4a
6 changed files with 137 additions and 15 deletions

View file

@ -31,10 +31,23 @@ import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import javax.inject.Inject;
import javax.inject.Singleton;
/** Frontend metrics instrumentation. */
@Singleton
public class FrontendMetrics {
/**
* Labels to register front metrics with.
*
* <p>The client certificate hash value is only used for EPP metrics. For WHOIS metrics, it will
* always be {@code "none"}. In order to get the actual registrar name, one can use the {@code
* nomulus} tool:
*
* <pre>
* nomulus -e production list_registrars -f clientCertificateHash | grep $HASH
* </pre>
*/
private static final ImmutableSet<LabelDescriptor> LABELS =
ImmutableSet.of(
LabelDescriptor.create("protocol", "Name of the protocol."),
@ -68,6 +81,14 @@ public class FrontendMetrics {
"Connections",
LABELS);
static final IncrementableMetric quotaRejectionsCounter =
MetricRegistryImpl.getDefault()
.newIncrementableMetric(
"/proxy/frontend/quota_rejections",
"Total number rejected quota request made by proxy for each connection.",
"Rejections",
LABELS);
@Inject
public FrontendMetrics() {}
@ -96,4 +117,9 @@ public class FrontendMetrics {
}
channelGroup.add(channel);
}
@NonFinalForTesting
public void registerQuotaRejection(String protocol, String certHash) {
quotaRejectionsCounter.increment(protocol, certHash);
}
}