DerGut opened a new issue, #1466: URL: https://github.com/apache/iceberg-rust/issues/1466
### Is your feature request related to a problem or challenge? I'd like to get the [Metrics Reporting](https://iceberg.apache.org/docs/latest/metrics-reporting/) API into Rust. It's part of the catalog spec and currently only implemented by Iceberg Java (Python, Go and Rust haven't implemented it yet). In short, the Metrics API allows us to monitor and better understand how clients operate on Iceberg files by providing numbers around: - how long did the scan planning phase take (e.g. determining the data files to look at) - how many manifest files were considered, skipped and scanned (from a manifest list) - how many data files were considered, skipped and scanned (from a manifest file) - same for delete files - similar metrics for commits To me, this is a crucial piece of functionality. In an Iceberg deployment, various clients can use the same catalog but operate on cloud storage directly. From the catalog, we only get to see which tables are accessed, or how they are modified at a high level. The data plane is completely opaque to the catalog. This means it can be hard to understand how each of the clients is using the stored data, at least in a consistent way. The metrics reporting API provides a solution for this. I've checked in the [#rust](https://apache-iceberg.slack.com/archives/C05HTENMJG4) Slack channel and there seems to be general interest for this functionality 👍 ### Describe the solution you'd like :footprints: The general steps I think this can be broken down into: ```mermaid flowchart LR A["#3709: Reporter API"] --> C["#3736: Scan reporting"] B["#3732: Planning counters"] --> C C --> D["LoggingMetricsReporter"] C --> E["RestMetricsReporter"] C --> F["Handle failed & abandoned plans"] click A href "https://github.com/apache/iceberg-rust/pull/3709" _blank click B href "https://github.com/apache/iceberg-rust/pull/3732" _blank click C href "https://github.com/apache/iceberg-rust/pull/3736" _blank ``` #### 1. Reporter & Report APIs All other work items will re-use these APIs. ##### An API to consume reports (i.e. Java's [MetricsReporter](https://github.com/apache/iceberg/blob/40c0a73c6513711b2a58bb159cf8c562fe56c826/api/src/main/java/org/apache/iceberg/metrics/MetricsReporter.java#L26) interface) This trait will need to be async because it will likely use IO. The RestMetricsReporter is a good example using the network to send out its metrics reports. It will also need the supertraits `Debug`, `Send` and `Sync`. `Debug` is necessary because the structs that will hold the reporter are deriving it (e.g. [`TableScan`](https://github.com/apache/iceberg-rust/blob/772ae1ab194aa039b653648d9d8310d074609619/crates/iceberg/src/scan/mod.rs#L307-L308)). `Send` and `Sync` are necessary because the same reporter may be reused by many (concurrently running) operations. It's visibility can be `pub(crate)` for now. This allows us to integrate metrics reporting into the table operations, and provide a default implementation (like the `LoggingMetricsReporter`). Later, this will be made public so that users can implement their own, and we can add a `RestMetricsReporter`. While metrics reporting can fail (e.g. when using IO), an error during reporting shouldn't affect the table operation in any way. To emphasize this, I think it makes sense to force the user to handle or log any errors internally and not return a `Result<()>`. ```rs /// This trait defines the basic API for reporting metrics on table operations. #[async_trait] pub(crate) trait MetricsReporter: Debug + Send + Sync { /// Reports the metrics for a completed table operation. async fn report(&self, report: &MetricsReport); } ``` - [ ] https://github.com/apache/iceberg-rust/pull/3709 #### 2. Metrics Collection/ planning counters Relevant table operations will need to create metric reports, populate them with data and pass them to the metrics reporter. I've primarily looked at the table scan operation (see [`TableScan.plan_files`](https://github.com/apache/iceberg-rust/blob/772ae1ab194aa039b653648d9d8310d074609619/crates/iceberg/src/scan/mod.rs#L334)) so far (this partially equates to Java's [`SnapshotScan.planFiles`](https://github.com/apache/iceberg/blob/40c0a73c6513711b2a58bb159cf8c562fe56c826/core/src/main/java/org/apache/iceberg/SnapshotScan.java#L144-L157). Challenges I've identified are mainly around its multi-threaded nature. The operation spawns multiple threads to process and filter manifest files and data (+delete) files ([example](https://github.com/apache/iceberg-rust/blob/772ae1ab194aa039b653648d9d8310d074609619/crates/iceberg/src/scan/mod.rs#L414)). This means that we can't simply pass around the metrics structs but need to come up with a more sophisticated builder pattern that takes concurrent writes into account. My current implementation uses atomics for it. - [ ] https://github.com/apache/iceberg-rust/pull/3732 Commit reporting will likely be analogous but I didn't yet look into it. This could also be added as a follow-up contribution. #### 3. Wiring To keep PR sizes reviewable, both https://github.com/apache/iceberg-rust/pull/3709 and https://github.com/apache/iceberg-rust/pull/3732 operate independently. A third https://github.com/apache/iceberg-rust/pull/3736 then wires them together to publish the collected metrics+reports via the reporter API. - [ ] https://github.com/apache/iceberg-rust/pull/3736 #### 3. Follow-ups Multiple follow-ups will be necessary to complete this: 1. a (perhaps default) [`LoggingMetricsReporter`](https://github.com/apache/iceberg/blob/feeb045a73a315bd4e5104f770671108d44aef33/api/src/main/java/org/apache/iceberg/metrics/LoggingMetricsReporter.java) 2. a `RestMetricsReporter` that the `RestCatalog` defaults to (sends reports to the remote catalog) 3. better handling of more complex scan plan life cycles (failures & abandonments) 4. harden the report building (sanitize predicates, properly handle complex projections) --- Note: While I will be able to work on this independently, I'm still happy and thankful for feedback or comments! 🙏 ### Willingness to contribute I can contribute to this feature independently -- 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]
