wgtmac commented on code in PR #701:
URL: https://github.com/apache/iceberg-cpp/pull/701#discussion_r3499937977
##########
src/iceberg/manifest/manifest_group.cc:
##########
@@ -408,19 +438,27 @@ ManifestGroup::ReadEntries() {
manifest_evaluator->Evaluate(manifest));
if (!should_match) {
// Skip this manifest because it doesn't match partition filter
+ if (scan_metrics_) {
+ scan_metrics_->skipped_data_manifests->Increment(1);
+ }
return {};
}
+ if (scan_metrics_) {
Review Comment:
`scanned_data_manifests` is incremented before the later `ignore_deleted_` /
`ignore_existing_` manifest filters run. Java counts scanned data manifests
only after those manifest-level filters, so a manifest skipped by either filter
will be reported as scanned here.
##########
src/iceberg/manifest/manifest_group.cc:
##########
@@ -408,19 +438,27 @@ ManifestGroup::ReadEntries() {
manifest_evaluator->Evaluate(manifest));
if (!should_match) {
// Skip this manifest because it doesn't match partition filter
+ if (scan_metrics_) {
+ scan_metrics_->skipped_data_manifests->Increment(1);
+ }
return {};
}
+ if (scan_metrics_) {
+ scan_metrics_->scanned_data_manifests->Increment(1);
+ }
if (ignore_deleted_) {
// only scan manifests that have entries other than deletes
if (!manifest.has_added_files() && !manifest.has_existing_files()) {
+ if (scan_metrics_) scan_metrics_->skipped_data_files->Increment(1);
Review Comment:
This is a manifest-level skip, not a skipped data file. Java increments
`skippedDataManifests` for `ignoreDeleted` manifest pruning, so a manifest
containing only deleted entries should not add to `skipped_data_files`.
##########
src/iceberg/manifest/manifest_group.cc:
##########
@@ -408,19 +438,27 @@ ManifestGroup::ReadEntries() {
manifest_evaluator->Evaluate(manifest));
if (!should_match) {
// Skip this manifest because it doesn't match partition filter
+ if (scan_metrics_) {
+ scan_metrics_->skipped_data_manifests->Increment(1);
+ }
return {};
}
+ if (scan_metrics_) {
+ scan_metrics_->scanned_data_manifests->Increment(1);
+ }
if (ignore_deleted_) {
// only scan manifests that have entries other than deletes
if (!manifest.has_added_files() && !manifest.has_existing_files()) {
+ if (scan_metrics_) scan_metrics_->skipped_data_files->Increment(1);
return {};
}
}
if (ignore_existing_) {
// only scan manifests that have entries other than existing
if (!manifest.has_added_files() && !manifest.has_deleted_files()) {
+ if (scan_metrics_) scan_metrics_->skipped_data_files->Increment(1);
Review Comment:
Same counter issue for `ignoreExisting`: this skips the whole manifest, so
it should increment `skipped_data_manifests` instead of `skipped_data_files`.
##########
src/iceberg/test/CMakeLists.txt:
##########
@@ -301,6 +302,7 @@ if(ICEBERG_BUILD_REST)
endpoint_test.cc
rest_file_io_test.cc
rest_json_serde_test.cc
+ rest_metrics_reporter_test.cc
Review Comment:
CMake now builds `rest_metrics_reporter_test.cc`, but
`src/iceberg/test/meson.build` is not updated. Meson test runs will miss this
coverage.
##########
src/iceberg/meson.build:
##########
@@ -62,6 +62,7 @@ iceberg_sources = files(
'expression/projections.cc',
'expression/residual_evaluator.cc',
'expression/rewrite_not.cc',
+ 'expression/sanitize_expression.cc',
Review Comment:
`sanitize_expression.h` is a new public header, but
`src/iceberg/expression/meson.build` does not install it. Meson installs will
miss this API even though the source is built.
##########
src/iceberg/catalog/rest/meson.build:
##########
@@ -30,6 +30,7 @@ iceberg_rest_sources = files(
'resource_paths.cc',
'rest_catalog.cc',
'rest_file_io.cc',
+ 'rest_metrics_reporter.cc',
Review Comment:
Since this adds `RestMetricsReporter`, the Meson install list should also
include `rest_metrics_reporter.h`; otherwise CMake installs the new public
header but Meson installs do not.
##########
src/iceberg/manifest/manifest_group.cc:
##########
@@ -346,6 +372,10 @@ Result<std::unique_ptr<ManifestReader>>
ManifestGroup::MakeReader(
.CaseSensitive(case_sensitive_)
.Select(std::move(columns));
+ if (scan_metrics_) {
Review Comment:
`SkipCounter` only covers filtering done inside `ManifestReader`. The later
local filters in `ReadEntries` (`ignore_existing_`, `data_file_evaluator`, and
`manifest_entry_predicate_`) still `continue` without incrementing
`skipped_data_files`, unlike Java's entry-level filters wrapped with
`skippedDataFiles`.
##########
src/iceberg/catalog/rest/rest_metrics_reporter.cc:
##########
@@ -0,0 +1,69 @@
+/*
+ * 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.
+ */
+
+#include "iceberg/catalog/rest/rest_metrics_reporter.h"
+
+#include <cstdio>
+#include <utility>
+
+#include <nlohmann/json.hpp>
+
+#include "iceberg/catalog/rest/auth/auth_session.h"
+#include "iceberg/catalog/rest/error_handlers.h"
+#include "iceberg/catalog/rest/http_client.h"
+#include "iceberg/metrics/json_serde_internal.h"
+#include "iceberg/metrics/metrics_reporter.h"
+
+namespace iceberg::rest {
+
+namespace {
+
+constexpr std::string_view kReportType = "report-type";
+constexpr std::string_view kScanReportType = "scan-report";
+constexpr std::string_view kCommitReportType = "commit-report";
+
+} // namespace
+
+RestMetricsReporter::RestMetricsReporter(std::shared_ptr<HttpClient> client,
+ std::string metrics_endpoint,
+ std::shared_ptr<auth::AuthSession>
session)
+ : client_(std::move(client)),
+ metrics_endpoint_(std::move(metrics_endpoint)),
+ session_(std::move(session)) {}
+
+Status RestMetricsReporter::Report(const MetricsReport& report) {
+ // Serialize the report variant to JSON.
+ Result<nlohmann::json> json_result = std::visit(
+ [](const auto& r) -> Result<nlohmann::json> { return ToJson(r); },
report);
+ if (!json_result) {
+ return {};
+ }
+
+ // Inject "report-type" required by the REST spec (not included in core
ToJson).
+ auto& json = json_result.value();
+ json[kReportType] =
+ std::holds_alternative<ScanReport>(report) ? kScanReportType :
kCommitReportType;
+
+ // POST to the metrics endpoint; suppress errors to match Java
fire-and-forget behavior.
+ std::ignore = client_->Post(metrics_endpoint_, json.dump(), /*headers=*/{},
Review Comment:
`Report()` must not throw, but `json.dump()` and the HTTP call can throw
here. Since scan/commit callers ignore the returned status, this should catch
exceptions locally and keep the fire-and-forget metrics path from unwinding
user operations.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]