Repository navigation
refactor(metrics): relocate Iceberg metrics write path to extensions with enveloped core SPI (PR0 of 3) - #5068
Conversation
…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).
|
@dimas-b and @flyingImer - this is PR0. |
| * belong in the implementing class, not here. | ||
| */ | ||
| @Beta | ||
| public interface IcebergMetricsReporter { |
There was a problem hiding this comment.
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/serviceanyway, so adding that dependency does not cause a "dependency leak".
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
@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.
There was a problem hiding this comment.
I guess #5204 is the continuation of this discussion, right?
| } | ||
|
|
||
| @Override | ||
| public MetricsPersistence getOrCreateMetricsPersistence(RealmContext realmContext) { |
| LOGGER.warn( | ||
| "No IcebergMetricsReporter found for type '{}'; Iceberg metrics will be dropped", | ||
| config.type()); | ||
| return envelope -> {}; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 : Unfortunately, it looks like tests like |
|
Thanks @dimas-b, I will be offline starting tomorrow for 9 days. Merge at will. |
|
@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.
2ef5118 to
79d5931
Compare
Took a while, but it is fixed now. |
|
@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 😅 |
|
I believe this PR matches the refactoring direction as discussed on I'm merging it in current state. Further refactoring / improvement proposals are welcome, of course. |
flyingImer
left a comment
There was a problem hiding this comment.
LGTM overall, great progress! just the placement I'm not aligned with
| * belong in the implementing class, not here. | ||
| */ | ||
| @Beta | ||
| public interface IcebergMetricsReporter { |
There was a problem hiding this comment.
@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.
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.
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.
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
polaris-coreasIcebergMetricsReporter, taking aMetricsReportEnvelope(explicitMetricType+ resolved table context + Iceberg report) instead of a rawMetricsReport.LoggingMetricsReporter(default) andNoOpMetricsReporterinextensions/metrics-reports/base;PersistingMetricsReporter,MetricsRecordConverter, and a write-onlyJdbcMetricsPersistenceinextensions/metrics-reports/persistence/relational-jdbc.MetricsPersistencewrite SPI inpolaris-core; move the JDBC model classes into the extension.MetricsPersistenceimplementation fromJdbcBasePersistenceImpland removegetOrCreateMetricsPersistencefromMetaStoreManagerFactoryand its implementations. The extension'sJdbcMetricsPersistenceis now the soleMetricsPersistenceCDI bean.runtime/service(default typedefault= logging); the envelope is built at theIcebergCatalogHandlercall site.Testing
./gradlew buildand:polaris-runtime-service:intTest(Quarkus) pass.