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

@ -163,4 +163,23 @@ public class FrontendMetricsTest {
.and()
.hasNoOtherValues();
}
@Test
public void testSuccess_registerQuotaRejections() {
String otherCertHash = "foobar1234X";
String remoteAddress = "127.0.0.1";
String otherProtocol = "other protocol";
metrics.registerQuotaRejection(PROTOCOL, CERT_HASH);
metrics.registerQuotaRejection(PROTOCOL, otherCertHash);
metrics.registerQuotaRejection(PROTOCOL, otherCertHash);
metrics.registerQuotaRejection(otherProtocol, remoteAddress);
assertThat(FrontendMetrics.quotaRejectionsCounter)
.hasValueForLabels(1, PROTOCOL, CERT_HASH)
.and()
.hasValueForLabels(2, PROTOCOL, otherCertHash)
.and()
.hasValueForLabels(1, otherProtocol, remoteAddress)
.and()
.hasNoOtherValues();
}
}