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:
mcilwain 2017-10-04 14:26:20 -07:00 committed by jianglai
parent 7e68ffa16a
commit 302a27f0db
13 changed files with 283 additions and 61 deletions

View file

@ -15,12 +15,15 @@
package google.registry.monitoring.whitebox;
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.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import google.registry.model.eppoutput.Result.Code;
import google.registry.testing.AppEngineRule;
import google.registry.testing.FakeClock;
import org.joda.time.DateTime;
import org.junit.Rule;
import org.junit.Test;
@ -31,7 +34,45 @@ import org.junit.runners.JUnit4;
@RunWith(JUnit4.class)
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
public void testGetBigQueryRowEncoding_encodesCorrectly() throws Exception {
@ -42,6 +83,7 @@ public class EppMetricTest {
.setEndTimestamp(new DateTime(1338))
.setCommandName("command")
.setClientId("client")
.setTld("example")
.setPrivilegeLevel("level")
.setEppTarget("target")
.setStatus(Code.COMMAND_USE_ERROR)
@ -56,6 +98,7 @@ public class EppMetricTest {
.put("endTime", "1.338000")
.put("commandName", "command")
.put("clientId", "client")
.put("tld", "example")
.put("privilegeLevel", "level")
.put("eppTarget", "target")
.put("eppStatus", "2002")
@ -72,6 +115,7 @@ public class EppMetricTest {
.setEndTimestamp(new DateTime(1338))
.setCommandName("command")
.setClientId("client")
.setTld("example")
.setPrivilegeLevel("level")
.setEppTarget("target")
.setStatus(Code.COMMAND_USE_ERROR)