Only inject EPP metric builder in a single place

This fixes recording of number of attempts and command name on EPP
flows, which was broken because a separate metric builder was
being injected in two places, EppController and FlowRunner, with the
one injected into FlowRunner being discarded rather than having changes
applied to the same instance as in EppController.

This also adds a test that the metric is created successfully inside
a flow. Note that tests already exist for EppController to ensure that
the metric is recorded correctly.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=152306596
This commit is contained in:
mcilwain 2017-04-05 14:35:28 -07:00 committed by Ben McIlwain
parent 794743c7bc
commit 4606b1d08e
7 changed files with 58 additions and 36 deletions

View file

@ -62,12 +62,12 @@ public class FlowRunner {
@Inject @DryRun boolean isDryRun;
@Inject @Superuser boolean isSuperuser;
@Inject @Transactional boolean isTransactional;
@Inject EppMetric.Builder metric;
@Inject SessionMetadata sessionMetadata;
@Inject Trid trid;
@Inject FlowRunner() {}
public EppOutput run() throws EppException {
/** Runs the EPP flow, and records metrics on the given builder. */
public EppOutput run(final EppMetric.Builder eppMetricBuilder) throws EppException {
String prettyXml = prettyPrint(inputXmlBytes);
String xmlBase64 = base64().encode(inputXmlBytes);
// This log line is very fragile since it's used for ICANN reporting - DO NOT CHANGE.
@ -95,16 +95,16 @@ public class FlowRunner {
"xml", prettyXml,
"xmlBytes", xmlBase64,
"icannActivityReportField", extractActivityReportField(flowClass))));
metric.setCommandNameFromFlow(flowClass.getSimpleName());
eppMetricBuilder.setCommandNameFromFlow(flowClass.getSimpleName());
if (!isTransactional) {
metric.incrementAttempts();
eppMetricBuilder.incrementAttempts();
return EppOutput.create(flowProvider.get().run());
}
try {
return ofy().transact(new Work<EppOutput>() {
@Override
public EppOutput run() {
metric.incrementAttempts();
eppMetricBuilder.incrementAttempts();
try {
EppOutput output = EppOutput.create(flowProvider.get().run());
if (isDryRun) {