Skip to content

Commit

Permalink
Added metric logs
Browse files Browse the repository at this point in the history
  • Loading branch information
hr2904 committed Oct 24, 2024
1 parent f2d0d05 commit 17d8ea5
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,7 @@ public static boolean getRestrictPropagationThroughHierarchy(AtlasVertex classif
}

public static AtlasVertex getClassificationVertex(AtlasVertex entityVertex, String classificationName) {
AtlasPerfMetrics.MetricRecorder metrics = RequestContext.get().startMetricRecord("getClassificationVertex");
AtlasVertex ret = null;
Iterable edges = entityVertex.query().direction(AtlasEdgeDirection.OUT).label(CLASSIFICATION_LABEL)
.has(CLASSIFICATION_EDGE_IS_PROPAGATED_PROPERTY_KEY, false)
Expand All @@ -373,7 +374,7 @@ public static AtlasVertex getClassificationVertex(AtlasVertex entityVertex, Stri
ret = (edge != null) ? edge.getInVertex() : null;
}
}

RequestContext.get().endMetricRecord(metrics);
return ret;
}
public static Iterator<AtlasVertex> getClassificationVertices(AtlasGraph graph, String classificationName, int size) {
Expand Down Expand Up @@ -418,6 +419,7 @@ public static long getAssetsCountOfClassificationVertex(AtlasVertex classificati
return count;
}
public static AtlasEdge getClassificationEdge(AtlasVertex entityVertex, AtlasVertex classificationVertex) {
AtlasPerfMetrics.MetricRecorder metrics = RequestContext.get().startMetricRecord("getClassficationEdge");
AtlasEdge ret = null;
Iterable edges = entityVertex.query().direction(AtlasEdgeDirection.OUT).label(CLASSIFICATION_LABEL)
.has(CLASSIFICATION_EDGE_IS_PROPAGATED_PROPERTY_KEY, false)
Expand All @@ -431,7 +433,7 @@ public static AtlasEdge getClassificationEdge(AtlasVertex entityVertex, AtlasVer
ret = (edge != null && edge.getInVertex().equals(classificationVertex)) ? edge : null;
}
}

RequestContext.get().endMetricRecord(metrics);
return ret;
}

Expand Down Expand Up @@ -844,6 +846,7 @@ public static List<String> getAllTraitNames(AtlasVertex entityVertex) {
}

public static List<String> getTraitNames(AtlasVertex entityVertex, Boolean propagated) {
AtlasPerfMetrics.MetricRecorder getTraitNamesMetrics = RequestContext.get().startMetricRecord("getTraitNames");
List<String> ret = new ArrayList<>();
AtlasVertexQuery query = entityVertex.query().direction(AtlasEdgeDirection.OUT).label(CLASSIFICATION_LABEL);

Expand All @@ -862,7 +865,7 @@ public static List<String> getTraitNames(AtlasVertex entityVertex, Boolean propa
ret.add(AtlasGraphUtilsV2.getEncodedProperty(edge, CLASSIFICATION_EDGE_NAME_PROPERTY_KEY, String.class));
}
}

RequestContext.get().endMetricRecord(getTraitNamesMetrics);
return ret;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@ public boolean deleteEdgeReference(AtlasEdge edge, TypeCategory typeCategory, bo

public boolean deleteEdgeReference(AtlasEdge edge, TypeCategory typeCategory, boolean isOwned, boolean forceDeleteStructTrait,
AtlasRelationshipEdgeDirection relationshipDirection, AtlasVertex entityVertex) throws AtlasBaseException {
AtlasPerfMetrics.MetricRecorder metrics = RequestContext.get().startMetricRecord("deleteEdgeReference");
if (LOG.isDebugEnabled()) {
LOG.debug("Deleting {}, force = {}", string(edge), forceDeleteStructTrait);
}
Expand Down Expand Up @@ -406,7 +407,7 @@ public boolean deleteEdgeReference(AtlasEdge edge, TypeCategory typeCategory, bo
deleteEdge(edge, true, isInternalType || isCustomRelationship(edge));
}
}

RequestContext.get().endMetricRecord(metrics);
return !softDelete || forceDelete || isCustomRelationship(edge);
}

Expand Down Expand Up @@ -730,32 +731,39 @@ public void deleteEdgeReference(AtlasVertex outVertex, String edgeLabel, TypeCat

protected void deleteEdge(AtlasEdge edge, boolean updateInverseAttribute, boolean force) throws AtlasBaseException {
//update inverse attribute
if (updateInverseAttribute) {
String labelWithoutPrefix = edge.getLabel().substring(GraphHelper.EDGE_LABEL_PREFIX.length());
AtlasType parentType = typeRegistry.getType(AtlasGraphUtilsV2.getTypeName(edge.getOutVertex()));

if (parentType instanceof AtlasEntityType) {
AtlasEntityType parentEntityType = (AtlasEntityType) parentType;
AtlasStructType.AtlasAttribute attribute = parentEntityType.getAttribute(labelWithoutPrefix);

if (attribute == null) {
attribute = parentEntityType.getRelationshipAttribute(labelWithoutPrefix, AtlasGraphUtilsV2.getTypeName(edge));
}
AtlasPerfMetrics.MetricRecorder metrics = RequestContext.get().startMetricRecord("deleteEdge");
try{
if (updateInverseAttribute) {
String labelWithoutPrefix = edge.getLabel().substring(GraphHelper.EDGE_LABEL_PREFIX.length());
AtlasType parentType = typeRegistry.getType(AtlasGraphUtilsV2.getTypeName(edge.getOutVertex()));

if (parentType instanceof AtlasEntityType) {
AtlasEntityType parentEntityType = (AtlasEntityType) parentType;
AtlasStructType.AtlasAttribute attribute = parentEntityType.getAttribute(labelWithoutPrefix);

if (attribute == null) {
attribute = parentEntityType.getRelationshipAttribute(labelWithoutPrefix, AtlasGraphUtilsV2.getTypeName(edge));
}

if (attribute != null && attribute.getInverseRefAttribute() != null) {
deleteEdgeBetweenVertices(edge.getInVertex(), edge.getOutVertex(), attribute.getInverseRefAttribute());
if (attribute != null && attribute.getInverseRefAttribute() != null) {
deleteEdgeBetweenVertices(edge.getInVertex(), edge.getOutVertex(), attribute.getInverseRefAttribute());
}
}
}
}

if (isClassificationEdge(edge)) {
AtlasVertex classificationVertex = edge.getInVertex();
if (isClassificationEdge(edge)) {
AtlasVertex classificationVertex = edge.getInVertex();

AtlasGraphUtilsV2.setEncodedProperty(classificationVertex, CLASSIFICATION_ENTITY_STATUS,
RequestContext.get().getDeleteType() == DeleteType.HARD ? PURGED.name() : DELETED.name());
}
AtlasGraphUtilsV2.setEncodedProperty(classificationVertex, CLASSIFICATION_ENTITY_STATUS,
RequestContext.get().getDeleteType() == DeleteType.HARD ? PURGED.name() : DELETED.name());
}

deleteEdge(edge, force);
deleteEdge(edge, force);
RequestContext.get().endMetricRecord(metrics);
} catch (AtlasBaseException e){
RequestContext.get().endMetricRecord(metrics);
throw e;
}
}

protected void deleteTypeVertex(AtlasVertex instanceVertex, TypeCategory typeCategory, boolean force) throws AtlasBaseException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,7 @@ public AtlasObjectId toAtlasObjectIdWithoutGuid(AtlasEntity entity) {
}

public AtlasClassification toAtlasClassification(AtlasVertex classificationVertex) throws AtlasBaseException {
AtlasPerfMetrics.MetricRecorder metrics = RequestContext.get().startMetricRecord("toAtlasClassification");
AtlasClassification ret = null;
String classificationName = getTypeName(classificationVertex);

Expand All @@ -391,7 +392,7 @@ public AtlasClassification toAtlasClassification(AtlasVertex classificationVerte

mapAttributes(classificationVertex, ret, null);
}

RequestContext.get().endMetricRecord(metrics);
return ret;
}

Expand Down

0 comments on commit 17d8ea5

Please sign in to comment.