Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync beta with master #3770

Merged
merged 4 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 = StringUtils.isEmpty(this.clientOrigin) ? "other" :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 @@ -60,6 +60,7 @@ public class AuditFilter implements Filter {
private static final Logger AUDIT_LOG = LoggerFactory.getLogger("AUDIT");
public static final String TRACE_ID = "trace_id";
public static final String X_ATLAN_REQUEST_ID = "X-Atlan-Request-Id";
public static final String X_ATLAN_CLIENT_ORIGIN = "X-Atlan-Client-Origin";
private boolean deleteTypeOverrideEnabled = false;
private boolean createShellEntityForNonExistingReference = false;

Expand Down Expand Up @@ -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
Loading