Search in sources :

Example 1 with ThreadInfoSample

use of org.apache.flink.runtime.messages.ThreadInfoSample in project flink by apache.

the class ThreadInfoRequestCoordinatorTest method createMockTaskManagerGateway.

private static CompletableFuture<TaskExecutorThreadInfoGateway> createMockTaskManagerGateway(CompletionType completionType) {
    final CompletableFuture<TaskThreadInfoResponse> responseFuture = new CompletableFuture<>();
    switch(completionType) {
        case SUCCESSFULLY:
            ThreadInfoSample sample = JvmUtils.createThreadInfoSample(Thread.currentThread().getId(), 100).get();
            responseFuture.complete(new TaskThreadInfoResponse(Collections.singletonList(sample)));
            break;
        case EXCEPTIONALLY:
            responseFuture.completeExceptionally(new RuntimeException("Request failed."));
            break;
        case TIMEOUT:
            executorService.schedule(() -> responseFuture.completeExceptionally(new TimeoutException(REQUEST_TIMEOUT_MESSAGE)), REQUEST_TIMEOUT.toMillis(), TimeUnit.MILLISECONDS);
            break;
        case NEVER_COMPLETE:
            // do nothing
            break;
        default:
            throw new RuntimeException("Unknown completion type.");
    }
    final TaskExecutorThreadInfoGateway executorGateway = (taskExecutionAttemptId, requestParams, timeout) -> responseFuture;
    return CompletableFuture.completedFuture(executorGateway);
}
Also used : Matchers.emptyArray(org.hamcrest.Matchers.emptyArray) TaskThreadInfoResponse(org.apache.flink.runtime.messages.TaskThreadInfoResponse) BeforeClass(org.junit.BeforeClass) Matchers.not(org.hamcrest.Matchers.not) TimeoutException(java.util.concurrent.TimeoutException) ExceptionUtils(org.apache.flink.util.ExceptionUtils) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) ArrayList(java.util.ArrayList) After(org.junit.After) Duration(java.time.Duration) Map(java.util.Map) TestLogger(org.apache.flink.util.TestLogger) Timeout(org.junit.rules.Timeout) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Assert.fail(org.junit.Assert.fail) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Before(org.junit.Before) ThreadInfoSample(org.apache.flink.runtime.messages.ThreadInfoSample) AfterClass(org.junit.AfterClass) JvmUtils(org.apache.flink.runtime.util.JvmUtils) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) TaskExecutorThreadInfoGateway(org.apache.flink.runtime.taskexecutor.TaskExecutorThreadInfoGateway) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) ExecutionAttemptID(org.apache.flink.runtime.executiongraph.ExecutionAttemptID) List(java.util.List) Rule(org.junit.Rule) Assert.assertFalse(org.junit.Assert.assertFalse) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) TaskExecutorThreadInfoGateway(org.apache.flink.runtime.taskexecutor.TaskExecutorThreadInfoGateway) TaskThreadInfoResponse(org.apache.flink.runtime.messages.TaskThreadInfoResponse) CompletableFuture(java.util.concurrent.CompletableFuture) ThreadInfoSample(org.apache.flink.runtime.messages.ThreadInfoSample) TimeoutException(java.util.concurrent.TimeoutException)

Example 2 with ThreadInfoSample

use of org.apache.flink.runtime.messages.ThreadInfoSample in project flink by apache.

the class ThreadInfoSampleServiceTest method testSampleTaskThreadInfo.

/**
 * Tests successful thread info samples request.
 */
@Test(timeout = 10000L)
public void testSampleTaskThreadInfo() throws Exception {
    final List<ThreadInfoSample> threadInfoSamples = threadInfoSampleService.requestThreadInfoSamples(new TestTask(), requestParams).get();
    assertThat(threadInfoSamples, hasSize(NUMBER_OF_SAMPLES));
    for (ThreadInfoSample sample : threadInfoSamples) {
        StackTraceElement[] traces = sample.getStackTrace();
        assertTrue(sample.getStackTrace().length <= MAX_STACK_TRACK_DEPTH);
        assertThat(traces, is(arrayWithSize(lessThanOrEqualTo(MAX_STACK_TRACK_DEPTH))));
    }
}
Also used : ThreadInfoSample(org.apache.flink.runtime.messages.ThreadInfoSample) Test(org.junit.Test)

