From 660b91af5854ea09582a56662e0361f5af6ab759 Mon Sep 17 00:00:00 2001 From: Sarath Subramanian <sarath@apache.org> Date: Mon, 16 Sep 2019 09:54:34 -0700 Subject: [PATCH] ATLAS-3412: Update atlas metrics API to show shell entity count --- repository/src/main/java/org/apache/atlas/services/MetricsService.java | 41 +++++++++++++++++++++++++++++++++++------ 1 file changed, 35 insertions(+), 6 deletions(-) diff --git a/repository/src/main/java/org/apache/atlas/services/MetricsService.java b/repository/src/main/java/org/apache/atlas/services/MetricsService.java index 62e81e2..2a65b55 100644 --- a/repository/src/main/java/org/apache/atlas/services/MetricsService.java +++ b/repository/src/main/java/org/apache/atlas/services/MetricsService.java @@ -22,6 +22,8 @@ import org.apache.atlas.annotation.GraphTransaction; import org.apache.atlas.model.instance.AtlasEntity.Status; import org.apache.atlas.model.metrics.AtlasMetrics; import org.apache.atlas.repository.graphdb.AtlasGraph; +import org.apache.atlas.repository.graphdb.AtlasIndexQuery; +import org.apache.atlas.repository.graphdb.AtlasVertex; import org.apache.atlas.repository.store.graph.v2.AtlasGraphUtilsV2; import org.apache.atlas.type.AtlasTypeRegistry; import org.apache.atlas.util.AtlasMetricsUtil; @@ -30,16 +32,14 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import javax.inject.Inject; -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; +import java.util.*; import static org.apache.atlas.discovery.SearchProcessor.AND_STR; import static org.apache.atlas.model.instance.AtlasEntity.Status.ACTIVE; import static org.apache.atlas.model.instance.AtlasEntity.Status.DELETED; -import static org.apache.atlas.repository.Constants.ENTITY_TYPE_PROPERTY_KEY; -import static org.apache.atlas.repository.Constants.STATE_PROPERTY_KEY; -import static org.apache.atlas.repository.Constants.VERTEX_INDEX; +import static org.apache.atlas.repository.Constants.*; +import static org.apache.atlas.repository.graph.GraphHelper.getTypeName; +import static org.apache.atlas.repository.store.graph.v2.AtlasGraphUtilsV2.getIndexSearchPrefix; @AtlasService public class MetricsService { @@ -59,6 +59,7 @@ public class MetricsService { protected static final String METRIC_ENTITY_COUNT = ENTITY + "Count"; protected static final String METRIC_ENTITY_DELETED = ENTITY + "Deleted"; protected static final String METRIC_ENTITY_ACTIVE = ENTITY + "Active"; + protected static final String METRIC_ENTITY_SHELL = ENTITY + "Shell"; protected static final String METRIC_TAG_COUNT = TAG + "Count"; protected static final String METRIC_ENTITIES_PER_TAG = TAG + "Entities"; @@ -127,6 +128,7 @@ public class MetricsService { metrics.addMetric(ENTITY, METRIC_ENTITY_ACTIVE, activeEntityCount); metrics.addMetric(ENTITY, METRIC_ENTITY_DELETED, deletedEntityCount); + metrics.addMetric(ENTITY, METRIC_ENTITY_SHELL, getShellEntityCount()); metrics.addMetric(TAG, METRIC_ENTITIES_PER_TAG, taggedEntityCount); @@ -149,6 +151,33 @@ public class MetricsService { return ret == null ? 0L : ret; } + private Map<String, Long> getShellEntityCount() { + Map<String, Long> ret = new HashMap<>(); + String idxQueryString = getIndexSearchPrefix() + "\"" + IS_INCOMPLETE_PROPERTY_KEY + "\" : " + INCOMPLETE_ENTITY_VALUE.intValue(); + AtlasIndexQuery idxQuery = atlasGraph.indexQuery(VERTEX_INDEX, idxQueryString); + + try { + Iterator<AtlasIndexQuery.Result<Object, Object>> results = idxQuery.vertices(); + + while (results != null && results.hasNext()) { + AtlasVertex entityVertex = results.next().getVertex(); + String typeName = getTypeName(entityVertex); + + if (!ret.containsKey(typeName)) { + ret.put(typeName, 1L); + } else { + ret.put(typeName, ret.get(typeName) + 1); + } + } + } catch (Throwable t) { + LOG.warn("getShellEntityCount(): Returned empty result", t); + } finally { + atlasGraph.commit(); + } + + return ret; + } + private int getAllTypesCount() { Collection<String> allTypeNames = typeRegistry.getAllTypeNames(); -- libgit2 0.27.1