Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
187ca10
feat: added incident group endpoint
TeddyCr Jul 22, 2026
1b7dc45
feat: added owner, status, assignee, severiuty and bucket for client …
TeddyCr Jul 22, 2026
f8ffb84
Merge remote-tracking branch 'upstream/main' into ISSUE-30151
TeddyCr Jul 22, 2026
ed67f29
feat: added owner, status, assignee, severiuty and bucket for client …
TeddyCr Jul 22, 2026
1f2bdac
empty commit for CI trigger
TeddyCr Jul 22, 2026
a605054
Merge remote-tracking branch 'upstream/main' into ISSUE-30151
TeddyCr Jul 23, 2026
8e2aba1
feat: remove n+1 in entity ref. retrieval when resolving group refere…
TeddyCr Jul 23, 2026
4d6afbc
Merge remote-tracking branch 'upstream/main' into ISSUE-30151
TeddyCr Jul 23, 2026
9bc37fe
Merge remote-tracking branch 'upstream/main' into ISSUE-30151
TeddyCr Jul 23, 2026
c84239c
feat: ignore optional argumewnt static check error
TeddyCr Jul 23, 2026
556decd
Merge remote-tracking branch 'upstream/main' into ISSUE-30151
TeddyCr Jul 23, 2026
2a7063d
feat: address comments and fix failing integration tests
TeddyCr Jul 23, 2026
3d3d047
feat: revert pre existing migrations to 2.0
TeddyCr Jul 23, 2026
44e28bf
feat: address first pass review
TeddyCr Jul 23, 2026
4b999f4
Merge branch 'main' into ISSUE-30151
TeddyCr Jul 23, 2026
aa91e3f
feat: move endpoint data to summary table
TeddyCr Jul 24, 2026
aae4fe5
Merge remote-tracking branch 'upstream/main' into ISSUE-30151
TeddyCr Jul 24, 2026
fd497a9
feat: address comments
TeddyCr Jul 24, 2026
025705f
feat: address comments
TeddyCr Jul 24, 2026
236c968
Merge branch 'main' into ISSUE-30151
TeddyCr Jul 25, 2026
711f3e6
Merge remote-tracking branch 'upstream/main' into ISSUE-30151
TeddyCr Jul 28, 2026
164f07e
Merge remote-tracking branch 'origin/ISSUE-30151' into ISSUE-30151
TeddyCr Jul 28, 2026
7a42fb1
chore: fix migration
TeddyCr Jul 28, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 99 additions & 0 deletions PR_DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<!--
Thank you for your contribution!
Unless your change is trivial, please create an issue to discuss the change before creating a PR.
-->

### Describe your changes:

Fixes #30151

I worked on the **Incident Manager "Grouped Incidents" backend** because the incident manager redesign needs incidents normalized into triageable groups (by table, test definition, or test-case owner) instead of a flat alert list, and the existing APIs could neither serve the grouped view nor scale to catalogs with deep incident history.

**New API surface**

