Skip to content

fix(governance): index workflow run history reads and add run retention (2.0 backport #35920) - #36059

Merged
yan-3005 merged 3 commits into
2.0from
backport/35920-workflow-run-history-2.0
Oct 23, 2026
Merged

yan-3005 merged 3 commits into
2.0from
backport/35920-workflow-run-history-2.0

Conversation

@yan-3005

@yan-3005 yan-3005 commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Describe your changes:

Fixes open-metadata/openmetadata-collate#7630

Backport of #35920 to 2.0. Cherry-pick of the squash commit feca176f6f, with the conflicts resolved for 2.0. The behaviour matches main:

  • Run stages read (GET /v1/governance/workflowInstanceStates/{wf}/{id}) also filters on the indexed workflowInstanceId, so it no longer scans workflow_instance_state_time_series. No migration needed for this.
  • Run list for an entity (GET /v1/governance/workflowInstances?entityLink=) keys on the new idx_wf_instance_entity_link (md5(entityLink), workflowDefinitionId, timestamp).
  • Data Retention gains workflowInstanceRetentionPeriod (default 30 days, 0 = keep forever). A run is deleted together with all of its states only when all of these hold:
    • it isn't RUNNING;
    • no Flowable process for it is alive (no ACT_RU_EXECUTION row has the run id as its business key);
    • it is older than the retention period;
    • a newer run of the same workflow exists for the same entity.
  • Migration 2.0.7 builds the index from the version's Java data migration (migration/utils/v207/MigrationUtil) on both engines. Each step checks the catalog first, so a retried upgrade completes. On PostgreSQL an INVALID index left by an interrupted CONCURRENTLY build is dropped and rebuilt. The 2.0.7 SQL files are comment-only and byte-identical to main.

What differs from main

  • 2.0 has no automation-workflow retention (workflowRetentionPeriod, from a later main-only change). Only workflowInstanceRetentionPeriod is added here, anchored before extensions. A small isRetentionEnabled helper (0 or missing = keep forever) comes with it.
  • 2.0 has no CANCELLED workflow status, so it is dropped from the ended statuses and from the IT.
  • On 2.0 the workflow DAOs live in CollectionDAO, not WorkflowDocStoreDAOs. The new DAO methods were added to CollectionDAO.WorkflowInstanceTimeSeriesDAO and WorkflowInstanceStateTimeSeriesDAO.
  • DataRetentionTest doesn't exist on 2.0. It is added with the two tests that apply: 0/missing means keep forever, and an old saved config falls back to the 30-day default.
  • The UI jsons/applicationSchemas and jsons/ingestionSchemas copies don't exist on 2.0. Generated TypeScript types were updated by hand.

Review follow-ups

The same follow-ups as #36065 on main: a failed workflow-run page is charged one page (1,000) in the failed count, not 10,000; DataRetentionAppIT removes everything it seeds; nullOrEmpty, final and named constants per java.md.

Migration time (measured on main, same SQL/Java; local Docker, warm cache)

Workflow runs PostgreSQL (CREATE INDEX CONCURRENTLY) MySQL (column + index)
1.17M 2.5 s 0.05 s + 5.3 s
10M 27.4 s 0.16 s + 55.2 s

Writes are not blocked on either engine. The runner sets no statement timeout.

Type of change:

  • Bug fix

Tests:

Run on this branch:

  • Unit: 387/0 across the migration package; after the review follow-ups (chore(governance): review follow-ups for workflow run retention #36065, backported here) ListFilterTest 42/0 and DataRetentionTest 3/0 (adds aFailedWorkflowRunPageIsChargedOnePageOfRuns).
  • DataRetentionAppIT: 3/0 on PostgreSQL + OpenSearch and 3/0 on MySQL + Elasticsearch (the 2 existing tests + test_retentionRun_deletesExpiredWorkflowRunsButKeepsEachEntitysLatest, which seeds 1,200+ expired runs, live-process runs, RUNNING runs and runs inside the window, and checks the exact survivors, their states, the states endpoint and the run list including a non-ASCII entity link). The test database is built by the migration runner, so the 2.0.7 Java step runs on both engines.

🤖 Generated with Claude Code

RetriggerView in GreptileConfidence Score: 4/5

No new behavioral defect was found, but the outstanding repository requirements must be met before merging.

Findings

  1. P2 Test bypasses real database setup ▶
  2. P2 Unchanged values lack final ▶

Summary

Adds indexed governance workflow history reads and configurable run retention.

  • Data Retention removes old workflow runs but keeps each entity’s latest run.
  • Entity run lists use a matching hash index on both database engines.
  • Stage-history reads filter directly by workflow run ID.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Data Retention run] --> B{Retention period above zero?}
  B -->|No| C[Keep all workflow history]
  B -->|Yes| D[Read expired ended runs]
  D --> E{No live process and a newer run for the same workflow and entity?}
  E -->|No| F[Keep run and states]
  E -->|Yes| G[Delete states]
  G --> H[Delete run]
  H --> I[Continue through remaining pages]
Loading

Reviews (2) · Last reviewed commit: "test(governance): pin the one-page failu..." · Reviewed by Greptile

…on (#35920)

Backport of #35920 to 2.0.

The workflow instance states read also filters on the indexed
workflowInstanceId; the run list for an entity keys on the new
idx_wf_instance_entity_link (md5(entityLink), workflowDefinitionId,
timestamp), built by the 2.0.7 Java migration on both engines; Data
Retention gains workflowInstanceRetentionPeriod (default 30 days) and
deletes an ended run with its states only when no Flowable process of it is
alive, it is older than the period, and a newer run of the same workflow
exists for the same entity.

2.0 differences: no automation-workflow retention or CANCELLED status; the
workflow DAOs live in CollectionDAO.

(cherry picked from commit feca176)
@yan-3005
yan-3005 requested review from a team as code owners October 23, 2026 05:50
@yan-3005
yan-3005 requested review from manerow and sweta1308 and removed request for a team October 23, 2026 05:50
@github-actions

Copy link
Copy Markdown
Contributor

❌ PR checklist incomplete

This PR cannot be merged until the following are addressed on its linked issue:

  • No GitHub issue is linked. Link an issue in the Development section of the PR (or add Fixes #12345 to the description). For a same-org cross-repo issue, add Fixes open-metadata/<repo>#123 to the description.

The fields live on the linked issue in the Shipping project (open the issue → right sidebar → Projects). After you set them, re-run this check (or push a commit) — issue/project changes do not re-trigger it automatically.

Maintainers can bypass this check by adding the skip-pr-checks label.

@github-actions github-actions Bot added backend safe to test Add this label to run secure Github workflows on PRs labels Oct 23, 2026
@gitar-bot

gitar-bot Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Gitar is looking for additional findings

Code Review 1 closed / 1 findings
✅ 1 closed
✅ Quality: Failed workflow-run page is counted as 10,000 failed rows, not 1,000

📄 openmetadata-service/src/main/java/org/openmetadata/service/apps/bundles/dataRetention/DataRetention.java:282 📄 openmetadata-service/src/main/java/org/openmetadata/service/apps/bundles/dataRetention/DataRetention.java:502-516
cleanWorkflowRuns goes through drainInBatches, and that always passes BATCH_SIZE (10,000) to BatchDrain.drain as failedRowsPerBatch. A workflow-run page holds at most WORKFLOW_RUN_PAGE_SIZE (1,000) runs. So when listExpiredRuns or a delete throws (for example a lock timeout), the workflow_runs stats show 10,000 failed records, ten times the most that page could have lost. That misleads anyone reading the app run record. A fix is to let drainInBatches take the per-batch failure charge as a parameter and pass WORKFLOW_RUN_PAGE_SIZE here.

Verification

Rules No rules evaluated

Functional validation Not enabled

Set up

Auto-approval Not enabled

Set up

For more verification details, comment gitar display:verbose.

Options

Display: compact → Showing compact verification results.

Comment with these commands to change the behavior for this request:

Compact
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source

Comment on lines +567 to +570
try (MockedStatic<DatasourceConfig> ds = mockStatic(DatasourceConfig.class)) {
DatasourceConfig mysqlConfig = mock(DatasourceConfig.class);
ds.when(DatasourceConfig::getInstance).thenReturn(mysqlConfig);
when(mysqlConfig.isMySQL()).thenReturn(true);

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.

P2 Test bypasses real database setup

The new test mocks DatasourceConfig, an internal class. The repository guide requires mocks to target external boundaries, not the project's own classes. Check both database variants through real configuration or the existing database integration tests instead. This repository requirement must be satisfied before merging.

Context Used: CLAUDE.md (source)

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

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.

Keeping this as is. DatasourceConfig is the static dialect switch ListFilter reads; mocking it is how this test file already checks MySQL-vs-PostgreSQL SQL on main, and a unit test has no other way to flip the dialect. The real-database coverage is DataRetentionAppIT, which runs the run list and retention queries against both PostgreSQL and MySQL. The assertions pin the exact text the 2.0.7 index key needs.

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, that context makes sense. This test isolates the SQL-generation branch behind ListFilter’s static dialect switch, while DataRetentionAppIT validates the query against both real database engines; the same static-mocking pattern is also already used in ListFilterTest on main. Keeping this as-is is reasonable, so I’m withdrawing this finding.

Comment on lines +278 to +280
WorkflowRunHistory history = new WorkflowRunHistory(ns.prefix("retentionWorkflow"));
Set<String> keptRuns = TestSuiteBootstrap.getJdbi().withHandle(history::seedRunsToKeep);
Set<String> expiredRuns = TestSuiteBootstrap.getJdbi().withHandle(history::seedExpiredRuns);

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.

P2 Unchanged values lack final

The new locals history, keptRuns, and expiredRuns never change but lack final. The repository guide requires final on unchanged locals and parameters. Apply that convention throughout the new code, including entityLinkHash in getEntityLinkHashCondition(). This repository requirement must be satisfied before merging.

Context Used: CLAUDE.md (source)

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

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.

Fixed (701f55b): final on the unchanged locals and parameters in the new code, including entityLinkHash in getEntityLinkHashCondition().

@github-actions

Copy link
Copy Markdown
Contributor

Jest test Coverage

UI tests summary

Lines Statements Branches Functions
Coverage: 68%
68.32% (82943/121388) 53.23% (51386/96521) 53.97% (15280/28310)

…backport)

- Charge a failed workflow-run retention page as at most one page of runs
  (WORKFLOW_RUN_PAGE_SIZE), not BATCH_SIZE, in the app run's failed count.
- DataRetentionAppIT removes every run, state and live-process row it seeds,
  also when seeding or the app run fails.
- nullOrEmpty over isEmpty(), final on unchanged locals, and named constants
  for the SQL fragments ListFilterTest asserts.

(cherry picked from commit d73ef5f)
…tention (2.0 backport)

drainWorkflowRuns drains workflow-run pages with WORKFLOW_RUN_PAGE_SIZE as the
per-page failure charge, and DataRetentionTest makes the run DAO throw and
checks that exactly one page is charged. recordDrain holds the shared logging
and stats; the new parameters are final.

(cherry picked from commit edf56c8)
@yan-3005
yan-3005 enabled auto-merge (squash) October 23, 2026 06:43
@yan-3005
yan-3005 merged commit 407d6f1 into 2.0 Oct 23, 2026
65 of 70 checks passed
@yan-3005
yan-3005 deleted the backport/35920-workflow-run-history-2.0 branch October 23, 2026 06:44
@sonarqubecloud

Copy link
Copy Markdown

@sonarqubecloud

Copy link
Copy Markdown

This branch had an error being deployed

1 failed deployment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend safe to test Add this label to run secure Github workflows on PRs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants