forked from apache/helix
-
Notifications
You must be signed in to change notification settings - Fork 12
Surface per-task status summary in Helix JobContext #214
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
5d3303d
Surface per-task status summary in Helix JobContext
LZD-PratyushBhatt 95f5fd2
Add in-progress and timed-out counts to JobContext task status summary
LZD-PratyushBhatt cf33c5e
Add pending-task bucket and on-demand summary recompute; address revi…
LZD-PratyushBhatt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
144 changes: 144 additions & 0 deletions
144
helix-core/src/test/java/org/apache/helix/integration/task/TestJobTaskStatusSummary.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,144 @@ | ||
| package org.apache.helix.integration.task; | ||
|
|
||
| /* | ||
| * 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. | ||
| */ | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| import com.fasterxml.jackson.databind.JsonNode; | ||
| import com.fasterxml.jackson.databind.ObjectMapper; | ||
| import org.apache.helix.TestHelper; | ||
| import org.apache.helix.task.JobConfig; | ||
| import org.apache.helix.task.JobContext; | ||
| import org.apache.helix.task.TaskConfig; | ||
| import org.apache.helix.task.TaskPartitionState; | ||
| import org.apache.helix.task.TaskResult; | ||
| import org.apache.helix.task.TaskState; | ||
| import org.apache.helix.task.TaskUtil; | ||
| import org.apache.helix.task.Workflow; | ||
| import org.testng.Assert; | ||
| import org.testng.annotations.Test; | ||
|
|
||
| /** | ||
| * Verifies the aggregated per-task status summary that Helix writes into the JobContext when a job | ||
| * reaches a terminal state. The scenario mirrors a common validation setup: one job per table, one | ||
| * task per partition, and a high FailureThreshold so every task runs even if some fail. In that | ||
| * setup the job's own status flag is COMPLETED, which previously masked partition level failures. | ||
| * The summary must surface those failures. | ||
| */ | ||
| public class TestJobTaskStatusSummary extends TaskTestBase { | ||
|
|
||
| private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); | ||
|
|
||
| @Test | ||
| public void testSummaryReflectsPartialFailureOnCompletedJob() throws Exception { | ||
| int numTasks = 6; | ||
| // Indices of the tasks that should fail terminally. | ||
| final int fatalTask = 1; // FATAL_FAILED -> given up immediately -> TASK_ABORTED | ||
| final int exceptionTask = 3; // throws -> retried to exhaustion -> TASK_ERROR | ||
| final int expectedFailed = 2; | ||
| final int expectedCompleted = numTasks - expectedFailed; | ||
|
|
||
| String jobResource = TestHelper.getTestMethodName(); | ||
| JobConfig.Builder jobBuilder = new JobConfig.Builder(); | ||
| // FailureThreshold high (a common operator workaround) so all tasks run and the job still | ||
| // ends COMPLETED. | ||
| jobBuilder.setCommand(MockTask.TASK_COMMAND).setTimeoutPerTask(10000).setMaxAttemptsPerTask(2) | ||
| .setFailureThreshold(Integer.MAX_VALUE); | ||
|
|
||
| List<TaskConfig> taskConfigs = new ArrayList<>(); | ||
| for (int j = 0; j < numTasks; j++) { | ||
| TaskConfig.Builder configBuilder = new TaskConfig.Builder().setTaskId("task_" + j); | ||
| if (j == fatalTask) { | ||
| configBuilder.addConfig(MockTask.TASK_RESULT_STATUS, TaskResult.Status.FATAL_FAILED.name()); | ||
| } else if (j == exceptionTask) { | ||
| configBuilder.addConfig(MockTask.THROW_EXCEPTION, Boolean.TRUE.toString()); | ||
| } | ||
| configBuilder.setTargetPartition(String.valueOf(j)); | ||
| taskConfigs.add(configBuilder.build()); | ||
| } | ||
| jobBuilder.addTaskConfigs(taskConfigs); | ||
|
|
||
| Workflow flow = | ||
| WorkflowGenerator.generateSingleJobWorkflowBuilder(jobResource, jobBuilder).build(); | ||
| _driver.start(flow); | ||
|
|
||
| // The job completes even though tasks failed, because FailureThreshold is high. | ||
| _driver.pollForWorkflowState(jobResource, TaskState.COMPLETED); | ||
|
|
||
| String namespacedJob = TaskUtil.getNamespacedJobName(jobResource); | ||
| Assert.assertEquals(_driver.getWorkflowContext(jobResource).getJobState(namespacedJob), | ||
| TaskState.COMPLETED, "Job status flag should be COMPLETED (this is what masked failures)."); | ||
|
|
||
| JobContext ctx = _driver.getJobContext(namespacedJob); | ||
|
|
||
| // Cross-check the ground truth directly from per-partition states. | ||
| int actualCompleted = 0; | ||
| int actualFailed = 0; | ||
| for (int pId : ctx.getPartitionSet()) { | ||
| TaskPartitionState state = ctx.getPartitionState(pId); | ||
| if (state == TaskPartitionState.COMPLETED) { | ||
| actualCompleted++; | ||
| } else if (state == TaskPartitionState.TASK_ABORTED || state == TaskPartitionState.TASK_ERROR | ||
| || state == TaskPartitionState.TIMED_OUT || state == TaskPartitionState.ERROR) { | ||
| actualFailed++; | ||
| } | ||
| } | ||
| Assert.assertEquals(actualCompleted, expectedCompleted); | ||
| Assert.assertEquals(actualFailed, expectedFailed); | ||
|
|
||
| // Now the crux: the summary must be present and must match the ground truth. | ||
| String summaryJson = ctx.getTaskStatusSummary(); | ||
| Assert.assertNotNull(summaryJson, "Task status summary should be populated on a terminal job."); | ||
| JsonNode summary = OBJECT_MAPPER.readTree(summaryJson); | ||
|
|
||
| Assert.assertEquals(summary.get("total").asInt(), numTasks); | ||
| Assert.assertEquals(summary.get("completed").asInt(), expectedCompleted); | ||
| Assert.assertEquals(summary.get("failed").asInt(), expectedFailed); | ||
| Assert.assertEquals(summary.get("other").asInt(), 0); | ||
| Assert.assertEquals(summary.get("failedTasks").size(), expectedFailed); | ||
|
|
||
| // No task timed out or stayed in-flight in this scenario, but the counts must be present so | ||
| // operators can rely on them being part of the summary shape. | ||
| Assert.assertEquals(summary.get("timedOut").asInt(), 0); | ||
| Assert.assertEquals(summary.get("inProgress").asInt(), 0); | ||
| Assert.assertEquals(summary.get("pending").asInt(), 0); | ||
| Assert.assertEquals(summary.get("timedOutTasks").size(), 0); | ||
| Assert.assertEquals(summary.get("inProgressTasks").size(), 0); | ||
| Assert.assertEquals(summary.get("pendingTasks").size(), 0); | ||
| // The top-level counts partition the tasks: | ||
| // total = completed + failed + inProgress + pending + other. | ||
| Assert.assertEquals(summary.get("completed").asInt() + summary.get("failed").asInt() | ||
| + summary.get("inProgress").asInt() + summary.get("pending").asInt() | ||
| + summary.get("other").asInt(), numTasks); | ||
|
|
||
| JsonNode byState = summary.get("byState"); | ||
| Assert.assertEquals(byState.get(TaskPartitionState.COMPLETED.name()).asInt(), expectedCompleted); | ||
| Assert.assertEquals(byState.get(TaskPartitionState.TASK_ABORTED.name()).asInt(), 1); | ||
| Assert.assertEquals(byState.get(TaskPartitionState.TASK_ERROR.name()).asInt(), 1); | ||
|
|
||
| // The failed partition ids reported in the summary must actually be failed partitions. | ||
| for (JsonNode failedPidNode : summary.get("failedTasks")) { | ||
| TaskPartitionState state = ctx.getPartitionState(failedPidNode.asInt()); | ||
| Assert.assertTrue(state != TaskPartitionState.COMPLETED, | ||
| "Partition " + failedPidNode.asInt() + " reported as failed but state is " + state); | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is
byState?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good one, byState is just the raw per-state histogram behind the coarse counts. each TaskPartitionState name (plus UNSCHEDULED when a partition has no state yet) maps to how many tasks are in that state. added a javadoc para on updateTaskStatusSummary() spelling it out.