Correctly set clientId on EPP metrics in LoginFlow

This wasn't being recorded correctly because the clientId is only
set in LoginFlow after the flow succeeds, whereas we were
previously logging the clientId before executing the flow. This
adds special handling for LoginFlow. Note that we only set the
metric label to the clientId for valid registrar logins, to ensure
that metric cardinality doesn't grow unbounded (as it might if we
used every arbitrary string passed in as an attempted login).

This also refactors creation and handling of FakesAndMocksModule so
as to be able to make test assertions about EPP metrics from
integration flow tests.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=154048280
This commit is contained in:
mcilwain 2017-04-24 07:44:31 -07:00 committed by Ben McIlwain
parent 7dc3ddfc14
commit c1643fa3cd
7 changed files with 98 additions and 35 deletions

View file

@ -26,6 +26,7 @@ import com.google.common.net.MediaType;
import google.registry.config.RegistryConfig.ConfigModule.TmchCaMode;
import google.registry.flows.EppTestComponent.FakesAndMocksModule;
import google.registry.model.ofy.Ofy;
import google.registry.monitoring.whitebox.EppMetric;
import google.registry.testing.FakeClock;
import google.registry.testing.FakeHttpSession;
import google.registry.testing.FakeResponse;
@ -48,6 +49,7 @@ public class EppTestCase extends ShardableTestCase {
private SessionMetadata sessionMetadata;
private TransportCredentials credentials = new PasswordOnlyTransportCredentials();
private EppMetric.Builder eppMetricBuilder;
private boolean isSuperuser;
@Before
@ -114,8 +116,9 @@ public class EppTestCase extends ShardableTestCase {
EppRequestHandler handler = new EppRequestHandler();
FakeResponse response = new FakeResponse();
handler.response = response;
eppMetricBuilder = EppMetric.builderForRequest("request-id-1", clock);
handler.eppController = DaggerEppTestComponent.builder()
.fakesAndMocksModule(new FakesAndMocksModule(clock, TmchCaMode.PILOT))
.fakesAndMocksModule(FakesAndMocksModule.create(clock, TmchCaMode.PILOT, eppMetricBuilder))
.build()
.startRequest()
.eppController();
@ -133,4 +136,8 @@ public class EppTestCase extends ShardableTestCase {
EppXmlTransformer.validateOutput(result);
return result;
}
protected EppMetric getRecordedEppMetric() {
return eppMetricBuilder.build();
}
}