From 6d68b3422f9f9ac613658cd938f17f17ef6c346f Mon Sep 17 00:00:00 2001 From: Suman Das <59254445+sumandas0@users.noreply.github.com> Date: Wed, 7 Feb 2024 17:42:33 +0530 Subject: [PATCH 1/5] feat: bucket the requests for prom bucket --- .../metrics/MetricsRegistryServiceImpl.java | 17 ++++++++++++++++- .../apache/atlas/web/rest/DiscoveryREST.java | 11 ++++++++--- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/common/src/main/java/org/apache/atlas/service/metrics/MetricsRegistryServiceImpl.java b/common/src/main/java/org/apache/atlas/service/metrics/MetricsRegistryServiceImpl.java index 660f1b2160..7ffb4c90f4 100644 --- a/common/src/main/java/org/apache/atlas/service/metrics/MetricsRegistryServiceImpl.java +++ b/common/src/main/java/org/apache/atlas/service/metrics/MetricsRegistryServiceImpl.java @@ -15,6 +15,7 @@ import javax.inject.Inject; import java.io.IOException; import java.io.PrintWriter; +import java.time.Duration; import java.util.Arrays; import java.util.List; import java.util.Map; @@ -62,10 +63,24 @@ public void collect(String requestId, String requestUri, AtlasPerfMetrics metric return; } } + //Use this if you want to publish Histograms public void collect(String requestId, String requestUri, List applicationMetrics){ try { for(AtlasPerfMetrics.Metric metric : applicationMetrics){ - Timer.builder(APPLICATION_LEVEL_METRICS_SUMMARY).tags(convertToMicrometerTags(metric.getTags())).publishPercentiles(PERCENTILES) + Timer.builder(APPLICATION_LEVEL_METRICS_SUMMARY) + .serviceLevelObjectives( + Duration.ofMillis(500), + Duration.ofMillis(750), + Duration.ofMillis(1000), + Duration.ofMillis(1500), + Duration.ofSeconds(2), + Duration.ofSeconds(3), + Duration.ofSeconds(5), + Duration.ofSeconds(10), + Duration.ofSeconds(15) + ) + .publishPercentiles(PERCENTILES) + .tags(convertToMicrometerTags(metric.getTags())) .register(getMeterRegistry()).record(metric.getTotalTimeMSecs(), TimeUnit.MILLISECONDS); } } catch (Exception e) { diff --git a/webapp/src/main/java/org/apache/atlas/web/rest/DiscoveryREST.java b/webapp/src/main/java/org/apache/atlas/web/rest/DiscoveryREST.java index cc30e22612..84a804c868 100644 --- a/webapp/src/main/java/org/apache/atlas/web/rest/DiscoveryREST.java +++ b/webapp/src/main/java/org/apache/atlas/web/rest/DiscoveryREST.java @@ -66,6 +66,7 @@ import java.util.HashSet; import java.util.List; import java.util.Set; +import java.util.Arrays; import static org.apache.atlas.repository.Constants.QUALIFIED_NAME; import static org.apache.atlas.repository.Constants.REQUEST_HEADER_HOST; import static org.apache.atlas.repository.Constants.REQUEST_HEADER_USER_AGENT; @@ -92,6 +93,7 @@ public class DiscoveryREST { private final SearchLoggingManagement loggerManagement; private static final String INDEXSEARCH_TAG_NAME = "indexsearch"; + private static final Set TRACKING_UTM_TAGS = new HashSet<>(Arrays.asList("ui_main_list", "ui_popup_searchbar")); @Inject public DiscoveryREST(AtlasTypeRegistry typeRegistry, AtlasDiscoveryService discoveryService, @@ -427,11 +429,14 @@ public AtlasSearchResult indexSearch(@Context HttpServletRequest servletRequest, } throw abe; } finally { - if(parameters.getUtmTags() != null) { + if(CollectionUtils.isNotEmpty(parameters.getUtmTags())) { AtlasPerfMetrics.Metric indexsearchMetric = new AtlasPerfMetrics.Metric(INDEXSEARCH_TAG_NAME); - indexsearchMetric.addTag("utmTags", String.join(",", parameters.getUtmTags())); + for (String utmTag : parameters.getUtmTags()) { + if (TRACKING_UTM_TAGS.contains(utmTag)) { + indexsearchMetric.addTag("utmTag", utmTag); + } + } indexsearchMetric.addTag("name", INDEXSEARCH_TAG_NAME); - indexsearchMetric.addTag("querySize",parameters.getDsl().getOrDefault("size", 20).toString()); indexsearchMetric.setTotalTimeMSecs(System.currentTimeMillis() - startTime); RequestContext.get().addApplicationMetrics(indexsearchMetric); } From 2f3af93591779115e86dca03eddf6404ef148fc2 Mon Sep 17 00:00:00 2001 From: Suman Das <59254445+sumandas0@users.noreply.github.com> Date: Thu, 8 Feb 2024 13:01:43 +0530 Subject: [PATCH 2/5] fix: make tag consistent --- .../src/main/java/org/apache/atlas/web/rest/DiscoveryREST.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/webapp/src/main/java/org/apache/atlas/web/rest/DiscoveryREST.java b/webapp/src/main/java/org/apache/atlas/web/rest/DiscoveryREST.java index 84a804c868..f704ae5d00 100644 --- a/webapp/src/main/java/org/apache/atlas/web/rest/DiscoveryREST.java +++ b/webapp/src/main/java/org/apache/atlas/web/rest/DiscoveryREST.java @@ -431,9 +431,11 @@ public AtlasSearchResult indexSearch(@Context HttpServletRequest servletRequest, } finally { if(CollectionUtils.isNotEmpty(parameters.getUtmTags())) { AtlasPerfMetrics.Metric indexsearchMetric = new AtlasPerfMetrics.Metric(INDEXSEARCH_TAG_NAME); + indexsearchMetric.addTag("utmTag", "other"); for (String utmTag : parameters.getUtmTags()) { if (TRACKING_UTM_TAGS.contains(utmTag)) { indexsearchMetric.addTag("utmTag", utmTag); + break; } } indexsearchMetric.addTag("name", INDEXSEARCH_TAG_NAME); From 5c5787f200159cff365aaaf0363b39f3aac208af Mon Sep 17 00:00:00 2001 From: Suman Das <59254445+sumandas0@users.noreply.github.com> Date: Thu, 8 Feb 2024 16:20:47 +0530 Subject: [PATCH 3/5] fix: publish 70 histograms to avoid wrong approximation --- .../atlas/service/metrics/MetricsRegistry.java | 2 +- .../metrics/MetricsRegistryServiceImpl.java | 14 ++------------ .../main/java/org/apache/atlas/RequestContext.java | 2 +- 3 files changed, 4 insertions(+), 14 deletions(-) diff --git a/common/src/main/java/org/apache/atlas/service/metrics/MetricsRegistry.java b/common/src/main/java/org/apache/atlas/service/metrics/MetricsRegistry.java index a1b2d1e6eb..9fdf5b903e 100644 --- a/common/src/main/java/org/apache/atlas/service/metrics/MetricsRegistry.java +++ b/common/src/main/java/org/apache/atlas/service/metrics/MetricsRegistry.java @@ -10,7 +10,7 @@ public interface MetricsRegistry { void collect(String requestId, String requestUri, AtlasPerfMetrics metrics); - void collect(String requestId, String requestUri, List applicationMetrics); + void collectIndexsearch(String requestId, String requestUri, List applicationMetrics); void scrape(PrintWriter writer) throws IOException; diff --git a/common/src/main/java/org/apache/atlas/service/metrics/MetricsRegistryServiceImpl.java b/common/src/main/java/org/apache/atlas/service/metrics/MetricsRegistryServiceImpl.java index 7ffb4c90f4..5080e47135 100644 --- a/common/src/main/java/org/apache/atlas/service/metrics/MetricsRegistryServiceImpl.java +++ b/common/src/main/java/org/apache/atlas/service/metrics/MetricsRegistryServiceImpl.java @@ -64,21 +64,11 @@ public void collect(String requestId, String requestUri, AtlasPerfMetrics metric } } //Use this if you want to publish Histograms - public void collect(String requestId, String requestUri, List applicationMetrics){ + public void collectIndexsearch(String requestId, String requestUri, List applicationMetrics){ try { for(AtlasPerfMetrics.Metric metric : applicationMetrics){ Timer.builder(APPLICATION_LEVEL_METRICS_SUMMARY) - .serviceLevelObjectives( - Duration.ofMillis(500), - Duration.ofMillis(750), - Duration.ofMillis(1000), - Duration.ofMillis(1500), - Duration.ofSeconds(2), - Duration.ofSeconds(3), - Duration.ofSeconds(5), - Duration.ofSeconds(10), - Duration.ofSeconds(15) - ) + .publishPercentileHistogram() .publishPercentiles(PERCENTILES) .tags(convertToMicrometerTags(metric.getTags())) .register(getMeterRegistry()).record(metric.getTotalTimeMSecs(), TimeUnit.MILLISECONDS); diff --git a/server-api/src/main/java/org/apache/atlas/RequestContext.java b/server-api/src/main/java/org/apache/atlas/RequestContext.java index bcc4c0085b..1c7ccababb 100644 --- a/server-api/src/main/java/org/apache/atlas/RequestContext.java +++ b/server-api/src/main/java/org/apache/atlas/RequestContext.java @@ -175,7 +175,7 @@ public void clearCache() { } if (CollectionUtils.isNotEmpty(applicationMetrics)) { if (Objects.nonNull(this.metricsRegistry)){ - this.metricsRegistry.collect(traceId, this.requestUri, applicationMetrics); + this.metricsRegistry.collectIndexsearch(traceId, this.requestUri, applicationMetrics); } applicationMetrics.clear(); } From b30516167aab94ee29eb7ce6fabba59e4c3b508f Mon Sep 17 00:00:00 2001 From: Suman Das <59254445+sumandas0@users.noreply.github.com> Date: Thu, 8 Feb 2024 17:27:30 +0530 Subject: [PATCH 4/5] fix: revert back to SLOs --- .../metrics/MetricsRegistryServiceImpl.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/common/src/main/java/org/apache/atlas/service/metrics/MetricsRegistryServiceImpl.java b/common/src/main/java/org/apache/atlas/service/metrics/MetricsRegistryServiceImpl.java index 5080e47135..3a1ae2b08d 100644 --- a/common/src/main/java/org/apache/atlas/service/metrics/MetricsRegistryServiceImpl.java +++ b/common/src/main/java/org/apache/atlas/service/metrics/MetricsRegistryServiceImpl.java @@ -68,7 +68,20 @@ public void collectIndexsearch(String requestId, String requestUri, List Date: Thu, 8 Feb 2024 17:48:27 +0530 Subject: [PATCH 5/5] feat: add utm tags in the perf log --- .../java/org/apache/atlas/model/discovery/IndexSearchParams.java | 1 + 1 file changed, 1 insertion(+) diff --git a/intg/src/main/java/org/apache/atlas/model/discovery/IndexSearchParams.java b/intg/src/main/java/org/apache/atlas/model/discovery/IndexSearchParams.java index 84d9939242..384ac27360 100644 --- a/intg/src/main/java/org/apache/atlas/model/discovery/IndexSearchParams.java +++ b/intg/src/main/java/org/apache/atlas/model/discovery/IndexSearchParams.java @@ -78,6 +78,7 @@ public String toString() { ", persona='" + persona + '\'' + ", queryString='" + queryString + '\'' + ", allowDeletedRelations=" + allowDeletedRelations + + ", utmTags="+ getUtmTags() + '}'; } }