- `GET /v1/dataQuality/testCases/testCaseIncidentStatus/incidentGroups` — distinct open incidents grouped by `table`, `testDefinition`, or `owner`. Each group carries the full row the UI renders: `incidentCount`, most-critical `severity`, triage-ranked `status` (Assigned > Ack > New), current `assignees` + `assigneeCount`, `firstSeen`/`lastSeen`, and an 8-bucket `trend` with a `Rising`/`Falling`/`Steady` direction (the "recurring" signal). Filters: open statuses, current assignee, test case, domain, and a `createdAt`/`updatedAt` date range; sortable and paginated with opaque cursors.
- Drill-down filters on the existing incident list endpoint: `testDefinition`, `owner` (direct user/team owner of the test case), and a repaired `assignee` — so every group row can open its exact incident population.
- `PUT /v1/dataQuality/testCases/testCaseIncidentStatus/bulk` — bulk status/severity changes for up to 100 incidents per call (the UI's "Set status / Set severity on selection"), following the platform's `BulkOperationResult` pattern with per-entry validation, authorization, and success/failure detail.
- `failureSummary` denormalized onto every incident record at write time (failed result → incident task payload → sync handler), so incident listings can show the failure reason without a per-incident result lookup (no N+1).

**Fixes shipped along the way** (all found by tests or scale-testing this feature)

- The incident-groups cursor was emitted Base64-encoded but the endpoint only accepted a plain int offset — cursors now round-trip opaquely like the sibling list endpoint.
- Time-series listings without a `startTs`/`endTs` reported `paging.total: 0` (the count query evaluated `timestamp BETWEEN NULL AND NULL`), which also suppressed the `after` cursor. Fixed in `EntityTimeSeriesRepository` for all time-series entities.
- The incident list's `assignee` filter silently returned nothing: the generic `assignee` param had been repurposed by the task listing (name-hash → `ASSIGNED_TO` relationships). The incident list now maps it to a column comparison (`incidentAssignee`).
- `docker/mysql/Dockerfile_mysql` was pinned to the discontinued `mysql/mysql-server:latest` (frozen at 8.0.32, which crash-loops on a purge-thread FK assertion on case-insensitive filesystems). Swapped to the maintained `mysql:8.0`.

#
### Type of change:
- [x] New feature

#
### High-level design:

**Query architecture.** An incident is a `stateId` chain of status records in `test_case_resolution_status_time_series`. The grouping query reduces the chain in a `chain` CTE (`GROUP BY stateId` over the new `(stateId, timestamp)` index for first/last timestamps) and joins back on the last timestamp for the current status/assignee/severity — deliberately avoiding `ROW_NUMBER`/`MIN`/`MAX` window functions, which materialize three buffered passes over the whole table at scale. One SQL round-trip serves the entire page: the group total rides on `COUNT(*) OVER ()` and the per-group trend timestamps ride on `JSON_ARRAYAGG`/`JSON_AGG` (chosen over `GROUP_CONCAT`/`STRING_AGG` because JSON aggregates have no `group_concat_max_len`-style cap that would silently truncate a large group's trend). Trend bucketing and direction stay in Java (`TestCaseResolutionStatusRepository`), keeping the SQL dialect-free.

**Layering.** All SQL lives in `CollectionDAO.TestCaseResolutionStatusTimeSeriesDAO` — the CTE templates, the dialect-specific `@Define` expressions (`severityExpr`, `assigneesExpr`, `createdAtAgg`, dimension joins), and the parts assembly that splices `ListFilter` output into the right sub-query. The repository holds only orchestration and business mapping (rank→status, trend buckets, entity-reference resolution); the resource holds request parsing/auth. `addOriginEntityFQNJoin` moved from the repository into the DAO to complete the separation.

**Write-time denormalization.** `failureSummary` is captured when a failed test result opens an incident: the result text travels through `getOrCreateIncident` into the Task payload's existing `failureReason` field, and `IncidentTcrsSyncHandler` stamps it onto every TCRS record of the chain. Read paths never join to test results. Records predating the change are not backfilled (the field is optional).

**Bulk endpoint.** One-pass shape borrowed from `EntityResource.processBulkRequest`: all referenced test cases resolve via a single `findEntityByNames` batch and the caller reference resolves once; the per-entry loop then authorizes and creates with zero lookups. Synchronous by design — the caller is an interactive selection capped at 100 entries that needs inline per-entry results; the `async`/202 path can be added if a bot-scale consumer appears.

**Alternatives considered and rejected**
- *Embedding incident lists inside group rows*: unbounded nested payloads needing their own pagination; the drill-down filters make each group's population addressable instead.
- *Window-function CTE (original implementation)*: measured 3× slower per execution at 100k+ rows and ran three times per request (count + page + trend); replaced as above (measured ~10× end-to-end on the groups endpoint).
- *`STRAIGHT_JOIN` hints for the chain join*: measured slower than the optimizer's plan; SQL stays hint-free and portable.
- *Incident summary rollup table*: the right long-term answer for O(open-incidents) reads at any history depth (and would also fix the pre-existing `latest=true` slow path), but it is a migration + dual-write + backfill feature of its own; deliberately left as follow-up.

**Migrations / rollout.** Additive only: a new 2.1.0 native migration adds four indexes — `(stateId, timestamp)`, `(entityFQNHash, timestamp)`, and `(assignee, timestamp)` on the time-series table, and `(id)` on `test_case` (which predates the `PRIMARY KEY(id)` convention; the relationship join had no index target). New schema fields are optional; no data migration. The `mysql:8.0` image swap affects fresh dev environments on next image build; volumes initialized by 8.0.32 upgrade in place.

#
### Tests:

#### Use cases covered
- Incident manager groups by table, test definition, and owner with correct open-incident counts (resolved chains and deleted test cases excluded; a co-owned test case's incident counts once per owner but never twice within a group)
- Group rows render severity (most critical), status rollup, assignees, first/last seen, and trend sparkline data; a single-incident group reads `Steady` with all activity in the first bucket
- Group filters: open statuses (Resolved rejected with 400), current assignee, single test case, domain, `createdAt`/`updatedAt` date ranges; count-sorted ascending/descending
- Cursor pagination walks every group exactly once, forward and backward, with exact `before`/`after` arithmetic and correct behavior past the end of the list
- Drill-down listings scoped by test definition, by direct owner (user or team), and by assignee — including `latest=true` — with 404 on unknown filter targets
- Bulk status change applies per-entry with partial-success reporting; the applied entry appends to the incident chain
- A failed test result opens an incident whose records carry the denormalized failure text
- Unranged incident listings report real totals and working pagination cursors

#### Unit tests
- Files updated: `openmetadata-service/src/test/java/org/openmetadata/service/jdbi3/TestCaseResolutionStatusRepositoryTest.java` (15 tests; join-builder tests follow the helper to its new DAO location)

#### Backend integration tests
- [x] I added integration tests in `openmetadata-integration-tests/` for new/changed API endpoints.
- Files added/updated: `openmetadata-integration-tests/src/test/java/org/openmetadata/it/tests/IncidentGroupsIT.java` — 27 tests covering everything under "Use cases" above, run green on **both PostgreSQL and MySQL** (the SQL uses dialect-specific aggregate/JSON expressions, so both matter). New behaviors were RED-verified: each test was shown to fail with the feature toggled off (null aggregates, unfiltered result sets, 405 on the bulk path, missing failure summary, `total=0` paging) before going green.

#### Ingestion integration tests
- [ ] Not applicable (sample-data fixture updates only; no connector logic changes).

#### Playwright (UI) tests
- [ ] Not applicable (backend + generated TS models only; UI implementation is a follow-up PR).

#### Manual testing performed
1. Started the local stack (`docker/development`, MySQL) with the branch build; verified the 2.0.0 migrations create all four new indexes on a fresh volume.
2. Generated a synthetic catalog via API + SQL (800 tables, ~2,000 test cases, 200 users, 60 test definitions, 200k incident records / ~17k open incidents in realistic chains) and probed every endpoint with curl.
3. Measured on the running server at 200k records: groups 0.57–1.37 s for all three dimensions (vs 4.4–5.4 s for the original window-CTE implementation at *half* that volume), drill-down filters 40–144 ms, cursor page 2 at 697 ms with stable totals.
4. Verified cursor round-tripping (`paging.after` → `offset`), totals without time ranges, the repaired assignee filter (2.1 s → 40 ms after its index), and `Rising`/`Falling`/`Steady` trend variety across groups with different incident time profiles.

#
### UI screen recording / screenshots:

Not applicable.

#
### Checklist:
- [x] I have read the [**CONTRIBUTING**](https://docs.open-metadata.org/developers/contribute) document.
- [x] My PR title is `Fixes <issue-number>: <short explanation>`
- [x] My PR is linked to a GitHub issue via `Fixes #<issue-number>` above.
- [x] I have commented on my code, particularly in hard-to-understand areas.
- [x] For JSON Schema changes: I updated the migration scripts or explained why it is not needed.
- [ ] For UI changes: I attached a screen recording and/or screenshots above. (Not applicable — no UI changes.)
- [x] I have added tests (unit / integration / Playwright as applicable) and listed them above.

<!-- New feature -->
- [x] The issue properly describes why the new feature is needed, what's the goal, and how we are building it.
- [ ] I have updated the documentation. (API documentation is carried by the OpenAPI annotations on the new endpoints; no separate docs page yet.)
- [x] I have added tests around the new logic.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
-- Backfill test_case_incident from existing history: fold each stateId chain to its
-- first/last timestamps, pick the latest record (MAX(id) tie-break, matching the read
-- query this table replaces), and upsert one summary row per incident. Idempotent.
INSERT INTO test_case_incident (stateId, entityFQNHash, testCaseResolutionStatusType, assignee, severity, createdAt, updatedAt, latestRecordId)
WITH chain AS (
SELECT stateId, MIN(timestamp) AS createdAt, MAX(timestamp) AS updatedAt
FROM test_case_resolution_status_time_series
GROUP BY stateId
),
latestRecord AS (
SELECT c.stateId, c.createdAt, c.updatedAt, MAX(t.id) AS latestId
FROM chain c
INNER JOIN test_case_resolution_status_time_series t
ON t.stateId = c.stateId AND t.timestamp = c.updatedAt
GROUP BY c.stateId, c.createdAt, c.updatedAt
)
SELECT t.stateId, t.entityFQNHash, t.testCaseResolutionStatusType, t.assignee,
JSON_UNQUOTE(JSON_EXTRACT(t.json, '$.severity')), l.createdAt, l.updatedAt, t.id
FROM latestRecord l
INNER JOIN test_case_resolution_status_time_series t ON t.id = l.latestId
WHERE t.entityFQNHash IS NOT NULL
ON DUPLICATE KEY UPDATE
testCaseResolutionStatusType = VALUES(testCaseResolutionStatusType),
assignee = VALUES(assignee),
severity = VALUES(severity),
test_case_incident.createdAt = LEAST(test_case_incident.createdAt, VALUES(createdAt)),
updatedAt = VALUES(updatedAt),
latestRecordId = VALUES(latestRecordId);
37 changes: 37 additions & 0 deletions bootstrap/sql/migrations/native/2.1.0/mysql/schemaChanges.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
-- Incident Manager grouped incidents - OpenMetadata 2.1.0

-- Index the stateId partition used by the incident grouping endpoint (/testCaseIncidentStatus/incidentGroups)
ALTER TABLE test_case_resolution_status_time_series ADD INDEX idx_test_case_resolution_status_state_id (stateId, timestamp);

-- Serve entityFQNHash-driven access on the incident timeline: the /testCaseIncidentStatus list
-- filters (testCaseFQN scope, testDefinition semi-join) and the incident grouping CTE scope all
-- seek by entityFQNHash; only id-leading and timestamp-leading indexes existed before.
ALTER TABLE test_case_resolution_status_time_series ADD INDEX idx_test_case_resolution_status_fqn_ts (entityFQNHash, timestamp);

-- test_case predates the PRIMARY KEY(id) convention of newer entity tables and had no id index,
-- so entity_relationship joins on toId = test_case.id (testDefinition incident filter) and
-- id-based lookups fall back to full scans.
ALTER TABLE test_case ADD INDEX idx_test_case_id (id);

-- The incident list's assignee filter compares the generated assignee column, which had no
-- index and full-scanned the timeline at scale.
ALTER TABLE test_case_resolution_status_time_series ADD INDEX idx_test_case_resolution_status_assignee (assignee, timestamp);

-- Incident summary table: one row per incident (stateId chain), maintained at write time so
-- state-shaped reads (incidentGroups) are O(open incidents) instead of folding full history.
-- Column names deliberately mirror the time-series table so ListFilter conditions apply verbatim.
CREATE TABLE IF NOT EXISTS test_case_incident (
stateId varchar(36) NOT NULL,
entityFQNHash varchar(768) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
testCaseResolutionStatusType varchar(36) NOT NULL,
assignee varchar(256) DEFAULT NULL,
severity varchar(36) DEFAULT NULL,
createdAt bigint unsigned NOT NULL,
updatedAt bigint unsigned NOT NULL,
latestRecordId varchar(36) NOT NULL,
PRIMARY KEY (stateId),
INDEX idx_tci_status_fqn (testCaseResolutionStatusType, entityFQNHash),
INDEX idx_tci_fqn (entityFQNHash),
INDEX idx_tci_assignee (assignee, testCaseResolutionStatusType),
INDEX idx_tci_updated (updatedAt)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
-- Backfill test_case_incident from existing history: fold each stateId chain to its
-- first/last timestamps, pick the latest record (MAX(id) tie-break, matching the read
-- query this table replaces), and upsert one summary row per incident. Idempotent.
INSERT INTO test_case_incident (stateId, entityFQNHash, testCaseResolutionStatusType, assignee, severity, createdAt, updatedAt, latestRecordId)
WITH chain AS (
SELECT stateId, MIN(timestamp) AS createdAt, MAX(timestamp) AS updatedAt
FROM test_case_resolution_status_time_series
GROUP BY stateId
),
latestRecord AS (
SELECT c.stateId, c.createdAt, c.updatedAt, MAX(t.id) AS latestId
FROM chain c
INNER JOIN test_case_resolution_status_time_series t
ON t.stateId = c.stateId AND t.timestamp = c.updatedAt
GROUP BY c.stateId, c.createdAt, c.updatedAt
)
SELECT t.stateId, t.entityFQNHash, t.testCaseResolutionStatusType, t.assignee,
t.json ->> 'severity', l.createdAt, l.updatedAt, t.id
FROM latestRecord l
INNER JOIN test_case_resolution_status_time_series t ON t.id = l.latestId
WHERE t.entityFQNHash IS NOT NULL
ON CONFLICT (stateId) DO UPDATE SET
testCaseResolutionStatusType = EXCLUDED.testCaseResolutionStatusType,
assignee = EXCLUDED.assignee,
severity = EXCLUDED.severity,
createdAt = LEAST(test_case_incident.createdAt, EXCLUDED.createdAt),
updatedAt = EXCLUDED.updatedAt,
latestRecordId = EXCLUDED.latestRecordId;
37 changes: 37 additions & 0 deletions bootstrap/sql/migrations/native/2.1.0/postgres/schemaChanges.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
-- Incident Manager grouped incidents - OpenMetadata 2.1.0

-- Index the stateId partition used by the incident grouping endpoint (/testCaseIncidentStatus/incidentGroups)
CREATE INDEX IF NOT EXISTS idx_test_case_resolution_status_state_id ON test_case_resolution_status_time_series (stateId, timestamp);

-- Serve entityFQNHash-driven access on the incident timeline: the /testCaseIncidentStatus list
-- filters (testCaseFQN scope, testDefinition semi-join) and the incident grouping CTE scope all
-- seek by entityFQNHash; only id-leading and timestamp-leading indexes existed before.
CREATE INDEX IF NOT EXISTS idx_test_case_resolution_status_fqn_ts ON test_case_resolution_status_time_series (entityFQNHash, timestamp);

-- test_case predates the PRIMARY KEY(id) convention of newer entity tables and had no id index,
-- so entity_relationship joins on toId = test_case.id (testDefinition incident filter) and
-- id-based lookups fall back to full scans.
CREATE INDEX IF NOT EXISTS idx_test_case_id ON test_case (id);

-- The incident list's assignee filter compares the generated assignee column, which had no
-- index and full-scanned the timeline at scale.
CREATE INDEX IF NOT EXISTS idx_test_case_resolution_status_assignee ON test_case_resolution_status_time_series (assignee, timestamp);

-- Incident summary table: one row per incident (stateId chain), maintained at write time so
-- state-shaped reads (incidentGroups) are O(open incidents) instead of folding full history.
-- Column names deliberately mirror the time-series table so ListFilter conditions apply verbatim.
CREATE TABLE IF NOT EXISTS test_case_incident (
stateId varchar(36) NOT NULL,
entityFQNHash varchar(768) NOT NULL,
testCaseResolutionStatusType varchar(36) NOT NULL,
assignee varchar(256) DEFAULT NULL,
severity varchar(36) DEFAULT NULL,
createdAt bigint NOT NULL,
updatedAt bigint NOT NULL,
latestRecordId varchar(36) NOT NULL,
PRIMARY KEY (stateId)
);
CREATE INDEX IF NOT EXISTS idx_tci_status_fqn ON test_case_incident (testCaseResolutionStatusType, entityFQNHash);
CREATE INDEX IF NOT EXISTS idx_tci_fqn ON test_case_incident (entityFQNHash);
CREATE INDEX IF NOT EXISTS idx_tci_assignee ON test_case_incident (assignee, testCaseResolutionStatusType);
CREATE INDEX IF NOT EXISTS idx_tci_updated ON test_case_incident (updatedAt);
2 changes: 1 addition & 1 deletion docker/mysql/Dockerfile_mysql
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM mysql/mysql-server:latest
FROM mysql:8.0

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.

@TeddyCr is this on purpose

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

yes, mysql/mysql-server:latest this one is not maintained anymore, it was updated 3 years ago
image

WORKDIR /docker-entrypoint-initdb.d
COPY docker/mysql/mysql-script.sql .
RUN chmod -R 775 /docker-entrypoint-initdb.d
Loading
Loading