Skip to content
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

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

Merged
merged 12 commits into from
Sep 18, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -4408,10 +4408,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 @@ -4420,15 +4423,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);
}
}

class EntitiesCountRowMapper implements RowMapper<EntitiesCount> {
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 @@ -375,4 +375,17 @@ public void deleteTestCaseFailedSamples(TestCaseResolutionStatus entity) {
(TestCaseRepository) Entity.getEntityRepository(Entity.TEST_CASE);
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) \
ON entityFQNHash = testCaseHash
"""
+ condition;
}
return condition;
}
}
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.TableData;
import org.openmetadata.schema.type.TagLabel;
import org.openmetadata.schema.type.TaskStatus;
Expand Down Expand Up @@ -1569,6 +1570,34 @@
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);

Check failure on line 1588 in openmetadata-service/src/test/java/org/openmetadata/service/resources/dqtests/TestCaseResourceTest.java

View workflow job for this annotation

GitHub Actions / Test Report

TestCaseResourceTest.post_createTestCaseResultFailure(TestInfo)

no mapping for code
Raw output
java.lang.NullPointerException: no mapping for code
	at org.apache.johnzon.core.JsonObjectImpl.valueOrExcpetion(JsonObjectImpl.java:52)
	at org.apache.johnzon.core.JsonObjectImpl.getInt(JsonObjectImpl.java:100)
	at org.openmetadata.service.util.TestUtils.readResponseError(TestUtils.java:250)
	at org.openmetadata.service.util.TestUtils.readResponse(TestUtils.java:264)
	at org.openmetadata.service.util.TestUtils.get(TestUtils.java:389)
	at org.openmetadata.service.resources.dqtests.TestCaseResourceTest.getTestCaseFailureStatus(TestCaseResourceTest.java:2431)
	at org.openmetadata.service.resources.dqtests.TestCaseResourceTest.post_createTestCaseResultFailure(TestCaseResourceTest.java:1588)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:569)
	at org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:727)
	at org.junit.jupiter.engine.execution.MethodInvocation.proceed(MethodInvocation.java:60)
	at org.junit.jupiter.engine.execution.InvocationInterceptorChain$ValidatingInvocation.proceed(InvocationInterceptorChain.java:131)
	at org.junit.jupiter.engine.extension.TimeoutExtension.intercept(TimeoutExtension.java:156)
	at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestableMethod(TimeoutExtension.java:147)
	at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestMethod(TimeoutExtension.java:86)
	at org.junit.jupiter.engine.execution.InterceptingExecutableInvoker$ReflectiveInterceptorCall.lambda$ofVoidMethod$0(InterceptingExecutableInvoker.java:103)
	at org.junit.jupiter.engine.execution.InterceptingExecutableInvoker.lambda$invoke$0(InterceptingExecutableInvoker.java:93)
	at org.junit.jupiter.engine.execution.InvocationInterceptorChain$InterceptedInvocation.proceed(InvocationInterceptorChain.java:106)
	at org.junit.jupiter.engine.execution.InvocationInterceptorChain.proceed(InvocationInterceptorChain.java:64)
	at org.junit.jupiter.engine.execution.InvocationInterceptorChain.chainAndInvoke(InvocationInterceptorChain.java:45)
	at org.junit.jupiter.engine.execution.InvocationInterceptorChain.invoke(InvocationInterceptorChain.java:37)
	at org.junit.jupiter.engine.execution.InterceptingExecutableInvoker.invoke(InterceptingExecutableInvoker.java:92)
	at org.junit.jupiter.engine.execution.InterceptingExecutableInvoker.invoke(InterceptingExecutableInvoker.java:86)
	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeTestMethod$7(TestMethodTestDescriptor.java:217)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.invokeTestMethod(TestMethodTestDescriptor.java:213)
	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:138)
	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:68)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:151)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141)
	at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
	at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:41)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:155)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141)
	at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
	at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:41)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:155)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141)
	at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95)
	at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.submit(SameThreadHierarchicalTestExecutorService.java:35)
	at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:57)
	at org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:54)
	at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:147)
	at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:127)
	at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:90)
	at org.junit.platform.launcher.core.EngineExecutionOrchestrator.lambda$execute$0(EngineExecutionOrchestrator.java:55)
	at org.junit.platform.launcher.core.EngineExecutionOrchestrator.withInterceptedStreams(EngineExecutionOrchestrator.java:102)
	at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:54)
	at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:114)
	at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:86)
	at org.junit.platform.launcher.core.DefaultLauncherSession$DelegatingLauncher.execute(DefaultLauncherSession.java:86)
	at org.apache.maven.surefire.junitplatform.LazyLauncher.execute(LazyLauncher.java:56)
	at org.apache.maven.surefire.junitplatform.JUnitPlatformProvider.execute(JUnitPlatformProvider.java:184)
	at org.apache.maven.surefire.junitplatform.JUnitPlatformProvider.invokeAllTests(JUnitPlatformProvider.java:148)
	at org.apache.maven.surefire.junitplatform.JUnitPlatformProvider.invoke(JUnitPlatformProvider.java:120)
	at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:385)
	at org.apache.maven.surefire.booter.ForkedBooter.execute(ForkedBooter.java:162)
	at org.apache.maven.surefire.booter.ForkedBooter.run(ForkedBooter.java:507)
	at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:495)
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 @@ -2385,9 +2414,13 @@
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 @@ -2401,6 +2434,16 @@
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
Loading