Skip to content

Commit

Permalink
Merge pull request #3760 from atlanhq/client-tag
Browse files Browse the repository at this point in the history
feat: add client origin tag in prometheus metrics
  • Loading branch information
sumandas0 authored Nov 18, 2024
2 parents 236228b + d20be85 commit 40a2b3c
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<AtlasPerfMetrics.Metric> applicationMetrics);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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;
Expand All @@ -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);
}
}
Expand Down
11 changes: 10 additions & 1 deletion server-api/src/main/java/org/apache/atlas/RequestContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ public class RequestContext {
private Set<String> userGroups;
private String clientIPAddress;
private List<String> forwardedAddresses;
private String clientOrigin;
private DeleteType deleteType = DeleteType.DEFAULT;
private boolean isPurgeRequested = false;
private int maxAttempts = 1;
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ public void doFilter(ServletRequest request, ServletResponse response, FilterCha
final Set<String> 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));
Expand All @@ -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));
Expand Down

0 comments on commit 40a2b3c

Please sign in to comment.