Repository navigation
Conversation
Expose the reporter contract and read-only scan report types independently from scan metric collection and delivery.
0e3729a to
7dc00ea
Compare
xanderbailey
left a comment
There was a problem hiding this comment.
Great to see metrics being worked on!
|
|
||
| /// Metrics collected while planning a table scan. | ||
| #[derive(Debug)] | ||
| pub struct ScanMetrics { |
There was a problem hiding this comment.
Java makes these nullable I.e. not reported, do you think we should do the same?
There was a problem hiding this comment.
I could see two reasons to make them nullable/ optional that both don't apply to the Rust code base (and it seems the nullability isn't exercised in Java either):
An individual metric not always being available
The currently implemented metrics are always available when a scan is completed, so no need to make individual ones optional (same in Java). Maybe this will be relevant for future metrics, but we can then make only those optional.
Overall metric collection disabled
When a user doesn't want to report metrics, we could skip the collection and not provide a report at all. In the Rust implementation from #3732 we're always counting, but then discarding the report when it's not needed. An optional report could be an improvement, but I don't see it necessary at the metric level.
I tried to run a benchmark of the counting overhead to assess whether it's worth implementing a skip option. This isn't really realistic because in practice there's a bunch of IO going on to spread the actual counter increments apart, but in the worst case where multiple workers (8 in the benchmark) are contending to update the atomics counters, 200ns per file/ 200ms per million files. That's not a small amount, but small enough given the unlikelyness of this setup that we can defer such a feature IMO.
Java btw doesn't do this either. It always counts and I don't really understand why it uses nullable counters 🤷
There was a problem hiding this comment.
Makes sense to me, I haven't looked at your other PRs yet so apologies if this doesn't make sense but elsewhere in iceberg we try and use the builder macro rather than having crate pub fields, we're a little inconsistent but would that make sense here? Or do we end up mutating this struct in a number of places?
There was a problem hiding this comment.
I see what you're pointing at and I think the PlanningCounters type introduced in #3736 may be what you're looking for.
The ScanMetrics struct is indeed supposed to be an immutable type. It is only being constructed internally during scan planning. In a follow-up PR the mutable PlanningCounters introduces something close to a builder pattern in scan/metrics.rs.
I wouldn't consider it a regular builder and therefore didn't name it like that because it's used concurrently throughout scan planning and each "setter" is called multiple times to increment counters.
| /// Information and metrics collected while planning a table scan. | ||
| #[derive(Debug)] | ||
| pub struct ScanReport { | ||
| pub(crate) table_ident: TableIdent, |
There was a problem hiding this comment.
https://github.com/apache/iceberg/blob/95aac2f4b100db7f8f37563d58d09daf01196d47/core/src/main/java/org/apache/iceberg/metrics/ScanReport.java#L30 Java just takes the name here, is there a reason to take the ident out of interest?
There was a problem hiding this comment.
There's no technical reason, I only feel like a typed/ named thing is usually more descriptive and flexible than a plain string. We can easily derive the name from it and its a tad harder to assign a wrong value 🤷
But nothing I have a strong opinion about if you prefer to be consistent with Java.
There was a problem hiding this comment.
Reasoning makes sense, I'm happy with this!
Which issue does this PR close?
This PR works towards #1466 to make iceberg-rust participate in metrics reporting. This is relevant to analyze access patterns and troubleshoot problems with table layout.
I realized that #3667 is too big to get started and am instead attempting to land the API first, because the metrics counting logic can re-use it for tests.
flowchart LR A["This PR: Reporter API"] --> C["#3736: Scan reporting"] B["#3732: Planning counters"] --> C C --> D["Follow-ups"] click B href "https://github.com/apache/iceberg-rust/pull/3732" _blank click C href "https://github.com/apache/iceberg-rust/pull/3736" _blankWhat changes are included in this PR?
This PR builds the public reporter contract and scan report types).
Note that it's
asyncbecause theRestCatalogwill, by default, send reports to a catalog server.I plan to have the scan report's fields match Java's. This makes it much easier to analyze metrics across different language clients.
The Java implementation uses custom classes for both
DurationMetricandCounterMetric. I don't see a lot of value in creating a separate type for the duration because the unit is already encoded instd::time::Duration.This is not the case for u64s, and a custom
Countercould be a possible addition.Are these changes tested?
Yes, other PRs build on this API showing that it's design is plausible. The PR doesn't include any logic.
AI Disclosure
Generated the with an agent.