Skip to content

refactor(metrics): relocate Iceberg metrics write path to extensions with enveloped core SPI (PR0 of 3) - #5068

Merged
dimas-b merged 5 commits into
apache:mainfrom
obelix74:metrics-pr0-spi-refactor
Jul 21, 2026
Merged

dimas-b merged 5 commits into
apache:mainfrom
obelix74:metrics-pr0-spi-refactor

Conversation

@obelix74

Copy link
Copy Markdown
Contributor

What / Why

Per the community sync (EJ, Dmitri, Anand), the Iceberg metrics work is being re-sliced into three PRs so the persistence-code-placement refactor is reviewable on its own, separate from the query feature:

This PR contains no query / read / REST code — only the write-path reorganization.

Changes

  • Move the Iceberg metrics reporter SPI into polaris-core as IcebergMetricsReporter, taking a MetricsReportEnvelope (explicit MetricType + resolved table context + Iceberg report) instead of a raw MetricsReport.
  • Relocate reporter implementations to extensions: LoggingMetricsReporter (default) and NoOpMetricsReporter in extensions/metrics-reports/base; PersistingMetricsReporter, MetricsRecordConverter, and a write-only JdbcMetricsPersistence in extensions/metrics-reports/persistence/relational-jdbc.
  • Keep the neutral record types and the MetricsPersistence write SPI in polaris-core; move the JDBC model classes into the extension.
  • Decouple metrics from core persistence: drop the MetricsPersistence implementation from JdbcBasePersistenceImpl and remove getOrCreateMetricsPersistence from MetaStoreManagerFactory and its implementations. The extension's JdbcMetricsPersistence is now the sole MetricsPersistence CDI bean.
  • Reporter selection stays in runtime/service (default type default = logging); the envelope is built at the IcebergCatalogHandler call site.

Testing

  • ./gradlew build and :polaris-runtime-service:intTest (Quarkus) pass.

Anand Kumar Sankaran added 3 commits July 15, 2026 14:12
…with enveloped core SPI (PR0)

Extract the metrics write-path reorganization into its own change (agreed
with EJ and Dmitri) ahead of the query REST API (PR1) and JDBC query impl
(PR2):

- Move the Iceberg metrics reporter SPI into polaris-core as
  IcebergMetricsReporter, taking a MetricsReportEnvelope (explicit
  MetricType + resolved table context + Iceberg report) instead of a raw
  MetricsReport.
- Relocate reporter implementations to extensions: LoggingMetricsReporter
  (default) and NoOpMetricsReporter in metrics-reports/base;
  PersistingMetricsReporter, MetricsRecordConverter and a write-only
  JdbcMetricsPersistence in metrics-reports/persistence/relational-jdbc.
- Keep the neutral record types and MetricsPersistence write-SPI in
  polaris-core; move the JDBC model classes into the extension.
- Decouple metrics from core persistence: drop the MetricsPersistence
  implementation from JdbcBasePersistenceImpl and remove
  getOrCreateMetricsPersistence from MetaStoreManagerFactory and its
  implementations; the extension's JdbcMetricsPersistence is now the sole
  MetricsPersistence CDI bean.
- Wire reporter selection in runtime/service (default type 'default' =
  logging) and build the envelope at the IcebergCatalogHandler call site.
…BC metrics models to the extension (PR0)

