Skip to content

Commit

Permalink
ES latency
Browse files Browse the repository at this point in the history
  • Loading branch information
n5nk committed Oct 15, 2023
1 parent 37a5a46 commit 58ea82f
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 2 deletions.
1 change: 1 addition & 0 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ on:
- development
- master
- lineageondemand
- perfes

jobs:
build:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/trivy-docker-scan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ on:
- development
- master
- lineageondemand
- perfes


jobs:
Expand Down
16 changes: 14 additions & 2 deletions common/src/main/java/org/apache/atlas/utils/AtlasPerfMetrics.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ public MetricRecorder getMetricRecorder(String name) {
public void recordMetric(MetricRecorder recorder) {
if (recorder != null) {
final String name = recorder.name;
final long timeTaken = recorder.getElapsedTime();
final long elapsedTime = recorder.getElapsedTime();
final long timeTaken = recorder.getTimeTaken();

Metric metric = metrics.get(name);

Expand All @@ -45,7 +46,11 @@ public void recordMetric(MetricRecorder recorder) {
}

metric.invocations++;
metric.totalTimeMSecs += timeTaken;
if(timeTaken == -1){
metric.totalTimeMSecs += elapsedTime;
} else {
metric.totalTimeMSecs += timeTaken;
}
}
}

Expand Down Expand Up @@ -91,11 +96,18 @@ public String toString() {
public class MetricRecorder {
private final String name;
private final long startTimeMs = System.currentTimeMillis();
private long timeTaken = -1;

MetricRecorder(String name) {
this.name = name;
}

public void setTimeTaken(long timeTaken){
this.timeTaken = timeTaken;
}
long getTimeTaken(){
return this.timeTaken;
}
long getElapsedTime() {
return System.currentTimeMillis() - startTimeMs;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public class DirectIndexQueryResult<V, E> {
private Iterator<AtlasIndexQuery.Result<V, E>> iterator;
private Map<String, Aggregation> aggregationMap;
private Integer approximateCount;
private long responseTimeInMS;

public Iterator<AtlasIndexQuery.Result<V, E>> getIterator() {
return iterator;
Expand All @@ -33,4 +34,12 @@ public Integer getApproximateCount() {
public void setApproximateCount(Integer approximateCount) {
this.approximateCount = approximateCount;
}

public long getResponseTimeInMS() {
return this.responseTimeInMS;
}

public void setResponseTimeInMS(long responseTimeInMS) {
this.responseTimeInMS = responseTimeInMS;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ private DirectIndexQueryResult getResultFromResponse(String responseString) {
Map<String, LinkedHashMap> responseMap = AtlasType.fromJson(responseString, Map.class);

Map<String, LinkedHashMap> hits_0 = AtlasType.fromJson(AtlasType.toJson(responseMap.get("hits")), Map.class);
result.setResponseTimeInMS(Long.parseLong(String.valueOf(responseMap.get("took"))));
this.vertexTotals = (Integer) hits_0.get("total").get("value");

List<LinkedHashMap> hits_1 = AtlasType.fromJson(AtlasType.toJson(hits_0.get("hits")), List.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -999,6 +999,9 @@ public AtlasSearchResult directIndexSearch(SearchParams searchParams) throws Atl
AtlasPerfMetrics.MetricRecorder elasticSearchQueryMetric = RequestContext.get().startMetricRecord("elasticSearchQuery");
DirectIndexQueryResult indexQueryResult = indexQuery.vertices(searchParams);
RequestContext.get().endMetricRecord(elasticSearchQueryMetric);
AtlasPerfMetrics.MetricRecorder estimetaken = RequestContext.get().startMetricRecord("estimetaken");
estimetaken.setTimeTaken(indexQueryResult.getResponseTimeInMS());
RequestContext.get().endMetricRecord(estimetaken);
prepareSearchResult(ret, indexQueryResult, resultAttributes, true);

ret.setAggregations(indexQueryResult.getAggregationMap());
Expand Down

0 comments on commit 58ea82f

Please sign in to comment.