Prepare ICANN reporting for production

This originally started as a small change, but quickly grew into a major refactor as I realized the original parameter structure wasn't conducive to a cron task and manual re-runs.

The changes are as follows:
1. Adds DNS metrics to activity reports, thanks to Nick's work with the Zoneman Dremel -> #plx workflow.
2. Surrounds registrar names in transactions reports with quotes, to escape possible commas.
3. Factors out the report generation logic into IcannReportingStager.
4. Assigns default values to the three main parameters
  - yearMonth defaults to the previous month
  - subdir defaults to "icann/monthly/yearMonth", i.e. "gs://domain-registry-reporting/icann/monthly/yyyy-MM"
  - reportType defaults to both reports
5. Adds "Total" row generation logic to transactions reports
  - This was a previously overlooked requirement.
6. Adds "MANIFEST.txt" generation and upload logic.
  - The MANIFEST lists out which files need to be uploaded in the subdirectory.
7. Increases urlfetch timeout from 5s to 10s in backend tasks.
  - Backend tasks should be more latency tolerant anyway, and this reduces the number of incorrect timeouts we see for services like Bigquery which might take some time to respond.

TESTED=Extensive testing in alpha, and ran FOSS test.
TODO: send out an e-mail for report generation and upload, and add reporting to cron.xml

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=172738344
This commit is contained in:
larryruili 2017-10-19 07:02:22 -07:00 committed by jianglai
parent 06f0ec4f2f
commit f1c76d035f
39 changed files with 1092 additions and 589 deletions

View file

@ -15,7 +15,6 @@
package google.registry.reporting;
import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth8.assertThat;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
@ -30,7 +29,7 @@ public class ActivityReportingQueryBuilderTest {
private ActivityReportingQueryBuilder getQueryBuilder() {
ActivityReportingQueryBuilder queryBuilder = new ActivityReportingQueryBuilder();
queryBuilder.yearMonth = "2017-06";
queryBuilder.yearMonth = "2017-09";
queryBuilder.projectId = "domain-registry-alpha";
return queryBuilder;
}
@ -41,28 +40,28 @@ public class ActivityReportingQueryBuilderTest {
assertThat(queryBuilder.getReportQuery())
.isEqualTo(
"#standardSQL\nSELECT * FROM "
+ "`domain-registry-alpha.icann_reporting.activity_report_aggregation_201706`");
+ "`domain-registry-alpha.icann_reporting.activity_report_aggregation_201709`");
}
@Test
public void testIntermediaryQueryMatch() throws IOException {
ActivityReportingQueryBuilder queryBuilder = getQueryBuilder();
ImmutableList<String> queryNames =
ImmutableList<String> expectedQueryNames =
ImmutableList.of(
ActivityReportingQueryBuilder.REGISTRAR_OPERATING_STATUS,
ActivityReportingQueryBuilder.DNS_COUNTS,
ActivityReportingQueryBuilder.MONTHLY_LOGS,
ActivityReportingQueryBuilder.DNS_COUNTS,
ActivityReportingQueryBuilder.EPP_METRICS,
ActivityReportingQueryBuilder.WHOIS_COUNTS,
ActivityReportingQueryBuilder.ACTIVITY_REPORT_AGGREGATION);
ActivityReportingQueryBuilder queryBuilder = getQueryBuilder();
ImmutableMap<String, String> actualQueries = queryBuilder.getViewQueryMap();
for (String queryName : queryNames) {
String actualTableName = String.format("%s_201706", queryName);
for (String queryName : expectedQueryNames) {
String actualTableName = String.format("%s_201709", queryName);
String testFilename = String.format("%s_test.sql", queryName);
assertThat(actualQueries.get(actualTableName))
.isEqualTo(ReportingTestData.getString(testFilename));
}
}
}
}

View file

