Skip to content

Commit

Permalink
MINOR - Create Test Case Resolution ts entry & delete resolution when… (
Browse files Browse the repository at this point in the history
#14541)

* MINOR - Create Test Case Resolution ts entry & delete resolution when Test Case is deleted
  • Loading branch information
pmbrull authored Jan 5, 2024
1 parent a07ef89 commit 0255171
Show file tree
Hide file tree
Showing 14 changed files with 468 additions and 302 deletions.
16 changes: 0 additions & 16 deletions ingestion/examples/sample_data/tests/testSuites.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@
],
"resolutions": {
"sequenceOne": [
{
"testCaseResolutionStatusType": "New",
"severity": "Severity1"
},
{
"testCaseResolutionStatusType": "Ack",
"severity": "Severity1"
Expand Down Expand Up @@ -108,10 +104,6 @@
],
"resolutions": {
"sequenceOne": [
{
"testCaseResolutionStatusType": "New",
"severity": "Severity1"
},
{
"testCaseResolutionStatusType": "Ack",
"severity": "Severity1"
Expand Down Expand Up @@ -186,10 +178,6 @@
],
"resolutions": {
"sequenceOne": [
{
"testCaseResolutionStatusType": "New",
"severity": "Severity1"
},
{
"testCaseResolutionStatusType": "Ack",
"severity": "Severity1"
Expand Down Expand Up @@ -264,10 +252,6 @@
],
"resolutions": {
"sequenceOne": [
{
"testCaseResolutionStatusType": "New",
"severity": "Severity1"
},
{
"testCaseResolutionStatusType": "Ack",
"severity": "Severity1"
Expand Down
9 changes: 9 additions & 0 deletions ingestion/src/metadata/ingestion/models/tests_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
from pydantic import BaseModel

from metadata.generated.schema.api.tests.createTestCase import CreateTestCaseRequest
from metadata.generated.schema.api.tests.createTestCaseResolutionStatus import (
CreateTestCaseResolutionStatus,
)
from metadata.generated.schema.api.tests.createTestSuite import CreateTestSuiteRequest
from metadata.generated.schema.tests.basic import TestCaseResult
from metadata.generated.schema.tests.testCase import TestCase
Expand All @@ -38,3 +41,9 @@ class OMetaTestCaseSample(BaseModel):
class OMetaTestCaseResultsSample(BaseModel):
test_case_results: TestCaseResult
test_case_name: str


class OMetaTestCaseResolutionStatus(BaseModel):
"""For sample data"""

test_case_resolution: CreateTestCaseResolutionStatus
13 changes: 13 additions & 0 deletions ingestion/src/metadata/ingestion/sink/metadata_rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@
from metadata.generated.schema.entity.teams.user import User
from metadata.generated.schema.tests.basic import TestCaseResult
from metadata.generated.schema.tests.testCase import TestCase
from metadata.generated.schema.tests.testCaseResolutionStatus import (
TestCaseResolutionStatus,
)
from metadata.generated.schema.tests.testSuite import TestSuite
from metadata.generated.schema.type.schema import Topic
from metadata.ingestion.api.models import Either, Entity, StackTraceError
Expand All @@ -67,6 +70,7 @@
from metadata.ingestion.models.search_index_data import OMetaIndexSampleData
from metadata.ingestion.models.tests_data import (
OMetaLogicalTestSuiteSample,
OMetaTestCaseResolutionStatus,
OMetaTestCaseResultsSample,
OMetaTestCaseSample,
OMetaTestSuiteSample,
Expand Down Expand Up @@ -411,6 +415,15 @@ def write_test_case_results(self, record: TestCaseResultResponse):
)
return Either(right=res)

@_run_dispatch.register
def write_test_case_resolution_status(
self, record: OMetaTestCaseResolutionStatus
) -> TestCaseResolutionStatus:
"""For sample data"""
res = self.metadata.create_test_case_resolution(record.test_case_resolution)

return Either(right=res)

@_run_dispatch.register
def write_data_insight_sample(
self, record: OMetaDataInsightSample
Expand Down
17 changes: 15 additions & 2 deletions ingestion/src/metadata/ingestion/source/database/sample_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@
from metadata.ingestion.models.profile_data import OMetaTableProfileSampleData
from metadata.ingestion.models.tests_data import (
OMetaLogicalTestSuiteSample,
OMetaTestCaseResolutionStatus,
OMetaTestCaseResultsSample,
OMetaTestCaseSample,
OMetaTestSuiteSample,
Expand Down Expand Up @@ -566,6 +567,7 @@ def _iter(self, *_, **__) -> Iterable[Entity]:
yield from self.ingest_test_suite()
yield from self.ingest_test_case()
yield from self.ingest_test_case_results()
yield from self.ingest_incidents()
yield from self.ingest_logical_test_suite()
yield from self.ingest_data_insights()
yield from self.ingest_life_cycle()
Expand Down Expand Up @@ -1408,6 +1410,15 @@ def ingest_test_case(self) -> Iterable[Either[OMetaTestCaseSample]]:
)
yield Either(right=test_case_req)

def ingest_incidents(self) -> Iterable[Either[OMetaTestCaseResolutionStatus]]:
"""
Ingest incidents after the first test failures have been added.
The test failure already creates the incident with NEW, so we
start always from ACK in the sample flows.
"""
for test_suite in self.tests_suites["tests"]:
for test_case in test_suite["testCases"]:
test_case_fqn = f"{entity_link.get_table_or_column_fqn(test_case['entityLink'])}.{test_case['name']}"

for _, resolutions in test_case["resolutions"].items():
Expand Down Expand Up @@ -1449,8 +1460,10 @@ def ingest_test_case(self) -> Iterable[Either[OMetaTestCaseSample]]:
testCaseFailureComment="Resolution comment",
)

self.metadata.create_test_case_resolution(
create_test_case_resolution
yield Either(
right=OMetaTestCaseResolutionStatus(
test_case_resolution=create_test_case_resolution
)
)

def ingest_test_case_results(self) -> Iterable[Either[OMetaTestCaseResultsSample]]:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package org.openmetadata.service.exception;

import javax.ws.rs.core.Response;
import org.openmetadata.schema.tests.type.TestCaseResolutionStatusTypes;
import org.openmetadata.sdk.exception.WebServiceException;

public class IncidentManagerException extends WebServiceException {

protected IncidentManagerException(Response.Status status, String message) {
super(status.getStatusCode(), message);
}

public IncidentManagerException(String message) {
super(Response.Status.INTERNAL_SERVER_ERROR, message);
}

public static IncidentManagerException invalidStatus(
TestCaseResolutionStatusTypes lastStatus, TestCaseResolutionStatusTypes newStatus) {
return new IncidentManagerException(
Response.Status.BAD_REQUEST,
String.format("Incident with status [%s] cannot be moved to [%s]", lastStatus, newStatus));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3592,6 +3592,32 @@ interface DataQualityDataTimeSeriesDAO extends EntityTimeSeriesDAO {
default String getTimeSeriesTableName() {
return "data_quality_data_time_series";
}

@ConnectionAwareSqlQuery(
value =
"SELECT json FROM data_quality_data_time_series where entityFQNHash = :testCaseFQNHash "
+ "AND JSON_EXTRACT(json, '$.incidentId') IS NOT NULL",
connectionType = MYSQL)
@ConnectionAwareSqlQuery(
value =
"SELECT json FROM data_quality_data_time_series where entityFQNHash = :testCaseFQNHash "
+ "AND json ->> 'incidentId' IS NOT NULL",
connectionType = POSTGRES)
List<String> getResultsWithIncidents(@Bind("testCaseFQNHash") String testCaseFQNHash);

@ConnectionAwareSqlUpdate(
value =
"SELECT json FROM data_quality_data_time_series where entityFQNHash = :entityFQNHash "
+ "AND JSON_EXTRACT(json, '$.incidentId') IS NOT NULL",
connectionType = MYSQL)
@ConnectionAwareSqlUpdate(
value =
"SELECT json FROM data_quality_data_time_series where entityFQNHash = :entityFQNHash "
+ "AND json ->> 'incidentId' IS NOT NULL",
connectionType = POSTGRES)
// TODO: need to find the right way to get this cleaned
void cleanTestCaseIncidents(
@Bind("entityFQNHash") String entityFQNHash, @Bind("stateId") String stateId);
}

interface TestCaseResolutionStatusTimeSeriesDAO extends EntityTimeSeriesDAO {
Expand All @@ -3605,6 +3631,10 @@ default String getTimeSeriesTableName() {
"SELECT json FROM test_case_resolution_status_time_series "
+ "WHERE stateId = :stateId ORDER BY timestamp DESC")
List<String> listTestCaseResolutionStatusesForStateId(@Bind("stateId") String stateId);

@SqlUpdate(
"DELETE FROM test_case_resolution_status_time_series WHERE entityFQNHash = :entityFQNHash")
void delete(@BindFQN("entityFQNHash") String entityFQNHash);
}

class EntitiesCountRowMapper implements RowMapper<EntitiesCount> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public abstract class EntityTimeSeriesRepository<T extends EntityTimeSeriesInter
@Getter protected final SearchRepository searchRepository;
@Getter protected final String entityType;
@Getter protected final Class<T> entityClass;
@Getter protected final CollectionDAO daoCollection;

protected EntityTimeSeriesRepository(
String collectionPath,
Expand All @@ -30,6 +31,7 @@ protected EntityTimeSeriesRepository(
this.entityClass = entityClass;
this.entityType = entityType;
this.searchRepository = Entity.getSearchRepository();
this.daoCollection = Entity.getCollectionDAO();
Entity.registerEntity(entityClass, entityType, this);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,7 @@ public final PatchResponse<Thread> patchThread(

restorePatchAttributes(original, updated);

if (!updated.getReactions().isEmpty()) {
if (!nullOrEmpty(updated.getReactions())) {
populateUserReactions(updated.getReactions());
updated
.getReactions()
Expand Down Expand Up @@ -885,8 +885,10 @@ private boolean fieldsChanged(Thread original, Thread updated) {
&& !Collections.isEmpty(updated.getReactions()))
|| (!Collections.isEmpty(original.getReactions())
&& Collections.isEmpty(updated.getReactions()))
|| original.getReactions().size() != updated.getReactions().size()
|| !original.getReactions().containsAll(updated.getReactions())
|| (original.getReactions() != null
&& updated.getReactions() != null
&& (original.getReactions().size() != updated.getReactions().size()
|| !original.getReactions().containsAll(updated.getReactions())))
|| (original.getAnnouncement() != null
&& (!original
.getAnnouncement()
Expand Down
Loading

0 comments on commit 0255171

Please sign in to comment.