Skip to content

Commit 8ed1609

Browse files
authored
Add two new parameters for trace control (#24209)
Add two new parameters for trace control
1 parent 2edc8bc commit 8ed1609

File tree

4 files changed

+104
-4
lines changed

4 files changed

+104
-4
lines changed

presto-docs/src/main/sphinx/presto_cpp/properties-session.rst

Lines changed: 64 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,11 +307,73 @@ Minimum number of rows to use prefix-sort.
307307
The default value has been derived using micro-benchmarking.
308308

309309
``native_op_trace_directory_create_config``
310-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
310+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
311311

312312
* **Type:** ``varchar``
313313
* **Default value:** ``""``
314314

315315
Native Execution only. Config used to create operator trace directory. This config is provided
316316
to underlying file system and the config is free form. The form should be defined by the
317-
underlying file system.
317+
underlying file system.
318+
319+
``native_query_trace_enabled``
320+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
321+
322+
* **Type:** ``boolean``
323+
* **Default value:** ``false``
324+
325+
Enable query tracing. After enabled, trace data will be generated with query execution, and
326+
can be used by TraceReplayer. It needs to be used together with native_query_trace_node_ids,
327+
native_query_trace_max_bytes, native_query_trace_fragment_id, and native_query_trace_shard_id
328+
to match the task to be traced.
329+
330+
331+
``native_query_trace_dir``
332+
^^^^^^^^^^^^^^^^^^^^^^^^^^
333+
334+
* **Type:** ``varchar``
335+
* **Default value:** ``""``
336+
337+
The location to store the trace files.
338+
339+
``native_query_trace_node_ids``
340+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
341+
342+
* **Type:** ``varchar``
343+
* **Default value:** ``""``
344+
345+
A comma-separated list of plan node ids whose input data will be traced.
346+
Empty string if only want to trace the query metadata.
347+
348+
``native_query_trace_max_bytes``
349+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
350+
351+
* **Type:** ``integer``
352+
* **Default value:** ``0``
353+
354+
The max trace bytes limit. Tracing is disabled if zero.
355+
356+
``native_query_trace_fragment_id``
357+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
358+
359+
* **Type:** ``varchar``
360+
* **Default value:** ``.*``
361+
362+
The fragment id to be traced. If not specified, all fragments will be matched.
363+
364+
``native_query_trace_shard_id``
365+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
366+
367+
* **Type:** ``varchar``
368+
* **Default value:** ``.*``
369+
370+
The shard id to be traced. If not specified, all shards will be matched.
371+
372+
``native_query_trace_task_reg_exp``
373+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
374+
375+
* **Type:** ``varchar``
376+
* **Default value:** ``""``
377+
378+
The regular expression to match a task for tracing. It will be deprecated if there is
379+
no issue with native_query_trace_fragment_id and native_query_trace_shard_id.

presto-main/src/main/java/com/facebook/presto/sessionpropertyproviders/NativeWorkerSessionPropertyProvider.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ public class NativeWorkerSessionPropertyProvider
6161
public static final String NATIVE_QUERY_TRACE_NODE_IDS = "native_query_trace_node_ids";
6262
public static final String NATIVE_QUERY_TRACE_MAX_BYTES = "native_query_trace_max_bytes";
6363
public static final String NATIVE_QUERY_TRACE_REG_EXP = "native_query_trace_task_reg_exp";
64+
public static final String NATIVE_QUERY_TRACE_FRAGMENT_ID = "native_query_trace_fragment_id";
65+
public static final String NATIVE_QUERY_TRACE_SHARD_ID = "native_query_trace_shard_id";
6466
public static final String NATIVE_MAX_LOCAL_EXCHANGE_PARTITION_COUNT = "native_max_local_exchange_partition_count";
6567
public static final String NATIVE_SPILL_PREFIXSORT_ENABLED = "native_spill_prefixsort_enabled";
6668
public static final String NATIVE_PREFIXSORT_NORMALIZED_KEY_MAX_BYTES = "native_prefixsort_normalized_key_max_bytes";
@@ -231,6 +233,14 @@ public NativeWorkerSessionPropertyProvider(FeaturesConfig featuresConfig)
231233
"Config used to create operator trace directory. This config is provided to underlying file system and the config is free form. The form should be defined by the underlying file system.",
232234
"",
233235
!nativeExecution),
236+
stringProperty(NATIVE_QUERY_TRACE_FRAGMENT_ID,
237+
"The fragment id of the traced task.",
238+
"",
239+
!nativeExecution),
240+
stringProperty(NATIVE_QUERY_TRACE_SHARD_ID,
241+
"The shard id of the traced task.",
242+
"",
243+
!nativeExecution),
234244
longProperty(NATIVE_MAX_OUTPUT_BUFFER_SIZE,
235245
"The maximum size in bytes for the task's buffered output. The buffer is shared among all drivers.",
236246
200L << 20,

presto-native-execution/presto_cpp/main/QueryContextManager.cpp

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,9 +217,17 @@ QueryContextManager::toVeloxConfigs(
217217
// Use base velox query config as the starting point and add Presto session
218218
// properties on top of it.
219219
auto configs = BaseVeloxQueryConfig::instance()->values();
220+
std::optional<std::string> traceFragmentId;
221+
std::optional<std::string> traceShardId;
220222
for (const auto& it : session.systemProperties) {
221-
configs[sessionProperties_.toVeloxConfig(it.first)] = it.second;
222-
sessionProperties_.updateVeloxConfig(it.first, it.second);
223+
if (it.first == SessionProperties::kQueryTraceFragmentId) {
224+
traceFragmentId = it.second;
225+
} else if (it.first == SessionProperties::kQueryTraceShardId) {
226+
traceShardId = it.second;
227+
} else {
228+
configs[sessionProperties_.toVeloxConfig(it.first)] = it.second;
229+
sessionProperties_.updateVeloxConfig(it.first, it.second);
230+
}
223231
}
224232

225233
// If there's a timeZoneKey, convert to timezone name and add to the
@@ -229,6 +237,16 @@ QueryContextManager::toVeloxConfigs(
229237
velox::core::QueryConfig::kSessionTimezone,
230238
velox::tz::getTimeZoneName(session.timeZoneKey));
231239
}
240+
241+
// Construct query tracing regex and pass to Velox config.
242+
// It replaces the given native_query_trace_task_reg_exp if also set.
243+
if (traceFragmentId.has_value() || traceShardId.has_value()) {
244+
configs.emplace(
245+
velox::core::QueryConfig::kQueryTraceTaskRegExp,
246+
".*\\." + traceFragmentId.value_or(".*") + "\\..*\\." +
247+
traceShardId.value_or(".*") + "\\..*");
248+
}
249+
232250
updateFromSystemConfigs(configs);
233251
return configs;
234252
}

presto-native-execution/presto_cpp/main/SessionProperties.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,16 @@ class SessionProperties {
213213
static constexpr const char* kOpTraceDirectoryCreateConfig =
214214
"native_op_trace_directory_create_config";
215215

216+
/// The fragment id of the traced task. Used to construct
217+
/// the regular expression for matching
218+
static constexpr const char* kQueryTraceFragmentId =
219+
"native_query_trace_fragment_id";
220+
221+
/// The shard id of the traced task. Used to construct
222+
/// the regular expression for matching
223+
static constexpr const char* kQueryTraceShardId =
224+
"native_query_trace_shard_id";
225+
216226
/// The maximum size in bytes for the task's buffered output. The buffer is
217227
/// shared among all drivers.
218228
static constexpr const char* kMaxOutputBufferSize =

0 commit comments

Comments
 (0)