Skip to content

(feat) Implement metrics rest api - #4115

Merged
dimas-b merged 1 commit into
apache:mainfrom
obelix74:implement_metrics_rest_api
Nov 26, 2026
Merged

dimas-b merged 1 commit into
apache:mainfrom
obelix74:implement_metrics_rest_api

Conversation

@obelix74

@obelix74 obelix74 commented Apr 2, 2026 •

Copy link
Copy Markdown
Contributor

What / Why

Part of the 3-PR split of the Iceberg metrics work (agreed with EJ, Dmitri, Anand):

Depends on #5068. This branch is stacked on the PR0 branch, so until #5068 merges the diff here also shows PR0's changes. Review the commits from feat(metrics): add Table Metrics Reports query REST API (PR1) onward.

Changes

  • OpenAPI spec + generated module under extensions/metrics-reports/api (polaris-extensions-metrics-reports-api) — the metrics API ships as an optional, extension-scoped feature.
  • MetricsQuerySpi in extensions/metrics-reports/spi; a no-op default (NoOpMetricsQuery, @DefaultBean) in extensions/metrics-reports/base so the read path returns an empty page (HTTP 200) until a durable backend is installed.
  • Thin HTTP→SPI handler MetricsReportsService in runtime/service (resolves names→ids, authorizes, delegates to MetricsQuerySpi).
  • Read-path authorization in polaris-core: TABLE_READ_METRICS privilege + LIST_TABLE_METRICS operation, wired through the authorizer/RBAC and mirrored in the Ranger extension.

Testing

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

@github-project-automation github-project-automation Bot moved this to PRs In Progress in Basic Kanban Board Apr 2, 2026
@obelix74 obelix74 mentioned this pull request Apr 2, 2026
3 of 6 tasks
@jbonofre
jbonofre self-requested a review April 3, 2026 11:25
@obelix74
obelix74 force-pushed the implement_metrics_rest_api branch from 1d37c50 to ac66c27 Compare April 10, 2026 14:26

@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 pushing this feature forward, @obelix74 !

The PR LGTM in general. Posting some comments about code organization, subject to discussion, of course.

Comment thread spec/metrics-reports-service.yml Resolved
Comment thread spec/metrics-reports-service.yml Resolved
Comment thread spec/metrics-reports-service.yml Resolved
Comment thread spec/metrics-reports-service.yml Resolved
Comment thread runtime/service/build.gradle.kts Resolved

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

LGTM with one minor remaining comment 😅

@sungwy , @sneethiraj : FYI about the new AuthZ operation.

Comment thread gradle/projects.main.properties Resolved
Comment thread CHANGELOG.md Resolved
Comment thread spec/metrics-reports-service.yml Resolved
@obelix74
obelix74 requested a review from dimas-b April 16, 2026 16:08

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

The direction looks right to me

Two structural observations:

  • With this PR, MetricsPersistence grows from 2 write methods to 4 (read + write). It's marked @beta and the javadoc calls it a "Service Provider Interface." But it lives on BasePersistence, which only local DB backends implement. NoSqlMetaStoreManager and RemotePolarisMetaStoreManager go through empty BasePersistence implementations, so these methods are permanently no-op for them. Meanwhile, the actual SPI interfaces (PolarisMetricsReporter, PolarisMetricsManager) have no annotation at all. The @beta signal is on the wrong layer IIUC

  • The write path enters through PolarisMetricsManager on MetaStoreManager, but this read path bypasses that layer and goes straight to BasePersistence via callContext.getMetaStore(). If we want the metrics read API to work for non-JDBC backends, it would need a MetaStoreManager-level entry point, same as writes.

Not blocking on this. I think the question of where metrics persistence should sit architecturally is worth a discussion on dev@.

@obelix74

Copy link
Copy Markdown
Contributor Author

The direction looks right to me

Two structural observations:

  • With this PR, MetricsPersistence grows from 2 write methods to 4 (read + write). It's marked @beta and the javadoc calls it a "Service Provider Interface." But it lives on BasePersistence, which only local DB backends implement. NoSqlMetaStoreManager and RemotePolarisMetaStoreManager go through empty BasePersistence implementations, so these methods are permanently no-op for them. Meanwhile, the actual SPI interfaces (PolarisMetricsReporter, PolarisMetricsManager) have no annotation at all. The @beta signal is on the wrong layer IIUC
  • The write path enters through PolarisMetricsManager on MetaStoreManager, but this read path bypasses that layer and goes straight to BasePersistence via callContext.getMetaStore(). If we want the metrics read API to work for non-JDBC backends, it would need a MetaStoreManager-level entry point, same as writes.

Not blocking on this. I think the question of where metrics persistence should sit architecturally is worth a discussion on dev@.

Thank you. I have added @Beta annotation to PolarisMetricsManager and PolarisMetricsReporter.

About the second point, thank you. Would this mean a read method to PolarisMetricsManager and MetaStoreManager mirroring the write path? Should I do it in this PR or can this wait?

@flyingImer

Copy link
Copy Markdown
Collaborator

The direction looks right to me
Two structural observations:

  • With this PR, MetricsPersistence grows from 2 write methods to 4 (read + write). It's marked @beta and the javadoc calls it a "Service Provider Interface." But it lives on BasePersistence, which only local DB backends implement. NoSqlMetaStoreManager and RemotePolarisMetaStoreManager go through empty BasePersistence implementations, so these methods are permanently no-op for them. Meanwhile, the actual SPI interfaces (PolarisMetricsReporter, PolarisMetricsManager) have no annotation at all. The @beta signal is on the wrong layer IIUC
  • The write path enters through PolarisMetricsManager on MetaStoreManager, but this read path bypasses that layer and goes straight to BasePersistence via callContext.getMetaStore(). If we want the metrics read API to work for non-JDBC backends, it would need a MetaStoreManager-level entry point, same as writes.

Not blocking on this. I think the question of where metrics persistence should sit architecturally is worth a discussion on dev@.

Thank you. I have added @Beta annotation to PolarisMetricsManager and PolarisMetricsReporter.

About the second point, thank you. Would this mean a read method to PolarisMetricsManager and MetaStoreManager mirroring the write path? Should I do it in this PR or can this wait?

Thanks for adding @beta.

Reads should go through MetaStoreManager too, same as writes. If reads stay on BasePersistence, non-JDBC backends can't implement the read API at all. I'd prefer fixing that in this PR so the read path ships with the same layering as writes.

Separately, the persistence schema discussion on dev@ is still open. A follow-up issue linking to that thread would help track it.

@obelix74

Copy link
Copy Markdown
Contributor Author

Reads should go through MetaStoreManager too, same as writes. If reads stay on BasePersistence, non-JDBC backends can't implement the read API at all. I'd prefer fixing that in this PR so the read path ships with the same layering as writes.

Separately, the persistence schema discussion on dev@ is still open. A follow-up issue linking to that thread would help track it.

Pushed a commit (and rebased against updated main). listScanMetrics and listCommitMetrics are now on PolarisMetricsManager (and therefore MetaStoreManager), following the same pattern as the write methods. MetricsReportsService now injects PolarisMetaStoreManager and routes reads through it rather than calling callContext.getMetaStore() directly.

