Skip to content

Commit

Permalink
Wrap ML model loading task in new tracing context (#89024)
Browse files Browse the repository at this point in the history
Part of #84369.

ML uses the task framework to register a tasks for each loaded model.
These tasks are not executed in the usual sense, and it does not make
sense to trace them using APM. Therefore, make it possible to register
a task without also starting tracing.
  • Loading branch information
pugnascotia authored Aug 2, 2022
1 parent 577c1c9 commit 5f14c79
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
13 changes: 12 additions & 1 deletion server/src/main/java/org/elasticsearch/tasks/TaskManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,15 @@ public void setTaskCancellationService(TaskCancellationService taskCancellationS
* Registers a task without parent task
*/
public Task register(String type, String action, TaskAwareRequest request) {
return register(type, action, request, true);
}

/**
* Registers a task without a parent task, and specifies whether to trace the request. You should prefer
* to call {@link #register(String, String, TaskAwareRequest)}, since it is rare to want to avoid
* tracing a task.
*/
public Task register(String type, String action, TaskAwareRequest request, boolean traceRequest) {
Map<String, String> headers = new HashMap<>();
long headerSize = 0;
long maxSize = maxHeaderSize.getBytes();
Expand Down Expand Up @@ -149,7 +158,9 @@ public Task register(String type, String action, TaskAwareRequest request) {
} else {
Task previousTask = tasks.put(task.getId(), task);
assert previousTask == null;
startTrace(threadContext, task);
if (traceRequest) {
startTrace(threadContext, task);
}
}
return task;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,8 @@ void prepareModelToLoad(StartTrainedModelDeploymentAction.TaskParams taskParams)
TrainedModelDeploymentTask task = (TrainedModelDeploymentTask) taskManager.register(
TRAINED_MODEL_ASSIGNMENT_TASK_TYPE,
TRAINED_MODEL_ASSIGNMENT_TASK_ACTION,
taskAwareRequest(taskParams)
taskAwareRequest(taskParams),
false
);
// threadsafe check to verify we are not loading/loaded the model
if (modelIdToTask.putIfAbsent(taskParams.getModelId(), task) == null) {
Expand Down

0 comments on commit 5f14c79

Please sign in to comment.