Skip to content

[#12566] feat(core): Dispatch events for catalog connection tests - #12585

Merged
mchades merged 9 commits into
apache:mainfrom
VedantMadane:fix/issue-12566
Oct 28, 2026
Merged

mchades merged 9 commits into
apache:mainfrom
VedantMadane:fix/issue-12566

Conversation

@VedantMadane

@VedantMadane VedantMadane commented Aug 24, 2026 •

Copy link
Copy Markdown
Contributor

What changes were proposed in this pull request?

Dispatch pre, success, and failure events for all three catalog connection-test overloads: pre-create, stored configuration, and proposed changes. Map TEST_CONNECTION_CATALOG in both audit implementations.

Events retain the supplied pre-create catalog information or proposed changes, and failure events retain the original exception, following existing catalog event conventions. A private helper centralizes event dispatch and captures the username once.

Why are the changes needed?

Allow listeners and auditing integrations to observe catalog connection tests with the appropriate operation context.

Fixes #12566.

Does this PR introduce any user-facing change?

Listeners receive TestConnectionPreEvent, TestConnectionEvent, and TestConnectionFailureEvent. Audit records identify these operations as TEST_CONNECTION_CATALOG.

Custom listeners can access request parameters and the original exception and are responsible for redaction before logging or forwarding them. Existing built-in audit formatting and redaction behavior is unchanged.

How was this patch tested?

  • ./gradlew :core:spotlessApply
  • ./gradlew :core:test --tests org.apache.gravitino.listener.api.event.TestCatalogConnectionEvent --tests org.apache.gravitino.listener.api.event.TestCatalogEvent --tests org.apache.gravitino.audit.TestOperation --tests org.apache.gravitino.audit.v2.TestCompatibilityUtils -PskipITs -PskipDockerTests=true --max-workers=2 --console=plain: 56 tests passed, no failures or skips.
  • Coverage includes all overloads and empty changes, request context, event ordering and counts, user identity, original exception propagation, pre-event vetoes, failing listeners, and exclusion of request payloads from built-in audit output.

Copilot AI 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.

Copilot review overview

🟡 Changes recommended

One or more issues must be addressed before approval.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 2 Medium severity · 2 Low severity

Open (4)
What changed in this PR

Adds event support for catalog connection tests through the listener event bus.

Changes:

  • Adds connection-test operation and event types.
  • Dispatches pre/success/failure events for two connection-test overloads.
  • Adds success and failure tests.
File Description
core/​src/​test/​java/​org/​apache/​gravitino/​listener/​api/​event/​TestCatalogEvent.java Updated as part of this pull request.
core/​src/​main/​java/​org/​apache/​gravitino/​listener/​CatalogEventDispatcher.java Updated as part of this pull request.
core/​src/​main/​java/​org/​apache/​gravitino/​listener/​api/​event/​TestConnectionPreEvent.java Updated as part of this pull request.
core/​src/​main/​java/​org/​apache/​gravitino/​listener/​api/​event/​TestConnectionFailureEvent.java Updated as part of this pull request.
core/​src/​main/​java/​org/​apache/​gravitino/​listener/​api/​event/​TestConnectionEvent.java Updated as part of this pull request.
core/​src/​main/​java/​org/​apache/​gravitino/​listener/​api/​event/​OperationType.java Updated as part of this pull request.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread core/src/main/java/org/apache/gravitino/listener/CatalogEventDispatcher.java Outdated
Comment thread core/src/main/java/org/apache/gravitino/listener/CatalogEventDispatcher.java Outdated
@VedantMadane

Copy link
Copy Markdown
Contributor Author

Addressed Copilot review on the latest head:

  1. CatalogChange overload — testConnection(NameIdentifier, CatalogChange...) now has the same pre/success/failure event lifecycle (no credential-bearing payload on events).
  2. Audit map — TEST_CONNECTION_CATALOG mapped in CompatibilityUtils / AuditLog so legacy audit conversion stays concrete.
  3. Imports — TestConnection* imports after LoadCatalog* (spotless order).
  4. Tests — existing-catalog overload success/failure coverage in TestCatalogEvent.

Ready for re-review.

@VedantMadane

Copy link
Copy Markdown
Contributor Author

Resolved 4 review threads that are addressed on current head:

  • CatalogChange testConnection overload now has pre/success/failure event wrapping
  • TEST_CONNECTION_CATALOG mapped in audit CompatibilityUtils + AuditLog.Operation
  • TestConnection* imports ordered after LoadCatalog*
  • Existing-catalog overload success/failure coverage in TestCatalogEvent

@mchades

mchades commented Oct 11, 2026

Copy link
Copy Markdown
Contributor

could you please resolve the conflicts?

@mchades mchades changed the title feat: dispatch events for catalog connection tests [#12566] feat(core): Dispatch events for catalog connection tests Oct 12, 2026
@mchades
mchades requested review from jerryshao and a lite review from Copilot October 12, 2026 10:38

Copilot AI 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.

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Copilot review overview

2 open findings
4 resolved since last review

🧠 Review effort: Lite

Comment thread core/src/main/java/org/apache/gravitino/listener/CatalogEventDispatcher.java Outdated
@github-actions

github-actions Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

Code Coverage Report

Overall Project 72.01% +0.19% 🟢
Files changed 96.5% 🟢

Module Coverage
aliyun 19.74% 🔴
api 54.68% 🟢
authorization-common 85.96% 🟢
authorization-ranger 14.44% 🔴
aws 53.54% 🟢
aws-bundle 0.0% 🔴
azure 32.1% 🔴
azure-bundle 0.0% 🔴
catalog-common 29.49% 🔴
catalog-fileset 82.37% 🟢
catalog-glue 73.24% 🟢
catalog-hive 83.63% 🟢
catalog-jdbc-common 57.62% 🟢
catalog-jdbc-doris 87.56% 🟢
catalog-jdbc-mysql 81.91% 🟢
catalog-jdbc-postgresql 84.02% 🟢
catalog-jdbc-starrocks 79.16% 🟢
catalog-kafka 75.21% 🟢
catalog-lakehouse-generic 80.67% 🟢
catalog-lakehouse-hudi 79.1% 🟢
catalog-lakehouse-iceberg 85.93% 🟢
catalog-lakehouse-paimon 84.36% 🟢
catalog-model 77.99% 🟢
cli 44.62% 🟢
client-java 79.32% 🟢
client-java-runtime 0.0% 🔴
common 60.49% 🟢
core 87.47% +0.27% 🟢
filesystem-hadoop3 76.89% 🟢
flink 55.36% 🟢
flink-common 32.2% 🔴
flink-runtime 0.0% 🔴
gcp 32.2% 🔴
hadoop-auth 68.0% 🟢
hadoop-common 17.84% 🔴
hive-metastore-common 62.3% 🟢
hive-metastore3-libs 58.8% 🟢
iceberg-aliyun-bundle 0.0% 🔴
iceberg-common 66.53% 🟢
iceberg-rest-server 77.01% 🟢
idp-basic 86.77% 🟢
integration-test-common 0.0% 🔴
jobs 70.23% 🟢
k8s-job-executor 99.81% 🟢
lance-common 39.9% 🔴
lance-rest-server 69.51% 🟢
lineage 59.39% 🟢
optimizer 84.27% 🟢
optimizer-api 40.87% 🟢
server 91.43% 🟢
server-common 83.85% 🟢
spark 61.79% 🟢
tencent 81.78% 🟢
tms 79.75% +0.04% 🟢
trino-connector 63.31% 🟢
Files
Module File Coverage
core CatalogEventDispatcher.java 100.0% 🟢
OperationType.java 100.0% 🟢
TestConnectionEvent.java 100.0% 🟢
TestConnectionFailureEvent.java 100.0% 🟢
TestConnectionPreEvent.java 100.0% 🟢
CompatibilityUtils.java 99.44% 🟢
AuditLog.java 97.9% 🟢
tms TableSnapshotMetricsMetaService.java 100.0% 🟢
TableMaintenanceActionBaseSQLProvider.java 84.21% 🟢
TableMaintenanceActionMetaService.java 75.0% 🟢

VedantMadane and others added 6 commits October 14, 2026 16:47
- OperationType: add TEST_CONNECTION_CATALOG
- add TestConnectionPreEvent/Event/FailureEvent without properties payload
- CatalogEventDispatcher: dispatch pre/success/failure for testConnection
- TestCatalogEvent: success and failure coverage for testConnection events

Fixes apache#12566

Signed-off-by: Vedant Madane <6527493+VedantMadane@users.noreply.github.com>
Signed-off-by: Vedant Madane <6527493+VedantMadane@users.noreply.github.com>
Wrap the CatalogChange overload with pre/success/failure events, map
TEST_CONNECTION_CATALOG in CompatibilityUtils/AuditLog, and cover the
existing-catalog overload in tests.

Signed-off-by: Vedant Madane <6527493+VedantMadane@users.noreply.github.com>
Signed-off-by: Vedant Madane <6527493+VedantMadane@users.noreply.github.com>
@VedantMadane

Copy link
Copy Markdown
Contributor Author

Rebased fix/issue-12566 onto latest main (was 22 commits behind; merge was clean, no conflict markers left). Force-pushed with lease.

On the outdated Copilot note about pre/post event ordering in TestCatalogEvent: agreeing with @mchades — ordering is already covered in TestCatalogConnectionEvent.assertEvents via Mockito InOrder (pre → delegate → post), and DummyEventListener keeps pre/post queues separate so pop order there does not assert dispatch order. Resolved that thread.

@jerryshao jerryshao 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 contribution! The event model, audit mapping, username capture, and exception propagation look consistent with the existing catalog events, and sensitive properties stay out of the built-in audit formatters. One small issue inline: a pre-listener veto currently surfaces as HTTP 500 instead of 403.

ConnectionTestAction action)
throws Exception {
String user = PrincipalUtils.getCurrentUserName();
eventBus.dispatchEvent(new TestConnectionPreEvent(user, ident, catalogInfo, changes));

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.

Pre-event veto works in CatalogEventDispatcher, but both test-connection REST methods (CatalogOperations.java:226 and :273) pass the thrown ForbiddenException to handleTestConnectionException (ExceptionHandlers.java:245), which has no forbidden branch and returns HTTP 500 via Utils.internalError. Other catalog handlers map this to Utils.forbidden (403). Please handle ForbiddenException there and add a REST test for both endpoints so a synchronous pre-listener veto stays a 403 and does not run the connection test.

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.

Mapped ForbiddenException to HTTP 403 in the shared handler. Added REST tests for both endpoints, covering stored configuration, proposed changes, and empty changes. They verify that a synchronous pre-listener veto never reaches the delegate and preserves the existing stack-trace behavior.

@mchades
mchades requested a review from jerryshao October 22, 2026 14:29
yuqi1129 added a commit that referenced this pull request Oct 27, 2026
…pshots (#14276)

### What changes were proposed in this pull request?

Validate Fork CI caller jobs against `required_ci.needs` of the upstream
commit the run tested: the base-branch commit merged into the head for
fork runs (already verified to be on the base branch), or the dispatch
commit for trusted runs. A suite added later does not fail an earlier
run, but a run that tested a base with the suite must have run it; a
missing suite reports "merge the latest base branch and push". After a
full rerun, the newest Required CI attempt selects the tested base.
Share workflow contents reads with migration detection, retry transient
reads on the next polling pass, and retain the existing execution,
context and trust checks.

Also require trusted verification when changed CI definitions report
only a fail-fast watcher failure.

### Why are the changes needed?

The publisher currently applies the latest hard-coded suite list to
historical runs. Adding TMS on main (#14222) therefore turned successful
Fork CI runs into `Fork CI needs attention` errors, even though their
workflows did not contain TMS. Re-running the same old workflow cannot
satisfy the newer list. On 2026-10-27 this affected 13 open PRs: #14241,
#14233, #14214, #14210, #14197, #14194, #13950, #13929 (a trusted run
dispatched before TMS), #13914, #13904, #13880, #13586 and #12585.

Related to #14197.

After merge, these statuses do not all recover at once: a completed
status whose run is unchanged is treated as settled while the PR was
updated in the last six hours. A committer should dispatch **Update Fork
CI Status** with each PR number above; it only calls the GitHub API.

### Does this PR introduce _any_ user-facing change?

Historical successful Fork CI runs keep their correct status when
required callers change on main. No application API or configuration
changes.

### How was this patch tested?

- `node --test .github/scripts/tests/*.test.cjs`: 108 tests passed.
- Read-only replay of `mirror()` against the live GitHub API (no status
writes) for all 13 affected PRs: each returns `All required suites
passed`, including the trusted run of #13929.
- Regression tests cover added/removed callers, ordinary versus trusted
definition snapshots, a newer tested base with and without a later
suite, a full rerun against a newer base, a trusted run missing a suite,
malformed workflow contents, API failures, shared reads, recovery from
transient base and trusted lookup failures across polling passes, a
missing `eligibility` caller, contents GitHub does not return inline,
and the changed-definition watcher-only path.
- The six initial regression tests fail against the original
implementation. Mutation checks: the latest hard-coded suite list fails
9 tests, the PR base snapshot instead of the tested base fails 2, the PR
base for trusted runs fails 4, reporting a changed-definition
watcher-only failure as an error fails 1, and dropping the eligibility
check, the inline-content check or the base read retry fails 1 each.
- Replayed PR #14197's actual run/job metadata with its historical
workflow: the latest list reports missing TMS; the matching historical
list reports success.
- `node --check` for changed scripts and `git diff --check` passed. No
live commit statuses were modified during validation.
@mchades
mchades merged commit 2ddee09 into apache:main Oct 28, 2026
4 checks passed
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.

[Improvement] Support event dispatching for catalog connection tests

5 participants