Skip to content

feat: Add metrics reporting API - #3709

Open
DerGut wants to merge 1 commit into
apache:mainfrom
DerGut:scan-reporter
Open

DerGut wants to merge 1 commit into
apache:mainfrom
DerGut:scan-reporter

Conversation

@DerGut

@DerGut DerGut commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

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" _blank
Loading

What changes are included in this PR?

This PR builds the public reporter contract and scan report types).

#[async_trait]
pub trait MetricsReporter: Debug + Send + Sync {
    /// Reports the metrics for a completed table operation.
    async fn report(&self, report: &MetricsReport);
}

Note that it's async because the RestCatalog will, 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 DurationMetric and CounterMetric. I don't see a lot of value in creating a separate type for the duration because the unit is already encoded in std::time::Duration.
This is not the case for u64s, and a custom Counter could 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.

@DerGut DerGut changed the title feat(iceberg): add metrics reporting API feat: Add metrics reporting API Nov 17, 2026
@DerGut
DerGut marked this pull request as ready for review November 17, 2026 17:59
Expose the reporter contract and read-only scan report types independently
from scan metric collection and delivery.

@xanderbailey xanderbailey left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great to see metrics being worked on!


/// Metrics collected while planning a table scan.
#[derive(Debug)]
pub struct ScanMetrics {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 🤷

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reasoning makes sense, I'm happy with this!

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants