Repository navigation
Conversation
This patch improves consistency of query metrics across the native and MSQ engines in the following ways: 1) Emit context queryId as "queryId" in all query metrics. Previously, native metrics emitted this as "id"; MSQ metrics emitted it as "queryId"; and SQL metrics did not emit it at all. 2) Add "engine" to QueryMetrics and set it appropriately, so query metrics can optionally gain this dimension. Out-of-box, it is not included. 3) MSQ's query/time and query/cpu/time metrics are now emitted using QueryMetrics rather than ad hoc metric construction. This better aligns them with native query metrics. 4) Add MSQ query/load/* and query/segments/count metrics, matching the analogous native metrics.
FrankChen021
left a comment
There was a problem hiding this comment.
🟢 Approval recommended
No actionable issues found in the reviewed changes. The PR can merge from this review.
Reviewed 42 of 42 changed files.
This is an automated review by Codex GPT-5.6-Luna(max)
amaechler
left a comment
There was a problem hiding this comment.
Some comments from a local Claude review.
| DartSqlEngine.NAME, | ||
| new ServiceMetricEvent.Builder() | ||
| .setDimensionIfNotNull( | ||
| QueryContextParameters.DART_QUERY_ID.getName(), | ||
| context.get(QueryContextParameters.DART_QUERY_ID) | ||
| ) |
There was a problem hiding this comment.
sqlQueryId is dropped from query/time and query/cpu/time here: DefaultQueryMetrics#sqlQueryId is a no-op, and the extras only carry dartQueryId. Previously MSQMetricEventBuilder set it on every MSQ metric. makeMetricBuilder() already holds id, queryId, sqlQueryId, type, engine and dartQueryId, and ExtraDimensionsServiceEmitter only fills keys that are absent, so reusing it restores sqlQueryId and removes the throwaway builder:
| DartSqlEngine.NAME, | |
| new ServiceMetricEvent.Builder() | |
| .setDimensionIfNotNull( | |
| QueryContextParameters.DART_QUERY_ID.getName(), | |
| context.get(QueryContextParameters.DART_QUERY_ID) | |
| ) | |
| DartSqlEngine.NAME, | |
| makeMetricBuilder() |
One caveat: makeMetricBuilder() sets dartQueryId with setDimension, which throws on null, whereas this code uses setDimensionIfNotNull. DartSqlEngine always sets it, so I don't think it can be null here, but worth keeping in mind. Is dropping the top-level sqlQueryId intentional? If so, could it be documented? test_queryMetrics_metricsQuery in IndexerControllerContextTest sets sqlQueryId in the context, but its expected map does not include it.
There was a problem hiding this comment.
It was intentional to change sqlQueryId in this way for MSQ query/* metrics, because this aligns them better with native query/* metrics. Sites with custom QueryMetrics extensions that override sqlQueryId will still emit it, just like native metrics.
| queryMetrics, | ||
| toolbox.getEmitter(), | ||
| MSQTaskSqlEngine.NAME, | ||
| task.getMetricBuilder().getDimensions() |
There was a problem hiding this comment.
Same as the Dart controller: the task dimensions do not include sqlQueryId, so it is lost on query/time. makeMetricBuilder() is the task builder plus the query dimensions, so this restores it:
| task.getMetricBuilder().getDimensions() | |
| makeMetricBuilder().getDimensions() |
The worker contexts (IndexerWorkerContext#emitQueryMetrics, DartWorkerContext#emitQueryMetrics) have the same gap and need sqlQueryId from the query context added to their extra dimensions when non-null.
There was a problem hiding this comment.
I think this is the same point as #20947 (comment).
| final Query<?> metricsQuery; | ||
|
|
||
| if (querySpec instanceof LegacyMSQSpec) { | ||
| // Use the native query, so metrics have the same dimensions as they would for native execution. |
There was a problem hiding this comment.
Using the native query here changes the controller query/time event compared to workers and ingest/*: type becomes scan/groupBy (workers stay msq), interval and duration come from the outer native query instead of the union of stage table intervals, success is a string, and context is new. MSQControllerTask always holds a LegacyMSQSpec, so this covers every task-based controller. Dashboards filtering on type=msq will stop matching. I suspect interval is eternity for nested queries with the time filter in the inner query, but I did not run it. Could you document this (suggestion on metrics.md) and mention it in the release notes?
There was a problem hiding this comment.
This is intentional, the purpose is to align MSQ query/* metrics with native query metrics as much asa possible on the Broker (where the controller runs). I updated the docs to note it.
There was a problem hiding this comment.
Added a release note to the PR description too.
|
|
||
| Query metrics have these ID dimensions: | ||
|
|
||
| * `queryId`: the [`queryId`](../querying/query-context-reference.md) of the query. Use it to correlate metrics across services and query types. |
There was a problem hiding this comment.
Suggest documenting the MSQ dimension changes, after the "Native queries always have a queryId..." paragraph:
MSQ controller
query/timeuses the native query'stype,intervalanddurationwhen the query has one, andtype=msqotherwise. MSQ workerquery/timeandquery/cpu/timealways reporttype=msq.successis emitted as a string, like native metrics.
There was a problem hiding this comment.
I added these to metrics.md in a different way, folded into the table.
This patch improves consistency of query metrics across the native and MSQ engines in the following ways:
Emit context queryId as "queryId" in all query metrics. Previously,
native metrics emitted this as "id"; MSQ metrics emitted it as
"queryId"; and SQL metrics did not emit it at all.
Add "engine" to QueryMetrics and set it appropriately, so query
metrics can optionally gain this dimension. Out-of-box, it is not
included.
MSQ's query/time and query/cpu/time metrics are now emitted using
QueryMetrics rather than ad hoc metric construction. This better
aligns them with native query metrics.
Add MSQ query/load/* and query/segments/count metrics, matching the
analogous native metrics.
Release note
MSQ query metrics, such as
query/timeandquery/cpu/time, now use the same dimensions as native query metrics. This affects the existing dimensionstype(will be a native query type on the controller if a native query was used in planning) andsqlQueryId(no longer included by default).