Repository navigation
GCP: Add CloudMonitoringMetricsReporter to export Iceberg metrics to Cloud Monitoring #16107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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
157 changes: 157 additions & 0 deletions
157
...on/java/org/apache/iceberg/gcp/metrics/TestCloudMonitoringMetricsReporterIntegration.java
This file contains hidden or 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,157 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you 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 org.apache.iceberg.gcp.metrics; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
| import static org.assertj.core.api.Assumptions.assumeThat; | ||
|
|
||
| import com.google.cloud.ServiceOptions; | ||
| import com.google.cloud.monitoring.v3.MetricServiceClient; | ||
| import com.google.cloud.monitoring.v3.MetricServiceClient.ListTimeSeriesPagedResponse; | ||
| import com.google.monitoring.v3.ListTimeSeriesRequest; | ||
| import com.google.monitoring.v3.ProjectName; | ||
| import com.google.monitoring.v3.TimeInterval; | ||
| import com.google.monitoring.v3.TimeSeries; | ||
| import com.google.protobuf.util.Timestamps; | ||
| import java.time.Duration; | ||
| import java.util.Map; | ||
| import org.apache.iceberg.CatalogProperties; | ||
| import org.apache.iceberg.FileScanTask; | ||
| import org.apache.iceberg.Table; | ||
| import org.apache.iceberg.catalog.TableIdentifier; | ||
| import org.apache.iceberg.gcp.GCPProperties; | ||
| import org.apache.iceberg.io.CloseableIterable; | ||
| import org.apache.iceberg.relocated.com.google.common.collect.Maps; | ||
| import org.apache.iceberg.rest.RESTCatalog; | ||
| import org.awaitility.Awaitility; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| /** | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This isn't being run in CI, correct? Do you have some test logs you can show to help us understand that these tests pass? |
||
| * Integration test that exercises {@link CloudMonitoringMetricsReporter} end-to-end against a real | ||
| * Cloud Monitoring project and a configured catalog. Skipped automatically unless the required | ||
| * properties below are provided. | ||
| * | ||
| * <p>Required configuration (system properties or environment variables): | ||
| * | ||
| * <ul> | ||
| * <li>{@code iceberg.gcp.project} (or default GCP credentials project) | ||
| * <li>{@code iceberg.gcp.it.catalog-uri} — REST catalog URI | ||
| * <li>{@code iceberg.gcp.it.warehouse} — warehouse location (e.g. {@code gs://...}) | ||
| * <li>{@code iceberg.gcp.it.namespace} and {@code iceberg.gcp.it.table} — table to scan | ||
| * </ul> | ||
| * | ||
| * Optional: {@code iceberg.gcp.it.catalog-properties} as a comma-separated list of {@code k=v} | ||
| * pairs for catalog-specific properties (e.g. headers, scan-planning-mode). | ||
| */ | ||
| public class TestCloudMonitoringMetricsReporterIntegration { | ||
|
|
||
| private static final String SYS_PROJECT = "iceberg.gcp.project"; | ||
| private static final String SYS_CATALOG_URI = "iceberg.gcp.it.catalog-uri"; | ||
| private static final String SYS_WAREHOUSE = "iceberg.gcp.it.warehouse"; | ||
| private static final String SYS_NAMESPACE = "iceberg.gcp.it.namespace"; | ||
| private static final String SYS_TABLE = "iceberg.gcp.it.table"; | ||
| private static final String SYS_CATALOG_PROPS = "iceberg.gcp.it.catalog-properties"; | ||
|
|
||
| @Test | ||
| void testMetricsReporting() throws Exception { | ||
| String projectId = System.getProperty(SYS_PROJECT, ServiceOptions.getDefaultProjectId()); | ||
| String catalogUri = System.getProperty(SYS_CATALOG_URI); | ||
| String warehouse = System.getProperty(SYS_WAREHOUSE); | ||
| String namespace = System.getProperty(SYS_NAMESPACE); | ||
| String tableName = System.getProperty(SYS_TABLE); | ||
| assumeThat(projectId).as("GCP project ID is not configured").isNotNull(); | ||
| assumeThat(catalogUri).as("%s is not set", SYS_CATALOG_URI).isNotNull(); | ||
| assumeThat(warehouse).as("%s is not set", SYS_WAREHOUSE).isNotNull(); | ||
| assumeThat(namespace).as("%s is not set", SYS_NAMESPACE).isNotNull(); | ||
| assumeThat(tableName).as("%s is not set", SYS_TABLE).isNotNull(); | ||
|
|
||
| Map<String, String> properties = Maps.newHashMap(); | ||
| properties.put(CatalogProperties.URI, catalogUri); | ||
| properties.put(CatalogProperties.WAREHOUSE_LOCATION, warehouse); | ||
| properties.put(CatalogProperties.FILE_IO_IMPL, "org.apache.iceberg.gcp.gcs.GCSFileIO"); | ||
| properties.put( | ||
| CatalogProperties.METRICS_REPORTER_IMPL, CloudMonitoringMetricsReporter.class.getName()); | ||
| properties.put(GCPProperties.GCP_MONITORING_PROJECT_ID, projectId); | ||
| properties.putAll(parseExtraProperties(System.getProperty(SYS_CATALOG_PROPS, ""))); | ||
|
|
||
| long startMillis = System.currentTimeMillis(); | ||
| String catalogId = "iceberg_cloud_monitoring_it"; | ||
|
|
||
| RESTCatalog catalog = new RESTCatalog(); | ||
| catalog.initialize(catalogId, properties); | ||
|
|
||
| Table table = catalog.loadTable(TableIdentifier.of(namespace, tableName)); | ||
| try (CloseableIterable<FileScanTask> tasks = table.newScan().planFiles()) { | ||
| tasks.forEach(t -> {}); | ||
| } | ||
|
|
||
| String prefix = | ||
| properties.getOrDefault( | ||
| GCPProperties.GCP_MONITORING_METRIC_PREFIX, | ||
| GCPProperties.GCP_MONITORING_METRIC_PREFIX_DEFAULT); | ||
| String filter = | ||
| String.format( | ||
| "metric.type=\"%s/scan_metrics\" AND metric.label.\"metric_name\"=\"scan_operations\"", | ||
| prefix); | ||
|
|
||
| try (MetricServiceClient client = MetricServiceClient.create()) { | ||
| Awaitility.await("scan_operations metric appears in Cloud Monitoring") | ||
| .atMost(Duration.ofMinutes(3)) | ||
| .pollInterval(Duration.ofSeconds(5)) | ||
| .until(() -> findScanOperations(client, projectId, filter, startMillis)); | ||
| } | ||
| } | ||
|
|
||
| private static boolean findScanOperations( | ||
| MetricServiceClient client, String projectId, String filter, long startMillis) { | ||
| TimeInterval interval = | ||
| TimeInterval.newBuilder() | ||
| .setStartTime(Timestamps.fromMillis(startMillis)) | ||
| .setEndTime(Timestamps.fromMillis(System.currentTimeMillis())) | ||
| .build(); | ||
| ListTimeSeriesRequest request = | ||
| ListTimeSeriesRequest.newBuilder() | ||
| .setName(ProjectName.of(projectId).toString()) | ||
| .setFilter(filter) | ||
| .setInterval(interval) | ||
| .build(); | ||
| ListTimeSeriesPagedResponse response = client.listTimeSeries(request); | ||
| for (TimeSeries ts : response.iterateAll()) { | ||
| assertThat(ts.getMetric().getLabelsMap()).containsKey("table"); | ||
| assertThat(ts.getMetric().getLabelsMap()).containsKey("catalog"); | ||
| assertThat(ts.getMetric().getLabelsMap()).doesNotContainKeys("filter", "queried_field_ids"); | ||
| return true; | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| private static Map<String, String> parseExtraProperties(String raw) { | ||
| Map<String, String> out = Maps.newHashMap(); | ||
| if (raw == null || raw.isBlank()) { | ||
| return out; | ||
| } | ||
| for (String pair : raw.split(",")) { | ||
| int eq = pair.indexOf('='); | ||
| if (eq > 0) { | ||
| out.put(pair.substring(0, eq).trim(), pair.substring(eq + 1).trim()); | ||
| } | ||
| } | ||
| return out; | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should be very careful with dependency change for runtime bundle jar. was this PR created after all the dependency/license fixes. at least, rebase with the latest main branch. CI should catch dependency/license problems nowadays.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes I created this PR Last Friday. How can I verify that ? There is also license check too
https://github.com/apache/iceberg/actions/runs/25008117162/job/73236359466?pr=16107
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 #16103 + #16081 should enforce any runtime dep changes in CI, via
[check-runtime-deps](https://github.com/apache/iceberg/actions/runs/25399058172/job/74493503774?pr=16107#logs)taskTheres also #16182 which is updating the LICENSE for GCP bundle.
Lets wait for all 3 PRs to land so we have a good baseline, and then we can look at adding new deps
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i would expect the runtime-deps.txt file to be modifed based on this addition...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't see the GitHub action for licensing checks run.
@talatuyarer - can you rebase off of main to make sure that you've got Russell's new dependency checks?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks like it was already pulled transitively and already part of runtime-deps.txt, hence no diff here
iceberg/gcp-bundle/runtime-deps.txt
Line 44 in b7ef9f1
👍