Skip to content

Commit

Permalink
feat(graphql): Support tagging incidents and assertions via GraphQL A…
Browse files Browse the repository at this point in the history
…PI (#10575)

Co-authored-by: John Joyce <[email protected]>
Co-authored-by: John Joyce <[email protected]>
  • Loading branch information
3 people authored May 24, 2024
1 parent 1c1450e commit 043221f
Show file tree
Hide file tree
Showing 10 changed files with 68 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package com.linkedin.datahub.graphql.types.assertion;

import static com.linkedin.metadata.Constants.GLOBAL_TAGS_ASPECT_NAME;

import com.linkedin.assertion.AssertionInfo;
import com.linkedin.common.DataPlatformInstance;
import com.linkedin.common.GlobalTags;
import com.linkedin.common.Status;
import com.linkedin.common.urn.Urn;
import com.linkedin.data.DataMap;
Expand All @@ -20,6 +23,7 @@
import com.linkedin.datahub.graphql.generated.SchemaFieldRef;
import com.linkedin.datahub.graphql.types.common.mappers.DataPlatformInstanceAspectMapper;
import com.linkedin.datahub.graphql.types.common.mappers.StringMapMapper;
import com.linkedin.datahub.graphql.types.tag.mappers.GlobalTagsMapper;
import com.linkedin.entity.EntityResponse;
import com.linkedin.entity.EnvelopedAspect;
import com.linkedin.entity.EnvelopedAspectMap;
Expand Down Expand Up @@ -62,6 +66,13 @@ public static Assertion map(@Nullable QueryContext context, final EntityResponse
result.setStatus(mapStatus(new Status(envelopedStatus.getValue().data())));
}

final EnvelopedAspect envelopedTags = aspects.get(GLOBAL_TAGS_ASPECT_NAME);
if (envelopedTags != null) {
result.setTags(
GlobalTagsMapper.map(
context, new GlobalTags(envelopedTags.getValue().data()), entityUrn));
}

return result;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ public class AssertionType
ImmutableSet.of(
Constants.ASSERTION_KEY_ASPECT_NAME,
Constants.ASSERTION_INFO_ASPECT_NAME,
Constants.DATA_PLATFORM_INSTANCE_ASPECT_NAME);
Constants.DATA_PLATFORM_INSTANCE_ASPECT_NAME,
Constants.GLOBAL_TAGS_ASPECT_NAME);

private final EntityClient _entityClient;

public AssertionType(final EntityClient entityClient) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.linkedin.datahub.graphql.types.incident;

import static com.linkedin.metadata.Constants.GLOBAL_TAGS_ASPECT_NAME;

import com.linkedin.common.GlobalTags;
import com.linkedin.common.urn.Urn;
import com.linkedin.data.template.GetMode;
import com.linkedin.datahub.graphql.QueryContext;
Expand All @@ -12,6 +15,7 @@
import com.linkedin.datahub.graphql.generated.IncidentType;
import com.linkedin.datahub.graphql.types.common.mappers.AuditStampMapper;
import com.linkedin.datahub.graphql.types.common.mappers.UrnToEntityMapper;
import com.linkedin.datahub.graphql.types.tag.mappers.GlobalTagsMapper;
import com.linkedin.entity.EntityResponse;
import com.linkedin.entity.EnvelopedAspect;
import com.linkedin.entity.EnvelopedAspectMap;
Expand Down Expand Up @@ -50,6 +54,14 @@ public static Incident map(@Nullable QueryContext context, final EntityResponse
} else {
throw new RuntimeException(String.format("Incident does not exist!. urn: %s", entityUrn));
}

final EnvelopedAspect envelopedTags = aspects.get(GLOBAL_TAGS_ASPECT_NAME);
if (envelopedTags != null) {
result.setTags(
GlobalTagsMapper.map(
context, new GlobalTags(envelopedTags.getValue().data()), entityUrn));
}

