mirror of
https://github.com/google/nomulus.git
synced 2025-05-13 16:07:15 +02:00
Record a version of EPP metrics with TLD for domain commands
Also fixes the issue that dry run EPP commands were incorrectly being reported on. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=171062984
This commit is contained in:
parent
7e68ffa16a
commit
302a27f0db
13 changed files with 283 additions and 61 deletions
|
@ -17,6 +17,7 @@ package google.registry.flows;
|
||||||
import static com.google.common.base.Strings.nullToEmpty;
|
import static com.google.common.base.Strings.nullToEmpty;
|
||||||
import static com.google.common.io.BaseEncoding.base64;
|
import static com.google.common.io.BaseEncoding.base64;
|
||||||
import static google.registry.flows.EppXmlTransformer.unmarshal;
|
import static google.registry.flows.EppXmlTransformer.unmarshal;
|
||||||
|
import static google.registry.flows.FlowReporter.extractTlds;
|
||||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||||
|
|
||||||
import com.google.common.annotations.VisibleForTesting;
|
import com.google.common.annotations.VisibleForTesting;
|
||||||
|
@ -89,6 +90,9 @@ public final class EppController {
|
||||||
}
|
}
|
||||||
if (!eppInput.getTargetIds().isEmpty()) {
|
if (!eppInput.getTargetIds().isEmpty()) {
|
||||||
eppMetricBuilder.setEppTarget(Joiner.on(',').join(eppInput.getTargetIds()));
|
eppMetricBuilder.setEppTarget(Joiner.on(',').join(eppInput.getTargetIds()));
|
||||||
|
if (eppInput.isDomainResourceType()) {
|
||||||
|
eppMetricBuilder.setTlds(extractTlds(eppInput.getTargetIds()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
EppOutput output = runFlowConvertEppErrors(flowComponentBuilder
|
EppOutput output = runFlowConvertEppErrors(flowComponentBuilder
|
||||||
.flowModule(new FlowModule.Builder()
|
.flowModule(new FlowModule.Builder()
|
||||||
|
@ -106,12 +110,14 @@ public final class EppController {
|
||||||
}
|
}
|
||||||
return output;
|
return output;
|
||||||
} finally {
|
} finally {
|
||||||
|
if (!isDryRun) {
|
||||||
EppMetric metric = eppMetricBuilder.build();
|
EppMetric metric = eppMetricBuilder.build();
|
||||||
bigQueryMetricsEnqueuer.export(metric);
|
bigQueryMetricsEnqueuer.export(metric);
|
||||||
eppMetrics.incrementEppRequests(metric);
|
eppMetrics.incrementEppRequests(metric);
|
||||||
eppMetrics.recordProcessingTime(metric);
|
eppMetrics.recordProcessingTime(metric);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** Runs an EPP flow and converts known exceptions into EPP error responses. */
|
/** Runs an EPP flow and converts known exceptions into EPP error responses. */
|
||||||
private EppOutput runFlowConvertEppErrors(FlowComponent flowComponent) {
|
private EppOutput runFlowConvertEppErrors(FlowComponent flowComponent) {
|
||||||
|
|
|
@ -14,6 +14,8 @@
|
||||||
|
|
||||||
package google.registry.flows;
|
package google.registry.flows;
|
||||||
|
|
||||||
|
import static google.registry.monitoring.metrics.EventMetric.DEFAULT_FITTER;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
import google.registry.monitoring.metrics.EventMetric;
|
import google.registry.monitoring.metrics.EventMetric;
|
||||||
import google.registry.monitoring.metrics.IncrementableMetric;
|
import google.registry.monitoring.metrics.IncrementableMetric;
|
||||||
|
@ -25,31 +27,57 @@ import javax.inject.Inject;
|
||||||
/** EPP Instrumentation. */
|
/** EPP Instrumentation. */
|
||||||
public class EppMetrics {
|
public class EppMetrics {
|
||||||
|
|
||||||
private static final ImmutableSet<LabelDescriptor> LABEL_DESCRIPTORS =
|
private static final ImmutableSet<LabelDescriptor> LABEL_DESCRIPTORS_BY_REGISTRAR =
|
||||||
ImmutableSet.of(
|
ImmutableSet.of(
|
||||||
LabelDescriptor.create("command", "The name of the command."),
|
LabelDescriptor.create("command", "The name of the command."),
|
||||||
LabelDescriptor.create("client_id", "The name of the client."),
|
LabelDescriptor.create("client_id", "The name of the client."),
|
||||||
LabelDescriptor.create("status", "The return status of the command."));
|
LabelDescriptor.create("status", "The return status of the command."));
|
||||||
|
|
||||||
private static final IncrementableMetric eppRequests =
|
private static final ImmutableSet<LabelDescriptor> LABEL_DESCRIPTORS_BY_TLD =
|
||||||
|
ImmutableSet.of(
|
||||||
|
LabelDescriptor.create("command", "The name of the command."),
|
||||||
|
LabelDescriptor.create("tld", "The TLD acted on by the command (if applicable)."),
|
||||||
|
LabelDescriptor.create("status", "The return status of the command."));
|
||||||
|
|
||||||
|
private static final IncrementableMetric eppRequestsByRegistrar =
|
||||||
MetricRegistryImpl.getDefault()
|
MetricRegistryImpl.getDefault()
|
||||||
.newIncrementableMetric(
|
.newIncrementableMetric(
|
||||||
"/epp/requests", "Count of EPP Requests", "count", LABEL_DESCRIPTORS);
|
"/epp/requests",
|
||||||
|
"Count of EPP Requests By Registrar",
|
||||||
|
"count",
|
||||||
|
LABEL_DESCRIPTORS_BY_REGISTRAR);
|
||||||
|
|
||||||
private static final EventMetric processingTime =
|
private static final IncrementableMetric eppRequestsByTld =
|
||||||
|
MetricRegistryImpl.getDefault()
|
||||||
|
.newIncrementableMetric(
|
||||||
|
"/epp/requests_by_tld",
|
||||||
|
"Count of EPP Requests By TLD",
|
||||||
|
"count",
|
||||||
|
LABEL_DESCRIPTORS_BY_TLD);
|
||||||
|
|
||||||
|
private static final EventMetric processingTimeByRegistrar =
|
||||||
MetricRegistryImpl.getDefault()
|
MetricRegistryImpl.getDefault()
|
||||||
.newEventMetric(
|
.newEventMetric(
|
||||||
"/epp/processing_time",
|
"/epp/processing_time",
|
||||||
"EPP Processing Time",
|
"EPP Processing Time By Registrar",
|
||||||
"milliseconds",
|
"milliseconds",
|
||||||
LABEL_DESCRIPTORS,
|
LABEL_DESCRIPTORS_BY_REGISTRAR,
|
||||||
EventMetric.DEFAULT_FITTER);
|
DEFAULT_FITTER);
|
||||||
|
|
||||||
|
private static final EventMetric processingTimeByTld =
|
||||||
|
MetricRegistryImpl.getDefault()
|
||||||
|
.newEventMetric(
|
||||||
|
"/epp/processing_time_by_tld",
|
||||||
|
"EPP Processing Time By TLD",
|
||||||
|
"milliseconds",
|
||||||
|
LABEL_DESCRIPTORS_BY_TLD,
|
||||||
|
DEFAULT_FITTER);
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public EppMetrics() {}
|
public EppMetrics() {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Increment a counter which tracks EPP requests.
|
* Increments the counters which tracks EPP requests.
|
||||||
*
|
*
|
||||||
* @see EppController
|
* @see EppController
|
||||||
* @see FlowRunner
|
* @see FlowRunner
|
||||||
|
@ -57,20 +85,21 @@ public class EppMetrics {
|
||||||
public void incrementEppRequests(EppMetric metric) {
|
public void incrementEppRequests(EppMetric metric) {
|
||||||
String eppStatusCode =
|
String eppStatusCode =
|
||||||
metric.getStatus().isPresent() ? String.valueOf(metric.getStatus().get().code) : "";
|
metric.getStatus().isPresent() ? String.valueOf(metric.getStatus().get().code) : "";
|
||||||
eppRequests.increment(
|
eppRequestsByRegistrar.increment(
|
||||||
metric.getCommandName().or(""),
|
metric.getCommandName().or(""), metric.getClientId().or(""), eppStatusCode);
|
||||||
metric.getClientId().or(""),
|
eppRequestsByTld.increment(
|
||||||
eppStatusCode);
|
metric.getCommandName().or(""), metric.getTld().or(""), eppStatusCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Record the server-side processing time for an EPP request. */
|
/** Records the server-side processing time for an EPP request. */
|
||||||
public void recordProcessingTime(EppMetric metric) {
|
public void recordProcessingTime(EppMetric metric) {
|
||||||
String eppStatusCode =
|
String eppStatusCode =
|
||||||
metric.getStatus().isPresent() ? String.valueOf(metric.getStatus().get().code) : "";
|
metric.getStatus().isPresent() ? String.valueOf(metric.getStatus().get().code) : "";
|
||||||
processingTime.record(
|
long processingTime =
|
||||||
metric.getEndTimestamp().getMillis() - metric.getStartTimestamp().getMillis(),
|
metric.getEndTimestamp().getMillis() - metric.getStartTimestamp().getMillis();
|
||||||
metric.getCommandName().or(""),
|
processingTimeByRegistrar.record(
|
||||||
metric.getClientId().or(""),
|
processingTime, metric.getCommandName().or(""), metric.getClientId().or(""), eppStatusCode);
|
||||||
eppStatusCode);
|
processingTimeByTld.record(
|
||||||
|
processingTime, metric.getCommandName().or(""), metric.getTld().or(""), eppStatusCode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,29 +65,32 @@ public class FlowReporter {
|
||||||
logger.infofmt(
|
logger.infofmt(
|
||||||
"%s: %s",
|
"%s: %s",
|
||||||
EPPINPUT_LOG_SIGNATURE,
|
EPPINPUT_LOG_SIGNATURE,
|
||||||
JSONValue.toJSONString(ImmutableMap.<String, Object>of(
|
JSONValue.toJSONString(
|
||||||
|
ImmutableMap.<String, Object>of(
|
||||||
"xml", prettyPrint(inputXmlBytes),
|
"xml", prettyPrint(inputXmlBytes),
|
||||||
"xmlBytes", base64().encode(inputXmlBytes))));
|
"xmlBytes", base64().encode(inputXmlBytes))));
|
||||||
// Explicitly log flow metadata separately from the EPP XML itself so that it stays compact
|
// Explicitly log flow metadata separately from the EPP XML itself so that it stays compact
|
||||||
// enough to be sure to fit in a single log entry (the XML part in rare cases could be long
|
// enough to be sure to fit in a single log entry (the XML part in rare cases could be long
|
||||||
// enough to overflow into multiple log entries, breaking routine parsing of the JSON format).
|
// enough to overflow into multiple log entries, breaking routine parsing of the JSON format).
|
||||||
String resourceType = eppInput.getResourceType().or("");
|
|
||||||
boolean isDomain = "domain".equals(resourceType);
|
|
||||||
String singleTargetId = eppInput.getSingleTargetId().or("");
|
String singleTargetId = eppInput.getSingleTargetId().or("");
|
||||||
ImmutableList<String> targetIds = eppInput.getTargetIds();
|
ImmutableList<String> targetIds = eppInput.getTargetIds();
|
||||||
logger.infofmt(
|
logger.infofmt(
|
||||||
"%s: %s",
|
"%s: %s",
|
||||||
METADATA_LOG_SIGNATURE,
|
METADATA_LOG_SIGNATURE,
|
||||||
JSONValue.toJSONString(new ImmutableMap.Builder<String, Object>()
|
JSONValue.toJSONString(
|
||||||
|
new ImmutableMap.Builder<String, Object>()
|
||||||
.put("serverTrid", trid.getServerTransactionId())
|
.put("serverTrid", trid.getServerTransactionId())
|
||||||
.put("clientId", clientId)
|
.put("clientId", clientId)
|
||||||
.put("commandType", eppInput.getCommandType())
|
.put("commandType", eppInput.getCommandType())
|
||||||
.put("resourceType", resourceType)
|
.put("resourceType", eppInput.getResourceType().or(""))
|
||||||
.put("flowClassName", flowClass.getSimpleName())
|
.put("flowClassName", flowClass.getSimpleName())
|
||||||
.put("targetId", singleTargetId)
|
.put("targetId", singleTargetId)
|
||||||
.put("targetIds", targetIds)
|
.put("targetIds", targetIds)
|
||||||
.put("tld", isDomain ? extractTld(singleTargetId).or("") : "")
|
.put(
|
||||||
.put("tlds", isDomain ? extractTlds(targetIds).asList() : EMPTY_LIST)
|
"tld", eppInput.isDomainResourceType() ? extractTld(singleTargetId).or("") : "")
|
||||||
|
.put(
|
||||||
|
"tlds",
|
||||||
|
eppInput.isDomainResourceType() ? extractTlds(targetIds).asList() : EMPTY_LIST)
|
||||||
.put("icannActivityReportField", extractActivityReportField(flowClass))
|
.put("icannActivityReportField", extractActivityReportField(flowClass))
|
||||||
.build()));
|
.build()));
|
||||||
}
|
}
|
||||||
|
@ -113,7 +116,7 @@ public class FlowReporter {
|
||||||
* Returns the set of unique results of {@link #extractTld} applied to each given domain name,
|
* Returns the set of unique results of {@link #extractTld} applied to each given domain name,
|
||||||
* excluding any absent results (i.e. cases where no TLD was detected).
|
* excluding any absent results (i.e. cases where no TLD was detected).
|
||||||
*/
|
*/
|
||||||
private static final ImmutableSet<String> extractTlds(Iterable<String> domainNames) {
|
public static final ImmutableSet<String> extractTlds(Iterable<String> domainNames) {
|
||||||
ImmutableSet.Builder<String> set = new ImmutableSet.Builder<>();
|
ImmutableSet.Builder<String> set = new ImmutableSet.Builder<>();
|
||||||
for (String domainName : domainNames) {
|
for (String domainName : domainNames) {
|
||||||
Optional<String> extractedTld = extractTld(domainName);
|
Optional<String> extractedTld = extractTld(domainName);
|
||||||
|
|
|
@ -111,6 +111,11 @@ public class EppInput extends ImmutableObject {
|
||||||
return Optional.absent();
|
return Optional.absent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Returns whether this EppInput represents a command that operates on domain resources. */
|
||||||
|
public boolean isDomainResourceType() {
|
||||||
|
return getResourceType().or("").equals("domain");
|
||||||
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private ResourceCommand getResourceCommand() {
|
private ResourceCommand getResourceCommand() {
|
||||||
InnerCommand innerCommand = commandWrapper.getCommand();
|
InnerCommand innerCommand = commandWrapper.getCommand();
|
||||||
|
|
|
@ -68,6 +68,11 @@ public final class Counter extends AbstractMetric<Long>
|
||||||
*/
|
*/
|
||||||
private final Striped<Lock> valueLocks = Striped.lock(DEFAULT_CONCURRENCY_LEVEL);
|
private final Striped<Lock> valueLocks = Striped.lock(DEFAULT_CONCURRENCY_LEVEL);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a new Counter.
|
||||||
|
*
|
||||||
|
* <p>Note that the order of the labels is significant.
|
||||||
|
*/
|
||||||
Counter(
|
Counter(
|
||||||
String name,
|
String name,
|
||||||
String description,
|
String description,
|
||||||
|
|
|
@ -42,6 +42,11 @@ public final class MetricRegistryImpl implements MetricRegistry {
|
||||||
return INSTANCE;
|
return INSTANCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new event metric.
|
||||||
|
*
|
||||||
|
* <p>Note that the order of the labels is significant.
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public EventMetric newEventMetric(
|
public EventMetric newEventMetric(
|
||||||
String name,
|
String name,
|
||||||
|
@ -57,6 +62,11 @@ public final class MetricRegistryImpl implements MetricRegistry {
|
||||||
return metric;
|
return metric;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new gauge metric.
|
||||||
|
*
|
||||||
|
* <p>Note that the order of the labels is significant.
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
@CanIgnoreReturnValue
|
@CanIgnoreReturnValue
|
||||||
public <V> Metric<V> newGauge(
|
public <V> Metric<V> newGauge(
|
||||||
|
@ -75,6 +85,11 @@ public final class MetricRegistryImpl implements MetricRegistry {
|
||||||
return metric;
|
return metric;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new settable metric.
|
||||||
|
*
|
||||||
|
* <p>Note that the order of the labels is significant.
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public <V> SettableMetric<V> newSettableMetric(
|
public <V> SettableMetric<V> newSettableMetric(
|
||||||
String name,
|
String name,
|
||||||
|
@ -90,6 +105,11 @@ public final class MetricRegistryImpl implements MetricRegistry {
|
||||||
return metric;
|
return metric;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new incrementable metric.
|
||||||
|
*
|
||||||
|
* <p>Note that the order of the labels is significant.
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public IncrementableMetric newIncrementableMetric(
|
public IncrementableMetric newIncrementableMetric(
|
||||||
String name,
|
String name,
|
||||||
|
|
|
@ -22,8 +22,11 @@ import com.google.auto.value.AutoValue;
|
||||||
import com.google.common.base.Optional;
|
import com.google.common.base.Optional;
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
import com.google.common.collect.ImmutableSet;
|
||||||
|
import com.google.common.collect.Iterables;
|
||||||
import google.registry.bigquery.BigqueryUtils.FieldType;
|
import google.registry.bigquery.BigqueryUtils.FieldType;
|
||||||
import google.registry.model.eppoutput.Result.Code;
|
import google.registry.model.eppoutput.Result.Code;
|
||||||
|
import google.registry.model.registry.Registries;
|
||||||
import google.registry.util.Clock;
|
import google.registry.util.Clock;
|
||||||
import org.joda.time.DateTime;
|
import org.joda.time.DateTime;
|
||||||
|
|
||||||
|
@ -43,6 +46,7 @@ public abstract class EppMetric implements BigQueryMetric {
|
||||||
new TableFieldSchema().setName("endTime").setType(FieldType.TIMESTAMP.name()),
|
new TableFieldSchema().setName("endTime").setType(FieldType.TIMESTAMP.name()),
|
||||||
new TableFieldSchema().setName("commandName").setType(FieldType.STRING.name()),
|
new TableFieldSchema().setName("commandName").setType(FieldType.STRING.name()),
|
||||||
new TableFieldSchema().setName("clientId").setType(FieldType.STRING.name()),
|
new TableFieldSchema().setName("clientId").setType(FieldType.STRING.name()),
|
||||||
|
new TableFieldSchema().setName("tld").setType(FieldType.STRING.name()),
|
||||||
new TableFieldSchema().setName("privilegeLevel").setType(FieldType.STRING.name()),
|
new TableFieldSchema().setName("privilegeLevel").setType(FieldType.STRING.name()),
|
||||||
new TableFieldSchema().setName("eppTarget").setType(FieldType.STRING.name()),
|
new TableFieldSchema().setName("eppTarget").setType(FieldType.STRING.name()),
|
||||||
new TableFieldSchema().setName("eppStatus").setType(FieldType.INTEGER.name()),
|
new TableFieldSchema().setName("eppStatus").setType(FieldType.INTEGER.name()),
|
||||||
|
@ -58,6 +62,8 @@ public abstract class EppMetric implements BigQueryMetric {
|
||||||
|
|
||||||
public abstract Optional<String> getClientId();
|
public abstract Optional<String> getClientId();
|
||||||
|
|
||||||
|
public abstract Optional<String> getTld();
|
||||||
|
|
||||||
public abstract Optional<String> getPrivilegeLevel();
|
public abstract Optional<String> getPrivilegeLevel();
|
||||||
|
|
||||||
public abstract Optional<String> getEppTarget();
|
public abstract Optional<String> getEppTarget();
|
||||||
|
@ -88,6 +94,7 @@ public abstract class EppMetric implements BigQueryMetric {
|
||||||
// Populate optional values, if present
|
// Populate optional values, if present
|
||||||
addOptional("commandName", getCommandName(), map);
|
addOptional("commandName", getCommandName(), map);
|
||||||
addOptional("clientId", getClientId(), map);
|
addOptional("clientId", getClientId(), map);
|
||||||
|
addOptional("tld", getTld(), map);
|
||||||
addOptional("privilegeLevel", getPrivilegeLevel(), map);
|
addOptional("privilegeLevel", getPrivilegeLevel(), map);
|
||||||
addOptional("eppTarget", getEppTarget(), map);
|
addOptional("eppTarget", getEppTarget(), map);
|
||||||
if (getStatus().isPresent()) {
|
if (getStatus().isPresent()) {
|
||||||
|
@ -155,6 +162,37 @@ public abstract class EppMetric implements BigQueryMetric {
|
||||||
|
|
||||||
public abstract Builder setClientId(Optional<String> clientId);
|
public abstract Builder setClientId(Optional<String> clientId);
|
||||||
|
|
||||||
|
public abstract Builder setTld(String tld);
|
||||||
|
|
||||||
|
public abstract Builder setTld(Optional<String> tld);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the single TLD field from a list of TLDs associated with a command.
|
||||||
|
*
|
||||||
|
* <p>Due to cardinality reasons we cannot record combinations of different TLDs as might be
|
||||||
|
* seen in a domain check command, so if this happens we record "_various" instead. We also
|
||||||
|
* record "_invalid" for a TLD that does not exist in our system, as again that could blow up
|
||||||
|
* cardinality. Underscore prefixes are used for these sentinel values so that they cannot be
|
||||||
|
* confused with actual TLDs, which cannot start with underscores.
|
||||||
|
*/
|
||||||
|
public Builder setTlds(ImmutableSet<String> tlds) {
|
||||||
|
switch (tlds.size()) {
|
||||||
|
case 0:
|
||||||
|
setTld(Optional.<String>absent());
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
String tld = Iterables.getOnlyElement(tlds);
|
||||||
|
// Only record TLDs that actually exist, otherwise we can blow up cardinality by recording
|
||||||
|
// an arbitrarily large number of strings.
|
||||||
|
setTld(Optional.fromNullable(Registries.getTlds().contains(tld) ? tld : "_invalid"));
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
setTld("_various");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public abstract Builder setPrivilegeLevel(String privilegeLevel);
|
public abstract Builder setPrivilegeLevel(String privilegeLevel);
|
||||||
|
|
||||||
public abstract Builder setEppTarget(String eppTarget);
|
public abstract Builder setEppTarget(String eppTarget);
|
||||||
|
|
|
@ -17,13 +17,16 @@ package google.registry.flows;
|
||||||
import static com.google.common.io.BaseEncoding.base64;
|
import static com.google.common.io.BaseEncoding.base64;
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
import static google.registry.flows.EppXmlTransformer.marshal;
|
import static google.registry.flows.EppXmlTransformer.marshal;
|
||||||
|
import static google.registry.testing.DatastoreHelper.createTld;
|
||||||
import static google.registry.testing.LogsSubject.assertAboutLogs;
|
import static google.registry.testing.LogsSubject.assertAboutLogs;
|
||||||
import static google.registry.testing.TestDataHelper.loadFileWithSubstitutions;
|
import static google.registry.testing.TestDataHelper.loadFileWithSubstitutions;
|
||||||
import static google.registry.testing.TestLogHandlerUtils.findFirstLogRecordWithMessagePrefix;
|
import static google.registry.testing.TestLogHandlerUtils.findFirstLogRecordWithMessagePrefix;
|
||||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||||
import static java.util.logging.Level.INFO;
|
import static java.util.logging.Level.INFO;
|
||||||
import static java.util.logging.Level.SEVERE;
|
import static java.util.logging.Level.SEVERE;
|
||||||
|
import static org.mockito.Matchers.eq;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
|
import static org.mockito.Mockito.verifyZeroInteractions;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import com.google.common.base.Splitter;
|
import com.google.common.base.Splitter;
|
||||||
|
@ -64,12 +67,12 @@ import org.mockito.runners.MockitoJUnitRunner;
|
||||||
public class EppControllerTest extends ShardableTestCase {
|
public class EppControllerTest extends ShardableTestCase {
|
||||||
|
|
||||||
@Rule
|
@Rule
|
||||||
public AppEngineRule appEngineRule = new AppEngineRule.Builder().build();
|
public AppEngineRule appEngineRule = new AppEngineRule.Builder().withDatastore().build();
|
||||||
|
|
||||||
@Mock SessionMetadata sessionMetadata;
|
@Mock SessionMetadata sessionMetadata;
|
||||||
@Mock TransportCredentials transportCredentials;
|
@Mock TransportCredentials transportCredentials;
|
||||||
@Mock EppMetrics eppMetrics;
|
@Mock EppMetrics eppMetrics;
|
||||||
@Mock BigQueryMetricsEnqueuer metricsEnqueuer;
|
@Mock BigQueryMetricsEnqueuer bigQueryMetricsEnqueuer;
|
||||||
@Mock FlowComponent.Builder flowComponentBuilder;
|
@Mock FlowComponent.Builder flowComponentBuilder;
|
||||||
@Mock FlowComponent flowComponent;
|
@Mock FlowComponent flowComponent;
|
||||||
@Mock FlowRunner flowRunner;
|
@Mock FlowRunner flowRunner;
|
||||||
|
@ -77,9 +80,9 @@ public class EppControllerTest extends ShardableTestCase {
|
||||||
@Mock EppResponse eppResponse;
|
@Mock EppResponse eppResponse;
|
||||||
@Mock Result result;
|
@Mock Result result;
|
||||||
|
|
||||||
private static final DateTime startTime = DateTime.parse("2016-09-01T00:00:00Z");
|
private static final DateTime START_TIME = DateTime.parse("2016-09-01T00:00:00Z");
|
||||||
|
|
||||||
private final Clock clock = new FakeClock(startTime);
|
private final Clock clock = new FakeClock(START_TIME);
|
||||||
private final TestLogHandler logHandler = new TestLogHandler();
|
private final TestLogHandler logHandler = new TestLogHandler();
|
||||||
|
|
||||||
private final String domainCreateXml =
|
private final String domainCreateXml =
|
||||||
|
@ -105,7 +108,7 @@ public class EppControllerTest extends ShardableTestCase {
|
||||||
eppController = new EppController();
|
eppController = new EppController();
|
||||||
eppController.eppMetricBuilder = EppMetric.builderForRequest("request-id-1", clock);
|
eppController.eppMetricBuilder = EppMetric.builderForRequest("request-id-1", clock);
|
||||||
when(flowRunner.run(eppController.eppMetricBuilder)).thenReturn(eppOutput);
|
when(flowRunner.run(eppController.eppMetricBuilder)).thenReturn(eppOutput);
|
||||||
eppController.bigQueryMetricsEnqueuer = metricsEnqueuer;
|
eppController.bigQueryMetricsEnqueuer = bigQueryMetricsEnqueuer;
|
||||||
eppController.flowComponentBuilder = flowComponentBuilder;
|
eppController.flowComponentBuilder = flowComponentBuilder;
|
||||||
eppController.eppMetrics = eppMetrics;
|
eppController.eppMetrics = eppMetrics;
|
||||||
eppController.serverTridProvider = new FakeServerTridProvider();
|
eppController.serverTridProvider = new FakeServerTridProvider();
|
||||||
|
@ -130,10 +133,10 @@ public class EppControllerTest extends ShardableTestCase {
|
||||||
new byte[0]);
|
new byte[0]);
|
||||||
|
|
||||||
ArgumentCaptor<EppMetric> metricCaptor = ArgumentCaptor.forClass(EppMetric.class);
|
ArgumentCaptor<EppMetric> metricCaptor = ArgumentCaptor.forClass(EppMetric.class);
|
||||||
verify(metricsEnqueuer).export(metricCaptor.capture());
|
verify(bigQueryMetricsEnqueuer).export(metricCaptor.capture());
|
||||||
EppMetric metric = metricCaptor.getValue();
|
EppMetric metric = metricCaptor.getValue();
|
||||||
assertThat(metric.getRequestId()).isEqualTo("request-id-1");
|
assertThat(metric.getRequestId()).isEqualTo("request-id-1");
|
||||||
assertThat(metric.getStartTimestamp()).isEqualTo(startTime);
|
assertThat(metric.getStartTimestamp()).isEqualTo(START_TIME);
|
||||||
assertThat(metric.getEndTimestamp()).isEqualTo(clock.nowUtc());
|
assertThat(metric.getEndTimestamp()).isEqualTo(clock.nowUtc());
|
||||||
assertThat(metric.getClientId()).hasValue("some-client");
|
assertThat(metric.getClientId()).hasValue("some-client");
|
||||||
assertThat(metric.getPrivilegeLevel()).hasValue("NORMAL");
|
assertThat(metric.getPrivilegeLevel()).hasValue("NORMAL");
|
||||||
|
@ -141,7 +144,7 @@ public class EppControllerTest extends ShardableTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testHandleEppCommand_regularEppCommand_exportsMetric() throws Exception {
|
public void testHandleEppCommand_regularEppCommand_exportsBigQueryMetric() throws Exception {
|
||||||
eppController.handleEppCommand(
|
eppController.handleEppCommand(
|
||||||
sessionMetadata,
|
sessionMetadata,
|
||||||
transportCredentials,
|
transportCredentials,
|
||||||
|
@ -151,10 +154,10 @@ public class EppControllerTest extends ShardableTestCase {
|
||||||
domainCreateXml.getBytes(UTF_8));
|
domainCreateXml.getBytes(UTF_8));
|
||||||
|
|
||||||
ArgumentCaptor<EppMetric> metricCaptor = ArgumentCaptor.forClass(EppMetric.class);
|
ArgumentCaptor<EppMetric> metricCaptor = ArgumentCaptor.forClass(EppMetric.class);
|
||||||
verify(metricsEnqueuer).export(metricCaptor.capture());
|
verify(bigQueryMetricsEnqueuer).export(metricCaptor.capture());
|
||||||
EppMetric metric = metricCaptor.getValue();
|
EppMetric metric = metricCaptor.getValue();
|
||||||
assertThat(metric.getRequestId()).isEqualTo("request-id-1");
|
assertThat(metric.getRequestId()).isEqualTo("request-id-1");
|
||||||
assertThat(metric.getStartTimestamp()).isEqualTo(startTime);
|
assertThat(metric.getStartTimestamp()).isEqualTo(START_TIME);
|
||||||
assertThat(metric.getEndTimestamp()).isEqualTo(clock.nowUtc());
|
assertThat(metric.getEndTimestamp()).isEqualTo(clock.nowUtc());
|
||||||
assertThat(metric.getClientId()).hasValue("some-client");
|
assertThat(metric.getClientId()).hasValue("some-client");
|
||||||
assertThat(metric.getPrivilegeLevel()).hasValue("SUPERUSER");
|
assertThat(metric.getPrivilegeLevel()).hasValue("SUPERUSER");
|
||||||
|
@ -162,6 +165,46 @@ public class EppControllerTest extends ShardableTestCase {
|
||||||
assertThat(metric.getEppTarget()).hasValue("example.tld");
|
assertThat(metric.getEppTarget()).hasValue("example.tld");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testHandleEppCommand_regularEppCommand_exportsEppMetrics() throws Exception {
|
||||||
|
createTld("tld");
|
||||||
|
// Note that some of the EPP metric fields, like # of attempts and command name, are set in
|
||||||
|
// FlowRunner, not EppController, and since FlowRunner is mocked out for these tests they won't
|
||||||
|
// actually get values.
|
||||||
|
EppMetric.Builder metricBuilder =
|
||||||
|
EppMetric.builderForRequest("request-id-1", clock)
|
||||||
|
.setClientId("some-client")
|
||||||
|
.setEppTarget("example.tld")
|
||||||
|
.setStatus(Code.SUCCESS_WITH_NO_MESSAGES)
|
||||||
|
.setTld("tld")
|
||||||
|
.setPrivilegeLevel("SUPERUSER");
|
||||||
|
eppController.handleEppCommand(
|
||||||
|
sessionMetadata,
|
||||||
|
transportCredentials,
|
||||||
|
EppRequestSource.UNIT_TEST,
|
||||||
|
false,
|
||||||
|
true,
|
||||||
|
domainCreateXml.getBytes(UTF_8));
|
||||||
|
|
||||||
|
EppMetric expectedMetric = metricBuilder.build();
|
||||||
|
verify(eppMetrics).incrementEppRequests(eq(expectedMetric));
|
||||||
|
verify(eppMetrics).recordProcessingTime(eq(expectedMetric));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testHandleEppCommand_dryRunEppCommand_doesNotExportMetric() throws Exception {
|
||||||
|
eppController.handleEppCommand(
|
||||||
|
sessionMetadata,
|
||||||
|
transportCredentials,
|
||||||
|
EppRequestSource.UNIT_TEST,
|
||||||
|
true,
|
||||||
|
true,
|
||||||
|
domainCreateXml.getBytes(UTF_8));
|
||||||
|
|
||||||
|
verifyZeroInteractions(bigQueryMetricsEnqueuer);
|
||||||
|
verifyZeroInteractions(eppMetrics);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testHandleEppCommand_unmarshallableData_loggedAtInfo_withJsonData() throws Exception {
|
public void testHandleEppCommand_unmarshallableData_loggedAtInfo_withJsonData() throws Exception {
|
||||||
eppController.handleEppCommand(
|
eppController.handleEppCommand(
|
||||||
|
|
|
@ -50,6 +50,8 @@ public class EppLifecycleContactTest extends EppTestCase {
|
||||||
assertThat(getRecordedEppMetric())
|
assertThat(getRecordedEppMetric())
|
||||||
.hasClientId("NewRegistrar")
|
.hasClientId("NewRegistrar")
|
||||||
.and()
|
.and()
|
||||||
|
.hasNoTld()
|
||||||
|
.and()
|
||||||
.hasCommandName("ContactCreate")
|
.hasCommandName("ContactCreate")
|
||||||
.and()
|
.and()
|
||||||
.hasEppTarget("sh8013")
|
.hasEppTarget("sh8013")
|
||||||
|
|
|
@ -206,6 +206,8 @@ public class EppLifecycleDomainTest extends EppTestCase {
|
||||||
assertThat(getRecordedEppMetric())
|
assertThat(getRecordedEppMetric())
|
||||||
.hasClientId("NewRegistrar")
|
.hasClientId("NewRegistrar")
|
||||||
.and()
|
.and()
|
||||||
|
.hasNoTld()
|
||||||
|
.and()
|
||||||
.hasCommandName("Login")
|
.hasCommandName("Login")
|
||||||
.and()
|
.and()
|
||||||
.hasStatus(SUCCESS);
|
.hasStatus(SUCCESS);
|
||||||
|
@ -233,6 +235,8 @@ public class EppLifecycleDomainTest extends EppTestCase {
|
||||||
assertThat(getRecordedEppMetric())
|
assertThat(getRecordedEppMetric())
|
||||||
.hasClientId("NewRegistrar")
|
.hasClientId("NewRegistrar")
|
||||||
.and()
|
.and()
|
||||||
|
.hasTld("example")
|
||||||
|
.and()
|
||||||
.hasCommandName("DomainDelete")
|
.hasCommandName("DomainDelete")
|
||||||
.and()
|
.and()
|
||||||
.hasEppTarget("fakesite.example")
|
.hasEppTarget("fakesite.example")
|
||||||
|
@ -353,6 +357,8 @@ public class EppLifecycleDomainTest extends EppTestCase {
|
||||||
.and()
|
.and()
|
||||||
.hasEppTarget("rich.example")
|
.hasEppTarget("rich.example")
|
||||||
.and()
|
.and()
|
||||||
|
.hasTld("example")
|
||||||
|
.and()
|
||||||
.hasStatus(SUCCESS);
|
.hasStatus(SUCCESS);
|
||||||
|
|
||||||
assertCommandAndResponse("logout.xml", "logout_response.xml");
|
assertCommandAndResponse("logout.xml", "logout_response.xml");
|
||||||
|
|
|
@ -100,6 +100,8 @@ public class FlowReporterTest extends ShardableTestCase {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRecordToLogs_metadata_basic() throws Exception {
|
public void testRecordToLogs_metadata_basic() throws Exception {
|
||||||
|
when(flowReporter.eppInput.isDomainResourceType()).thenReturn(true);
|
||||||
|
when(flowReporter.eppInput.getResourceType()).thenReturn(Optional.of("domain"));
|
||||||
flowReporter.recordToLogs();
|
flowReporter.recordToLogs();
|
||||||
assertThat(parseJsonMap(findFirstLogMessageByPrefix(handler, "FLOW-LOG-SIGNATURE-METADATA: ")))
|
assertThat(parseJsonMap(findFirstLogMessageByPrefix(handler, "FLOW-LOG-SIGNATURE-METADATA: ")))
|
||||||
.containsExactly(
|
.containsExactly(
|
||||||
|
@ -136,6 +138,7 @@ public class FlowReporterTest extends ShardableTestCase {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRecordToLogs_metadata_notResourceFlow_noResourceTypeOrTld() throws Exception {
|
public void testRecordToLogs_metadata_notResourceFlow_noResourceTypeOrTld() throws Exception {
|
||||||
|
when(flowReporter.eppInput.isDomainResourceType()).thenReturn(false);
|
||||||
when(flowReporter.eppInput.getResourceType()).thenReturn(Optional.<String>absent());
|
when(flowReporter.eppInput.getResourceType()).thenReturn(Optional.<String>absent());
|
||||||
flowReporter.recordToLogs();
|
flowReporter.recordToLogs();
|
||||||
Map<String, Object> json =
|
Map<String, Object> json =
|
||||||
|
@ -148,6 +151,7 @@ public class FlowReporterTest extends ShardableTestCase {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRecordToLogs_metadata_notDomainFlow_noTld() throws Exception {
|
public void testRecordToLogs_metadata_notDomainFlow_noTld() throws Exception {
|
||||||
|
when(flowReporter.eppInput.isDomainResourceType()).thenReturn(false);
|
||||||
when(flowReporter.eppInput.getResourceType()).thenReturn(Optional.of("contact"));
|
when(flowReporter.eppInput.getResourceType()).thenReturn(Optional.of("contact"));
|
||||||
flowReporter.recordToLogs();
|
flowReporter.recordToLogs();
|
||||||
Map<String, Object> json =
|
Map<String, Object> json =
|
||||||
|
@ -159,6 +163,8 @@ public class FlowReporterTest extends ShardableTestCase {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRecordToLogs_metadata_multipartDomainName_multipartTld() throws Exception {
|
public void testRecordToLogs_metadata_multipartDomainName_multipartTld() throws Exception {
|
||||||
|
when(flowReporter.eppInput.isDomainResourceType()).thenReturn(true);
|
||||||
|
when(flowReporter.eppInput.getResourceType()).thenReturn(Optional.of("domain"));
|
||||||
when(flowReporter.eppInput.getSingleTargetId()).thenReturn(Optional.of("target.co.uk"));
|
when(flowReporter.eppInput.getSingleTargetId()).thenReturn(Optional.of("target.co.uk"));
|
||||||
when(flowReporter.eppInput.getTargetIds()).thenReturn(ImmutableList.of("target.co.uk"));
|
when(flowReporter.eppInput.getTargetIds()).thenReturn(ImmutableList.of("target.co.uk"));
|
||||||
flowReporter.recordToLogs();
|
flowReporter.recordToLogs();
|
||||||
|
@ -172,6 +178,7 @@ public class FlowReporterTest extends ShardableTestCase {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRecordToLogs_metadata_multipleTargetIds_uniqueTldSet() throws Exception {
|
public void testRecordToLogs_metadata_multipleTargetIds_uniqueTldSet() throws Exception {
|
||||||
|
when(flowReporter.eppInput.isDomainResourceType()).thenReturn(true);
|
||||||
when(flowReporter.eppInput.getSingleTargetId()).thenReturn(Optional.<String>absent());
|
when(flowReporter.eppInput.getSingleTargetId()).thenReturn(Optional.<String>absent());
|
||||||
when(flowReporter.eppInput.getTargetIds())
|
when(flowReporter.eppInput.getTargetIds())
|
||||||
.thenReturn(ImmutableList.of("target.co.uk", "foo.uk", "bar.uk", "baz.com"));
|
.thenReturn(ImmutableList.of("target.co.uk", "foo.uk", "bar.uk", "baz.com"));
|
||||||
|
@ -187,6 +194,7 @@ public class FlowReporterTest extends ShardableTestCase {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRecordToLogs_metadata_uppercaseDomainName_lowercaseTld() throws Exception {
|
public void testRecordToLogs_metadata_uppercaseDomainName_lowercaseTld() throws Exception {
|
||||||
|
when(flowReporter.eppInput.isDomainResourceType()).thenReturn(true);
|
||||||
when(flowReporter.eppInput.getSingleTargetId()).thenReturn(Optional.of("TARGET.FOO"));
|
when(flowReporter.eppInput.getSingleTargetId()).thenReturn(Optional.of("TARGET.FOO"));
|
||||||
when(flowReporter.eppInput.getTargetIds()).thenReturn(ImmutableList.of("TARGET.FOO"));
|
when(flowReporter.eppInput.getTargetIds()).thenReturn(ImmutableList.of("TARGET.FOO"));
|
||||||
flowReporter.recordToLogs();
|
flowReporter.recordToLogs();
|
||||||
|
@ -200,6 +208,7 @@ public class FlowReporterTest extends ShardableTestCase {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRecordToLogs_metadata_invalidDomainName_stillGuessesTld() throws Exception {
|
public void testRecordToLogs_metadata_invalidDomainName_stillGuessesTld() throws Exception {
|
||||||
|
when(flowReporter.eppInput.isDomainResourceType()).thenReturn(true);
|
||||||
when(flowReporter.eppInput.getSingleTargetId()).thenReturn(Optional.of("<foo@bar.com>"));
|
when(flowReporter.eppInput.getSingleTargetId()).thenReturn(Optional.of("<foo@bar.com>"));
|
||||||
when(flowReporter.eppInput.getTargetIds()).thenReturn(ImmutableList.of("<foo@bar.com>"));
|
when(flowReporter.eppInput.getTargetIds()).thenReturn(ImmutableList.of("<foo@bar.com>"));
|
||||||
flowReporter.recordToLogs();
|
flowReporter.recordToLogs();
|
||||||
|
@ -213,6 +222,7 @@ public class FlowReporterTest extends ShardableTestCase {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRecordToLogs_metadata_domainWithoutPeriod_noTld() throws Exception {
|
public void testRecordToLogs_metadata_domainWithoutPeriod_noTld() throws Exception {
|
||||||
|
when(flowReporter.eppInput.isDomainResourceType()).thenReturn(true);
|
||||||
when(flowReporter.eppInput.getSingleTargetId()).thenReturn(Optional.of("target,foo"));
|
when(flowReporter.eppInput.getSingleTargetId()).thenReturn(Optional.of("target,foo"));
|
||||||
when(flowReporter.eppInput.getTargetIds()).thenReturn(ImmutableList.of("target,foo"));
|
when(flowReporter.eppInput.getTargetIds()).thenReturn(ImmutableList.of("target,foo"));
|
||||||
flowReporter.recordToLogs();
|
flowReporter.recordToLogs();
|
||||||
|
|
|
@ -15,12 +15,15 @@
|
||||||
package google.registry.monitoring.whitebox;
|
package google.registry.monitoring.whitebox;
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
import static google.registry.testing.DatastoreHelper.createTld;
|
||||||
|
import static google.registry.testing.DatastoreHelper.createTlds;
|
||||||
|
|
||||||
import com.google.api.services.bigquery.model.TableFieldSchema;
|
import com.google.api.services.bigquery.model.TableFieldSchema;
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
import google.registry.model.eppoutput.Result.Code;
|
import google.registry.model.eppoutput.Result.Code;
|
||||||
import google.registry.testing.AppEngineRule;
|
import google.registry.testing.AppEngineRule;
|
||||||
|
import google.registry.testing.FakeClock;
|
||||||
import org.joda.time.DateTime;
|
import org.joda.time.DateTime;
|
||||||
import org.junit.Rule;
|
import org.junit.Rule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
@ -31,7 +34,45 @@ import org.junit.runners.JUnit4;
|
||||||
@RunWith(JUnit4.class)
|
@RunWith(JUnit4.class)
|
||||||
public class EppMetricTest {
|
public class EppMetricTest {
|
||||||
|
|
||||||
@Rule public final AppEngineRule appEngine = AppEngineRule.builder().build();
|
@Rule public final AppEngineRule appEngine = AppEngineRule.builder().withDatastore().build();
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test_invalidTld_isRecordedAsInvalid() throws Exception {
|
||||||
|
EppMetric metric =
|
||||||
|
EppMetric.builderForRequest("request-id-1", new FakeClock())
|
||||||
|
.setTlds(ImmutableSet.of("notarealtld"))
|
||||||
|
.build();
|
||||||
|
assertThat(metric.getTld()).hasValue("_invalid");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test_validTld_isRecorded() throws Exception {
|
||||||
|
createTld("example");
|
||||||
|
EppMetric metric =
|
||||||
|
EppMetric.builderForRequest("request-id-1", new FakeClock())
|
||||||
|
.setTlds(ImmutableSet.of("example"))
|
||||||
|
.build();
|
||||||
|
assertThat(metric.getTld()).hasValue("example");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test_multipleTlds_areRecordedAsVarious() throws Exception {
|
||||||
|
createTlds("foo", "bar");
|
||||||
|
EppMetric metric =
|
||||||
|
EppMetric.builderForRequest("request-id-1", new FakeClock())
|
||||||
|
.setTlds(ImmutableSet.of("foo", "bar", "baz"))
|
||||||
|
.build();
|
||||||
|
assertThat(metric.getTld()).hasValue("_various");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test_zeroTlds_areRecordedAsAbsent() throws Exception {
|
||||||
|
EppMetric metric =
|
||||||
|
EppMetric.builderForRequest("request-id-1", new FakeClock())
|
||||||
|
.setTlds(ImmutableSet.<String>of())
|
||||||
|
.build();
|
||||||
|
assertThat(metric.getTld()).isAbsent();
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetBigQueryRowEncoding_encodesCorrectly() throws Exception {
|
public void testGetBigQueryRowEncoding_encodesCorrectly() throws Exception {
|
||||||
|
@ -42,6 +83,7 @@ public class EppMetricTest {
|
||||||
.setEndTimestamp(new DateTime(1338))
|
.setEndTimestamp(new DateTime(1338))
|
||||||
.setCommandName("command")
|
.setCommandName("command")
|
||||||
.setClientId("client")
|
.setClientId("client")
|
||||||
|
.setTld("example")
|
||||||
.setPrivilegeLevel("level")
|
.setPrivilegeLevel("level")
|
||||||
.setEppTarget("target")
|
.setEppTarget("target")
|
||||||
.setStatus(Code.COMMAND_USE_ERROR)
|
.setStatus(Code.COMMAND_USE_ERROR)
|
||||||
|
@ -56,6 +98,7 @@ public class EppMetricTest {
|
||||||
.put("endTime", "1.338000")
|
.put("endTime", "1.338000")
|
||||||
.put("commandName", "command")
|
.put("commandName", "command")
|
||||||
.put("clientId", "client")
|
.put("clientId", "client")
|
||||||
|
.put("tld", "example")
|
||||||
.put("privilegeLevel", "level")
|
.put("privilegeLevel", "level")
|
||||||
.put("eppTarget", "target")
|
.put("eppTarget", "target")
|
||||||
.put("eppStatus", "2002")
|
.put("eppStatus", "2002")
|
||||||
|
@ -72,6 +115,7 @@ public class EppMetricTest {
|
||||||
.setEndTimestamp(new DateTime(1338))
|
.setEndTimestamp(new DateTime(1338))
|
||||||
.setCommandName("command")
|
.setCommandName("command")
|
||||||
.setClientId("client")
|
.setClientId("client")
|
||||||
|
.setTld("example")
|
||||||
.setPrivilegeLevel("level")
|
.setPrivilegeLevel("level")
|
||||||
.setEppTarget("target")
|
.setEppTarget("target")
|
||||||
.setStatus(Code.COMMAND_USE_ERROR)
|
.setStatus(Code.COMMAND_USE_ERROR)
|
||||||
|
|
|
@ -61,6 +61,17 @@ public class EppMetricSubject extends Subject<EppMetricSubject, EppMetric> {
|
||||||
return new And<>(this);
|
return new And<>(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public And<EppMetricSubject> hasTld(String tld) {
|
||||||
|
return hasValue(tld, actual().getTld(), "has tld");
|
||||||
|
}
|
||||||
|
|
||||||
|
public And<EppMetricSubject> hasNoTld() {
|
||||||
|
if (actual().getTld().isPresent()) {
|
||||||
|
fail("has no tld");
|
||||||
|
}
|
||||||
|
return new And<>(this);
|
||||||
|
}
|
||||||
|
|
||||||
private <E> And<EppMetricSubject> hasValue(E expected, Optional<E> actual, String verb) {
|
private <E> And<EppMetricSubject> hasValue(E expected, Optional<E> actual, String verb) {
|
||||||
checkArgumentNotNull(expected, "Expected value cannot be null");
|
checkArgumentNotNull(expected, "Expected value cannot be null");
|
||||||
if (actual == null) {
|
if (actual == null) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue