-
Notifications
You must be signed in to change notification settings - Fork 276
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Lai Jiang <[email protected]>
- Loading branch information
Showing
30 changed files
with
264 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
core/src/main/java/google/registry/reporting/icann/CloudDnsCountQueryCoordinator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
// 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 com.google.common.flogger.FluentLogger; | ||
import com.google.common.io.Resources; | ||
import google.registry.bigquery.BigqueryUtils.TableType; | ||
import google.registry.util.ResourceUtils; | ||
import google.registry.util.SqlTemplate; | ||
import java.util.concurrent.ExecutionException; | ||
import org.joda.time.YearMonth; | ||
import org.joda.time.format.DateTimeFormat; | ||
|
||
/** | ||
* DNS Count query that relies on a table Cloud DNS publishes internally to Google. | ||
* | ||
* <p>The internal Plx table is exposed as a BigQuery table via BQ-TS federation. This is not | ||
* applicable to external users who also happen to use Cloud DNS as the plx table is specific to | ||
* Google Registry's zones. External (non-Google) users must re-implement the abstract class and | ||
* configure the usage of the new class using the `registryPolicy.dnsCountQueryCoordinatorClass` | ||
* field in the config file. | ||
*/ | ||
public class CloudDnsCountQueryCoordinator extends DnsCountQueryCoordinator { | ||
private static final FluentLogger logger = FluentLogger.forEnclosingClass(); | ||
private static final String PLX_DNS_TABLE_NAME = "dns_counts_from_plx"; | ||
private static final String TABLE_ID = "zoneman_daily_query_counts"; | ||
|
||
@Override | ||
public String createQuery() { | ||
String template = | ||
ResourceUtils.readResourceUtf8( | ||
Resources.getResource(this.getClass(), "sql/dns_counts_cloud.sql")); | ||
return SqlTemplate.create(template) | ||
.put("PROJECT_ID", projectId) | ||
.put("ICANN_REPORTING_DATA_SET", icannReportingDataSet) | ||
.put("DNS_TABLE_NAME", PLX_DNS_TABLE_NAME) | ||
.build(); | ||
} | ||
|
||
@Override | ||
public void prepareForQuery(YearMonth yearMonth) throws InterruptedException { | ||
logger.atInfo().log("Generating intermediary table dns_counts"); | ||
String query = getPlxDnsTableQuery(yearMonth); | ||
try { | ||
bigquery | ||
.startQuery( | ||
query, | ||
bigquery | ||
.buildDestinationTable(PLX_DNS_TABLE_NAME) | ||
.description("A table holding DNS query counts to generate ACTIVITY reports.") | ||
.type(TableType.TABLE) | ||
.build()) | ||
.get(); | ||
} catch (ExecutionException e) { | ||
throw new RuntimeException("Error while running BigQuery query", e.getCause()); | ||
} | ||
} | ||
|
||
String getPlxDnsTableQuery(YearMonth yearMonth) { | ||
String template = | ||
ResourceUtils.readResourceUtf8( | ||
Resources.getResource(this.getClass(), "sql/prepare_dns_counts_internal.sql")); | ||
SqlTemplate queryTemplate = | ||
SqlTemplate.create(template) | ||
.put("PROJECT_ID", projectId) | ||
.put("DATASET_ID", icannReportingDataSet) | ||
.put("TABLE_ID", TABLE_ID) | ||
.put("YEAR_MONTH", DateTimeFormat.forPattern("yyyyMM").print(yearMonth)); | ||
return queryTemplate.build(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 0 additions & 41 deletions
41
core/src/main/java/google/registry/reporting/icann/DnsCountQueryCoordinatorModule.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
31 changes: 31 additions & 0 deletions
31
core/src/main/resources/google/registry/reporting/icann/sql/prepare_dns_counts_internal.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
`%PROJECT_ID%.%DATASET_ID%.%TABLE_ID%` | ||
WHERE | ||
STARTS_WITH(date_utc, '%YEAR_MONTH%') | ||
GROUP BY | ||
tld, | ||
metricName |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
core/src/test/java/google/registry/reporting/icann/CloudDnsCountQueryCoordinatorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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")); | ||
} | ||
} |
Oops, something went wrong.