You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@atlas.apache.org by sa...@apache.org on 2019/09/16 21:49:51 UTC
[atlas] branch branch-2.0 updated: ATLAS-3412: Update atlas metrics
API to show shell entity count
This is an automated email from the ASF dual-hosted git repository.
sarath pushed a commit to branch branch-2.0
in repository https://gitbox.apache.org/repos/asf/atlas.git
The following commit(s) were added to refs/heads/branch-2.0 by this push:
new 5057f90 ATLAS-3412: Update atlas metrics API to show shell entity count
5057f90 is described below
commit 5057f908ef91cb48558542ac2a80fb87030a12de
Author: Sarath Subramanian <sa...@apache.org>
AuthorDate: Mon Sep 16 09:54:34 2019 -0700
ATLAS-3412: Update atlas metrics API to show shell entity count
(cherry picked from commit 660b91af5854ea09582a56662e0361f5af6ab759)
---
.../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();