You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@atlas.apache.org by ma...@apache.org on 2019/02/20 21:43:30 UTC
[atlas] branch master updated: ATLAS-3052: removed caching of
metrics query results
This is an automated email from the ASF dual-hosted git repository.
madhan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/atlas.git
The following commit(s) were added to refs/heads/master by this push:
new ee99930 ATLAS-3052: removed caching of metrics query results
ee99930 is described below
commit ee99930f5203ac321a5da41b9e3ab63df98e2faf
Author: Nikhil Bonte <ni...@freestoneinfotech.com>
AuthorDate: Wed Feb 13 23:17:49 2019 -0800
ATLAS-3052: removed caching of metrics query results
Change-Id: Ifeabb13acb387781a72d00146d4acd4ea9a279d8
Signed-off-by: Madhan Neethiraj <ma...@apache.org>
---
.../org/apache/atlas/services/MetricsService.java | 133 +++++++++------------
.../apache/atlas/services/MetricsServiceTest.java | 2 +-
.../apache/atlas/web/resources/AdminResource.java | 4 +-
3 files changed, 57 insertions(+), 82 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 d74acfb..607b830 100644
--- a/repository/src/main/java/org/apache/atlas/services/MetricsService.java
+++ b/repository/src/main/java/org/apache/atlas/services/MetricsService.java
@@ -59,108 +59,95 @@ public class MetricsService {
protected static final String METRIC_TAG_COUNT = TAG + "Count";
protected static final String METRIC_ENTITIES_PER_TAG = TAG + "Entities";
- public static final String METRIC_QUERY_CACHE_TTL = "atlas.metric.query.cache.ttlInSecs";
- public static final String METRIC_QUERY_GREMLIN_TYPES_BATCH_SIZE = "atlas.metric.query.gremlin.typesBatchSize";
- public static final int DEFAULT_CACHE_TTL_IN_SECS = 900;
public static final String METRIC_COLLECTION_TIME = "collectionTime";
private final AtlasGraph atlasGraph;
private final AtlasTypeRegistry typeRegistry;
- private final int cacheTTLInSecs;
private final String indexSearchPrefix = AtlasGraphUtilsV2.getIndexSearchPrefix();
- private AtlasMetrics cachedMetrics = null;
- private long cacheExpirationTime = 0;
-
@Inject
- public MetricsService(final Configuration configuration, final AtlasGraph graph, final AtlasTypeRegistry typeRegistry) {
- this.atlasGraph = graph;
- this.cacheTTLInSecs = configuration != null ? configuration.getInt(METRIC_QUERY_CACHE_TTL, DEFAULT_CACHE_TTL_IN_SECS) : DEFAULT_CACHE_TTL_IN_SECS;
+ public MetricsService(final AtlasGraph graph, final AtlasTypeRegistry typeRegistry) {
+ this.atlasGraph = graph;
this.typeRegistry = typeRegistry;
}
@SuppressWarnings("unchecked")
- public AtlasMetrics getMetrics(boolean ignoreCache) {
- if (ignoreCache || !isCacheValid()) {
- AtlasMetrics metrics = new AtlasMetrics();
+ public AtlasMetrics getMetrics() {
+ AtlasMetrics metrics = new AtlasMetrics();
- metrics.addMetric(GENERAL, METRIC_TYPE_COUNT, getAllTypesCount());
- metrics.addMetric(GENERAL, METRIC_TAG_COUNT, getAllTagsCount());
+ metrics.addMetric(GENERAL, METRIC_TYPE_COUNT, getAllTypesCount());
+ metrics.addMetric(GENERAL, METRIC_TAG_COUNT, getAllTagsCount());
- Map<String, Long> activeCountMap = new HashMap<>();
- Map<String, Long> deletedCountMap = new HashMap<>();
+ Map<String, Long> activeCountMap = new HashMap<>();
+ Map<String, Long> deletedCountMap = new HashMap<>();
- // metrics for classifications
- Collection<String> classificationDefNames = typeRegistry.getAllClassificationDefNames();
+ // metrics for classifications
+ Collection<String> classificationDefNames = typeRegistry.getAllClassificationDefNames();
- if (classificationDefNames != null) {
- for (String classificationDefName : classificationDefNames) {
- activeCountMap.put(classificationDefName, getTypeCount(classificationDefName, ACTIVE));
- }
+ if (classificationDefNames != null) {
+ for (String classificationDefName : classificationDefNames) {
+ activeCountMap.put(classificationDefName, getTypeCount(classificationDefName, ACTIVE));
}
+ }
- // metrics for entities
- Collection<String> entityDefNames = typeRegistry.getAllEntityDefNames();
+ // metrics for entities
+ Collection<String> entityDefNames = typeRegistry.getAllEntityDefNames();
- if (entityDefNames != null) {
- for (String entityDefName : entityDefNames) {
- activeCountMap.put(entityDefName, getTypeCount(entityDefName, ACTIVE));
- deletedCountMap.put(entityDefName, getTypeCount(entityDefName, DELETED));
- }
+ if (entityDefNames != null) {
+ for (String entityDefName : entityDefNames) {
+ activeCountMap.put(entityDefName, getTypeCount(entityDefName, ACTIVE));
+ deletedCountMap.put(entityDefName, getTypeCount(entityDefName, DELETED));
}
+ }
- Map<String, Long> activeEntityCount = new HashMap<>();
- Map<String, Long> deletedEntityCount = new HashMap<>();
- long unusedTypeCount = 0;
- long totalEntities = 0;
+ Map<String, Long> activeEntityCount = new HashMap<>();
+ Map<String, Long> deletedEntityCount = new HashMap<>();
+ long unusedTypeCount = 0;
+ long totalEntities = 0;
- for (String entityDefName : typeRegistry.getAllEntityDefNames()) {
- Long activeCount = activeCountMap.get(entityDefName);
- Long deletedCount = deletedCountMap.get(entityDefName);
+ for (String entityDefName : typeRegistry.getAllEntityDefNames()) {
+ Long activeCount = activeCountMap.get(entityDefName);
+ Long deletedCount = deletedCountMap.get(entityDefName);
- if (activeCount > 0) {
- activeEntityCount.put(entityDefName, activeCount);
- totalEntities += activeCount.longValue();
- }
+ if (activeCount > 0) {
+ activeEntityCount.put(entityDefName, activeCount);
+ totalEntities += activeCount.longValue();
+ }
- if (deletedCount > 0) {
- deletedEntityCount.put(entityDefName, deletedCount);
- totalEntities += deletedCount.longValue();
- }
+ if (deletedCount > 0) {
+ deletedEntityCount.put(entityDefName, deletedCount);
+ totalEntities += deletedCount.longValue();
+ }
- if (activeCount == 0 && deletedCount == 0) {
- unusedTypeCount++;
- }
+ if (activeCount == 0 && deletedCount == 0) {
+ unusedTypeCount++;
}
+ }
- metrics.addMetric(GENERAL, METRIC_TYPE_UNUSED_COUNT, unusedTypeCount);
- metrics.addMetric(GENERAL, METRIC_ENTITY_COUNT, totalEntities);
- metrics.addMetric(ENTITY, METRIC_ENTITY_ACTIVE, activeEntityCount);
- metrics.addMetric(ENTITY, METRIC_ENTITY_DELETED, deletedEntityCount);
+ metrics.addMetric(GENERAL, METRIC_TYPE_UNUSED_COUNT, unusedTypeCount);
+ metrics.addMetric(GENERAL, METRIC_ENTITY_COUNT, totalEntities);
+ metrics.addMetric(ENTITY, METRIC_ENTITY_ACTIVE, activeEntityCount);
+ metrics.addMetric(ENTITY, METRIC_ENTITY_DELETED, deletedEntityCount);
- Map<String, Long> taggedEntityCount = new HashMap<>();
+ Map<String, Long> taggedEntityCount = new HashMap<>();
- for (String classificationName : typeRegistry.getAllClassificationDefNames()) {
- Long count = activeCountMap.get(classificationName);
+ for (String classificationName : typeRegistry.getAllClassificationDefNames()) {
+ Long count = activeCountMap.get(classificationName);
- if (count > 0) {
- taggedEntityCount.put(classificationName, count);
- }
+ if (count > 0) {
+ taggedEntityCount.put(classificationName, count);
}
+ }
- metrics.addMetric(TAG, METRIC_ENTITIES_PER_TAG, taggedEntityCount);
-
- // Miscellaneous metrics
- long collectionTime = System.currentTimeMillis();
+ metrics.addMetric(TAG, METRIC_ENTITIES_PER_TAG, taggedEntityCount);
- metrics.addMetric(GENERAL, METRIC_COLLECTION_TIME, collectionTime);
+ // Miscellaneous metrics
+ long collectionTime = System.currentTimeMillis();
- this.cachedMetrics = metrics;
- this.cacheExpirationTime = (collectionTime + cacheTTLInSecs * 1000);
- }
+ metrics.addMetric(GENERAL, METRIC_COLLECTION_TIME, collectionTime);
- return cachedMetrics;
+ return metrics;
}
private Long getTypeCount(String typeName, Status status) {
@@ -183,16 +170,4 @@ public class MetricsService {
return CollectionUtils.isNotEmpty(allTagNames) ? allTagNames.size() : 0;
}
-
- private boolean isCacheValid() {
- boolean valid = cachedMetrics != null && System.currentTimeMillis() < cacheExpirationTime;
-
- if (LOG.isDebugEnabled()) {
- LOG.debug("cachedMetrics: {}", cachedMetrics != null);
- LOG.debug("cacheExpirationTime: {}", cacheExpirationTime);
- LOG.debug("valid: {}", valid);
- }
-
- return valid;
- }
}
\ No newline at end of file
diff --git a/repository/src/test/java/org/apache/atlas/services/MetricsServiceTest.java b/repository/src/test/java/org/apache/atlas/services/MetricsServiceTest.java
index 2b8d837..78e5803 100644
--- a/repository/src/test/java/org/apache/atlas/services/MetricsServiceTest.java
+++ b/repository/src/test/java/org/apache/atlas/services/MetricsServiceTest.java
@@ -124,7 +124,7 @@ public class MetricsServiceTest {
@Test
public void testGetMetrics() {
- AtlasMetrics metrics = metricsService.getMetrics(true);
+ AtlasMetrics metrics = metricsService.getMetrics();
assertNotNull(metrics);
diff --git a/webapp/src/main/java/org/apache/atlas/web/resources/AdminResource.java b/webapp/src/main/java/org/apache/atlas/web/resources/AdminResource.java
index 9659a38..088aafc 100755
--- a/webapp/src/main/java/org/apache/atlas/web/resources/AdminResource.java
+++ b/webapp/src/main/java/org/apache/atlas/web/resources/AdminResource.java
@@ -319,12 +319,12 @@ public class AdminResource {
@GET
@Path("metrics")
@Produces(Servlets.JSON_MEDIA_TYPE)
- public AtlasMetrics getMetrics(@QueryParam("ignoreCache") boolean ignoreCache) {
+ public AtlasMetrics getMetrics() {
if (LOG.isDebugEnabled()) {
LOG.debug("==> AdminResource.getMetrics()");
}
- AtlasMetrics metrics = metricsService.getMetrics(ignoreCache);
+ AtlasMetrics metrics = metricsService.getMetrics();
if (LOG.isDebugEnabled()) {
LOG.debug("<== AdminResource.getMetrics()");