Migrate DNS query table (#2543)

Co-authored-by: Lai Jiang <jianglai@google.com>
This commit is contained in:
gbrodman
2024-09-04 17:42:12 +00:00
committed by GitHub
co-authored by Lai Jiang
parent d9ad39cdad
commit ab60ac44fd
30 changed files with 264 additions and 96 deletions
@@ -29,14 +29,11 @@ class ActivityReportingQueryBuilderTest {
@SuppressWarnings("NonCanonicalType")
private ActivityReportingQueryBuilder createQueryBuilder(String datasetName) {
return new ActivityReportingQueryBuilder(
"domain-registry-alpha",
datasetName,
new BasicDnsCountQueryCoordinator(
new BasicDnsCountQueryCoordinator.Params(null, "domain-registry-alpha", datasetName)));
"domain-registry-alpha", datasetName, new DummyDnsCountQueryCoordinator());
}
@Test
void testAggregateQueryMatch_cloudSql() {
void testAggregateQueryMatch() {
ActivityReportingQueryBuilder queryBuilder = createQueryBuilder("cloud_sql_icann_reporting");
assertThat(queryBuilder.getReportQuery(yearMonth))
.isEqualTo(
@@ -46,7 +43,7 @@ class ActivityReportingQueryBuilderTest {
}
@Test
void testIntermediaryQueryMatch_cloudSql() {
void testIntermediaryQueryMatch() {
ImmutableList<String> expectedQueryNames =
ImmutableList.of(
ActivityReportingQueryBuilder.REGISTRAR_OPERATING_STATUS,
@@ -60,7 +57,7 @@ class ActivityReportingQueryBuilderTest {
ImmutableMap<String, String> actualQueries = queryBuilder.getViewQueryMap(yearMonth);
for (String queryName : expectedQueryNames) {
String actualTableName = String.format("%s_201709", queryName);
String testFilename = String.format("%s_test_cloud_sql.sql", queryName);
String testFilename = String.format("%s_test.sql", queryName);
assertThat(actualQueries.get(actualTableName))
.isEqualTo(ReportingTestData.loadFile(testFilename));
}
@@ -0,0 +1,46 @@
// Copyright 2024 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.icann;
import static com.google.common.truth.Truth.assertThat;
import org.joda.time.YearMonth;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
/** Unit tests for {@link CloudDnsCountQueryCoordinator}. */
public class CloudDnsCountQueryCoordinatorTest {
public CloudDnsCountQueryCoordinatorTest() {}
private final YearMonth yearMonth = new YearMonth(2017, 9);
CloudDnsCountQueryCoordinator coordinator = new CloudDnsCountQueryCoordinator();
@BeforeEach
public void setUp() {
coordinator.projectId = "domain-registry-test";
coordinator.icannReportingDataSet = "icann_reporting";
}
@Test
public void testPreparatoryQueryConstruction() {
assertThat(coordinator.getPlxDnsTableQuery(yearMonth))
.isEqualTo(ReportingTestData.loadFile("prepare_dns_counts_cloud_test.sql"));
}
@Test
public void testQueryCreation() {
assertThat(coordinator.createQuery())
.isEqualTo(ReportingTestData.loadFile("dns_counts_cloud_test.sql"));
}
}
@@ -50,7 +50,7 @@ class IcannReportingStagerTest {
IcannReportingStager action = new IcannReportingStager();
action.activityQueryBuilder =
new ActivityReportingQueryBuilder(
"test-project", "icann_reporting", new BasicDnsCountQueryCoordinator(null));
"test-project", "icann_reporting", new DummyDnsCountQueryCoordinator());
action.transactionsQueryBuilder =
new TransactionsReportingQueryBuilder("test-project", "icann_reporting");
action.reportingBucket = "test-bucket";
@@ -31,7 +31,7 @@ class TransactionsReportingQueryBuilderTest {
}
@Test
void testAggregateQueryMatch_cloud_sql() {
void testAggregateQueryMatch() {
TransactionsReportingQueryBuilder queryBuilder =
createQueryBuilder("cloud_sql_icann_reporting");
assertThat(queryBuilder.getReportQuery(yearMonth))
@@ -43,7 +43,7 @@ class TransactionsReportingQueryBuilderTest {
}
@Test
void testIntermediaryQueryMatch_cloud_sql() {
void testIntermediaryQueryMatch() {
ImmutableList<String> expectedQueryNames =
ImmutableList.of(
TransactionsReportingQueryBuilder.REGISTRAR_IANA_ID,
@@ -59,7 +59,7 @@ class TransactionsReportingQueryBuilderTest {
ImmutableMap<String, String> actualQueries = queryBuilder.getViewQueryMap(yearMonth);
for (String queryName : expectedQueryNames) {
String actualTableName = String.format("%s_201709", queryName);
String testFilename = String.format("%s_test_cloud_sql.sql", queryName);
String testFilename = String.format("%s_test.sql", queryName);
assertThat(actualQueries.get(actualTableName))
.isEqualTo(ReportingTestData.loadFile(testFilename));
}
@@ -15,10 +15,5 @@
-- 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`
FROM `domain-registry-test.icann_reporting.dns_counts_from_plx`
@@ -0,0 +1,31 @@
#standardSQL
-- Copyright 2024 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.
SELECT
tld,
CASE
WHEN transport = 'tcp' THEN 'dns-tcp-queries'
WHEN transport = 'udp' THEN 'dns-udp-queries'
END AS metricName,
SUM(query_count) AS count
FROM
`domain-registry-test.icann_reporting.zoneman_daily_query_counts`
WHERE
STARTS_WITH(date_utc, '201709')
GROUP BY
tld,
metricName