-
Notifications
You must be signed in to change notification settings - Fork 2.2k
fix(dq): stale incident status on the Test Case page after reopening a resolved incident (1.13) #30183
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 1.13
Are you sure you want to change the base?
fix(dq): stale incident status on the Test Case page after reopening a resolved incident (1.13) #30183
Changes from all commits
8acd111
83572ce
047640a
62078c4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -75,6 +75,7 @@ | |
| import org.openmetadata.schema.tests.type.TestCaseResolutionStatus; | ||
| import org.openmetadata.schema.tests.type.TestCaseResolutionStatusTypes; | ||
| import org.openmetadata.schema.tests.type.TestCaseResult; | ||
| import org.openmetadata.schema.tests.type.TestCaseStatus; | ||
| import org.openmetadata.schema.type.ApiStatus; | ||
| import org.openmetadata.schema.type.ChangeDescription; | ||
| import org.openmetadata.schema.type.EntityReference; | ||
|
|
@@ -411,27 +412,47 @@ private void fetchAndSetTestCaseResultsAndIncidents( | |
| fqnHashToFqn.put(FullyQualifiedName.buildHash(fqn), fqn); | ||
| } | ||
|
|
||
| List<CollectionDAO.LatestRecordWithFQNHash> records = | ||
| daoCollection.dataQualityDataTimeSeriesDao().getLatestRecordBatch(fqns); | ||
|
|
||
| Map<String, TestCaseResult> fqnToResult = new HashMap<>(); | ||
| for (CollectionDAO.LatestRecordWithFQNHash record : records) { | ||
| String fqn = fqnHashToFqn.get(record.getEntityFQNHash()); | ||
| if (fqn != null && record.getJson() != null) { | ||
| TestCaseResult result = JsonUtils.readValue(record.getJson(), TestCaseResult.class); | ||
| if (result != null) { | ||
| fqnToResult.put(fqn, result); | ||
| if (setResults || setIncidents) { | ||
| List<CollectionDAO.LatestRecordWithFQNHash> records = | ||
| daoCollection.dataQualityDataTimeSeriesDao().getLatestRecordBatch(fqns); | ||
| for (CollectionDAO.LatestRecordWithFQNHash record : records) { | ||
| String fqn = fqnHashToFqn.get(record.getEntityFQNHash()); | ||
| if (fqn != null && record.getJson() != null) { | ||
| TestCaseResult result = JsonUtils.readValue(record.getJson(), TestCaseResult.class); | ||
| if (result != null) { | ||
| fqnToResult.put(fqn, result); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| Map<String, UUID> fqnToOngoingIncident = new HashMap<>(); | ||
| if (setIncidents) { | ||
| List<CollectionDAO.LatestRecordWithFQNHash> incidentRecords = | ||
| daoCollection.testCaseResolutionStatusTimeSeriesDao().getLatestRecordBatch(fqns); | ||
| for (CollectionDAO.LatestRecordWithFQNHash record : incidentRecords) { | ||
| String fqn = fqnHashToFqn.get(record.getEntityFQNHash()); | ||
| if (fqn != null && record.getJson() != null) { | ||
| TestCaseResolutionStatus latest = | ||
| JsonUtils.readValue(record.getJson(), TestCaseResolutionStatus.class); | ||
| if (latest != null | ||
| && latest.getStateId() != null | ||
| && !TestCaseResolutionStatusTypes.Resolved.equals( | ||
| latest.getTestCaseResolutionStatusType()) | ||
| && isFailedResult(fqnToResult.get(fqn))) { | ||
| fqnToOngoingIncident.put(fqn, latest.getStateId()); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| for (TestCase testCase : testCases) { | ||
| TestCaseResult result = fqnToResult.get(testCase.getFullyQualifiedName()); | ||
| if (setResults) { | ||
| testCase.setTestCaseResult(result); | ||
| testCase.setTestCaseResult(fqnToResult.get(testCase.getFullyQualifiedName())); | ||
| } | ||
| if (setIncidents) { | ||
| testCase.setIncidentId(result != null ? result.getIncidentId() : null); | ||
| testCase.setIncidentId(fqnToOngoingIncident.get(testCase.getFullyQualifiedName())); | ||
| } | ||
| } | ||
| } | ||
|
|
@@ -1053,22 +1074,29 @@ private TestCaseResult getTestCaseResult(TestCase testCase) { | |
| return testCaseResult; | ||
| } | ||
|
|
||
| /** | ||
| * Check all the test case results that have an ongoing incident and get the stateId of the | ||
| * incident | ||
| */ | ||
| /** StateId of the test case's ongoing incident: latest unresolved record, or null if resolved. */ | ||
| private UUID getIncidentId(TestCase test) { | ||
| UUID ongoingIncident = null; | ||
|
|
||
| String json = | ||
| daoCollection.dataQualityDataTimeSeriesDao().getLatestRecord(test.getFullyQualifiedName()); | ||
| TestCaseResult latestTestCaseResult = JsonUtils.readValue(json, TestCaseResult.class); | ||
| if (!latestResultIsFailed(test.getFullyQualifiedName())) { | ||
| return null; | ||
| } | ||
| TestCaseResolutionStatusRepository tcrsRepo = | ||
| (TestCaseResolutionStatusRepository) | ||
| Entity.getEntityTimeSeriesRepository(Entity.TEST_CASE_RESOLUTION_STATUS); | ||
| TestCaseResolutionStatus latest = tcrsRepo.getLatestRecord(test.getFullyQualifiedName()); | ||
| return Boolean.TRUE.equals(tcrsRepo.unresolvedIncident(latest)) ? latest.getStateId() : null; | ||
| } | ||
|
|
||
| if (!nullOrEmpty(latestTestCaseResult)) { | ||
| ongoingIncident = latestTestCaseResult.getIncidentId(); | ||
| private boolean latestResultIsFailed(String testCaseFqn) { | ||
| List<CollectionDAO.LatestRecordWithFQNHash> records = | ||
| daoCollection.dataQualityDataTimeSeriesDao().getLatestRecordBatch(List.of(testCaseFqn)); | ||
| if (records.isEmpty() || records.get(0).getJson() == null) { | ||
|
Comment on lines
1078
to
+1092
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Performance: getIncidentId re-queries latest result already fetched in setFieldsIn Was this helpful? React with 👍 / 👎 |
||
| return false; | ||
| } | ||
| return isFailedResult(JsonUtils.readValue(records.get(0).getJson(), TestCaseResult.class)); | ||
| } | ||
|
|
||
| return ongoingIncident; | ||
| private static boolean isFailedResult(TestCaseResult result) { | ||
| return result != null && result.getTestCaseStatus() == TestCaseStatus.Failed; | ||
| } | ||
|
|
||
| public int getTestCaseCount(List<UUID> testCaseIds) { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.