diff --git a/processing/src/main/java/io/druid/query/MetricsEmittingQueryRunner.java b/processing/src/main/java/io/druid/query/MetricsEmittingQueryRunner.java index dbad443cb36..0d1d39910fb 100644 --- a/processing/src/main/java/io/druid/query/MetricsEmittingQueryRunner.java +++ b/processing/src/main/java/io/druid/query/MetricsEmittingQueryRunner.java @@ -33,10 +33,13 @@ import java.io.IOException; */ public class MetricsEmittingQueryRunner implements QueryRunner { + private static final String DEFAULT_METRIC_NAME = "query/time"; + private final ServiceEmitter emitter; private final Function, ServiceMetricEvent.Builder> builderFn; private final QueryRunner queryRunner; private final long creationTime; + private final String metricName; public MetricsEmittingQueryRunner( ServiceEmitter emitter, @@ -44,25 +47,38 @@ public class MetricsEmittingQueryRunner implements QueryRunner QueryRunner queryRunner ) { - this(emitter, builderFn, queryRunner, -1); + this(emitter, builderFn, queryRunner, DEFAULT_METRIC_NAME); } public MetricsEmittingQueryRunner( ServiceEmitter emitter, Function, ServiceMetricEvent.Builder> builderFn, QueryRunner queryRunner, - long creationTime + long creationTime, + String metricName ) { this.emitter = emitter; this.builderFn = builderFn; this.queryRunner = queryRunner; this.creationTime = creationTime; + this.metricName = metricName; } + public MetricsEmittingQueryRunner( + ServiceEmitter emitter, + Function, ServiceMetricEvent.Builder> builderFn, + QueryRunner queryRunner, + String metricName + ) + { + this(emitter, builderFn, queryRunner, -1, metricName); + } + + public MetricsEmittingQueryRunner withWaitMeasuredFromNow() { - return new MetricsEmittingQueryRunner(emitter, builderFn, queryRunner, System.currentTimeMillis()); + return new MetricsEmittingQueryRunner(emitter, builderFn, queryRunner, System.currentTimeMillis(), metricName); } @Override @@ -97,9 +113,9 @@ public class MetricsEmittingQueryRunner implements QueryRunner finally { long timeTaken = System.currentTimeMillis() - startTime; - emitter.emit(builder.build("query/time", timeTaken)); + emitter.emit(builder.build(metricName, timeTaken)); - if(creationTime > 0) { + if (creationTime > 0) { emitter.emit(builder.build("query/wait", startTime - creationTime)); } } @@ -173,12 +189,13 @@ public class MetricsEmittingQueryRunner implements QueryRunner } long timeTaken = System.currentTimeMillis() - startTime; - emitter.emit(builder.build("query/time", timeTaken)); + emitter.emit(builder.build(metricName, timeTaken)); if (creationTime > 0) { emitter.emit(builder.build("query/wait", startTime - creationTime)); } - } finally { + } + finally { yielder.close(); } } diff --git a/server/src/main/java/io/druid/server/coordination/ServerManager.java b/server/src/main/java/io/druid/server/coordination/ServerManager.java index 8f545f492d2..e79e4a3a978 100644 --- a/server/src/main/java/io/druid/server/coordination/ServerManager.java +++ b/server/src/main/java/io/druid/server/coordination/ServerManager.java @@ -390,30 +390,42 @@ public class ServerManager implements QuerySegmentWalker { SpecificSegmentSpec segmentSpec = new SpecificSegmentSpec(segmentDescriptor); return new SpecificSegmentQueryRunner( - new BySegmentQueryRunner( - adapter.getIdentifier(), - adapter.getDataInterval().getStart(), - new CachingQueryRunner( + new MetricsEmittingQueryRunner( + emitter, + new Function, ServiceMetricEvent.Builder>() + { + @Override + public ServiceMetricEvent.Builder apply(@Nullable final Query input) + { + return toolChest.makeMetricBuilder(input); + } + }, + new BySegmentQueryRunner( adapter.getIdentifier(), - segmentDescriptor, - objectMapper, - cache, - toolChest, - new MetricsEmittingQueryRunner( - emitter, - new Function, ServiceMetricEvent.Builder>() - { - @Override - public ServiceMetricEvent.Builder apply(@Nullable final Query input) - { - return toolChest.makeMetricBuilder(input); - } - }, - new ReferenceCountingSegmentQueryRunner(factory, adapter) - ).withWaitMeasuredFromNow(), - cacheConfig + adapter.getDataInterval().getStart(), + new CachingQueryRunner( + adapter.getIdentifier(), + segmentDescriptor, + objectMapper, + cache, + toolChest, + new MetricsEmittingQueryRunner( + emitter, + new Function, ServiceMetricEvent.Builder>() + { + @Override + public ServiceMetricEvent.Builder apply(@Nullable final Query input) + { + return toolChest.makeMetricBuilder(input); + } + }, + new ReferenceCountingSegmentQueryRunner(factory, adapter), + "scan/time" + ).withWaitMeasuredFromNow(), + cacheConfig + ) ) - ), + ).withWaitMeasuredFromNow(), segmentSpec ); }