Example 3 with ThreadInfoSample

use of org.apache.flink.runtime.messages.ThreadInfoSample in project flink by apache.

the class ThreadInfoSampleServiceTest method testTruncateStackTraceIfLimitIsSpecified.

/**
 * Tests that stack traces are truncated when exceeding the configured depth.
 */
@Test(timeout = 10000L)
public void testTruncateStackTraceIfLimitIsSpecified() throws Exception {
    final List<ThreadInfoSample> threadInfoSamples1 = threadInfoSampleService.requestThreadInfoSamples(new TestTask(), requestParams).get();
    final List<ThreadInfoSample> threadInfoSamples2 = threadInfoSampleService.requestThreadInfoSamples(new TestTask(), new ThreadInfoSamplesRequest(1, NUMBER_OF_SAMPLES, DELAY_BETWEEN_SAMPLES, MAX_STACK_TRACK_DEPTH - 5)).get();
    for (ThreadInfoSample sample : threadInfoSamples1) {
        assertThat(sample.getStackTrace(), is(arrayWithSize(lessThanOrEqualTo(MAX_STACK_TRACK_DEPTH))));
        assertTrue(sample.getStackTrace().length <= MAX_STACK_TRACK_DEPTH);
    }
    for (ThreadInfoSample sample : threadInfoSamples2) {
        assertThat(sample.getStackTrace(), is(arrayWithSize(MAX_STACK_TRACK_DEPTH - 5)));
    }
}
Also used : ThreadInfoSample(org.apache.flink.runtime.messages.ThreadInfoSample) ThreadInfoSamplesRequest(org.apache.flink.runtime.webmonitor.threadinfo.ThreadInfoSamplesRequest) Test(org.junit.Test)

Example 4 with ThreadInfoSample

use of org.apache.flink.runtime.messages.ThreadInfoSample in project flink by apache.

the class JobVertexFlameGraphFactory method createFlameGraphFromSample.

private static JobVertexFlameGraph createFlameGraphFromSample(JobVertexThreadInfoStats sample, Set<Thread.State> threadStates) {
    final NodeBuilder root = new NodeBuilder("root");
    for (List<ThreadInfoSample> threadInfoSubSamples : sample.getSamplesBySubtask().values()) {
        for (ThreadInfoSample threadInfo : threadInfoSubSamples) {
            if (threadStates.contains(threadInfo.getThreadState())) {
                StackTraceElement[] traces = threadInfo.getStackTrace();
                root.incrementHitCount();
                NodeBuilder parent = root;
                for (int i = traces.length - 1; i >= 0; i--) {
                    final String name = traces[i].getClassName() + "." + traces[i].getMethodName() + ":" + traces[i].getLineNumber();
                    parent = parent.addChild(name);
                }
            }
        }
    }
    return new JobVertexFlameGraph(sample.getEndTime(), root.toNode());
}
Also used : ThreadInfoSample(org.apache.flink.runtime.messages.ThreadInfoSample)

Aggregations

ThreadInfoSample (org.apache.flink.runtime.messages.ThreadInfoSample)4 Test (org.junit.Test)3 Duration (java.time.Duration)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 ExecutionException (java.util.concurrent.ExecutionException)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1 ScheduledThreadPoolExecutor (java.util.concurrent.ScheduledThreadPoolExecutor)1 TimeUnit (java.util.concurrent.TimeUnit)1 TimeoutException (java.util.concurrent.TimeoutException)1 ExecutionAttemptID (org.apache.flink.runtime.executiongraph.ExecutionAttemptID)1 TaskThreadInfoResponse (org.apache.flink.runtime.messages.TaskThreadInfoResponse)1 TaskExecutorThreadInfoGateway (org.apache.flink.runtime.taskexecutor.TaskExecutorThreadInfoGateway)1 JvmUtils (org.apache.flink.runtime.util.JvmUtils)1 ThreadInfoSamplesRequest (org.apache.flink.runtime.webmonitor.threadinfo.ThreadInfoSamplesRequest)1 ExceptionUtils (org.apache.flink.util.ExceptionUtils)1