mirror of
https://github.com/google/nomulus.git
synced 2025-05-16 17:37:13 +02:00
Refactor EppMetrics into the EppMetric value type
This change refactors EppMetrics from the mutable self-exporting thing that it was into a real value type EppMetric, and delegates exporting functionality to the BigQueryMetricsEnqueuer. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=132387660
This commit is contained in:
parent
b77ebd1df9
commit
42a39b0ddc
16 changed files with 484 additions and 234 deletions
|
@ -25,7 +25,8 @@ import google.registry.model.eppoutput.EppOutput;
|
|||
import google.registry.model.eppoutput.EppResponse;
|
||||
import google.registry.model.eppoutput.Result;
|
||||
import google.registry.model.eppoutput.Result.Code;
|
||||
import google.registry.monitoring.whitebox.EppMetrics;
|
||||
import google.registry.monitoring.whitebox.BigQueryMetricsEnqueuer;
|
||||
import google.registry.monitoring.whitebox.EppMetric;
|
||||
import google.registry.util.Clock;
|
||||
import google.registry.util.FormattingLogger;
|
||||
import javax.inject.Inject;
|
||||
|
@ -41,7 +42,8 @@ public final class EppController {
|
|||
|
||||
@Inject Clock clock;
|
||||
@Inject FlowComponent.Builder flowComponentBuilder;
|
||||
@Inject EppMetrics metrics;
|
||||
@Inject EppMetric.Builder metric;
|
||||
@Inject BigQueryMetricsEnqueuer bigQueryMetricsEnqueuer;
|
||||
@Inject EppController() {}
|
||||
|
||||
/** Read EPP XML, execute the matching flow, and return an {@link EppOutput}. */
|
||||
|
@ -52,20 +54,20 @@ public final class EppController {
|
|||
boolean isDryRun,
|
||||
boolean isSuperuser,
|
||||
byte[] inputXmlBytes) {
|
||||
metrics.setClientId(sessionMetadata.getClientId());
|
||||
metrics.setPrivilegeLevel(isSuperuser ? "SUPERUSER" : "NORMAL");
|
||||
metric.setClientId(sessionMetadata.getClientId());
|
||||
metric.setPrivilegeLevel(isSuperuser ? "SUPERUSER" : "NORMAL");
|
||||
try {
|
||||
EppInput eppInput;
|
||||
try {
|
||||
eppInput = unmarshal(EppInput.class, inputXmlBytes);
|
||||
} catch (EppException e) {
|
||||
// Send the client an error message, with no clTRID since we couldn't unmarshal it.
|
||||
metrics.setEppStatus(e.getResult().getCode());
|
||||
metric.setStatus(e.getResult().getCode());
|
||||
return getErrorResponse(clock, e.getResult(), Trid.create(null));
|
||||
}
|
||||
metrics.setCommandName(eppInput.getCommandName());
|
||||
metric.setCommandName(eppInput.getCommandName());
|
||||
if (!eppInput.getTargetIds().isEmpty()) {
|
||||
metrics.setEppTarget(Joiner.on(',').join(eppInput.getTargetIds()));
|
||||
metric.setEppTarget(Joiner.on(',').join(eppInput.getTargetIds()));
|
||||
}
|
||||
EppOutput output = runFlowConvertEppErrors(flowComponentBuilder
|
||||
.flowModule(new FlowModule.Builder()
|
||||
|
@ -79,11 +81,11 @@ public final class EppController {
|
|||
.build())
|
||||
.build());
|
||||
if (output.isResponse()) {
|
||||
metrics.setEppStatus(output.getResponse().getResult().getCode());
|
||||
metric.setStatus(output.getResponse().getResult().getCode());
|
||||
}
|
||||
return output;
|
||||
} finally {
|
||||
metrics.export();
|
||||
bigQueryMetricsEnqueuer.export(metric.build());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@ import google.registry.flows.FlowModule.Transactional;
|
|||
import google.registry.model.eppcommon.Trid;
|
||||
import google.registry.model.eppinput.EppInput;
|
||||
import google.registry.model.eppoutput.EppOutput;
|
||||
import google.registry.monitoring.whitebox.EppMetrics;
|
||||
import google.registry.monitoring.whitebox.EppMetric;
|
||||
import google.registry.util.Clock;
|
||||
import google.registry.util.FormattingLogger;
|
||||
import javax.annotation.Nullable;
|
||||
|
@ -67,7 +67,7 @@ public class FlowRunner {
|
|||
@Inject @DryRun boolean isDryRun;
|
||||
@Inject @Superuser boolean isSuperuser;
|
||||
@Inject @Transactional boolean isTransactional;
|
||||
@Inject EppMetrics metrics;
|
||||
@Inject EppMetric.Builder metric;
|
||||
@Inject SessionMetadata sessionMetadata;
|
||||
@Inject Trid trid;
|
||||
@Inject FlowRunner() {}
|
||||
|
@ -100,7 +100,7 @@ public class FlowRunner {
|
|||
"xml", prettyXml,
|
||||
"xmlBytes", xmlBase64)));
|
||||
if (!isTransactional) {
|
||||
metrics.incrementAttempts();
|
||||
metric.incrementAttempts();
|
||||
return createAndInitFlow(clock.nowUtc()).run();
|
||||
}
|
||||
// We log the command in a structured format. Note that we do this before the transaction;
|
||||
|
@ -111,20 +111,24 @@ public class FlowRunner {
|
|||
.add("privileges", isSuperuser ? "SUPERUSER" : "NORMAL")
|
||||
.add("xmlBytes", xmlBase64));
|
||||
try {
|
||||
EppOutput flowResult = ofy().transact(new Work<EppOutput>() {
|
||||
@Override
|
||||
public EppOutput run() {
|
||||
metrics.incrementAttempts();
|
||||
try {
|
||||
EppOutput output = createAndInitFlow(ofy().getTransactionTime()).run();
|
||||
if (isDryRun) {
|
||||
throw new DryRunException(output);
|
||||
}
|
||||
return output;
|
||||
} catch (EppException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}});
|
||||
EppOutput flowResult =
|
||||
ofy()
|
||||
.transact(
|
||||
new Work<EppOutput>() {
|
||||
@Override
|
||||
public EppOutput run() {
|
||||
metric.incrementAttempts();
|
||||
try {
|
||||
EppOutput output = createAndInitFlow(ofy().getTransactionTime()).run();
|
||||
if (isDryRun) {
|
||||
throw new DryRunException(output);
|
||||
}
|
||||
return output;
|
||||
} catch (EppException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
});
|
||||
logger.info("EPP_Mutation_Committed " + new JsonLogStatement(trid)
|
||||
.add("createdRepoId", flowResult.getResponse().getCreatedRepoId())
|
||||
.add("executionTime", flowResult.getResponse().getExecutionTime().getMillis()));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue