GEN 1507 - Implement Origin Entity FQN parms to incident manager listing (#17890)

* fix import issue

* feat: added originEntityFQN param in incident listing

* chore: removed table alias

* fix: added alias to derived table

* style: ran java linting

---------

Co-authored-by: Chirag Madlani <12962843+chirag-madlani@users.noreply.github.com>
This commit is contained in:
Teddy 2024-09-18 22:45:36 +02:00 committed by GitHub
parent 0f5746499a
commit 4331570f7f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 1449 additions and 1355 deletions

View File

@ -4411,10 +4411,13 @@ public interface CollectionDAO {
outerFilter.addQueryParam("testCaseResolutionStatusType", testCaseResolutionStatusType);
outerFilter.addQueryParam("assignee", assignee);
String condition = filter.getCondition();
condition = TestCaseResolutionStatusRepository.addOriginEntityFQNJoin(filter, condition);
return listWithOffset(
getTimeSeriesTableName(),
filter.getQueryParams(),
filter.getCondition(),
condition,
getPartitionFieldName(),
limit,
offset,
@ -4423,15 +4426,32 @@ public interface CollectionDAO {
filter.getQueryParams(),
outerFilter.getCondition());
}
String condition = filter.getCondition();
condition = TestCaseResolutionStatusRepository.addOriginEntityFQNJoin(filter, condition);
return listWithOffset(
getTimeSeriesTableName(),
filter.getQueryParams(),
filter.getCondition(),
condition,
limit,
offset,
startTs,
endTs);
}
@Override
default int listCount(ListFilter filter, Long startTs, Long endTs, boolean latest) {
String condition = filter.getCondition();
condition = TestCaseResolutionStatusRepository.addOriginEntityFQNJoin(filter, condition);
return latest
? listCount(
getTimeSeriesTableName(),
getPartitionFieldName(),
filter.getQueryParams(),
condition,
startTs,
endTs)
: listCount(getTimeSeriesTableName(), filter.getQueryParams(), condition, startTs, endTs);
}
}
interface TestCaseResultTimeSeriesDAO extends EntityTimeSeriesDAO {

View File

@ -36,6 +36,7 @@ public class ListFilter extends Filter<ListFilter> {
conditions.add(getWebhookCondition(tableName));
conditions.add(getWebhookTypeCondition(tableName));
conditions.add(getTestCaseCondition());
conditions.add(getTestCaseIncidentCondition());
conditions.add(getTestSuiteTypeCondition(tableName));
conditions.add(getTestSuiteFQNCondition());
conditions.add(getDomainCondition(tableName));
@ -231,6 +232,18 @@ public class ListFilter extends Filter<ListFilter> {
return addCondition(conditions);
}
private String getTestCaseIncidentCondition() {
String originEntityFQN = getQueryParam("originEntityFQN");
if (originEntityFQN != null) {
queryParams.put(
"originEntityFQNLike",
originEntityFQN + ".%"); // Add wildcard to get all column test cases under the entity
return "(testCaseEntityFQN = :originEntityFQN\n"
+ " OR testCaseEntityFQN LIKE :originEntityFQNLike)";
}
return "";
}
private String getTestSuiteTypeCondition(String tableName) {
String testSuiteType = getQueryParam("testSuiteType");

View File

@ -384,6 +384,19 @@ public class TestCaseResolutionStatusRepository
testCaseRepository.deleteTestCaseFailedRowsSample(entity.getTestCaseReference().getId());
}
public static String addOriginEntityFQNJoin(ListFilter filter, String condition) {
// if originEntityFQN is present, we need to join with test_case table
if (filter.getQueryParam("originEntityFQN") != null) {
condition =
"""
INNER JOIN (SELECT entityFQN AS testCaseEntityFQN,fqnHash AS testCaseHash FROM test_case) tc \
ON entityFQNHash = testCaseHash
"""
+ condition;
}
return condition;
}
protected static UUID getOrCreateIncident(TestCase testCase, String updatedBy) {
CollectionDAO daoCollection = Entity.getCollectionDAO();
TestCaseResolutionStatusRepository testCaseResolutionStatusRepository =

View File

@ -48,6 +48,7 @@ import org.openmetadata.service.security.Authorizer;
import org.openmetadata.service.security.policyevaluator.OperationContext;
import org.openmetadata.service.security.policyevaluator.ReportDataContext;
import org.openmetadata.service.security.policyevaluator.ResourceContextInterface;
import org.openmetadata.service.util.FullyQualifiedName;
import org.openmetadata.service.util.RestUtil;
import org.openmetadata.service.util.ResultList;
@ -134,7 +135,12 @@ public class TestCaseResolutionStatusResource
String assignee,
@Parameter(description = "Test case fully qualified name", schema = @Schema(type = "String"))
@QueryParam("testCaseFQN")
String testCaseFQN) {
String testCaseFQN,
@Parameter(
description = "Origin entity for which the incident was opened for",
schema = @Schema(type = "String"))
@QueryParam("originEntityFQN")
String originEntityFQN) {
OperationContext operationContext =
new OperationContext(Entity.TEST_CASE, MetadataOperation.VIEW_ALL);
ResourceContextInterface resourceContext = ReportDataContext.builder().build();
@ -143,7 +149,8 @@ public class TestCaseResolutionStatusResource
ListFilter filter = new ListFilter(null);
filter.addQueryParam("testCaseResolutionStatusType", testCaseResolutionStatusType);
filter.addQueryParam("assignee", assignee);
filter.addQueryParam("entityFQNHash", testCaseFQN);
filter.addQueryParam("entityFQNHash", FullyQualifiedName.buildHash(testCaseFQN));
filter.addQueryParam("originEntityFQN", originEntityFQN);
return repository.list(offset, startTs, endTs, limitParam, filter, latest);
}

View File

@ -95,6 +95,7 @@ import org.openmetadata.schema.tests.type.TestSummary;
import org.openmetadata.schema.type.ChangeDescription;
import org.openmetadata.schema.type.Column;
import org.openmetadata.schema.type.ColumnDataType;
import org.openmetadata.schema.type.EntityReference;
import org.openmetadata.schema.type.Include;
import org.openmetadata.schema.type.TableData;
import org.openmetadata.schema.type.TagLabel;
@ -1161,6 +1162,34 @@ public class TestCaseResourceTest extends EntityResourceTest<TestCase, CreateTes
TestCaseResolutionStatusTypes.Ack,
storedTestCaseResolutions.getData().get(0).getTestCaseResolutionStatusType());
// Get the test case resolution by FQN
Map<String, String> queryParams = new HashMap<>();
queryParams.put("testCaseFQN", TEST_TABLE1.getFullyQualifiedName());
storedTestCaseResolutions = getTestCaseFailureStatus(startTs, endTs, null, null, queryParams);
assertTrue(
storedTestCaseResolutions.getData().stream()
.allMatch(
t ->
t.getTestCaseReference()
.getFullyQualifiedName()
.equals(testCaseEntity1.getFullyQualifiedName())));
// Get the test case resolution by origin entity FQN
queryParams.clear();
queryParams.put("originEntityFQN", TEST_TABLE1.getFullyQualifiedName());
storedTestCaseResolutions = getTestCaseFailureStatus(startTs, endTs, null, null, queryParams);
for (TestCaseResolutionStatus testCaseResolution : storedTestCaseResolutions.getData()) {
EntityReference testCaseReference = testCaseResolution.getTestCaseReference();
TestCase testCase = getEntity(testCaseReference.getId(), ADMIN_AUTH_HEADERS);
MessageParser.EntityLink entityLink =
MessageParser.EntityLink.parse(testCase.getEntityLink());
assertEquals(entityLink.getEntityFQN(), TEST_TABLE1.getFullyQualifiedName());
}
queryParams.put("originEntityFQN", "IDONOTEXIST123");
storedTestCaseResolutions = getTestCaseFailureStatus(startTs, endTs, null, null, queryParams);
assertEquals(0, storedTestCaseResolutions.getData().size());
// Delete test case recursively and check that the test case resolution status is also deleted
// 1. soft delete - should not delete the test case resolution status
// 2. hard delete - should delete the test case resolution status
@ -2839,9 +2868,13 @@ public class TestCaseResourceTest extends EntityResourceTest<TestCase, CreateTes
Long startTs,
Long endTs,
String assignee,
TestCaseResolutionStatusTypes testCaseResolutionStatusType)
TestCaseResolutionStatusTypes testCaseResolutionStatusType,
Map<String, String> fields)
throws HttpResponseException {
WebTarget target = getCollection().path("/testCaseIncidentStatus");
for (Map.Entry<String, String> entry : fields.entrySet()) {
target = target.queryParam(entry.getKey(), entry.getValue());
}
target = target.queryParam("startTs", startTs);
target = target.queryParam("endTs", endTs);
target = assignee != null ? target.queryParam("assignee", assignee) : target;
@ -2855,6 +2888,16 @@ public class TestCaseResourceTest extends EntityResourceTest<TestCase, CreateTes
ADMIN_AUTH_HEADERS);
}
public ResultList<TestCaseResolutionStatus> getTestCaseFailureStatus(
Long startTs,
Long endTs,
String assignee,
TestCaseResolutionStatusTypes testCaseResolutionStatusType)
throws HttpResponseException {
return getTestCaseFailureStatus(
startTs, endTs, assignee, testCaseResolutionStatusType, new HashMap<>());
}
private TestCaseResolutionStatus getTestCaseFailureStatusById(UUID id)
throws HttpResponseException {
String pathUrl = "/testCaseIncidentStatus/" + id;

View File

@ -125,7 +125,6 @@ class MysqlIngestionClass extends ServiceBaseClass {
)
.then((res) => res.json());
// Re-deploy before running the ingestion
await page.click(
`[data-row-key*="${response.data[0].name}"] [data-testid="more-actions"]`

View File

@ -131,7 +131,6 @@ class PostgresIngestionClass extends ServiceBaseClass {
)
.then((res) => res.json());
// Re-deploy before running the ingestion
await page.click(
`[data-row-key*="${response.data[0].name}"] [data-testid="more-actions"]`