The metrics JDBC model classes (ModelScanMetricsReport, ModelCommitMetricsReport)
moved to the polaris-extensions-metrics-reports-jdbc module in this change, so the
core relational-jdbc test that converts against them no longer compiles there.
Model/record conversion is covered by the relocated model tests (and, in PR2, by
the extension's SpiModelConverterTest).
@obelix74

Copy link
Copy Markdown
Contributor Author

@dimas-b and @flyingImer - this is PR0.

@dimas-b dimas-b 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.

Thanks for the quick refactoring, @obelix74 !

This PR LGTM 👍 Only the comment about the WARN log message is a concern from my POV. Other comments are optional.

* belong in the implementing class, not here.
*/
@Beta
public interface IcebergMetricsReporter {

@dimas-b dimas-b Jul 16, 2026 •

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.

Now that metrics have been detached from BasePersistence, I do not see any use cases for this interface in polaris-core. Only the REST API service code needs it, but that code is located in runtime/service.

I believe moving it to runtime/service might be a good idea (together with MetricsReportEnvelope and MetricsType, of course).

  • It keeps core free from extraneous code.
  • Implementations of this interface can only work in conjunction with runtime/service anyway, so adding that dependency does not cause a "dependency leak".

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.

Done — moved IcebergMetricsReporter, MetricsReportEnvelope and MetricType to runtime/service (org.apache.polaris.service.metrics); polaris-core no longer carries them. The base and JDBC reporter extensions now depend on polaris-runtime-service, matching the existing pattern in extensions/semantic-models. Thanks for the suggestion.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@dimas-b I want to push back on the runtime/service move specifically.

I don't think "only the REST service code needs it today" is the right test for where a contract lives. The real question: is this a runtime-agnostic contract, portable enough that someone could call it from outside Quarkus entirely like a Lambda, a Spring app, whatever they're running Polaris logic inside, without dragging in anything Quarkus-specific to do it?

semantic check: Callback to the platform-flexibility bar (the north star) you raised in previous metrics sync, I interpret it as: Polaris being a platform should have the flexibility to support different backends per concern, not force every consumer through one runtime module. And it's the exact boundary rule from the SPI mental-model preview a few syncs later: provider impls should compile against public contracts only, never against runtime/service wiring. This SPI is a contract a provider implements. By that rule it belongs where contracts live, not where wiring lives. I am fully aware that our current situation is far from this desired shape, I'm collecting a short list.

syntactic check: Look at the interface itself: zero CDI, zero JAX-RS, nothing Quarkus about it. Nothing in the TYPE stops it from being portable. Only the module we put it in does that. Pinning it to runtime/service doesn't describe a fact about the contract, IMO it introduces undesired dependency challenges.

On your second bullet, that implementations can only work in conjunction with runtime/service anyway so it's not a dependency leak: I agree with the rule. But I see it as out of the box Polaris experience has a hard dependency on runtime framework we choose here, but not the contract. A contract can live in the module every implementation modules dependable, which is core/.

Current placement put SPI in runtime/, which requires alternative impls to depend on runtime/ module rather than core/ module. It creates a weird dependency of extensions/ -> runtime/ -> core/ and extensions/, which should have been runtime/ -> extensions/ and core/. I think extensions/ module can be framework aware, but not in a way directly depend on runtime/ but depending on framework modules as runtime/ would do IMHO.

If "keeps core free of extraneous code" is the real worry, I'm fine with extensions/ instead of core/ for now, I think we briefly discussed this placement model early on. I'm still working out how I want to mental-model where a contract like this settles long-term, happy to leave that open. Just not runtime/service, that's the one placement that doesn't hold up IMO.

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.

I guess #5204 is the continuation of this discussion, right?

}

@Override
public MetricsPersistence getOrCreateMetricsPersistence(RealmContext realmContext) {

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.

nice cleanup 👍

Comment on lines +455 to +458
LOGGER.warn(
"No IcebergMetricsReporter found for type '{}'; Iceberg metrics will be dropped",
config.type());
return envelope -> {};

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.

I'm not sure a WARN log is justified here. IcebergMetricsReporter is a required parameter for IcebergCatalogHandler, but if a particular downstream build chooses not to bundle a metrics reporter, this warning will be a false alarm.

It might be best to return an implementation that fails (and logs) if reportMetric() is actually invoked.

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.

Good point — removed the startup WARN. The producer now returns a reporter that logs an error and throws IllegalStateException only if reportMetric() is actually invoked, so a downstream build that intentionally omits a metrics reporter won't get a false alarm at startup.

…ke fallback (PR0 review)

Address review feedback from @dimas-b on apache#5068:

- Move IcebergMetricsReporter, MetricsReportEnvelope and MetricType from
  polaris-core to runtime/service (org.apache.polaris.service.metrics). With
  metrics detached from BasePersistence, core no longer needs the reporter SPI;
  only runtime/service and the reporter extensions use it. The base and JDBC
  reporter extensions now depend on polaris-runtime-service (same pattern as
  extensions/semantic-models).
- ServiceProducers.metricsReporter no longer logs a WARN at startup when no
  reporter matches the configured type (a false alarm for downstream builds that
  intentionally omit a reporter). It now returns a reporter that logs an error
  and throws only if reportMetric() is actually invoked.
@obelix74
obelix74 requested a review from dimas-b July 16, 2026 05:31
dimas-b
dimas-b previously approved these changes Jul 16, 2026

@dimas-b dimas-b 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.

Thanks, @obelix74 !

@github-project-automation github-project-automation Bot moved this from PRs In Progress to Ready to merge in Basic Kanban Board Jul 16, 2026
@dimas-b
dimas-b requested a review from flyingImer July 16, 2026 14:18
@dimas-b

dimas-b commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

@obelix74 : Unfortunately, it looks like tests like PolarisRestCatalogMinIOIT > testSendMetricsReport() fail now 🤷 🤔

dimas-b
dimas-b previously approved these changes Jul 16, 2026
@obelix74

Copy link
Copy Markdown
Contributor Author

Thanks @dimas-b, I will be offline starting tomorrow for 9 days. Merge at will.

@dimas-b

dimas-b commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

@obelix74 : sure, but CI failed again 😅

…R0 review)

The reporter SPI moved to runtime/service, and the reporter impls had moved to the
metrics-reports extensions. But runtime/service's own @QuarkusIntegrationTest apps
are built from runtime/service's runtime classpath, which cannot include the base
extension (base depends on runtime/service for the SPI — that would be a dependency
cycle). With no reporter bundled, the fail-on-invoke fallback threw on reportMetrics,
breaking the reportMetrics authz tests and testSendMetricsReport (500 vs 204).

Keep the default LoggingMetricsReporter (@Identifier("default")) in runtime/service
(where it lived originally), co-located with the SPI. The extensions keep the
alternative reporters (no-op in base, persisting in the JDBC extension). This makes
every runtime/service app resolve the default reporter, while the fail-on-invoke
fallback still guards genuinely stripped-down downstream builds.
@obelix74

Copy link
Copy Markdown
Contributor Author

@obelix74 : sure, but CI failed again 😅

Took a while, but it is fixed now.

@dimas-b

dimas-b commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

@flyingImer : Any concerns from your side? If not I propose to merge on Jul 21. Follow-up changes are always welcome even if we miss something in this PR 😅

@dimas-b

dimas-b commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

I believe this PR matches the refactoring direction as discussed on dev.

https://lists.apache.org/thread/0jz0zd6q2hn9drfpx6w1mzj9sv309q8r

I'm merging it in current state. Further refactoring / improvement proposals are welcome, of course.

@dimas-b
dimas-b merged commit b81766a into apache:main Jul 21, 2026
25 checks passed
@github-project-automation github-project-automation Bot moved this from Ready to merge to Done in Basic Kanban Board Jul 21, 2026

@flyingImer flyingImer left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM overall, great progress! just the placement I'm not aligned with

* belong in the implementing class, not here.
*/
@Beta
public interface IcebergMetricsReporter {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@dimas-b I want to push back on the runtime/service move specifically.

I don't think "only the REST service code needs it today" is the right test for where a contract lives. The real question: is this a runtime-agnostic contract, portable enough that someone could call it from outside Quarkus entirely like a Lambda, a Spring app, whatever they're running Polaris logic inside, without dragging in anything Quarkus-specific to do it?

semantic check: Callback to the platform-flexibility bar (the north star) you raised in previous metrics sync, I interpret it as: Polaris being a platform should have the flexibility to support different backends per concern, not force every consumer through one runtime module. And it's the exact boundary rule from the SPI mental-model preview a few syncs later: provider impls should compile against public contracts only, never against runtime/service wiring. This SPI is a contract a provider implements. By that rule it belongs where contracts live, not where wiring lives. I am fully aware that our current situation is far from this desired shape, I'm collecting a short list.

syntactic check: Look at the interface itself: zero CDI, zero JAX-RS, nothing Quarkus about it. Nothing in the TYPE stops it from being portable. Only the module we put it in does that. Pinning it to runtime/service doesn't describe a fact about the contract, IMO it introduces undesired dependency challenges.

On your second bullet, that implementations can only work in conjunction with runtime/service anyway so it's not a dependency leak: I agree with the rule. But I see it as out of the box Polaris experience has a hard dependency on runtime framework we choose here, but not the contract. A contract can live in the module every implementation modules dependable, which is core/.

Current placement put SPI in runtime/, which requires alternative impls to depend on runtime/ module rather than core/ module. It creates a weird dependency of extensions/ -> runtime/ -> core/ and extensions/, which should have been runtime/ -> extensions/ and core/. I think extensions/ module can be framework aware, but not in a way directly depend on runtime/ but depending on framework modules as runtime/ would do IMHO.

If "keeps core free of extraneous code" is the real worry, I'm fine with extensions/ instead of core/ for now, I think we briefly discussed this placement model early on. I'm still working out how I want to mental-model where a contract like this settles long-term, happy to leave that open. Just not runtime/service, that's the one placement that doesn't hold up IMO.

@obelix74
obelix74 deleted the metrics-pr0-spi-refactor branch July 29, 2026 17:04
flyingImer added a commit to flyingImer/polaris that referenced this pull request Aug 5, 2026
PR apache#5068 moved this SPI (plus its MetricsReportEnvelope carrier and
MetricType discriminator) into runtime/service. As raised in review
(apache#5068 (comment)),
the interface has no CDI/Quarkus/JAX-RS dependency at all: only guava,
jspecify, and Iceberg's own types. Nothing in the type stops it from
being implemented outside Quarkus; only the module we put it in did.

Move it to polaris-core, alongside the existing
org.apache.polaris.core.persistence.metrics package (the durable-
storage side of metrics, which this leaves untouched). This lets every
implementation module depend on polaris-core for the contract instead
of on runtime/service.

Package-only change, no other edits.
flyingImer added a commit to flyingImer/polaris that referenced this pull request Aug 12, 2026
PR apache#5068 put this SPI (plus its MetricsReportEnvelope carrier and
MetricType discriminator) in runtime/service. As raised in review
(apache#5068 (comment)),
the interface has no CDI, Quarkus or JAX-RS dependency at all: only
guava, jspecify, and Iceberg's own types. Nothing in the type stops it
being implemented outside Quarkus; only the module we put it in did.

Introduces a shared spi module for framework-free contracts and lands
these three types in it. The reporter is a substrate contract rather
than a feature one: the user-facing operation is the Iceberg REST
catalog's own metrics endpoint, gated by the ordinary table data
privileges, and the reporter is the replaceable sink that endpoint
hands the report to. That puts it alongside authorization in the call
graph, which is why it sits under spi.substrate rather than spi.feature.

Only the metrics contracts move here. Relocating anything else out of
polaris-core is deliberately left out of this change.
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.

3 participants