return result;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
public class IncidentType
implements com.linkedin.datahub.graphql.types.EntityType<Incident, String> {

static final Set<String> ASPECTS_TO_FETCH = ImmutableSet.of(Constants.INCIDENT_INFO_ASPECT_NAME);
static final Set<String> ASPECTS_TO_FETCH =
ImmutableSet.of(Constants.INCIDENT_INFO_ASPECT_NAME, Constants.GLOBAL_TAGS_ASPECT_NAME);
private final EntityClient _entityClient;

public IncidentType(final EntityClient entityClient) {
Expand Down
5 changes: 5 additions & 0 deletions datahub-graphql-core/src/main/resources/entity.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -7293,6 +7293,11 @@ type Assertion implements EntityWithRelationships & Entity {
"""
status: Status

"""
The standard tags for the Assertion
"""
tags: GlobalTags

"""
Experimental API.
For fetching extra aspects that do not have custom UI code yet
Expand Down
5 changes: 5 additions & 0 deletions datahub-graphql-core/src/main/resources/incident.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@ type Incident implements Entity {
"""
created: AuditStamp!

"""
The standard tags for the Incident
"""
tags: GlobalTags

"""
List of relationships between the source Entity and some destination entities with a given types
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;

import com.google.common.collect.ImmutableMap;
import com.linkedin.common.AuditStamp;
import com.linkedin.common.GlobalTags;
import com.linkedin.common.TagAssociationArray;
import com.linkedin.common.UrnArray;
import com.linkedin.common.urn.TagUrn;
import com.linkedin.common.urn.Urn;
import com.linkedin.data.template.SetMode;
import com.linkedin.datahub.graphql.generated.EntityType;
Expand Down Expand Up @@ -64,9 +68,22 @@ public void testMap() throws Exception {
incidentInfo.setCreated(created);

envelopedIncidentInfo.setValue(new Aspect(incidentInfo.data()));

EnvelopedAspect envelopedTagsAspect = new EnvelopedAspect();
GlobalTags tags = new GlobalTags();
tags.setTags(
new TagAssociationArray(
new TagAssociationArray(
Collections.singletonList(
new com.linkedin.common.TagAssociation()
.setTag(TagUrn.createFromString("urn:li:tag:test"))))));
envelopedTagsAspect.setValue(new Aspect(tags.data()));

entityResponse.setAspects(
new EnvelopedAspectMap(
Collections.singletonMap(Constants.INCIDENT_INFO_ASPECT_NAME, envelopedIncidentInfo)));
ImmutableMap.of(
Constants.INCIDENT_INFO_ASPECT_NAME, envelopedIncidentInfo,
Constants.GLOBAL_TAGS_ASPECT_NAME, envelopedTagsAspect)));

Incident incident = IncidentMapper.map(null, entityResponse);

Expand All @@ -92,5 +109,9 @@ public void testMap() throws Exception {
assertEquals(incident.getStatus().getLastUpdated().getActor(), userUrn.toString());
assertEquals(incident.getCreated().getTime().longValue(), 1000L);
assertEquals(incident.getCreated().getActor(), userUrn.toString());

assertEquals(incident.getTags().getTags().size(), 1);
assertEquals(
incident.getTags().getTags().get(0).getTag().getUrn().toString(), "urn:li:tag:test");
}
}
3 changes: 3 additions & 0 deletions datahub-web-react/src/graphql/assertion.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ fragment assertionDetails on Assertion {
}
description
}
tags {
...globalTagsFields
}
}

fragment assertionRunEventDetails on AssertionRunEvent {
Expand Down
3 changes: 3 additions & 0 deletions datahub-web-react/src/graphql/incident.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ fragment incidentsFields on EntityIncidentsResult {
time
actor
}
tags {
...globalTagsFields
}
}
}

Expand Down
2 changes: 2 additions & 0 deletions metadata-models/src/main/resources/entity-registry.yml
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ entities:
- assertionRunEvent
- assertionActions
- status
- globalTags
- name: dataHubRetention
category: internal
keyAspect: dataHubRetentionKey
Expand Down Expand Up @@ -464,6 +465,7 @@ entities:
keyAspect: incidentKey
aspects:
- incidentInfo
- globalTags
- name: dataHubRole
category: core
keyAspect: dataHubRoleKey
Expand Down

0 comments on commit 043221f

Please sign in to comment.