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 8974155487..60c1553f9c 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 @@ -8,7 +8,7 @@ public interface MetricsRegistry { - void collect(String requestId, String requestUri, AtlasPerfMetrics metrics); + void collect(String requestId, String requestUri, AtlasPerfMetrics metrics, String clientOrigin); void collectApplicationMetrics(String requestId, String requestUri, List applicationMetrics); 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 19171325e2..e11fc5725f 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 @@ -30,6 +30,7 @@ public class MetricsRegistryServiceImpl implements MetricsRegistry { private static final String NAME = "name"; private static final String URI = "uri"; + private static final String ORIGIN = "origin"; private static final String METHOD_DIST_SUMMARY = "method_dist_summary"; private static final String APPLICATION_LEVEL_METRICS_SUMMARY = "application_level_metrics_summary"; private static final double[] PERCENTILES = {0.99}; @@ -43,7 +44,7 @@ public MetricsRegistryServiceImpl() throws AtlasException { } @Override - public void collect(String requestId, String requestUri, AtlasPerfMetrics metrics) { + public void collect(String requestId, String requestUri, AtlasPerfMetrics metrics, String clientOrigin) { try { if (!ApplicationProperties.get().getBoolean(METHOD_LEVEL_METRICS_ENABLE, false)) { return; @@ -52,7 +53,7 @@ public void collect(String requestId, String requestUri, AtlasPerfMetrics metric for (String name : this.filteredMethods) { if(metrics.hasMetric(name)) { AtlasPerfMetrics.Metric metric = metrics.getMetric(name); - Timer.builder(METHOD_DIST_SUMMARY).tags(Tags.of(NAME, metric.getName(), URI, requestUri)).publishPercentiles(PERCENTILES) + Timer.builder(METHOD_DIST_SUMMARY).tags(Tags.of(NAME, metric.getName(), URI, requestUri, ORIGIN, clientOrigin)).publishPercentiles(PERCENTILES) .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 814a4cb450..a2dad1b68d 100644 --- a/server-api/src/main/java/org/apache/atlas/RequestContext.java +++ b/server-api/src/main/java/org/apache/atlas/RequestContext.java @@ -80,6 +80,7 @@ public class RequestContext { private Set userGroups; private String clientIPAddress; private List forwardedAddresses; + private String clientOrigin; private DeleteType deleteType = DeleteType.DEFAULT; private boolean isPurgeRequested = false; private int maxAttempts = 1; @@ -178,7 +179,7 @@ public void clearCache() { if (metrics != null && !metrics.isEmpty()) { METRICS.debug(metrics.toString()); if (Objects.nonNull(this.metricsRegistry)){ - this.metricsRegistry.collect(traceId, this.requestUri, metrics); + this.metricsRegistry.collect(traceId, this.requestUri, metrics, this.getClientOrigin()); } metrics.clear(); } @@ -744,6 +745,14 @@ public void setIncludeClassificationNames(boolean includeClassificationNames) { this.includeClassificationNames = includeClassificationNames; } + public String getClientOrigin() { + return clientOrigin; + } + + public void setClientOrigin(String clientOrigin) { + this.clientOrigin = clientOrigin; + } + public class EntityGuidPair { private final Object entity; private final String guid; diff --git a/webapp/src/main/java/org/apache/atlas/web/filters/AuditFilter.java b/webapp/src/main/java/org/apache/atlas/web/filters/AuditFilter.java index d3cb21b94d..53a8213be9 100755 --- a/webapp/src/main/java/org/apache/atlas/web/filters/AuditFilter.java +++ b/webapp/src/main/java/org/apache/atlas/web/filters/AuditFilter.java @@ -90,6 +90,7 @@ public void doFilter(ServletRequest request, ServletResponse response, FilterCha final Set userGroups = AtlasAuthorizationUtils.getCurrentUserGroups(); final String deleteType = httpRequest.getParameter("deleteType"); final boolean skipFailedEntities = Boolean.parseBoolean(httpRequest.getParameter("skipFailedEntities")); + final String clientOrigin = httpRequest.getHeader("X-Atlan-Client-Origin"); try { currentThread.setName(formatName(oldName, internalRequestId)); @@ -103,6 +104,7 @@ public void doFilter(ServletRequest request, ServletResponse response, FilterCha requestContext.setCreateShellEntityForNonExistingReference(createShellEntityForNonExistingReference); requestContext.setForwardedAddresses(AtlasAuthorizationUtils.getForwardedAddressesFromRequest(httpRequest)); requestContext.setSkipFailedEntities(skipFailedEntities); + requestContext.setClientOrigin(httpRequest.getHeader("X-Atlan-Client-Origin")); requestContext.setMetricRegistry(metricsRegistry); MDC.put(TRACE_ID, internalRequestId); MDC.put(X_ATLAN_REQUEST_ID, ofNullable(httpRequest.getHeader(X_ATLAN_REQUEST_ID)).orElse(EMPTY));