For the persistence schema discussion — I'll open a follow-up issue linking to the dev@ thread once there's a message to reference. Happy to do that now if you can share the thread link (I don't have it handy). Please let me know.

@obelix74
obelix74 requested a review from flyingImer April 28, 2026 18:00

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

The metrics API story LGTM 👍

I still have more general concerns related to SPI design and service wiring, but they are not specific to this feature.

Thanks for working on this @obelix74 !

@github-project-automation github-project-automation Bot moved this from PRs In Progress to Ready to merge in Basic Kanban Board May 15, 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.

Are you planning to merge as-is now that Dmitri approved, or is there another round? Asking because the May 7 metrics sync landed on a few directional items that touch the schema and SPI shape here. Left some questions inline.

@obelix74
obelix74 requested a review from dimas-b May 19, 2026 15:26
dimas-b
dimas-b previously approved these changes May 19, 2026
@dimas-b

dimas-b commented May 26, 2026

Copy link
Copy Markdown
Contributor

@obelix74 : it looks like this PR got a lot of conflicts 🤷

@obelix74

Copy link
Copy Markdown
Contributor Author

@obelix74 : it looks like this PR got a lot of conflicts 🤷

Resolved all conflicts and push. Rebased against main.

dimas-b
dimas-b previously approved these changes May 26, 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.

Thanks for continuing to push this forward. The direction still looks good to me: exposing persisted metrics through a beta read API, using a stable response envelope, keeping the API in an extension module, and routing reads through table-scoped authz all make sense.

One thing I would still like to clarify before this merges is sequencing with the metrics SPI/schema work we discussed after the May 7 sync.

From the previous review thread, I think we already converged on a few points:

  • the current MetricsPersistence / PolarisMetricsManager layering is transitional, and #4397 is expected to move metrics persistence out of the old aggregated BasePersistence shape;
  • the current scan_metrics_report / commit_metrics_report split is also transitional, with the follow-up direction being a single metrics report model/table with a metric type discriminator;
  • listScanMetrics / listCommitMetrics are therefore likely interim API/SPI shapes, and may collapse or be rerouted when the schema/SPI consolidation happens.

I don't think this PR has to solve all of that before it can make progress. But I do think we should avoid accidentally standardizing the transitional shape just because this PR is ready first.

Could we make the sequencing explicit before merge? For example, either rebase on #4397 if that lands first, or link a concrete follow-up that tracks:

  1. moving metrics persistence to the standalone SPI shape,
  2. consolidating the metrics schema/model,
  3. deciding whether the per-type list methods remain public SPI surface or collapse behind a typed query API.

Comment thread spec/metrics-reports-service.yml Resolved
dimas-b
dimas-b previously approved these changes May 28, 2026

@flyrain flyrain 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 a lot for working on it @obelix74 . The spec looks much better now. I think we should be ready to go once the new comments got resolved.

- metricTypes
- objects
properties:
metricTypes:

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.

It looks like the REST spec uses lowercase, hyphenated field names, such as metric-type, rather than uppercase names like metricTypes. Can we fix all field names?

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.

Renamed all of them to lowercase hyphenated: metric-types, page-token, page-size, timestamp-from, timestamp-to, next-page-token, snapshot-id, metric-type and timestamp-ms. I regenerated the bundled spec too. Fixed in ebfec76.

Defaults to `iceberg-table` when omitted. Currently, only `iceberg-table` is supported;
entries with unsupported values are ignored.
snapshotId:
type: integer

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.

Could we define snapshotId as a string and treat it as an opaque, format specific identifier if we want this API to support table formats beyond Iceberg? Delta and Paimon use numeric IDs, Hudi uses instant times, and Lance uses unsigned version IDs, so int64 would not cover all of them. The service could validate and resolve the value based on the table format. Each format would still need backend support.

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.

Changed snapshot-id to a string and described it as an opaque, format-specific identifier. For iceberg-table the service parses it as a long and returns a 400 if it isn't numeric, and responses return it as a string. Other table formats would need their own validation and backend support. Fixed in ebfec76.

Comment on lines +151 to +153
Maximum number of results to return per page. When omitted, the server selects the page
size (`METRICS_QUERY_DEFAULT_PAGE_SIZE`, 100 by default). Values above the server maximum
(`METRICS_QUERY_MAX_PAGE_SIZE`, 1000 by default) are reduced to it.

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.

We shouldn't tie the REST spec to a server config. I think we can remove the description first, and adopt the pagination schema in #6028 after it's merged in a followup PR.

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.

Removed the config names from the spec and dropped the page-size description. I'll move to the pagination schema from #6028 in a follow-up PR once it's merged. Fixed in ebfec76.

Comment on lines +139 to +140
Overlapping entries do not duplicate reports. The server limits the number of entries
per request (`METRICS_QUERY_MAX_OBJECTS`, 100 by default) and rejects larger requests

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.

Same here. I removed METRICS_QUERY_MAX_OBJECTS from the objects description, it now just says the server limits the number of entries and rejects larger requests with a 400. Fixed in ebfec76.

@obelix74

Copy link
Copy Markdown
Contributor Author

Pushed ebfec76 with fixes for all the open review threads (replies are on each one). Remaining follow-up: switch to the pagination schema from #6028 once it lands.

orca-review-bot
orca-review-bot approved these changes Nov 10, 2026 •
items:
$ref: '#/components/schemas/CatalogObject'
page-token:
$ref: '../iceberg-rest-catalog-open-api.yaml#/components/schemas/PageToken'

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 am very much against reusing and promoting the IRC paginations definitions.

Servers that support pagination must return all results in a single response with the value
of `next-page-token` set to `null` if the query parameter `pageToken` is not set in the
request.

I do believe that the requirement for servers to return all data is generally unreasonable and with metrics queries it specifically makes servers vulnerable to DoS via OOM attacks.

This has been discussed at length on dev.

https://lists.apache.org/thread/k81ptyktdbdf8gynncgk3o04mqt85zyk
https://lists.apache.org/thread/mmqllcbt2lfsrq571cfwbymgfwoxqdf0

@flyrain : If you proposed this reference (apologies, but I am lost in the multitude of comments on this PR), let's open a dedicated dev discussion to settle this matter.

I believe, the option for servers to fail on overly long result sets is not a replacement for a specification that instructs clients how to properly process large results.

Cf. #5927 (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.

Cf. #6028

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.

We could migrate once #6028 is done. What's your proposal for this PR, @dimas-b ?

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

I do not see a reason for adding a new API with a pagination spec that has known usability concerns. If we do that we'll be in the same situation as with the IRC API, which we had to deal with in the two dev discussions I linked above.

My proposal is using local pagination parameter definitions similar to #5927

After #6028 lands we can refactor YAML files to share some elements.

The critical point from my POV is NOT allowing clients to force servers into returning all data.

I might have missed that in my earlier reviews. Apologies about that.

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.

works for me

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.

@obelix74 : WDYT?

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.

Makes sense, I switched to local definitions following #5927. page-token in the request is now a plain string instead of a ref to the IRC PageToken, page-size is documented as a hint, and the operation description says any response may be paginated and clients can't ask for all results in one response. The server already paginated every request and capped the page size at METRICS_QUERY_MAX_PAGE_SIZE, so only the spec changed. I'll move this to the shared definitions once #6028 lands.

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.

thx!

flyrain
flyrain previously approved these changes Nov 12, 2026
dimas-b
dimas-b previously approved these changes Nov 12, 2026
@dimas-b

dimas-b commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

@obelix74 : Unfortunately, it looks like there are merge conflicts now 🤷

@obelix74

Copy link
Copy Markdown
Contributor Author

Rebased onto main to clear the merge conflicts. There were two: main added the LIST_VIEW import in RbacOperationSemantics right where this PR adds LIST_TABLE_METRICS (kept both), and both sides added an entry to the New Features section of CHANGELOG.md (kept both). I regenerated spec/generated/bundled-polaris-catalog-service.yaml with make spec-bundle instead of merging it by hand. Nothing else changed since the last round, which was the local pagination definitions for the query API.

@adnanhemani adnanhemani 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.

One comment left for me; I think there's a potential bug in MetricsReportService.java.

Map<Long, TableIdentifier> tableIdToIdentifier = resolved.tableIdToIdentifier();
if (tableIdToIdentifier.isEmpty()) {
// Missing and denied tables are indistinguishable, so this does not reveal which exist.
throw new ForbiddenException(

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.

This 403 fires whenever the authorized set is empty, including on a follow-up page if every previously readable table is gone or lost TABLE_READ_METRICS. A client walking next-page-token would see a 403 mid-listing.

Could later pages return 200 with empty reports and a null token instead, so a pager can treat this as end-of-results rather than an auth failure? Fine to keep 403 on the first page when nothing is readable.

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.

Agreed, done in c066b0d. When a request carries a page-token and none of the tables is readable anymore, the server now returns 200 with empty reports and a null next-page-token, so a pager treats it as the end of the results. The first page still returns 403. I added a test for the later-page case and described the behavior in the operation description.

403:
$ref: '../iceberg-rest-catalog-open-api.yaml#/components/responses/ForbiddenResponse'
404:
description: Not Found - The catalog does not exist

@adnanhemani adnanhemani Nov 13, 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.

Is "catalog does not exist" correct - or can it also be table?

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.

Catalog is correct. The tables are resolved as optional paths, so a missing table is left out of the result (or leads to the 403 when nothing is readable), and only a missing catalog produces a 404. The NoSuchTableError example under the 404 was wrong though, it made it look like a missing table returns 404. I dropped it in c066b0d and spelled out in the 404 description that missing tables never produce one.

adnanhemani
adnanhemani previously approved these changes Nov 13, 2026

@adnanhemani adnanhemani 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 addressing all the back-and-forth, @obelix74. Happy to see this finally getting over the line!

dimas-b
dimas-b previously approved these changes Nov 13, 2026
only to a request without a `page-token`: when none of the tables is readable on a later
page, for example because they were dropped or the privilege was revoked during the
listing, the server returns an empty `reports` list with no `next-page-token`. A 404 is
returned only when the catalog itself does not exist.

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.

Do we return a 404 if a catalog exists, but the caller doesn't have any privileges on it? That should be the default behavior

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.

My reading is that this sentence indicates that 404 is returned for non-existent catalogs, but not for non-existent entities. The latter receive 200 responses with no data.

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 meant specifically for a catalog that does exist, but that the user doesn't have any privileges on - not whether it had any underlying entities. I realize this isn't consistent behavior with the other apis. I'm ok to keep the behavior as is, though a future improvement would be to update entity access apis to return 404 if the user has no privileges on the underlying entity.

@adutra

adutra commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

Heads-up: #5967 has been merged, so CHANGELOG.md is no longer edited directly. Changelog entries now go in a fragment file under changelog.d/, which avoids merge conflicts on CHANGELOG.md. See changelog.d/README.md for the format.

Could you rebase onto main, revert your changes to CHANGELOG.md, and add a fragment file instead if your change needs a changelog entry? A fragment is only needed for things worth calling out in release notes, such as breaking changes, metastore schema changes, or changes that require manual steps during an upgrade. Thanks!

@obelix74

Copy link
Copy Markdown
Contributor Author

Thanks for the heads-up. I rebased onto main and reverted my change to CHANGELOG.md. The entry now lives in changelog.d/table-metrics-reports-api.md as a New Features item, since this adds a new REST API that users will want to see in the release notes.

The rebase had one real conflict, in polaris-ranger-servicedef.json. Main had already used itemId 70 for catalog-config-read, so table-metrics-read is now 71.

I couldn't run the full Gradle build locally (the Spotless plugin won't resolve on my machine because of a certificate error), so I'm leaning on CI to confirm formatting and compilation.

flyrain
flyrain previously approved these changes Nov 17, 2026
@dimas-b

dimas-b commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

@obelix74 : Some of the commits reference Claude as a formal co-author. Per Polaris contribution guidelines only humans can be "authors".

https://polaris.apache.org/community/contributing-guidelines/#guidelines-for-ai-assisted-contributions

Would you mind converting the co-author tags to something like Assisted-By or Generated-By?

Cf. https://lists.apache.org/thread/p8qpsr9ww5t2mkcz0252pbwklh3s5yr8

@obelix74

Copy link
Copy Markdown
Contributor Author

@obelix74 : Some of the commits reference Copilot as a formal co-author. Per Polaris contribution guidelines only humans can be "authors".

https://polaris.apache.org/community/contributing-guidelines/#guidelines-for-ai-assisted-contributions

Would you mind converting the co-author tags to something like Assisted-By or Generated-By?

Cf. https://lists.apache.org/thread/p8qpsr9ww5t2mkcz0252pbwklh3s5yr8

Squashed all commits and removed the Claude reference.

dimas-b
dimas-b previously approved these changes Nov 17, 2026
flyrain
flyrain previously approved these changes Nov 18, 2026
PolarisEntityType.TABLE_LIKE,
true));
}
ResolverStatus status = manifest.resolveAll();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I believe that both PolarisAuthorizerImpl and RangerPolarisAuthorizer/OpaPolarisAuthorizer call authzState.resolve() inside authorizer.resolveAuthorizationInputs(...), which invokes Resolver.resolveWithPlan(...).
Because manifest.resolveAll() was already called here on this line, Resolver.resolveWithPlan trips diagnostics.check(resolverStatus == null, "resolver_called") and throws an IllegalStateException (HTTP 500) whenever at least one requested table resolves (existing is not empty). MetricsReportsServiceTest masks this because manifest and authorizer are mocked.

