Repository navigation
fix(governance): index workflow run history reads and add run retention (2.0 backport #35920) - #36059
Conversation
…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)
❌ PR checklist incompleteThis PR cannot be merged until the following are addressed on its linked issue:
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 |
|
Code Review 1 closed / 1 findings✅ 1 closed✅ Quality: Failed workflow-run page is counted as 10,000 failed rows, not 1,000
VerificationRules No rules evaluated Functional validation Not enabledAuto-approval Not enabledFor more verification details, comment OptionsDisplay: compact → Showing compact verification results. Comment with these commands to change the behavior for this request:
Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source |
| try (MockedStatic<DatasourceConfig> ds = mockStatic(DatasourceConfig.class)) { | ||
| DatasourceConfig mysqlConfig = mock(DatasourceConfig.class); | ||
| ds.when(DatasourceConfig::getInstance).thenReturn(mysqlConfig); | ||
| when(mysqlConfig.isMySQL()).thenReturn(true); |
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
| WorkflowRunHistory history = new WorkflowRunHistory(ns.prefix("retentionWorkflow")); | ||
| Set<String> keptRuns = TestSuiteBootstrap.getJdbi().withHandle(history::seedRunsToKeep); | ||
| Set<String> expiredRuns = TestSuiteBootstrap.getJdbi().withHandle(history::seedExpiredRuns); |
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
Fixed (701f55b): final on the unchanged locals and parameters in the new code, including entityLinkHash in getEntityLinkHashCondition().
…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)
|
|



Describe your changes:
Fixes open-metadata/openmetadata-collate#7630
Backport of #35920 to
2.0. Cherry-pick of the squash commitfeca176f6f, with the conflicts resolved for 2.0. The behaviour matchesmain:GET /v1/governance/workflowInstanceStates/{wf}/{id}) also filters on the indexedworkflowInstanceId, so it no longer scansworkflow_instance_state_time_series. No migration needed for this.GET /v1/governance/workflowInstances?entityLink=) keys on the newidx_wf_instance_entity_link(md5(entityLink),workflowDefinitionId,timestamp).workflowInstanceRetentionPeriod(default 30 days, 0 = keep forever). A run is deleted together with all of its states only when all of these hold:ACT_RU_EXECUTIONrow has the run id as its business key);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 interruptedCONCURRENTLYbuild is dropped and rebuilt. The 2.0.7 SQL files are comment-only and byte-identical tomain.What differs from
main2.0has no automation-workflow retention (workflowRetentionPeriod, from a later main-only change). OnlyworkflowInstanceRetentionPeriodis added here, anchored beforeextensions. A smallisRetentionEnabledhelper (0 or missing = keep forever) comes with it.2.0has noCANCELLEDworkflow status, so it is dropped from the ended statuses and from the IT.2.0the workflow DAOs live inCollectionDAO, notWorkflowDocStoreDAOs. The new DAO methods were added toCollectionDAO.WorkflowInstanceTimeSeriesDAOandWorkflowInstanceStateTimeSeriesDAO.DataRetentionTestdoesn't exist on2.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.jsons/applicationSchemasandjsons/ingestionSchemascopies don't exist on2.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;DataRetentionAppITremoves everything it seeds;nullOrEmpty,finaland named constants perjava.md.Migration time (measured on
main, same SQL/Java; local Docker, warm cache)CREATE INDEX CONCURRENTLY)Writes are not blocked on either engine. The runner sets no statement timeout.
Type of change:
Tests:
Run on this branch:
ListFilterTest42/0 andDataRetentionTest3/0 (addsaFailedWorkflowRunPageIsChargedOnePageOfRuns).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
No new behavioral defect was found, but the outstanding repository requirements must be met before merging.
Findings
Summary
Adds indexed governance workflow history reads and configurable run retention.
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]Reviews (2) · Last reviewed commit: "test(governance): pin the one-page failu..." · Reviewed by Greptile