Search in sources :

Example 6 with IOMetricsInfo

use of org.apache.flink.runtime.rest.messages.job.metrics.IOMetricsInfo in project flink by apache.

the class SubtaskCurrentAttemptDetailsHandlerTest method testHandleRequest.

@Test
public void testHandleRequest() throws Exception {
    // Prepare the execution graph.
    final JobID jobID = new JobID();
    final JobVertexID jobVertexID = new JobVertexID();
    // The testing subtask.
    final long deployingTs = System.currentTimeMillis() - 1024;
    final long finishedTs = System.currentTimeMillis();
    final long bytesIn = 1L;
    final long bytesOut = 10L;
    final long recordsIn = 20L;
    final long recordsOut = 30L;
    final IOMetrics ioMetrics = new IOMetrics(bytesIn, bytesOut, recordsIn, recordsOut);
    final long[] timestamps = new long[ExecutionState.values().length];
    timestamps[ExecutionState.DEPLOYING.ordinal()] = deployingTs;
    final ExecutionState expectedState = ExecutionState.FINISHED;
    timestamps[expectedState.ordinal()] = finishedTs;
    final LocalTaskManagerLocation assignedResourceLocation = new LocalTaskManagerLocation();
    final AllocationID allocationID = new AllocationID();
    final int subtaskIndex = 1;
    final int attempt = 2;
    final ArchivedExecution execution = new ArchivedExecution(new StringifiedAccumulatorResult[0], ioMetrics, new ExecutionAttemptID(), attempt, expectedState, null, assignedResourceLocation, allocationID, subtaskIndex, timestamps);
    final ArchivedExecutionVertex executionVertex = new ArchivedExecutionVertex(subtaskIndex, "Test archived execution vertex", execution, new EvictingBoundedList<>(0));
    // Instance the handler.
    final RestHandlerConfiguration restHandlerConfiguration = RestHandlerConfiguration.fromConfiguration(new Configuration());
    final MetricFetcher metricFetcher = new MetricFetcherImpl<>(() -> null, address -> null, TestingUtils.defaultExecutor(), Time.milliseconds(1000L), MetricOptions.METRIC_FETCHER_UPDATE_INTERVAL.defaultValue());
    final SubtaskCurrentAttemptDetailsHandler handler = new SubtaskCurrentAttemptDetailsHandler(() -> null, Time.milliseconds(100), Collections.emptyMap(), SubtaskCurrentAttemptDetailsHeaders.getInstance(), new DefaultExecutionGraphCache(restHandlerConfiguration.getTimeout(), Time.milliseconds(restHandlerConfiguration.getRefreshInterval())), TestingUtils.defaultExecutor(), metricFetcher);
    final HashMap<String, String> receivedPathParameters = new HashMap<>(2);
    receivedPathParameters.put(JobIDPathParameter.KEY, jobID.toString());
    receivedPathParameters.put(JobVertexIdPathParameter.KEY, jobVertexID.toString());
    final HandlerRequest<EmptyRequestBody> request = HandlerRequest.resolveParametersAndCreate(EmptyRequestBody.getInstance(), new SubtaskMessageParameters(), receivedPathParameters, Collections.emptyMap(), Collections.emptyList());
    // Handle request.
    final SubtaskExecutionAttemptDetailsInfo detailsInfo = handler.handleRequest(request, executionVertex);
    // Verify
    final IOMetricsInfo ioMetricsInfo = new IOMetricsInfo(bytesIn, true, bytesOut, true, recordsIn, true, recordsOut, true);
    final SubtaskExecutionAttemptDetailsInfo expectedDetailsInfo = new SubtaskExecutionAttemptDetailsInfo(subtaskIndex, expectedState, attempt, assignedResourceLocation.getHostname(), deployingTs, finishedTs, finishedTs - deployingTs, ioMetricsInfo, assignedResourceLocation.getResourceID().getResourceIdString());
    assertEquals(expectedDetailsInfo, detailsInfo);
}
Also used : ExecutionState(org.apache.flink.runtime.execution.ExecutionState) Configuration(org.apache.flink.configuration.Configuration) RestHandlerConfiguration(org.apache.flink.runtime.rest.handler.RestHandlerConfiguration) HashMap(java.util.HashMap) JobVertexID(org.apache.flink.runtime.jobgraph.JobVertexID) ArchivedExecution(org.apache.flink.runtime.executiongraph.ArchivedExecution) IOMetrics(org.apache.flink.runtime.executiongraph.IOMetrics) LocalTaskManagerLocation(org.apache.flink.runtime.taskmanager.LocalTaskManagerLocation) DefaultExecutionGraphCache(org.apache.flink.runtime.rest.handler.legacy.DefaultExecutionGraphCache) IOMetricsInfo(org.apache.flink.runtime.rest.messages.job.metrics.IOMetricsInfo) MetricFetcherImpl(org.apache.flink.runtime.rest.handler.legacy.metrics.MetricFetcherImpl) SubtaskExecutionAttemptDetailsInfo(org.apache.flink.runtime.rest.messages.job.SubtaskExecutionAttemptDetailsInfo) RestHandlerConfiguration(org.apache.flink.runtime.rest.handler.RestHandlerConfiguration) ExecutionAttemptID(org.apache.flink.runtime.executiongraph.ExecutionAttemptID) AllocationID(org.apache.flink.runtime.clusterframework.types.AllocationID) ArchivedExecutionVertex(org.apache.flink.runtime.executiongraph.ArchivedExecutionVertex) EmptyRequestBody(org.apache.flink.runtime.rest.messages.EmptyRequestBody) MetricFetcher(org.apache.flink.runtime.rest.handler.legacy.metrics.MetricFetcher) SubtaskMessageParameters(org.apache.flink.runtime.rest.messages.job.SubtaskMessageParameters) JobID(org.apache.flink.api.common.JobID) Test(org.junit.Test)

Example 7 with IOMetricsInfo

use of org.apache.flink.runtime.rest.messages.job.metrics.IOMetricsInfo in project flink by apache.

the class SubtaskExecutionAttemptDetailsHandlerTest method testHandleRequest.

@Test
public void testHandleRequest() throws Exception {
    final JobID jobID = new JobID();
    final JobVertexID jobVertexId = new JobVertexID();
    // The testing subtask.
    final int subtaskIndex = 1;
    final ExecutionState expectedState = ExecutionState.FINISHED;
    final int attempt = 0;
    final StringifiedAccumulatorResult[] emptyAccumulators = new StringifiedAccumulatorResult[0];
    final long bytesIn = 1L;
    final long bytesOut = 10L;
    final long recordsIn = 20L;
    final long recordsOut = 30L;
    final IOMetrics ioMetrics = new IOMetrics(bytesIn, bytesOut, recordsIn, recordsOut);
    final ArchivedExecutionJobVertex archivedExecutionJobVertex = new ArchivedExecutionJobVertex(new ArchivedExecutionVertex[] { // the first subtask won't be queried
    null, new ArchivedExecutionVertex(subtaskIndex, "test task", new ArchivedExecution(emptyAccumulators, ioMetrics, new ExecutionAttemptID(), attempt, expectedState, null, null, null, subtaskIndex, new long[ExecutionState.values().length]), new EvictingBoundedList<>(0)) }, jobVertexId, "test", 1, 1, ResourceProfile.UNKNOWN, emptyAccumulators);
    // Change some fields so we can make it different from other sub tasks.
    final MetricFetcher metricFetcher = new MetricFetcherImpl<>(() -> null, address -> null, TestingUtils.defaultExecutor(), Time.milliseconds(1000L), MetricOptions.METRIC_FETCHER_UPDATE_INTERVAL.defaultValue());
    // Instance the handler.
    final RestHandlerConfiguration restHandlerConfiguration = RestHandlerConfiguration.fromConfiguration(new Configuration());
    final SubtaskExecutionAttemptDetailsHandler handler = new SubtaskExecutionAttemptDetailsHandler(() -> null, Time.milliseconds(100L), Collections.emptyMap(), SubtaskExecutionAttemptDetailsHeaders.getInstance(), new DefaultExecutionGraphCache(restHandlerConfiguration.getTimeout(), Time.milliseconds(restHandlerConfiguration.getRefreshInterval())), TestingUtils.defaultExecutor(), metricFetcher);
    final HashMap<String, String> receivedPathParameters = new HashMap<>(4);
    receivedPathParameters.put(JobIDPathParameter.KEY, jobID.toString());
    receivedPathParameters.put(JobVertexIdPathParameter.KEY, jobVertexId.toString());
    receivedPathParameters.put(SubtaskIndexPathParameter.KEY, Integer.toString(subtaskIndex));
    receivedPathParameters.put(SubtaskAttemptPathParameter.KEY, Integer.toString(attempt));
    final HandlerRequest<EmptyRequestBody> request = HandlerRequest.resolveParametersAndCreate(EmptyRequestBody.getInstance(), new SubtaskAttemptMessageParameters(), receivedPathParameters, Collections.emptyMap(), Collections.emptyList());
    // Handle request.
    final SubtaskExecutionAttemptDetailsInfo detailsInfo = handler.handleRequest(request, archivedExecutionJobVertex);
    // Verify
    final IOMetricsInfo ioMetricsInfo = new IOMetricsInfo(bytesIn, true, bytesOut, true, recordsIn, true, recordsOut, true);
    final SubtaskExecutionAttemptDetailsInfo expectedDetailsInfo = new SubtaskExecutionAttemptDetailsInfo(subtaskIndex, expectedState, attempt, "(unassigned)", -1L, 0L, -1L, ioMetricsInfo, "(unassigned)");
    assertEquals(expectedDetailsInfo, detailsInfo);
}
Also used : ExecutionState(org.apache.flink.runtime.execution.ExecutionState) ArchivedExecutionJobVertex(org.apache.flink.runtime.executiongraph.ArchivedExecutionJobVertex) Configuration(org.apache.flink.configuration.Configuration) RestHandlerConfiguration(org.apache.flink.runtime.rest.handler.RestHandlerConfiguration) HashMap(java.util.HashMap) JobVertexID(org.apache.flink.runtime.jobgraph.JobVertexID) ArchivedExecution(org.apache.flink.runtime.executiongraph.ArchivedExecution) IOMetrics(org.apache.flink.runtime.executiongraph.IOMetrics) DefaultExecutionGraphCache(org.apache.flink.runtime.rest.handler.legacy.DefaultExecutionGraphCache) IOMetricsInfo(org.apache.flink.runtime.rest.messages.job.metrics.IOMetricsInfo) MetricFetcherImpl(org.apache.flink.runtime.rest.handler.legacy.metrics.MetricFetcherImpl) SubtaskExecutionAttemptDetailsInfo(org.apache.flink.runtime.rest.messages.job.SubtaskExecutionAttemptDetailsInfo) RestHandlerConfiguration(org.apache.flink.runtime.rest.handler.RestHandlerConfiguration) ExecutionAttemptID(org.apache.flink.runtime.executiongraph.ExecutionAttemptID) SubtaskAttemptMessageParameters(org.apache.flink.runtime.rest.messages.job.SubtaskAttemptMessageParameters) ArchivedExecutionVertex(org.apache.flink.runtime.executiongraph.ArchivedExecutionVertex) StringifiedAccumulatorResult(org.apache.flink.runtime.accumulators.StringifiedAccumulatorResult) EmptyRequestBody(org.apache.flink.runtime.rest.messages.EmptyRequestBody) MetricFetcher(org.apache.flink.runtime.rest.handler.legacy.metrics.MetricFetcher) EvictingBoundedList(org.apache.flink.runtime.util.EvictingBoundedList) JobID(org.apache.flink.api.common.JobID) Test(org.junit.Test)

