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

Add parentRun alias to LineageEvent RunFacet to support older OpenLin… #2130

Merged
merged 2 commits into from
Sep 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Changelog

## [Unreleased](https://github.com/MarquezProject/marquez/compare/0.26.0...HEAD)
### Fixed
* Add support for `parentRun` facet as reported by older Airflow OpenLineage versions [@collado-mike](https://github.com/collado-mike)
## [0.26.0](https://github.com/MarquezProject/marquez/compare/0.25.0...0.26.0) - 2022-09-15

### Added
Expand Down
7 changes: 6 additions & 1 deletion api/src/main/java/marquez/service/models/LineageEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

package marquez.service.models;

import com.fasterxml.jackson.annotation.JsonAlias;
import com.fasterxml.jackson.annotation.JsonAnyGetter;
import com.fasterxml.jackson.annotation.JsonAnySetter;
import com.fasterxml.jackson.annotation.JsonIgnore;
Expand Down Expand Up @@ -71,7 +72,11 @@ public static class Run extends BaseJsonModel {
public static class RunFacet {

@Valid private NominalTimeRunFacet nominalTime;
@Valid private ParentRunFacet parent;

@JsonAlias(
"parentRun") // the Airflow integration previously reported parentRun instead of parent
@Valid
private ParentRunFacet parent;

@Builder.Default @JsonIgnore private Map<String, Object> additional = new LinkedHashMap<>();

Expand Down
134 changes: 134 additions & 0 deletions api/src/test/java/marquez/OpenLineageIntegrationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
Expand Down Expand Up @@ -235,6 +236,139 @@ public void testOpenLineageJobHierarchyAirflowIntegration()
assertThat(runsList).isNotEmpty().hasSize(1);
}

@Test
public void testOpenLineageJobHierarchyAirflowIntegrationWithParentRunFacet()
throws ExecutionException, InterruptedException, TimeoutException {
OpenLineage ol = new OpenLineage(URI.create("http://openlineage.test.com/"));
ZonedDateTime startOfHour =
Instant.now()
.atZone(LineageTestUtils.LOCAL_ZONE)
.with(ChronoField.MINUTE_OF_HOUR, 0)
.with(ChronoField.SECOND_OF_MINUTE, 0);
ZonedDateTime endOfHour = startOfHour.plusHours(1);
String airflowParentRunId = UUID.randomUUID().toString();
String task1Name = "task1";
String task2Name = "task2";
String dagName = "the_dag";
RunEvent airflowTask1 =
createAirflowRunEvent(
ol,
startOfHour,
endOfHour,
airflowParentRunId,
dagName,
dagName + "." + task1Name,
NAMESPACE_NAME);

// the older airflow integration reported parentRun instead of parent. We support this as an
// alias for compatibility
RunFacet parent = airflowTask1.getRun().getFacets().getAdditionalProperties().remove("parent");
airflowTask1.getRun().getFacets().getAdditionalProperties().put("parentRun", parent);

RunEvent airflowTask2 =
createAirflowRunEvent(
ol,
startOfHour,
endOfHour,
airflowParentRunId,
dagName,
dagName + "." + task2Name,
NAMESPACE_NAME);
parent = airflowTask2.getRun().getFacets().getAdditionalProperties().remove("parent");
airflowTask2.getRun().getFacets().getAdditionalProperties().put("parentRun", parent);

CompletableFuture<Integer> future = sendAllEvents(airflowTask1, airflowTask2);
future.get(5, TimeUnit.SECONDS);

Job job = client.getJob(NAMESPACE_NAME, dagName + "." + task1Name);
assertThat(job)
.isNotNull()
.hasFieldOrPropertyWithValue("id", new JobId(NAMESPACE_NAME, dagName + "." + task1Name))
.hasFieldOrPropertyWithValue("parentJobName", dagName);

Job parentJob = client.getJob(NAMESPACE_NAME, dagName);
assertThat(parentJob)
.isNotNull()
.hasFieldOrPropertyWithValue("id", new JobId(NAMESPACE_NAME, dagName))
.hasFieldOrPropertyWithValue("parentJobName", null);
List<Run> runsList = client.listRuns(NAMESPACE_NAME, dagName);
assertThat(runsList).isNotEmpty().hasSize(1);
}

@Test
public void testOpenLineageJobHierarchyAirflowIntegrationWithParentAndParentRunFacet()
throws ExecutionException, InterruptedException, TimeoutException {
OpenLineage ol = new OpenLineage(URI.create("http://openlineage.test.com/"));
ZonedDateTime startOfHour =
Instant.now()
.atZone(LineageTestUtils.LOCAL_ZONE)
.with(ChronoField.MINUTE_OF_HOUR, 0)
.with(ChronoField.SECOND_OF_MINUTE, 0);
ZonedDateTime endOfHour = startOfHour.plusHours(1);
String airflowParentRunId = UUID.randomUUID().toString();
String task1Name = "task1";
String task2Name = "task2";
String dagName = "the_dag";
RunEvent airflowTask1 =
createAirflowRunEvent(
ol,
startOfHour,
endOfHour,
airflowParentRunId,
dagName,
dagName + "." + task1Name,
NAMESPACE_NAME);

// the older airflow integration reported parentRun instead of parent. The new integration
// reports both. They are the same in the airflow integration, but this test verifies we handle
// the "parentRun" field first.
// It would be preferable to prioritize the "parent" field, but it seems Jackson prefers the
// alias first.
RunFacet parent = airflowTask1.getRun().getFacets().getAdditionalProperties().get("parent");
RunFacet newParent = ol.newRunFacet();
Map<String, Object> runFacetProps = newParent.getAdditionalProperties();
runFacetProps.put("run", parent.getAdditionalProperties().get("run"));
runFacetProps.put(
"job", ImmutableMap.of("name", "a_new_dag", "namespace", "incorrect_namespace"));
airflowTask1.getRun().getFacets().getAdditionalProperties().put("parentRun", parent);
airflowTask1.getRun().getFacets().getAdditionalProperties().put("parent", newParent);

RunEvent airflowTask2 =
createAirflowRunEvent(
ol,
startOfHour,
endOfHour,
airflowParentRunId,
dagName,
dagName + "." + task2Name,
NAMESPACE_NAME);
parent = airflowTask2.getRun().getFacets().getAdditionalProperties().get("parent");
newParent = ol.newRunFacet();
runFacetProps = newParent.getAdditionalProperties();
runFacetProps.put("run", parent.getAdditionalProperties().get("run"));
runFacetProps.put(
"job", ImmutableMap.of("name", "a_new_dag", "namespace", "incorrect_namespace"));
airflowTask2.getRun().getFacets().getAdditionalProperties().put("parentRun", parent);
airflowTask2.getRun().getFacets().getAdditionalProperties().put("parent", newParent);

CompletableFuture<Integer> future = sendAllEvents(airflowTask1, airflowTask2);
future.get(5, TimeUnit.SECONDS);

Job job = client.getJob(NAMESPACE_NAME, dagName + "." + task1Name);
assertThat(job)
.isNotNull()
.hasFieldOrPropertyWithValue("id", new JobId(NAMESPACE_NAME, dagName + "." + task1Name))
.hasFieldOrPropertyWithValue("parentJobName", dagName);

Job parentJob = client.getJob(NAMESPACE_NAME, dagName);
assertThat(parentJob)
.isNotNull()
.hasFieldOrPropertyWithValue("id", new JobId(NAMESPACE_NAME, dagName))
.hasFieldOrPropertyWithValue("parentJobName", null);
List<Run> runsList = client.listRuns(NAMESPACE_NAME, dagName);
assertThat(runsList).isNotEmpty().hasSize(1);
}

@Test
public void testOpenLineageJobHierarchyAirflowIntegrationWithDagNameWithDot()
throws ExecutionException, InterruptedException, TimeoutException {
Expand Down