We can resolve once by:

  1. Dropping the upfront manifest.resolveAll() call (and the unused PolarisEntityType.NAMESPACE passthrough paths, AuthorizationIntentResolver only looks up to TABLE_LIKE path).
  2. Building intents for all identifiers and calling authorizer.resolveAuthorizationInputs(authorizationState, new AuthorizationRequest(polarisPrincipal, allIntents)) once.
  3. Checking manifest.getPrimaryResolverStatusOrThrow() for ENTITY_COULD_NOT_BE_RESOLVED, collecting existing tables, and calling authorizer.authorize(...) only for those existing tables (since AuthorizationIntentResolver.resolve requires a resolved securable).

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 catch, you're right. I called manifest.resolveAll() and then the authorizer resolved the same manifest again, which trips the resolver_called check and turns into a 500 as soon as one requested table exists. The test didn't show it because the manifest and the authorizer were both mocks.

I took your suggestion. The upfront resolveAll() and the namespace passthrough paths are gone, the service builds an intent for every requested table, and resolveAuthorizationInputs runs once. After that I check the primary resolver status for a missing catalog, collect the tables that exist, and call authorize only for those, one table at a time so a denial on one doesn't affect the others.

The test now uses a manifest mock that throws on a second resolveAll(), and there's a test that checks the manifest is resolved once with an intent for each table (including a missing one). Against the old code 23 of the 32 tests in that class fail, so it does catch this. Pushed in 167f5f5.

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.