@ -18,7 +18,7 @@ import static com.google.common.net.MediaType.CSV_UTF_8;
import static com.google.common.net.MediaType.PLAIN_TEXT_UTF_8;
import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth.assertWithMessage;
import static com.google.common.truth.Truth8.assertThat;
import static google.registry.testing.DatastoreHelper.createTld;
import static java.nio.charset.StandardCharsets.UTF_8;
import com.google.api.client.http.LowLevelHttpRequest;
@ -29,11 +29,14 @@ import com.google.api.client.testing.http.MockLowLevelHttpResponse;
import com.google.api.client.util.Base64;
import com.google.api.client.util.StringUtils;
import com.google.common.io.ByteSource;
import google.registry.reporting.IcannReportingModule.ReportType;
import google.registry.request.HttpException.InternalServerErrorException;
import google.registry.testing.AppEngineRule;
import google.registry.testing.ExceptionRule;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
@ -46,9 +49,14 @@ public class IcannHttpReporterTest {
private static final ByteSource IIRDEA_GOOD_XML = ReportingTestData.get("iirdea_good.xml");
private static final ByteSource IIRDEA_BAD_XML = ReportingTestData.get("iirdea_bad.xml");
private static final byte[] FAKE_PAYLOAD = "test,csv\n1,2".getBytes(UTF_8);
private MockLowLevelHttpRequest mockRequest;
@Rule public final ExceptionRule thrown = new ExceptionRule();
@Rule public AppEngineRule appEngineRule = new AppEngineRule.Builder().withDatastore().build();
private MockHttpTransport createMockTransport (final ByteSource iirdeaResponse) {
return new MockHttpTransport() {
@Override
@ -69,7 +77,11 @@ public class IcannHttpReporterTest {
};
}
private static final byte[] FAKE_PAYLOAD = "test,csv\n1,2".getBytes(UTF_8);
@Before
public void setUp() {
createTld("test");
createTld("xn--abc123");
}
private IcannHttpReporter createReporter() {
IcannHttpReporter reporter = new IcannHttpReporter();
@ -83,7 +95,7 @@ public class IcannHttpReporterTest {
@Test
public void testSuccess() throws Exception {
IcannHttpReporter reporter = createReporter();
reporter.send(FAKE_PAYLOAD, "test", "2017-06", ReportType.TRANSACTIONS);
reporter.send(FAKE_PAYLOAD, "test-transactions-201706.csv");
assertThat(mockRequest.getUrl()).isEqualTo("https://fake-transactions.url/test/2017-06");
Map<String, List<String>> headers = mockRequest.getHeaders();
@ -94,15 +106,65 @@ public class IcannHttpReporterTest {
assertThat(headers.get("content-type")).containsExactly(CSV_UTF_8.toString());
}
@Test
public void testSuccess_internationalTld() throws Exception {
IcannHttpReporter reporter = createReporter();
reporter.send(FAKE_PAYLOAD, "xn--abc123-transactions-201706.csv");
assertThat(mockRequest.getUrl()).isEqualTo("https://fake-transactions.url/xn--abc123/2017-06");
Map<String, List<String>> headers = mockRequest.getHeaders();
String userPass = "xn--abc123_ry:fakePass";
String expectedAuth =
String.format("Basic %s", Base64.encodeBase64String(StringUtils.getBytesUtf8(userPass)));
assertThat(headers.get("authorization")).containsExactly(expectedAuth);
assertThat(headers.get("content-type")).containsExactly(CSV_UTF_8.toString());
}
@Test
public void testFail_BadIirdeaResponse() throws Exception {
IcannHttpReporter reporter = createReporter();
reporter.httpTransport = createMockTransport(IIRDEA_BAD_XML);
try {
reporter.send(FAKE_PAYLOAD, "test", "2017-06", ReportType.TRANSACTIONS);
reporter.send(FAKE_PAYLOAD, "test-transactions-201706.csv");
assertWithMessage("Expected InternalServerErrorException to be thrown").fail();
} catch (InternalServerErrorException expected) {
assertThat(expected).hasMessageThat().isEqualTo("The structure of the report is invalid.");
}
}
@Test
public void testFail_invalidFilename_nonSixDigitYearMonth() throws Exception {
thrown.expect(
IllegalArgumentException.class,
"Expected file format: tld-reportType-yyyyMM.csv, got test-transactions-20176.csv instead");
IcannHttpReporter reporter = createReporter();
reporter.send(FAKE_PAYLOAD, "test-transactions-20176.csv");
}
@Test
public void testFail_invalidFilename_notActivityOrTransactions() throws Exception {
thrown.expect(
IllegalArgumentException.class,
"Expected file format: tld-reportType-yyyyMM.csv, got test-invalid-201706.csv instead");
IcannHttpReporter reporter = createReporter();
reporter.send(FAKE_PAYLOAD, "test-invalid-201706.csv");
}
@Test
public void testFail_invalidFilename_invalidTldName() throws Exception {
thrown.expect(
IllegalArgumentException.class,
"Expected file format: tld-reportType-yyyyMM.csv, got n!-n-activity-201706.csv instead");
IcannHttpReporter reporter = createReporter();
reporter.send(FAKE_PAYLOAD, "n!-n-activity-201706.csv");
}
@Test
public void testFail_invalidFilename_tldDoesntExist() throws Exception {
thrown.expect(
IllegalArgumentException.class,
"TLD hello does not exist");
IcannHttpReporter reporter = createReporter();
reporter.send(FAKE_PAYLOAD, "hello-activity-201706.csv");
}
}

View file

@ -0,0 +1,97 @@
// Copyright 2017 The Nomulus Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package google.registry.reporting;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.mock;
import google.registry.reporting.IcannReportingModule.ReportType;
import google.registry.request.HttpException.BadRequestException;
import google.registry.testing.ExceptionRule;
import google.registry.testing.FakeClock;
import google.registry.util.Clock;
import java.util.Optional;
import javax.servlet.http.HttpServletRequest;
import org.joda.time.DateTime;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
/** Unit tests for {@link google.registry.reporting.IcannReportingModule}. */
@RunWith(JUnit4.class)
public class IcannReportingModuleTest {
HttpServletRequest req = mock(HttpServletRequest.class);
Clock clock;
@Rule public final ExceptionRule thrown = new ExceptionRule();
@Before
public void setUp() {
clock = new FakeClock(DateTime.parse("2017-07-01TZ"));
}
@Test
public void testEmptyYearMonth_returnsCurrentDate() {
assertThat(IcannReportingModule.provideYearMonth(Optional.empty(), clock)).isEqualTo("2017-06");
}
@Test
public void testGivenYearMonth_returnsThatMonth() {
assertThat(IcannReportingModule.provideYearMonth(Optional.of("2017-05"), clock))
.isEqualTo("2017-05");
}
@Test
public void testInvalidYearMonth_throwsException() {
thrown.expect(
BadRequestException.class, "yearMonth must be in yyyy-MM format, got 201705 instead");
IcannReportingModule.provideYearMonth(Optional.of("201705"), clock);
}
@Test
public void testEmptySubDir_returnsDefaultSubdir() {
assertThat(IcannReportingModule.provideSubdir(Optional.empty(), "2017-06"))
.isEqualTo("icann/monthly/2017-06");
}
@Test
public void testGivenSubdir_returnsManualSubdir() {
assertThat(IcannReportingModule.provideSubdir(Optional.of("manual/dir"), "2017-06"))
.isEqualTo("manual/dir");
}
@Test
public void testInvalidSubdir_throwsException() {
thrown.expect(
BadRequestException.class,
"subdir must not start or end with a \"/\", got /whoops instead.");
IcannReportingModule.provideSubdir(Optional.of("/whoops"), "2017-06");
}
@Test
public void testGivenReportType_returnsReportType() {
assertThat(IcannReportingModule.provideReportTypes(Optional.of(ReportType.ACTIVITY)))
.containsExactly(ReportType.ACTIVITY);
}
@Test
public void testNoReportType_returnsBothReportTypes() {
assertThat(IcannReportingModule.provideReportTypes(Optional.empty()))
.containsExactly(ReportType.ACTIVITY, ReportType.TRANSACTIONS);
}
}

View file

@ -0,0 +1,212 @@
// Copyright 2017 The Nomulus Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package google.registry.reporting;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.testing.GcsTestingUtils.readGcsFile;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import com.google.api.services.bigquery.model.TableFieldSchema;
import com.google.appengine.tools.cloudstorage.GcsFilename;
import com.google.appengine.tools.cloudstorage.GcsService;
import com.google.appengine.tools.cloudstorage.GcsServiceFactory;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableTable;
import com.google.common.util.concurrent.ListenableFuture;
import google.registry.bigquery.BigqueryConnection;
import google.registry.bigquery.BigqueryConnection.DestinationTable;
import google.registry.bigquery.BigqueryUtils.TableType;
import google.registry.gcs.GcsUtils;
import google.registry.reporting.IcannReportingModule.ReportType;
import google.registry.testing.AppEngineRule;
import google.registry.testing.FakeResponse;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
/** Unit tests for {@link google.registry.reporting.IcannReportingStager}. */
@RunWith(JUnit4.class)
public class IcannReportingStagerTest {
BigqueryConnection bigquery = mock(BigqueryConnection.class);
FakeResponse response = new FakeResponse();
GcsService gcsService = GcsServiceFactory.createGcsService();
@Rule
public final AppEngineRule appEngine = AppEngineRule.builder()
.withDatastore()
.withLocalModules()
.build();
private IcannReportingStager createStager() {
IcannReportingStager action = new IcannReportingStager();
ActivityReportingQueryBuilder activityBuilder = new ActivityReportingQueryBuilder();
activityBuilder.projectId = "test-project";
activityBuilder.yearMonth = "2017-06";
action.activityQueryBuilder = activityBuilder;
TransactionsReportingQueryBuilder transactionsBuilder = new TransactionsReportingQueryBuilder();
transactionsBuilder.projectId = "test-project";
transactionsBuilder.yearMonth = "2017-06";
action.transactionsQueryBuilder = transactionsBuilder;
action.reportingBucket = "test-bucket";
action.yearMonth = "2017-06";
action.subdir = "icann/monthly/2017-06";
action.bigquery = bigquery;
action.gcsUtils = new GcsUtils(gcsService, 1024);
return action;
}
private void setUpBigquery() {
when(bigquery.query(any(String.class), any(DestinationTable.class))).thenReturn(fakeFuture());
DestinationTable.Builder tableBuilder = new DestinationTable.Builder()
.datasetId("testdataset")
.type(TableType.TABLE)
.name("tablename")
.overwrite(true);
when(bigquery.buildDestinationTable(any(String.class))).thenReturn(tableBuilder);
}
@Test
public void testRunSuccess_activityReport() throws Exception {
setUpBigquery();
ImmutableTable<Integer, TableFieldSchema, Object> activityReportTable =
new ImmutableTable.Builder<Integer, TableFieldSchema, Object>()
.put(1, new TableFieldSchema().setName("tld"), "fooTld")
.put(1, new TableFieldSchema().setName("fooField"), "12")
.put(1, new TableFieldSchema().setName("barField"), "34")
.put(2, new TableFieldSchema().setName("tld"), "barTld")
.put(2, new TableFieldSchema().setName("fooField"), "56")
.put(2, new TableFieldSchema().setName("barField"), "78")
.build();
when(bigquery.queryToLocalTableSync(any(String.class))).thenReturn(activityReportTable);
IcannReportingStager stager = createStager();
stager.stageReports(ReportType.ACTIVITY);
String expectedReport1 = "fooField,barField\r\n12,34";
String expectedReport2 = "fooField,barField\r\n56,78";
byte[] generatedFile1 =
readGcsFile(
gcsService,
new GcsFilename("test-bucket/icann/monthly/2017-06", "fooTld-activity-201706.csv"));
assertThat(new String(generatedFile1, UTF_8)).isEqualTo(expectedReport1);
byte[] generatedFile2 =
readGcsFile(
gcsService,
new GcsFilename("test-bucket/icann/monthly/2017-06", "barTld-activity-201706.csv"));
assertThat(new String(generatedFile2, UTF_8)).isEqualTo(expectedReport2);
}
@Test
public void testRunSuccess_transactionsReport() throws Exception {
setUpBigquery();
/*
The fake table result looks like:
tld registrar iana field
1 fooTld reg1 123 10
2 fooTld reg2 456 20
3 barTld reg1 123 30
*/
ImmutableTable<Integer, TableFieldSchema, Object> transactionReportTable =
new ImmutableTable.Builder<Integer, TableFieldSchema, Object>()
.put(1, new TableFieldSchema().setName("tld"), "fooTld")
.put(1, new TableFieldSchema().setName("registrar"), "\"reg1\"")
.put(1, new TableFieldSchema().setName("iana"), "123")
.put(1, new TableFieldSchema().setName("field"), "10")
.put(2, new TableFieldSchema().setName("tld"), "fooTld")
.put(2, new TableFieldSchema().setName("registrar"), "\"reg2\"")
.put(2, new TableFieldSchema().setName("iana"), "456")
.put(2, new TableFieldSchema().setName("field"), "20")
.put(3, new TableFieldSchema().setName("tld"), "barTld")
.put(3, new TableFieldSchema().setName("registrar"), "\"reg1\"")
.put(3, new TableFieldSchema().setName("iana"), "123")
.put(3, new TableFieldSchema().setName("field"), "30")
.build();
when(bigquery.queryToLocalTableSync(any(String.class))).thenReturn(transactionReportTable);
IcannReportingStager stager = createStager();
stager.stageReports(ReportType.TRANSACTIONS);
String expectedReport1 =
"registrar,iana,field\r\n\"reg1\",123,10\r\n\"reg2\",456,20\r\nTotals,,30";
String expectedReport2 = "registrar,iana,field\r\n\"reg1\",123,30\r\nTotals,,30";
byte[] generatedFile1 =
readGcsFile(
gcsService,
new GcsFilename("test-bucket/icann/monthly/2017-06", "fooTld-transactions-201706.csv"));
assertThat(new String(generatedFile1, UTF_8)).isEqualTo(expectedReport1);
byte[] generatedFile2 =
readGcsFile(
gcsService,
new GcsFilename("test-bucket/icann/monthly/2017-06", "barTld-transactions-201706.csv"));
assertThat(new String(generatedFile2, UTF_8)).isEqualTo(expectedReport2);
}
@Test
public void testRunSuccess_createAndUploadManifest() throws Exception {
IcannReportingStager stager = createStager();
ImmutableList<String> filenames =
ImmutableList.of("fooTld-transactions-201706.csv", "barTld-activity-201706.csv");
stager.createAndUploadManifest(filenames);
String expectedManifest = "fooTld-transactions-201706.csv\nbarTld-activity-201706.csv\n";
byte[] generatedManifest =
readGcsFile(
gcsService, new GcsFilename("test-bucket/icann/monthly/2017-06", "MANIFEST.txt"));
assertThat(new String(generatedManifest, UTF_8)).isEqualTo(expectedManifest);
}
private ListenableFuture<DestinationTable> fakeFuture() {
return new ListenableFuture<DestinationTable>() {
@Override
public void addListener(Runnable runnable, Executor executor) {
// No-op
}
@Override
public boolean cancel(boolean mayInterruptIfRunning) {
return false;
}
@Override
public boolean isCancelled() {
return false;
}
@Override
public boolean isDone() {
return false;
}
@Override
public DestinationTable get() throws InterruptedException, ExecutionException {
return null;
}
@Override
public DestinationTable get(long timeout, TimeUnit unit)
throws InterruptedException, ExecutionException, TimeoutException {
return null;
}
};
}
}

View file

@ -14,32 +14,15 @@
package google.registry.reporting;
import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth8.assertThat;
import static google.registry.testing.GcsTestingUtils.readGcsFile;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import com.google.api.services.bigquery.model.TableFieldSchema;
import com.google.appengine.tools.cloudstorage.GcsFilename;
import com.google.appengine.tools.cloudstorage.GcsService;
import com.google.appengine.tools.cloudstorage.GcsServiceFactory;
import com.google.common.collect.ImmutableTable;
import com.google.common.util.concurrent.ListenableFuture;
import google.registry.bigquery.BigqueryConnection;
import google.registry.bigquery.BigqueryConnection.DestinationTable;
import google.registry.bigquery.BigqueryUtils.TableType;
import google.registry.gcs.GcsUtils;
import com.google.common.collect.ImmutableList;
import google.registry.reporting.IcannReportingModule.ReportType;
import google.registry.testing.AppEngineRule;
import google.registry.testing.FakeResponse;
import java.util.Optional;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
@ -51,9 +34,8 @@ import org.junit.runners.JUnit4;
@RunWith(JUnit4.class)
public class IcannReportingStagingActionTest {
BigqueryConnection bigquery = mock(BigqueryConnection.class);
FakeResponse response = new FakeResponse();
GcsService gcsService = GcsServiceFactory.createGcsService();
IcannReportingStager stager = mock(IcannReportingStager.class);
@Rule
public final AppEngineRule appEngine = AppEngineRule.builder()
@ -61,143 +43,36 @@ public class IcannReportingStagingActionTest {
.withLocalModules()
.build();
private IcannReportingStagingAction createAction(ReportType reportType) {
@Before
public void setUp() throws Exception {
when(stager.stageReports(ReportType.ACTIVITY)).thenReturn(ImmutableList.of("a", "b"));
when(stager.stageReports(ReportType.TRANSACTIONS)).thenReturn(ImmutableList.of("c", "d"));
}
private IcannReportingStagingAction createAction(ImmutableList<ReportType> reportingMode) {
IcannReportingStagingAction action = new IcannReportingStagingAction();
if (reportType == ReportType.ACTIVITY) {
ActivityReportingQueryBuilder activityBuilder = new ActivityReportingQueryBuilder();
activityBuilder.projectId = "test-project";
activityBuilder.yearMonth = "2017-06";
action.queryBuilder = activityBuilder;
} else {
TransactionsReportingQueryBuilder transactionsBuilder =
new TransactionsReportingQueryBuilder();
transactionsBuilder.projectId = "test-project";
transactionsBuilder.yearMonth = "2017-06";
action.queryBuilder = transactionsBuilder;
}
action.reportType = reportType;
action.reportingBucket = "test-bucket";
action.yearMonth = "2017-06";
action.subdir = Optional.empty();
action.bigquery = bigquery;
action.gcsUtils = new GcsUtils(gcsService, 1024);
action.reportTypes = reportingMode;
action.response = response;
action.stager = stager;
return action;
}
private void setUpBigquery() {
when(bigquery.query(any(String.class), any(DestinationTable.class))).thenReturn(fakeFuture());
DestinationTable.Builder tableBuilder = new DestinationTable.Builder()
.datasetId("testdataset")
.type(TableType.TABLE)
.name("tablename")
.overwrite(true);
when(bigquery.buildDestinationTable(any(String.class))).thenReturn(tableBuilder);
@Test
public void testActivityReportingMode_onlyStagesActivityReports() throws Exception {
IcannReportingStagingAction action = createAction(ImmutableList.of(ReportType.ACTIVITY));
action.run();
verify(stager).stageReports(ReportType.ACTIVITY);
verify(stager).createAndUploadManifest(ImmutableList.of("a", "b"));
}
@Test
public void testRunSuccess_activityReport() throws Exception {
setUpBigquery();
ImmutableTable<Integer, TableFieldSchema, Object> activityReportTable =
new ImmutableTable.Builder<Integer, TableFieldSchema, Object>()
.put(1, new TableFieldSchema().setName("tld"), "fooTld")
.put(1, new TableFieldSchema().setName("fooField"), "12")
.put(1, new TableFieldSchema().setName("barField"), "34")
.put(2, new TableFieldSchema().setName("tld"), "barTld")
.put(2, new TableFieldSchema().setName("fooField"), "56")
.put(2, new TableFieldSchema().setName("barField"), "78")
.build();
when(bigquery.queryToLocalTableSync(any(String.class))).thenReturn(activityReportTable);
IcannReportingStagingAction action = createAction(ReportType.ACTIVITY);
public void testAbsentReportingMode_stagesBothReports() throws Exception {
IcannReportingStagingAction action =
createAction(ImmutableList.of(ReportType.ACTIVITY, ReportType.TRANSACTIONS));
action.run();
String expectedReport1 = "fooField,barField\r\n12,34";
String expectedReport2 = "fooField,barField\r\n56,78";
byte[] generatedFile1 =
readGcsFile(
gcsService,
new GcsFilename("test-bucket/icann/monthly/2017-06", "fooTld-activity-201706.csv"));
assertThat(new String(generatedFile1, UTF_8)).isEqualTo(expectedReport1);
byte[] generatedFile2 =
readGcsFile(
gcsService,
new GcsFilename("test-bucket/icann/monthly/2017-06", "barTld-activity-201706.csv"));
assertThat(new String(generatedFile2, UTF_8)).isEqualTo(expectedReport2);
}
@Test
public void testRunSuccess_transactionsReport() throws Exception {
setUpBigquery();
/*
The fake table result looks like:
tld registrar field
1 fooTld reg1 10
2 fooTld reg2 20
3 barTld reg1 30
*/
ImmutableTable<Integer, TableFieldSchema, Object> transactionReportTable =
new ImmutableTable.Builder<Integer, TableFieldSchema, Object>()
.put(1, new TableFieldSchema().setName("tld"), "fooTld")
.put(1, new TableFieldSchema().setName("registrar"), "reg1")
.put(1, new TableFieldSchema().setName("field"), "10")
.put(2, new TableFieldSchema().setName("tld"), "fooTld")
.put(2, new TableFieldSchema().setName("registrar"), "reg2")
.put(2, new TableFieldSchema().setName("field"), "20")
.put(3, new TableFieldSchema().setName("tld"), "barTld")
.put(3, new TableFieldSchema().setName("registrar"), "reg1")
.put(3, new TableFieldSchema().setName("field"), "30")
.build();
when(bigquery.queryToLocalTableSync(any(String.class))).thenReturn(transactionReportTable);
IcannReportingStagingAction action = createAction(ReportType.TRANSACTIONS);
action.reportType = ReportType.TRANSACTIONS;
action.run();
String expectedReport1 = "registrar,field\r\nreg1,10\r\nreg2,20";
String expectedReport2 = "registrar,field\r\nreg1,30";
byte[] generatedFile1 =
readGcsFile(
gcsService,
new GcsFilename("test-bucket/icann/monthly/2017-06", "fooTld-transactions-201706.csv"));
assertThat(new String(generatedFile1, UTF_8)).isEqualTo(expectedReport1);
byte[] generatedFile2 =
readGcsFile(
gcsService,
new GcsFilename("test-bucket/icann/monthly/2017-06", "barTld-transactions-201706.csv"));
assertThat(new String(generatedFile2, UTF_8)).isEqualTo(expectedReport2);
}
private ListenableFuture<DestinationTable> fakeFuture() {
return new ListenableFuture<DestinationTable>() {
@Override
public void addListener(Runnable runnable, Executor executor) {
// No-op
}
@Override
public boolean cancel(boolean mayInterruptIfRunning) {
return false;
}
@Override
public boolean isCancelled() {
return false;
}
@Override
public boolean isDone() {
return false;
}
@Override
public DestinationTable get() throws InterruptedException, ExecutionException {
return null;
}
@Override
public DestinationTable get(long timeout, TimeUnit unit)
throws InterruptedException, ExecutionException, TimeoutException {
return null;
}
};
verify(stager).stageReports(ReportType.ACTIVITY);
verify(stager).stageReports(ReportType.TRANSACTIONS);
verify(stager).createAndUploadManifest(ImmutableList.of("a", "b", "c", "d"));
}
}

View file

@ -16,10 +16,6 @@ package google.registry.reporting;
import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth.assertWithMessage;
import static com.google.common.truth.Truth8.assertThat;
import static google.registry.reporting.IcannReportingModule.ReportType.ACTIVITY;
import static google.registry.reporting.IcannReportingModule.ReportType.TRANSACTIONS;
import static google.registry.testing.DatastoreHelper.createTld;
import static google.registry.testing.GcsTestingUtils.writeGcsFile;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.mockito.Mockito.doThrow;
@ -38,7 +34,6 @@ import google.registry.testing.FakeResponse;
import google.registry.testing.FakeSleeper;
import google.registry.util.Retrier;
import java.io.IOException;
import java.util.Optional;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
@ -52,37 +47,37 @@ public class IcannReportingUploadActionTest {
@Rule public final AppEngineRule appEngine = AppEngineRule.builder().withDatastore().build();
private static final byte[] FAKE_PAYLOAD = "test,csv\n13,37".getBytes(UTF_8);
private static final byte[] MANIFEST_PAYLOAD = "test-transactions-201706.csv\n".getBytes(UTF_8);
private final IcannHttpReporter mockReporter = mock(IcannHttpReporter.class);
private final FakeResponse response = new FakeResponse();
private final GcsService gcsService = GcsServiceFactory.createGcsService();
private final GcsFilename reportFile =
new GcsFilename("basin/icann/monthly/2017-06", "test-transactions-201706.csv");
private final GcsFilename manifestFile =
new GcsFilename("basin/icann/monthly/2017-06", "MANIFEST.txt");
private IcannReportingUploadAction createAction() {
IcannReportingUploadAction action = new IcannReportingUploadAction();
action.icannReporter = mockReporter;
action.gcsUtils = new GcsUtils(gcsService, 1024);
action.retrier = new Retrier(new FakeSleeper(new FakeClock()), 3);
action.yearMonth = "2017-06";
action.reportType = TRANSACTIONS;
action.subdir = Optional.empty();
action.tld = "test";
action.icannReportingBucket = "basin";
action.subdir = "icann/monthly/2017-06";
action.reportingBucket = "basin";
action.response = response;
return action;
}
@Before
public void before() throws Exception {
createTld("test");
writeGcsFile(gcsService, reportFile, FAKE_PAYLOAD);
writeGcsFile(gcsService, manifestFile, MANIFEST_PAYLOAD);
}
@Test
public void testSuccess() throws Exception {
IcannReportingUploadAction action = createAction();
action.run();
verify(mockReporter).send(FAKE_PAYLOAD, "test", "2017-06", TRANSACTIONS);
verify(mockReporter).send(FAKE_PAYLOAD, "test-transactions-201706.csv");
verifyNoMoreInteractions(mockReporter);
assertThat(((FakeResponse) action.response).getPayload())
.isEqualTo("OK, sending: test,csv\n13,37");
@ -94,90 +89,26 @@ public class IcannReportingUploadActionTest {
doThrow(new IOException("Expected exception."))
.doNothing()
.when(mockReporter)
.send(FAKE_PAYLOAD, "test", "2017-06", TRANSACTIONS);
.send(FAKE_PAYLOAD, "test-transactions-201706.csv");
action.run();
verify(mockReporter, times(2)).send(FAKE_PAYLOAD, "test", "2017-06", TRANSACTIONS);
verify(mockReporter, times(2)).send(FAKE_PAYLOAD, "test-transactions-201706.csv");
verifyNoMoreInteractions(mockReporter);
assertThat(((FakeResponse) action.response).getPayload())
.isEqualTo("OK, sending: test,csv\n13,37");
}
@Test
public void testFail_NonexisistentTld() throws Exception {
public void testFail_FileNotFound() throws Exception {
IcannReportingUploadAction action = createAction();
action.tld = "invalidTld";
action.subdir = "somewhere/else";
try {
action.run();
assertWithMessage("Expected IllegalArgumentException to be thrown").fail();
assertWithMessage("Expected IllegalStateException to be thrown").fail();
} catch (IllegalArgumentException expected) {
assertThat(expected)
.hasMessageThat()
.isEqualTo("TLD invalidTld does not exist");
.isEqualTo("Object MANIFEST.txt in bucket basin/somewhere/else not found");
}
}
@Test
public void testFail_InvalidYearMonth() throws Exception {
IcannReportingUploadAction action = createAction();
action.yearMonth = "2017-3";
try {
action.run();
assertWithMessage("Expected IllegalStateException to be thrown").fail();
} catch (IllegalStateException expected) {
assertThat(expected)
.hasMessageThat()
.isEqualTo("yearMonth must be in YYYY-MM format, got 2017-3 instead.");
}
}
@Test
public void testFail_InvalidSubdir() throws Exception {
IcannReportingUploadAction action = createAction();
action.subdir = Optional.of("/subdir/with/slash");
try {
action.run();
assertWithMessage("Expected IllegalStateException to be thrown").fail();
} catch (IllegalStateException expected) {
assertThat(expected)
.hasMessageThat()
.isEqualTo(
"subdir must not start or end with a \"/\", got /subdir/with/slash instead.");
}
}
@Test
public void testFail_FileNotFound() throws Exception {
IcannReportingUploadAction action = createAction();
action.yearMonth = "1234-56";
try {
action.run();
assertWithMessage("Expected IllegalStateException to be thrown").fail();
} catch (IllegalStateException expected) {
assertThat(expected)
.hasMessageThat()
.isEqualTo(
"ICANN report object test-transactions-123456.csv "
+ "in bucket basin/icann/monthly/1234-56 not found");
}
}
@Test
public void testSuccess_CreateFilename() throws Exception{
assertThat(IcannReportingUploadAction.createFilename("test", "2017-06", ACTIVITY))
.isEqualTo("test-activity-201706.csv");
assertThat(IcannReportingUploadAction.createFilename("foo", "1234-56", TRANSACTIONS))
.isEqualTo("foo-transactions-123456.csv");
}
@Test
public void testSuccess_CreateBucketname() throws Exception{
assertThat(
IcannReportingUploadAction
.createReportingBucketName("gs://my-reporting", Optional.<String>empty(), "2017-06"))
.isEqualTo("gs://my-reporting/icann/monthly/2017-06");
assertThat(
IcannReportingUploadAction
.createReportingBucketName("gs://my-reporting", Optional.of("manual"), "2017-06"))
.isEqualTo("gs://my-reporting/manual");
}
}

View file

@ -0,0 +1,40 @@
// Copyright 2017 The Nomulus Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package google.registry.reporting;
import static com.google.common.truth.Truth.assertThat;
import google.registry.reporting.IcannReportingModule.ReportType;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
/** Unit tests for {@link google.registry.reporting.ReportingUtils}. */
@RunWith(JUnit4.class)
public class ReportingUtilsTest {
@Test
public void testCreateFilename_success() {
assertThat(ReportingUtils.createFilename("test", "2017-06", ReportType.ACTIVITY))
.isEqualTo("test-activity-201706.csv");
assertThat(ReportingUtils.createFilename("foo", "2017-06", ReportType.TRANSACTIONS))
.isEqualTo("foo-transactions-201706.csv");
}
@Test
public void testCreateBucketName_success() {
assertThat(ReportingUtils.createReportingBucketName("gs://domain-registry-basin", "my/subdir"))
.isEqualTo("gs://domain-registry-basin/my/subdir");
}
}

View file

@ -15,7 +15,6 @@
package google.registry.reporting;
import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth8.assertThat;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
@ -30,7 +29,7 @@ public class TransactionsReportingQueryBuilderTest {
private TransactionsReportingQueryBuilder getQueryBuilder() {
TransactionsReportingQueryBuilder queryBuilder = new TransactionsReportingQueryBuilder();
queryBuilder.yearMonth = "2017-06";
queryBuilder.yearMonth = "2017-09";
queryBuilder.projectId = "domain-registry-alpha";
return queryBuilder;
}
@ -41,13 +40,12 @@ public class TransactionsReportingQueryBuilderTest {
assertThat(queryBuilder.getReportQuery())
.isEqualTo(
"#standardSQL\nSELECT * FROM "
+ "`domain-registry-alpha.icann_reporting.transactions_report_aggregation_201706`");
+ "`domain-registry-alpha.icann_reporting.transactions_report_aggregation_201709`");
}
@Test
public void testIntermediaryQueryMatch() throws IOException {
TransactionsReportingQueryBuilder queryBuilder = getQueryBuilder();
ImmutableList<String> queryNames =
ImmutableList<String> expectedQueryNames =
ImmutableList.of(
TransactionsReportingQueryBuilder.TRANSACTIONS_REPORT_AGGREGATION,
TransactionsReportingQueryBuilder.REGISTRAR_IANA_ID,
@ -57,9 +55,10 @@ public class TransactionsReportingQueryBuilderTest {
TransactionsReportingQueryBuilder.TRANSACTION_TRANSFER_LOSING,
TransactionsReportingQueryBuilder.ATTEMPTED_ADDS);
TransactionsReportingQueryBuilder queryBuilder = getQueryBuilder();
ImmutableMap<String, String> actualQueries = queryBuilder.getViewQueryMap();
for (String queryName : queryNames) {
String actualTableName = String.format("%s_201706", queryName);
for (String queryName : expectedQueryNames) {
String actualTableName = String.format("%s_201709", queryName);
String testFilename = String.format("%s_test.sql", queryName);
assertThat(actualQueries.get(actualTableName))
.isEqualTo(ReportingTestData.getString(testFilename));

View file

@ -19,8 +19,6 @@
SELECT
RealTlds.tld AS tld,
SUM(IF(metricName = 'operational-registrars', count, 0)) AS operational_registrars,
SUM(IF(metricName = 'ramp-up-registrars', count, 0)) AS ramp_up_registrars,
SUM(IF(metricName = 'pre-ramp-up-registrars', count, 0)) AS pre_ramp_up_registrars,
-- We use the Centralized Zone Data Service.
"CZDS" AS zfa_passwords,
SUM(IF(metricName = 'whois-43-queries', count, 0)) AS whois_43_queries,
@ -65,7 +63,7 @@ SELECT
-- filter so that only metrics with that TLD or a NULL TLD are counted
-- towards a given TLD.
FROM (
SELECT tldStr as tld
SELECT tldStr AS tld
FROM `domain-registry-alpha.latest_datastore_export.Registry`
WHERE tldType = 'REAL'
) as RealTlds
@ -82,16 +80,16 @@ CROSS JOIN(
SELECT STRING(NULL) AS tld, STRING(NULL) AS metricName, 0 as count
UNION ALL
SELECT * FROM
`domain-registry-alpha.icann_reporting.registrar_operating_status_201706`
`domain-registry-alpha.icann_reporting.registrar_operating_status_201709`
UNION ALL
SELECT * FROM
`domain-registry-alpha.icann_reporting.dns_counts_201706`
`domain-registry-alpha.icann_reporting.dns_counts_201709`
UNION ALL
SELECT * FROM
`domain-registry-alpha.icann_reporting.epp_metrics_201706`
`domain-registry-alpha.icann_reporting.epp_metrics_201709`
UNION ALL
SELECT * FROM
`domain-registry-alpha.icann_reporting.whois_counts_201706`
`domain-registry-alpha.icann_reporting.whois_counts_201709`
-- END INTERMEDIARY DATA SOURCES --
)) AS TldMetrics
WHERE RealTlds.tld = TldMetrics.tld OR TldMetrics.tld IS NULL

View file

@ -52,8 +52,8 @@ FROM (
FROM
`domain-registry-alpha.appengine_logs.appengine_googleapis_com_request_log_*`
WHERE _TABLE_SUFFIX
BETWEEN '20170601'
AND '20170630')
BETWEEN '20170901'
AND '20170930')
JOIN UNNEST(logMessage) AS logMessages
-- Look for metadata logs from epp and registrar console requests
WHERE requestPath IN ('/_dr/epp', '/_dr/epptool', '/registrar-xhr')

View file

@ -0,0 +1,24 @@
#standardSQL
-- Copyright 2017 The Nomulus Authors. All Rights Reserved.
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
-- Retrieve per-TLD DNS query counts.
-- This is a hack to enable using DNS counts from the internal-only #plx
-- workflow. See other references to b/67301320 in the codebase to see the
-- full extent of the hackery.
-- TODO(b/67301320): Delete this when we can make open-source DNS metrics.
SELECT *
FROM `domain-registry-alpha.icann_reporting.dns_counts_from_plx`

View file

@ -15,14 +15,13 @@
-- Query for DNS metrics.
-- This is a no-op until after we transition to Google Cloud DNS, which
-- will likely export metrics via Stackdriver.
-- You must configure this yourself to enable activity reporting, according
-- to whatever metrics your DNS provider makes available. We hope to make
-- this available in the open-source build in the near future.
SELECT
-- DNS metrics apply to all tlds, which requires the 'null' magic value.
STRING(NULL) AS tld,
metricName,
-- TODO(b/63388735): Change this to actually query Google Cloud DNS when ready.
-1 AS count
FROM ((
SELECT 'dns-udp-queries' AS metricName)

View file

@ -39,7 +39,7 @@ FROM (
-- Extract the logged JSON payload.
REGEXP_EXTRACT(logMessage, r'FLOW-LOG-SIGNATURE-METADATA: (.*)\n?$')
AS json
FROM `domain-registry-alpha.icann_reporting.monthly_logs_201706` AS logs
FROM `domain-registry-alpha.icann_reporting.monthly_logs_201709` AS logs
JOIN
UNNEST(logs.logMessage) AS logMessage
WHERE

View file

@ -27,4 +27,4 @@ SELECT
FROM
`domain-registry-alpha.appengine_logs.appengine_googleapis_com_request_log_*`
WHERE
_TABLE_SUFFIX BETWEEN '20170601' AND '20170630'
_TABLE_SUFFIX BETWEEN '20170901' AND '20170930'

View file

@ -26,5 +26,5 @@ FROM
UNNEST(allowedTlds) as allowed_tlds
WHERE (type = 'REAL' OR type = 'INTERNAL')
-- Filter out prober data
AND NOT ENDS_WITH(allowed_tlds, "test")
AND NOT ENDS_WITH(allowed_tlds, ".test")
ORDER BY tld, registrarName

View file

@ -23,5 +23,5 @@ SELECT
FROM
`domain-registry-alpha.latest_datastore_export.Registrar`
WHERE
type = 'REAL'
(type = 'REAL' OR type = 'INTERNAL')
GROUP BY metricName

View file

@ -32,7 +32,7 @@ JOIN
ON
currentSponsorClientId = registrar_table.__key__.name
WHERE
domain_table._d = "DomainResource"
AND (registrar_table.type = "REAL" OR registrar_table.type = "INTERNAL")
domain_table._d = 'DomainResource'
AND (registrar_table.type = 'REAL' OR registrar_table.type = 'INTERNAL')
GROUP BY tld, registrarName
ORDER BY tld, registrarName

View file

@ -45,12 +45,12 @@ JOIN (
`domain-registry-alpha.latest_datastore_export.DomainBase`,
UNNEST(nsHosts) AS hosts
WHERE _d = 'DomainResource'
AND creationTime <= TIMESTAMP("2017-06-30 23:59:59")
AND deletionTime > TIMESTAMP("2017-06-30 23:59:59") ) AS domain_table
AND creationTime <= TIMESTAMP("2017-09-30 23:59:59")
AND deletionTime > TIMESTAMP("2017-09-30 23:59:59") ) AS domain_table
ON
host_table.__key__.name = domain_table.referencedHostName
WHERE creationTime <= TIMESTAMP("2017-06-30 23:59:59")
AND deletionTime > TIMESTAMP("2017-06-30 23:59:59")
WHERE creationTime <= TIMESTAMP("2017-09-30 23:59:59")
AND deletionTime > TIMESTAMP("2017-09-30 23:59:59")
GROUP BY tld, registrarName
ORDER BY tld, registrarName

View file

@ -63,10 +63,8 @@ FROM (
WHERE entries.domainTransactionRecords IS NOT NULL )
-- Only look at this month's data
WHERE reportingTime
BETWEEN TIMESTAMP('2017-06-01 00:00:00')
AND TIMESTAMP('2017-06-30 23:59:59')
-- Ignore prober data
AND NOT ENDS_WITH(tld, "test")
BETWEEN TIMESTAMP('2017-09-01 00:00:00')
AND TIMESTAMP('2017-09-30 23:59:59')
GROUP BY
tld,
clientId,

View file

@ -63,10 +63,8 @@ FROM (
WHERE entries.domainTransactionRecords IS NOT NULL )
-- Only look at this month's data
WHERE reportingTime
BETWEEN TIMESTAMP('2017-06-01 00:00:00')
AND TIMESTAMP('2017-06-30 23:59:59')
-- Ignore prober data
AND NOT ENDS_WITH(tld, "test")
BETWEEN TIMESTAMP('2017-09-01 00:00:00')
AND TIMESTAMP('2017-09-30 23:59:59')
GROUP BY
tld,
clientId,

View file

@ -20,7 +20,8 @@
SELECT
registrars.tld as tld,
registrars.registrar_name as registrar_name,
-- Surround registrar names with quotes to handle names containing a comma.
FORMAT("\"%s\"", registrars.registrar_name) as registrar_name,
registrars.iana_id as iana_id,
SUM(IF(metrics.metricName = 'TOTAL_DOMAINS', metrics.metricValue, 0)) AS total_domains,
SUM(IF(metrics.metricName = 'TOTAL_NAMESERVERS', metrics.metricValue, 0)) AS total_nameservers,
@ -62,26 +63,33 @@ SELECT
0 AS agp_exemptions_granted,
0 AS agp_exempted_domains,
SUM(IF(metrics.metricName = 'ATTEMPTED_ADDS', metrics.metricValue, 0)) AS attempted_adds
FROM (
SELECT *
FROM `domain-registry-alpha.icann_reporting.registrar_iana_id_201706`) AS registrars
FROM
-- Only produce reports for real TLDs
(SELECT tldStr AS tld
FROM `domain-registry-alpha.latest_datastore_export.Registry`
WHERE tldType = 'REAL') AS registries
JOIN
(SELECT *
FROM `domain-registry-alpha.icann_reporting.registrar_iana_id_201709`)
AS registrars
ON registries.tld = registrars.tld
-- We LEFT JOIN to produce reports even if the registrar made no transactions
LEFT OUTER JOIN (
-- Gather all intermediary data views
SELECT *
FROM `domain-registry-alpha.icann_reporting.total_domains_201706`
FROM `domain-registry-alpha.icann_reporting.total_domains_201709`
UNION ALL
SELECT *
FROM `domain-registry-alpha.icann_reporting.total_nameservers_201706`
FROM `domain-registry-alpha.icann_reporting.total_nameservers_201709`
UNION ALL
SELECT *
FROM `domain-registry-alpha.icann_reporting.transaction_counts_201706`
FROM `domain-registry-alpha.icann_reporting.transaction_counts_201709`
UNION ALL
SELECT *
FROM `domain-registry-alpha.icann_reporting.transaction_transfer_losing_201706`
FROM `domain-registry-alpha.icann_reporting.transaction_transfer_losing_201709`
UNION ALL
SELECT *
FROM `domain-registry-alpha.icann_reporting.attempted_adds_201706` ) AS metrics
FROM `domain-registry-alpha.icann_reporting.attempted_adds_201709` ) AS metrics
-- Join on tld and registrar name
ON registrars.tld = metrics.tld
AND registrars.registrar_name = metrics.registrar_name

View file

@ -26,7 +26,7 @@ SELECT
END AS metricName,
COUNT(requestPath) AS count
FROM
`domain-registry-alpha.icann_reporting.monthly_logs_201706`
`domain-registry-alpha.icann_reporting.monthly_logs_201709`
GROUP BY
metricName
HAVING

View file

@ -19,6 +19,7 @@ import static com.google.common.truth.Truth8.assertThat;
import static google.registry.request.RequestParameters.extractBooleanParameter;
import static google.registry.request.RequestParameters.extractEnumParameter;
import static google.registry.request.RequestParameters.extractOptionalDatetimeParameter;
import static google.registry.request.RequestParameters.extractOptionalEnumParameter;
import static google.registry.request.RequestParameters.extractOptionalParameter;
import static google.registry.request.RequestParameters.extractRequiredDatetimeParameter;
import static google.registry.request.RequestParameters.extractRequiredParameter;
@ -147,6 +148,25 @@ public class RequestParametersTest {
extractEnumParameter(req, Club.class, "spin");
}
@Test
public void testOptionalExtractEnumValue_givenValue_returnsValue() throws Exception {
when(req.getParameter("spin")).thenReturn("DANCE");
assertThat(extractOptionalEnumParameter(req, Club.class, "spin")).hasValue(Club.DANCE);
}
@Test
public void testOptionalExtractEnumValue_noValue_returnsAbsent() throws Exception {
when(req.getParameter("spin")).thenReturn("");
assertThat(extractOptionalEnumParameter(req, Club.class, "spin")).isEmpty();
}
@Test
public void testOptionalExtractEnumValue_nonExistentValue_throwsBadRequest() throws Exception {
when(req.getParameter("spin")).thenReturn("sing");
thrown.expect(BadRequestException.class, "spin");
extractOptionalEnumParameter(req, Club.class, "spin");
}
@Test
public void testExtractRequiredDatetimeParameter_correctValue_works() throws Exception {
when(req.getParameter("timeParam")).thenReturn("2015-08-27T13:25:34.123Z");