Package org.apache.druid.query
Class DefaultQueryMetrics<QueryType extends Query<?>>
- java.lang.Object
-
- org.apache.druid.query.DefaultQueryMetrics<QueryType>
-
- All Implemented Interfaces:
QueryMetrics<QueryType>
- Direct Known Subclasses:
DefaultGroupByQueryMetrics
,DefaultTimeseriesQueryMetrics
,DefaultTopNQueryMetrics
public class DefaultQueryMetrics<QueryType extends Query<?>> extends Object implements QueryMetrics<QueryType>
DefaultQueryMetrics is unsafe for use from multiple threads. It fails with RuntimeException on access not from the thread where it was constructed. To "transfer" DefaultQueryMetrics from one thread to anotherownerThread
field should be updated.
-
-
Field Summary
Fields Modifier and Type Field Description protected ServiceMetricEvent.Builder
builder
protected Map<String,Number>
metrics
protected Thread
ownerThread
Non final to give subclasses ability to reassign it.
-
Constructor Summary
Constructors Constructor Description DefaultQueryMetrics()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
checkModifiedFromOwnerThread()
void
context(QueryType query)
SetsQuery.getContext()
of the given query as dimension.void
dataSource(QueryType query)
SetsQuery.getDataSource()
of the given query as dimension.void
duration(QueryType query)
SetsQuery.getDuration()
of the given query as dimension.void
emit(ServiceEmitter emitter)
Emits all metrics, registered since the lastemit()
call on this QueryMetrics object.void
hasFilters(QueryType query)
SetsQuery.hasFilters()
of the given query as dimension.void
identity(String identity)
Sets identity of the requester for a query.void
interval(QueryType query)
SetsQuery.getIntervals()
of the given query as dimension.BitmapResultFactory<?>
makeBitmapResultFactory(BitmapFactory factory)
Creates aBitmapResultFactory
which may record some information along bitmap construction fromQueryMetrics.preFilters(List)
.void
parallelMergeParallelism(int parallelism)
Sets broker merge parallelism, if parallel merges are enabled.void
postFilters(List<Filter> postFilters)
void
preFilters(List<Filter> preFilters)
void
query(QueryType query)
Pulls all information from the query object into dimensions of future metrics.void
queryId(String queryId)
Sets id of the given query as dimension.void
queryId(QueryType query)
SetsQuery.getId()
of the given query as dimension.void
queryType(QueryType query)
SetsQuery.getType()
of the given query as dimension.void
remoteAddress(String remoteAddress)
QueryMetrics<QueryType>
reportBackPressureTime(long timeNs)
Registers "time that channel is unreadable (backpressure)" metric.QueryMetrics<QueryType>
reportBitmapConstructionTime(long timeNs)
Reports the time spent constructing bitmap fromQueryMetrics.preFilters(List)
of the query.QueryMetrics<QueryType>
reportCpuTime(long timeNs)
Registers "cpu time" metric.protected QueryMetrics<QueryType>
reportMetric(String metricName, Number value)
QueryMetrics<QueryType>
reportNodeBytes(long byteCount)
Registers "node bytes" metric.QueryMetrics<QueryType>
reportNodeTime(long timeNs)
Registers "node time" metric.QueryMetrics<QueryType>
reportNodeTimeToFirstByte(long timeNs)
Registers "time to first byte" metric.QueryMetrics<QueryType>
reportParallelMergeFastestPartitionTime(long timeNs)
Reports broker "wall" time in nanoseconds for the fastest parallel merge sequence partition to be 'initialized', where 'initialized' is time to the first result batch is populated from data servers and merging can begin.QueryMetrics<QueryType>
reportParallelMergeInputRows(long numRows)
Reports total number of input rows processed by the broker during parallel merge.QueryMetrics<QueryType>
reportParallelMergeInputSequences(long numSequences)
Reports total number of input sequences processed by the broker during parallel merge.QueryMetrics<QueryType>
reportParallelMergeOutputRows(long numRows)
Reports broker total number of output rows after merging and combining input sequences (should be less than or equal to the value supplied toQueryMetrics.reportParallelMergeInputRows(long)
.QueryMetrics<QueryType>
reportParallelMergeParallelism(int parallelism)
Reports number of parallel tasks the broker used to process the query during parallel merge.QueryMetrics<QueryType>
reportParallelMergeSlowestPartitionTime(long timeNs)
Reports broker "wall" time in nanoseconds for the slowest parallel merge sequence partition to be 'initialized', where 'initialized' is time to the first result batch is populated from data servers and merging can begin.QueryMetrics<QueryType>
reportParallelMergeTaskCount(long numTasks)
Reports broker total number of fork join pool tasks required to complete queryQueryMetrics<QueryType>
reportParallelMergeTotalCpuTime(long timeNs)
Reports broker total CPU time in nanoseconds where fork join merge combine tasks were doing workQueryMetrics<QueryType>
reportParallelMergeTotalTime(long timeNs)
Reports broker total "wall" time in nanoseconds from parallel merge start sequence creation to total consumption.QueryMetrics<QueryType>
reportPreFilteredRows(long numRows)
Reports the number of rows to scan in the segment after applyingQueryMetrics.preFilters(List)
.QueryMetrics<QueryType>
reportQueriedSegmentCount(long segmentCount)
Registers "segments queried count" metric.QueryMetrics<QueryType>
reportQueryBytes(long byteCount)
Registers "query bytes" metric.QueryMetrics<QueryType>
reportQueryTime(long timeNs)
Registers "query time" metric.QueryMetrics<QueryType>
reportSegmentAndCacheTime(long timeNs)
Registers "segmentAndCache time" metric.QueryMetrics<QueryType>
reportSegmentRows(long numRows)
Reports the total number of rows in the processed segment.QueryMetrics<QueryType>
reportSegmentTime(long timeNs)
Registers "segment time" metric.QueryMetrics<QueryType>
reportWaitTime(long timeNs)
Registers "wait time" metric.void
segment(String segmentIdentifier)
void
server(String host)
protected void
setDimension(String dimension, Object value)
void
sqlQueryId(String sqlQueryId)
Sets sqlQueryId as a dimensionvoid
sqlQueryId(QueryType query)
SetsQuery.getSqlQueryId()
of the given query as dimensionvoid
status(String status)
void
subQueryId(QueryType query)
SetsQuery.getSubQueryId()
of the given query as dimension.void
success(boolean success)
void
vectorized(boolean vectorized)
Sets whether or not a segment scan has been vectorized.
-
-
-
Field Detail
-
builder
protected final ServiceMetricEvent.Builder builder
-
ownerThread
protected Thread ownerThread
Non final to give subclasses ability to reassign it.
-
-
Method Detail
-
checkModifiedFromOwnerThread
protected void checkModifiedFromOwnerThread()
-
query
public void query(QueryType query)
Description copied from interface:QueryMetrics
Pulls all information from the query object into dimensions of future metrics.- Specified by:
query
in interfaceQueryMetrics<QueryType extends Query<?>>
-
dataSource
public void dataSource(QueryType query)
Description copied from interface:QueryMetrics
SetsQuery.getDataSource()
of the given query as dimension.- Specified by:
dataSource
in interfaceQueryMetrics<QueryType extends Query<?>>
-
queryType
public void queryType(QueryType query)
Description copied from interface:QueryMetrics
SetsQuery.getType()
of the given query as dimension.- Specified by:
queryType
in interfaceQueryMetrics<QueryType extends Query<?>>
-
interval
public void interval(QueryType query)
Description copied from interface:QueryMetrics
SetsQuery.getIntervals()
of the given query as dimension.- Specified by:
interval
in interfaceQueryMetrics<QueryType extends Query<?>>
-
hasFilters
public void hasFilters(QueryType query)
Description copied from interface:QueryMetrics
SetsQuery.hasFilters()
of the given query as dimension.- Specified by:
hasFilters
in interfaceQueryMetrics<QueryType extends Query<?>>
-
duration
public void duration(QueryType query)
Description copied from interface:QueryMetrics
SetsQuery.getDuration()
of the given query as dimension.- Specified by:
duration
in interfaceQueryMetrics<QueryType extends Query<?>>
-
queryId
public void queryId(QueryType query)
Description copied from interface:QueryMetrics
SetsQuery.getId()
of the given query as dimension.- Specified by:
queryId
in interfaceQueryMetrics<QueryType extends Query<?>>
-
queryId
public void queryId(String queryId)
Description copied from interface:QueryMetrics
Sets id of the given query as dimension.- Specified by:
queryId
in interfaceQueryMetrics<QueryType extends Query<?>>
-
subQueryId
public void subQueryId(QueryType query)
Description copied from interface:QueryMetrics
SetsQuery.getSubQueryId()
of the given query as dimension.- Specified by:
subQueryId
in interfaceQueryMetrics<QueryType extends Query<?>>
-
sqlQueryId
public void sqlQueryId(QueryType query)
Description copied from interface:QueryMetrics
SetsQuery.getSqlQueryId()
of the given query as dimension- Specified by:
sqlQueryId
in interfaceQueryMetrics<QueryType extends Query<?>>
-
sqlQueryId
public void sqlQueryId(String sqlQueryId)
Description copied from interface:QueryMetrics
Sets sqlQueryId as a dimension- Specified by:
sqlQueryId
in interfaceQueryMetrics<QueryType extends Query<?>>
-
context
public void context(QueryType query)
Description copied from interface:QueryMetrics
SetsQuery.getContext()
of the given query as dimension.- Specified by:
context
in interfaceQueryMetrics<QueryType extends Query<?>>
-
server
public void server(String host)
- Specified by:
server
in interfaceQueryMetrics<QueryType extends Query<?>>
-
remoteAddress
public void remoteAddress(String remoteAddress)
- Specified by:
remoteAddress
in interfaceQueryMetrics<QueryType extends Query<?>>
-
status
public void status(String status)
- Specified by:
status
in interfaceQueryMetrics<QueryType extends Query<?>>
-
success
public void success(boolean success)
- Specified by:
success
in interfaceQueryMetrics<QueryType extends Query<?>>
-
segment
public void segment(String segmentIdentifier)
- Specified by:
segment
in interfaceQueryMetrics<QueryType extends Query<?>>
-
preFilters
public void preFilters(List<Filter> preFilters)
- Specified by:
preFilters
in interfaceQueryMetrics<QueryType extends Query<?>>
-
postFilters
public void postFilters(List<Filter> postFilters)
- Specified by:
postFilters
in interfaceQueryMetrics<QueryType extends Query<?>>
-
identity
public void identity(String identity)
Description copied from interface:QueryMetrics
Sets identity of the requester for a query. SeeAuthenticationResult
.- Specified by:
identity
in interfaceQueryMetrics<QueryType extends Query<?>>
-
vectorized
public void vectorized(boolean vectorized)
Description copied from interface:QueryMetrics
Sets whether or not a segment scan has been vectorized. Generally expected to only be attached to segment-level metrics, since at whole-query level we might have a mix of vectorized and non-vectorized segment scans.- Specified by:
vectorized
in interfaceQueryMetrics<QueryType extends Query<?>>
-
parallelMergeParallelism
public void parallelMergeParallelism(int parallelism)
Description copied from interface:QueryMetrics
Sets broker merge parallelism, if parallel merges are enabled. This will only appear in broker level metrics. This value is identical to theQueryMetrics.reportParallelMergeParallelism(int)
metric value, but optionally also available as a dimension.- Specified by:
parallelMergeParallelism
in interfaceQueryMetrics<QueryType extends Query<?>>
-
makeBitmapResultFactory
public BitmapResultFactory<?> makeBitmapResultFactory(BitmapFactory factory)
Description copied from interface:QueryMetrics
Creates aBitmapResultFactory
which may record some information along bitmap construction fromQueryMetrics.preFilters(List)
. The returned BitmapResultFactory may add some dimensions to this QueryMetrics from it'sBitmapResultFactory.toImmutableBitmap(Object)
method. SeeBitmapResultFactory
Javadoc for more information.- Specified by:
makeBitmapResultFactory
in interfaceQueryMetrics<QueryType extends Query<?>>
-
reportQueryTime
public QueryMetrics<QueryType> reportQueryTime(long timeNs)
Description copied from interface:QueryMetrics
Registers "query time" metric. Measures the time between a Jetty thread starting to handle a query, and the response being fully written to the response output stream. Does not include time spent waiting in a queue before the query runs.- Specified by:
reportQueryTime
in interfaceQueryMetrics<QueryType extends Query<?>>
-
reportQueryBytes
public QueryMetrics<QueryType> reportQueryBytes(long byteCount)
Description copied from interface:QueryMetrics
Registers "query bytes" metric. Measures the total number of bytes written by the query server thread to the response output stream. Emitted once per query.- Specified by:
reportQueryBytes
in interfaceQueryMetrics<QueryType extends Query<?>>
-
reportWaitTime
public QueryMetrics<QueryType> reportWaitTime(long timeNs)
Description copied from interface:QueryMetrics
Registers "wait time" metric. Measures the total time segment-processing runnables spent waiting for execution in the processing thread pool. Emitted once per segment.- Specified by:
reportWaitTime
in interfaceQueryMetrics<QueryType extends Query<?>>
-
reportSegmentTime
public QueryMetrics<QueryType> reportSegmentTime(long timeNs)
Description copied from interface:QueryMetrics
Registers "segment time" metric. Measures the total wall-clock time spent operating on segments in processing threads. Emitted once per segment.- Specified by:
reportSegmentTime
in interfaceQueryMetrics<QueryType extends Query<?>>
-
reportSegmentAndCacheTime
public QueryMetrics<QueryType> reportSegmentAndCacheTime(long timeNs)
Description copied from interface:QueryMetrics
Registers "segmentAndCache time" metric. Measures the total wall-clock time spent in processing threads, either operating on segments or retrieving items from cache. Emitted once per segment.- Specified by:
reportSegmentAndCacheTime
in interfaceQueryMetrics<QueryType extends Query<?>>
-
reportCpuTime
public QueryMetrics<QueryType> reportCpuTime(long timeNs)
Description copied from interface:QueryMetrics
Registers "cpu time" metric.- Specified by:
reportCpuTime
in interfaceQueryMetrics<QueryType extends Query<?>>
-
reportNodeTimeToFirstByte
public QueryMetrics<QueryType> reportNodeTimeToFirstByte(long timeNs)
Description copied from interface:QueryMetrics
Registers "time to first byte" metric.- Specified by:
reportNodeTimeToFirstByte
in interfaceQueryMetrics<QueryType extends Query<?>>
-
reportBackPressureTime
public QueryMetrics<QueryType> reportBackPressureTime(long timeNs)
Description copied from interface:QueryMetrics
Registers "time that channel is unreadable (backpressure)" metric.- Specified by:
reportBackPressureTime
in interfaceQueryMetrics<QueryType extends Query<?>>
-
reportNodeTime
public QueryMetrics<QueryType> reportNodeTime(long timeNs)
Description copied from interface:QueryMetrics
Registers "node time" metric.- Specified by:
reportNodeTime
in interfaceQueryMetrics<QueryType extends Query<?>>
-
reportNodeBytes
public QueryMetrics<QueryType> reportNodeBytes(long byteCount)
Description copied from interface:QueryMetrics
Registers "node bytes" metric.- Specified by:
reportNodeBytes
in interfaceQueryMetrics<QueryType extends Query<?>>
-
reportBitmapConstructionTime
public QueryMetrics<QueryType> reportBitmapConstructionTime(long timeNs)
Description copied from interface:QueryMetrics
Reports the time spent constructing bitmap fromQueryMetrics.preFilters(List)
of the query. Not reported, if there are no preFilters.- Specified by:
reportBitmapConstructionTime
in interfaceQueryMetrics<QueryType extends Query<?>>
-
reportSegmentRows
public QueryMetrics<QueryType> reportSegmentRows(long numRows)
Description copied from interface:QueryMetrics
Reports the total number of rows in the processed segment.- Specified by:
reportSegmentRows
in interfaceQueryMetrics<QueryType extends Query<?>>
-
reportPreFilteredRows
public QueryMetrics<QueryType> reportPreFilteredRows(long numRows)
Description copied from interface:QueryMetrics
Reports the number of rows to scan in the segment after applyingQueryMetrics.preFilters(List)
. If the are no preFilters, this metric is equal toQueryMetrics.reportSegmentRows(long)
.- Specified by:
reportPreFilteredRows
in interfaceQueryMetrics<QueryType extends Query<?>>
-
reportParallelMergeParallelism
public QueryMetrics<QueryType> reportParallelMergeParallelism(int parallelism)
Description copied from interface:QueryMetrics
Reports number of parallel tasks the broker used to process the query during parallel merge. This value is identical to theQueryMetrics.parallelMergeParallelism(int)
dimension value, but optionally also available as a metric.- Specified by:
reportParallelMergeParallelism
in interfaceQueryMetrics<QueryType extends Query<?>>
-
reportParallelMergeInputSequences
public QueryMetrics<QueryType> reportParallelMergeInputSequences(long numSequences)
Description copied from interface:QueryMetrics
Reports total number of input sequences processed by the broker during parallel merge.- Specified by:
reportParallelMergeInputSequences
in interfaceQueryMetrics<QueryType extends Query<?>>
-
reportParallelMergeInputRows
public QueryMetrics<QueryType> reportParallelMergeInputRows(long numRows)
Description copied from interface:QueryMetrics
Reports total number of input rows processed by the broker during parallel merge.- Specified by:
reportParallelMergeInputRows
in interfaceQueryMetrics<QueryType extends Query<?>>
-
reportParallelMergeOutputRows
public QueryMetrics<QueryType> reportParallelMergeOutputRows(long numRows)
Description copied from interface:QueryMetrics
Reports broker total number of output rows after merging and combining input sequences (should be less than or equal to the value supplied toQueryMetrics.reportParallelMergeInputRows(long)
.- Specified by:
reportParallelMergeOutputRows
in interfaceQueryMetrics<QueryType extends Query<?>>
-
reportParallelMergeTaskCount
public QueryMetrics<QueryType> reportParallelMergeTaskCount(long numTasks)
Description copied from interface:QueryMetrics
Reports broker total number of fork join pool tasks required to complete query- Specified by:
reportParallelMergeTaskCount
in interfaceQueryMetrics<QueryType extends Query<?>>
-
reportParallelMergeTotalCpuTime
public QueryMetrics<QueryType> reportParallelMergeTotalCpuTime(long timeNs)
Description copied from interface:QueryMetrics
Reports broker total CPU time in nanoseconds where fork join merge combine tasks were doing work- Specified by:
reportParallelMergeTotalCpuTime
in interfaceQueryMetrics<QueryType extends Query<?>>
-
reportParallelMergeTotalTime
public QueryMetrics<QueryType> reportParallelMergeTotalTime(long timeNs)
Description copied from interface:QueryMetrics
Reports broker total "wall" time in nanoseconds from parallel merge start sequence creation to total consumption.- Specified by:
reportParallelMergeTotalTime
in interfaceQueryMetrics<QueryType extends Query<?>>
-
reportParallelMergeFastestPartitionTime
public QueryMetrics<QueryType> reportParallelMergeFastestPartitionTime(long timeNs)
Description copied from interface:QueryMetrics
Reports broker "wall" time in nanoseconds for the fastest parallel merge sequence partition to be 'initialized', where 'initialized' is time to the first result batch is populated from data servers and merging can begin. Similar to query 'time to first byte' metrics, except is a composite of the whole group of data servers which are present in the merge partition, which all must supply an initial result batch before merging can actually begin.- Specified by:
reportParallelMergeFastestPartitionTime
in interfaceQueryMetrics<QueryType extends Query<?>>
-
reportParallelMergeSlowestPartitionTime
public QueryMetrics<QueryType> reportParallelMergeSlowestPartitionTime(long timeNs)
Description copied from interface:QueryMetrics
Reports broker "wall" time in nanoseconds for the slowest parallel merge sequence partition to be 'initialized', where 'initialized' is time to the first result batch is populated from data servers and merging can begin. Similar to query 'time to first byte' metrics, except is a composite of the whole group of data servers which are present in the merge partition, which all must supply an initial result batch before merging can actually begin.- Specified by:
reportParallelMergeSlowestPartitionTime
in interfaceQueryMetrics<QueryType extends Query<?>>
-
reportQueriedSegmentCount
public QueryMetrics<QueryType> reportQueriedSegmentCount(long segmentCount)
Description copied from interface:QueryMetrics
Registers "segments queried count" metric.- Specified by:
reportQueriedSegmentCount
in interfaceQueryMetrics<QueryType extends Query<?>>
-
emit
public void emit(ServiceEmitter emitter)
Description copied from interface:QueryMetrics
Emits all metrics, registered since the lastemit()
call on this QueryMetrics object.- Specified by:
emit
in interfaceQueryMetrics<QueryType extends Query<?>>
-
reportMetric
protected QueryMetrics<QueryType> reportMetric(String metricName, Number value)
-
-