Skip to content

Commit

Permalink
GEN 1507 - Implement Origin Entity FQN parms to incident manager list…
Browse files Browse the repository at this point in the history
…ing (#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>
  • Loading branch information
TeddyCr and chirag-madlani authored Sep 18, 2024
1 parent 0f57464 commit 4331570
Show file tree
Hide file tree
Showing 8 changed files with 1,449 additions and 1,355 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4411,10 +4411,13 @@ default List<String> listWithOffset(
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,
Expand All @@ -4423,15 +4426,32 @@ default List<String> listWithOffset(
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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public String getCondition(String tableName) {
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));
Expand Down Expand Up @@ -231,6 +232,18 @@ private String getTestCaseCondition() {
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");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,19 @@ public void deleteTestCaseFailedSamples(TestCaseResolutionStatus entity) {
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 =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
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;

Expand Down Expand Up @@ -134,7 +135,12 @@ public ResultList<TestCaseResolutionStatus> list(
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();
Expand All @@ -143,7 +149,8 @@ public ResultList<TestCaseResolutionStatus> list(
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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
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;
Expand Down Expand Up @@ -1161,6 +1162,34 @@ void post_createTestCaseResultFailure(TestInfo test)
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
Expand Down Expand Up @@ -2839,9 +2868,13 @@ public ResultList<TestCaseResolutionStatus> getTestCaseFailureStatus(
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;
Expand All @@ -2855,6 +2888,16 @@ public ResultList<TestCaseResolutionStatus> getTestCaseFailureStatus(
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"]`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"]`
Expand Down
Loading

0 comments on commit 4331570

Please sign in to comment.