Skip to content

Commit

Permalink
CompositeQueryLogicTransformer must implement WritesQueryMetrics inte…
Browse files Browse the repository at this point in the history
…rface, gather stats from delegates (#2479)

* CompositeQueryLogicTransformer must implement WritesQueryMetrics interface, gather stats from delegates

* Code formatting

---------

Co-authored-by: hgklohr <[email protected]>
  • Loading branch information
billoley and hgklohr authored Aug 28, 2024
1 parent 19d54b5 commit 2222de6
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@
import datawave.core.query.cachedresults.CacheableLogic;
import datawave.core.query.logic.AbstractQueryLogicTransformer;
import datawave.core.query.logic.QueryLogicTransformer;
import datawave.core.query.logic.WritesQueryMetrics;
import datawave.microservice.querymetric.BaseQueryMetric;
import datawave.webservice.query.cachedresults.CacheableQueryRow;
import datawave.webservice.query.exception.QueryException;
import datawave.webservice.result.BaseQueryResponse;

public class CompositeQueryLogicTransformer<I,O> extends AbstractQueryLogicTransformer<I,O> implements CacheableLogic {
public class CompositeQueryLogicTransformer<I,O> extends AbstractQueryLogicTransformer<I,O> implements CacheableLogic, WritesQueryMetrics {

protected static final Logger log = Logger.getLogger(CompositeQueryLogicTransformer.class);

Expand Down Expand Up @@ -82,4 +84,103 @@ public BaseQueryResponse createResponse(List<Object> resultList) {
return null;
}

@Override
public boolean hasMetrics() {
for (QueryLogicTransformer d : delegates) {
if (d instanceof WritesQueryMetrics) {
if (((WritesQueryMetrics) d).hasMetrics()) {
return true;
}
}
}
return false;
}

@Override
public void writeQueryMetrics(BaseQueryMetric metric) {
// if any timing details have been returned, add metrics
if (hasMetrics()) {
metric.setSourceCount(getSourceCount());
metric.setNextCount(getNextCount());
metric.setSeekCount(getSeekCount());
metric.setYieldCount(getYieldCount());
metric.setDocRanges(getDocRanges());
metric.setFiRanges(getFiRanges());
}
}

@Override
public void resetMetrics() {
for (QueryLogicTransformer d : delegates) {
if (d instanceof WritesQueryMetrics) {
((WritesQueryMetrics) d).resetMetrics();
}
}
}

@Override
public long getFiRanges() {
long total = 0;
for (QueryLogicTransformer d : delegates) {
if (d instanceof WritesQueryMetrics) {
total += ((WritesQueryMetrics) d).getFiRanges();
}
}
return total;
}

@Override
public long getDocRanges() {
long total = 0;
for (QueryLogicTransformer d : delegates) {
if (d instanceof WritesQueryMetrics) {
total += ((WritesQueryMetrics) d).getDocRanges();
}
}
return total;
}

@Override
public long getSourceCount() {
long total = 0;
for (QueryLogicTransformer d : delegates) {
if (d instanceof WritesQueryMetrics) {
total += ((WritesQueryMetrics) d).getSourceCount();
}
}
return total;
}

@Override
public long getSeekCount() {
long total = 0;
for (QueryLogicTransformer d : delegates) {
if (d instanceof WritesQueryMetrics) {
total += ((WritesQueryMetrics) d).getSeekCount();
}
}
return total;
}

@Override
public long getNextCount() {
long total = 0;
for (QueryLogicTransformer d : delegates) {
if (d instanceof WritesQueryMetrics) {
total += ((WritesQueryMetrics) d).getNextCount();
}
}
return total;
}

@Override
public long getYieldCount() {
long total = 0;
for (QueryLogicTransformer d : delegates) {
if (d instanceof WritesQueryMetrics) {
total += ((WritesQueryMetrics) d).getYieldCount();
}
}
return total;
}
}
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@
<version.microservice.metadata-utils>4.0.6</version.microservice.metadata-utils>
<version.microservice.metrics-reporter>3.0.0</version.microservice.metrics-reporter>
<version.microservice.query-api>1.0.0</version.microservice.query-api>
<version.microservice.query-metric-api>4.0.0</version.microservice.query-metric-api>
<version.microservice.query-metric-api>4.0.7</version.microservice.query-metric-api>
<version.microservice.type-utils>3.0.2</version.microservice.type-utils>
<version.minlog>1.2</version.minlog>
<version.mockito>2.23.0</version.mockito>
Expand Down

0 comments on commit 2222de6

Please sign in to comment.