Good catch! I missed that in my review 🤦 Thanks for the fix, @obelix74 !

request.getTimestampTo() != null ? request.getTimestampTo() : clock.millis();
timestampFrom = upperBound - Duration.ofDays(windowDays).toMillis();
}
MetricsQuerySpi provider = queryProvider.get();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

NoOpMetricsQuery lives in extensions/metrics-reports/base (polaris-extensions-metrics-reports), which is only a runtimeOnly dependency in runtime/server, not in runtime/service. In runtime/service own @QuarkusIntegrationTest apps or stripped-down downstream builds that omit the extension (see ServiceProducers.metricReporter), queryProvider.get() will fail with UnsatisfiedResolutionException (HTTP 500).

We should either check queryProvider.isResolvable() here or move NoOpMetricsQuery into runtime/service alongside MetricsReportsService.

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.

You're right, NoOpMetricsQuery only comes in through the extension module, so a build without it would fail on queryProvider.get().

I went with isResolvable() rather than moving the class. When no MetricsQuerySpi bean is available the service returns an empty page, which is what the no-op default returns anyway, and the module layout stays as it is. The authorization checks still run first. Added a test for the no-backend case. Pushed in 167f5f5.

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.

isResolvable() SGTM. We might want to refactor module deps later. I do not think that is critical for current PR :)

dimas-b
dimas-b previously approved these changes Nov 19, 2026
@obelix74

Copy link
Copy Markdown
Contributor Author

@dimas-b Fixed a merge conflict.

dimas-b
dimas-b previously approved these changes Nov 23, 2026
jbonofre
jbonofre previously approved these changes Nov 25, 2026
@dimas-b

dimas-b commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

@obelix74 : sadly, there are new merge conflicts... Could you fix them?

@obelix74

Copy link
Copy Markdown
Contributor Author

@obelix74 : sadly, there are new merge conflicts... Could you fix them?

Done.

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

Merging based on previous approvals.

Thanks again for your contribution, @obelix74 !

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.

10 participants