AHeise commented on a change in pull request #15054: URL: https://github.com/apache/flink/pull/15054#discussion_r605081738
########## File path: flink-runtime/src/main/java/org/apache/flink/runtime/webmonitor/threadinfo/ThreadInfoRequestCoordinator.java ########## @@ -0,0 +1,188 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.flink.runtime.webmonitor.threadinfo; + +import org.apache.flink.api.common.time.Time; +import org.apache.flink.api.java.tuple.Tuple2; +import org.apache.flink.runtime.concurrent.FutureUtils; +import org.apache.flink.runtime.execution.ExecutionState; +import org.apache.flink.runtime.executiongraph.AccessExecution; +import org.apache.flink.runtime.executiongraph.AccessExecutionVertex; +import org.apache.flink.runtime.executiongraph.ExecutionAttemptID; +import org.apache.flink.runtime.messages.TaskThreadInfoResponse; +import org.apache.flink.runtime.messages.ThreadInfoSample; +import org.apache.flink.runtime.taskexecutor.TaskExecutorGateway; +import org.apache.flink.runtime.webmonitor.stats.TaskStatsRequestCoordinator; + +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.Executor; + +import static org.apache.flink.util.Preconditions.checkArgument; +import static org.apache.flink.util.Preconditions.checkNotNull; + +/** A coordinator for triggering and collecting thread info stats of running operator subtasks. */ +public class ThreadInfoRequestCoordinator + extends TaskStatsRequestCoordinator<List<ThreadInfoSample>, OperatorThreadInfoStats> { + + /** + * Creates a new coordinator for the job. + * + * @param executor Used to execute the futures. + * @param requestTimeout Time out after the expected sampling duration. This is added to the + * expected duration of a request, which is determined by the number of samples and the + * delay between each sample. + */ + public ThreadInfoRequestCoordinator(Executor executor, long requestTimeout) { + super(executor, requestTimeout); + } + + /** + * Triggers collection of thread info stats of an operator by combining thread info responses + * from given subtasks. A thread info response of a subtask in turn consists of {@code + * numSamples}, collected with {@code delayBetweenSamples} milliseconds delay between them. + * + * @param subtasksWithGateways Execution vertices together with TaskExecutors running them. + * @param numSamples Number of thread info samples to collect from each subtask. + * @param delayBetweenSamples Delay between consecutive samples (ms). + * @param maxStackTraceDepth Maximum depth of the stack traces collected within thread info + * samples. + * @return A future of the completed thread info stats. + */ + public CompletableFuture<OperatorThreadInfoStats> triggerThreadInfoRequest( + List<Tuple2<AccessExecutionVertex, CompletableFuture<TaskExecutorGateway>>> + subtasksWithGateways, + int numSamples, + Time delayBetweenSamples, + int maxStackTraceDepth) { + + checkNotNull(subtasksWithGateways, "Tasks to sample"); + checkArgument(subtasksWithGateways.size() > 0, "No tasks to sample"); + checkArgument(numSamples >= 1, "No number of samples"); + checkArgument(maxStackTraceDepth >= 0, "Negative maximum stack trace depth"); + + // Execution IDs of running tasks + List<ExecutionAttemptID> runningSubtasksIds = new ArrayList<>(); + + // Check that all tasks are RUNNING before triggering anything. The + // triggering can still fail. + for (Tuple2<AccessExecutionVertex, CompletableFuture<TaskExecutorGateway>> + executionsWithGateway : subtasksWithGateways) { + AccessExecution execution = executionsWithGateway.f0.getCurrentExecutionAttempt(); Review comment: Filtering state before passing the `executionsWithGateway` now - that allows to only pass `AttemptID`. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org