Example 8 with IOMetricsInfo

use of org.apache.flink.runtime.rest.messages.job.metrics.IOMetricsInfo in project flink by apache.

the class JobVertexTaskManagersInfoTest method getTestResponseInstance.

@Override
protected JobVertexTaskManagersInfo getTestResponseInstance() throws Exception {
    final Random random = new Random();
    List<TaskManagersInfo> taskManagersInfoList = new ArrayList<>();
    final Map<ExecutionState, Integer> statusCounts = new HashMap<>(ExecutionState.values().length);
    final IOMetricsInfo jobVertexMetrics = new IOMetricsInfo(random.nextLong(), random.nextBoolean(), random.nextLong(), random.nextBoolean(), random.nextLong(), random.nextBoolean(), random.nextLong(), random.nextBoolean());
    int count = 100;
    for (ExecutionState executionState : ExecutionState.values()) {
        statusCounts.put(executionState, count++);
    }
    taskManagersInfoList.add(new TaskManagersInfo("host1", ExecutionState.CANCELING, 1L, 2L, 3L, jobVertexMetrics, statusCounts, "taskmanagerId"));
    return new JobVertexTaskManagersInfo(new JobVertexID(), "test", System.currentTimeMillis(), taskManagersInfoList);
}
Also used : ExecutionState(org.apache.flink.runtime.execution.ExecutionState) Random(java.util.Random) HashMap(java.util.HashMap) JobVertexID(org.apache.flink.runtime.jobgraph.JobVertexID) ArrayList(java.util.ArrayList) IOMetricsInfo(org.apache.flink.runtime.rest.messages.job.metrics.IOMetricsInfo) TaskManagersInfo(org.apache.flink.runtime.rest.messages.JobVertexTaskManagersInfo.TaskManagersInfo)

Example 9 with IOMetricsInfo

use of org.apache.flink.runtime.rest.messages.job.metrics.IOMetricsInfo in project flink by apache.

the class SubtaskExecutionAttemptDetailsInfo method create.

public static SubtaskExecutionAttemptDetailsInfo create(AccessExecution execution, @Nullable MetricFetcher metricFetcher, JobID jobID, JobVertexID jobVertexID) {
    final ExecutionState status = execution.getState();
    final long now = System.currentTimeMillis();
    final TaskManagerLocation location = execution.getAssignedResourceLocation();
    final String locationString = location == null ? "(unassigned)" : location.getHostname();
    String taskmanagerId = location == null ? "(unassigned)" : location.getResourceID().toString();
    long startTime = execution.getStateTimestamp(ExecutionState.DEPLOYING);
    if (startTime == 0) {
        startTime = -1;
    }
    final long endTime = status.isTerminal() ? execution.getStateTimestamp(status) : -1;
    final long duration = startTime > 0 ? ((endTime > 0 ? endTime : now) - startTime) : -1;
    final MutableIOMetrics ioMetrics = new MutableIOMetrics();
    ioMetrics.addIOMetrics(execution, metricFetcher, jobID.toString(), jobVertexID.toString());
    final IOMetricsInfo ioMetricsInfo = new IOMetricsInfo(ioMetrics.getNumBytesIn(), ioMetrics.isNumBytesInComplete(), ioMetrics.getNumBytesOut(), ioMetrics.isNumBytesOutComplete(), ioMetrics.getNumRecordsIn(), ioMetrics.isNumRecordsInComplete(), ioMetrics.getNumRecordsOut(), ioMetrics.isNumRecordsOutComplete());
    return new SubtaskExecutionAttemptDetailsInfo(execution.getParallelSubtaskIndex(), status, execution.getAttemptNumber(), locationString, startTime, endTime, duration, ioMetricsInfo, taskmanagerId);
}
Also used : ExecutionState(org.apache.flink.runtime.execution.ExecutionState) MutableIOMetrics(org.apache.flink.runtime.rest.handler.util.MutableIOMetrics) TaskManagerLocation(org.apache.flink.runtime.taskmanager.TaskManagerLocation) IOMetricsInfo(org.apache.flink.runtime.rest.messages.job.metrics.IOMetricsInfo)

Aggregations

IOMetricsInfo (org.apache.flink.runtime.rest.messages.job.metrics.IOMetricsInfo)9 ExecutionState (org.apache.flink.runtime.execution.ExecutionState)7 HashMap (java.util.HashMap)6 JobVertexID (org.apache.flink.runtime.jobgraph.JobVertexID)5 ArrayList (java.util.ArrayList)3 Random (java.util.Random)3 MutableIOMetrics (org.apache.flink.runtime.rest.handler.util.MutableIOMetrics)3 SubtaskExecutionAttemptDetailsInfo (org.apache.flink.runtime.rest.messages.job.SubtaskExecutionAttemptDetailsInfo)3 JobID (org.apache.flink.api.common.JobID)2 Configuration (org.apache.flink.configuration.Configuration)2 AccessExecutionVertex (org.apache.flink.runtime.executiongraph.AccessExecutionVertex)2 ArchivedExecution (org.apache.flink.runtime.executiongraph.ArchivedExecution)2 ArchivedExecutionVertex (org.apache.flink.runtime.executiongraph.ArchivedExecutionVertex)2 ExecutionAttemptID (org.apache.flink.runtime.executiongraph.ExecutionAttemptID)2 IOMetrics (org.apache.flink.runtime.executiongraph.IOMetrics)2 RestHandlerConfiguration (org.apache.flink.runtime.rest.handler.RestHandlerConfiguration)2 DefaultExecutionGraphCache (org.apache.flink.runtime.rest.handler.legacy.DefaultExecutionGraphCache)2 MetricFetcher (org.apache.flink.runtime.rest.handler.legacy.metrics.MetricFetcher)2 MetricFetcherImpl (org.apache.flink.runtime.rest.handler.legacy.metrics.MetricFetcherImpl)2 EmptyRequestBody (org.apache.flink.runtime.rest.messages.EmptyRequestBody)2