-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Allow users to pass task payload via deep storage instead of environment variable #14887
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
abhishekagarwal87
merged 32 commits into
apache:master
from
georgew5656:useTaskManagerForTaskPayload
Oct 3, 2023
Merged
Changes from all commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
7a86726
Separate out task logs
151b5c0
working with cleaner configs
455dfcf
Remove unneeded changes
6dd5713
Working with new configs
4823adc
Merge branch 'master' of github.com:georgew5656/druid into saveTaskLogs
14650c9
Pulling remote changes in
378a472
Fixing checkstyle
12374be
Cleanup unit tests
ea8a37b
fix checkstyle
39c62ac
Add more unit tests
ca17d62
Clean up check failures
bf21854
PR changes
be50e45
Fix spellign errors
3a59f3f
Fix spacing in docs
3bc19de
Don't overwrite table format
4b05f39
don't fix table format
ffcf0a7
Rename config
01989d7
Fix merge conflicts
baf9c75
fix merge conflicts
a74aad7
Remove config options
bbe7444
Small fixes
f3f8aac
Remove uneeded param
7760688
fix build
519b046
Merge branch 'master' of github.com:georgew5656/druid into useTaskMan…
4afa8f3
remove unneeded arg
0af80bf
Remove unused import
ba82cb1
PR changes
f200439
more pr changes
9f171fe
Merge branch 'master' into useTaskManagerForTaskPayload
59dc958
More pr changes
6123a3e
Fix static checks
99b68f0
Update extensions-contrib/kubernetes-overlord-extensions/src/main/jav…
georgew5656 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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -41,7 +41,10 @@ | |
| import io.fabric8.kubernetes.api.model.ResourceRequirementsBuilder; | ||
| import io.fabric8.kubernetes.api.model.batch.v1.Job; | ||
| import io.fabric8.kubernetes.api.model.batch.v1.JobBuilder; | ||
| import org.apache.commons.io.IOUtils; | ||
| import org.apache.commons.lang3.StringUtils; | ||
| import org.apache.druid.error.DruidException; | ||
| import org.apache.druid.error.InternalServerError; | ||
| import org.apache.druid.indexing.common.config.TaskConfig; | ||
| import org.apache.druid.indexing.common.task.Task; | ||
| import org.apache.druid.indexing.overlord.ForkingTaskRunner; | ||
|
|
@@ -57,8 +60,11 @@ | |
| import org.apache.druid.k8s.overlord.common.PeonCommandContext; | ||
| import org.apache.druid.server.DruidNode; | ||
| import org.apache.druid.server.log.StartupLoggingConfig; | ||
| import org.apache.druid.tasklogs.TaskLogs; | ||
|
|
||
| import java.io.IOException; | ||
| import java.io.InputStream; | ||
| import java.nio.charset.Charset; | ||
| import java.util.ArrayList; | ||
| import java.util.Collections; | ||
| import java.util.HashMap; | ||
|
|
@@ -89,14 +95,16 @@ public abstract class K8sTaskAdapter implements TaskAdapter | |
| protected final StartupLoggingConfig startupLoggingConfig; | ||
| protected final DruidNode node; | ||
| protected final ObjectMapper mapper; | ||
| protected final TaskLogs taskLogs; | ||
|
|
||
| public K8sTaskAdapter( | ||
| KubernetesClientApi client, | ||
| KubernetesTaskRunnerConfig taskRunnerConfig, | ||
| TaskConfig taskConfig, | ||
| StartupLoggingConfig startupLoggingConfig, | ||
| DruidNode node, | ||
| ObjectMapper mapper | ||
| ObjectMapper mapper, | ||
| TaskLogs taskLogs | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the name of this class has been confusing since it does so much more than dealing with task logs. could be fixed in some other PR someday. |
||
| ) | ||
| { | ||
| this.client = client; | ||
|
|
@@ -105,6 +113,7 @@ public K8sTaskAdapter( | |
| this.startupLoggingConfig = startupLoggingConfig; | ||
| this.node = node; | ||
| this.mapper = mapper; | ||
| this.taskLogs = taskLogs; | ||
| } | ||
|
|
||
| @Override | ||
|
|
@@ -132,11 +141,39 @@ public Task toTask(Job from) throws IOException | |
| Optional<EnvVar> taskJson = envVars.stream().filter(x -> "TASK_JSON".equals(x.getName())).findFirst(); | ||
| String contents = taskJson.map(envVar -> taskJson.get().getValue()).orElse(null); | ||
| if (contents == null) { | ||
| throw new IOException("No TASK_JSON environment variable found in pod: " + from.getMetadata().getName()); | ||
| log.info("No TASK_JSON environment variable found in pod: %s. Trying to load task payload from deep storage.", from.getMetadata().getName()); | ||
| return toTaskUsingDeepStorage(from); | ||
| } | ||
| return mapper.readValue(Base64Compression.decompressBase64(contents), Task.class); | ||
| } | ||
|
|
||
| private Task toTaskUsingDeepStorage(Job from) throws IOException | ||
| { | ||
| com.google.common.base.Optional<InputStream> taskBody = taskLogs.streamTaskPayload(getTaskId(from).getOriginalTaskId()); | ||
| if (!taskBody.isPresent()) { | ||
| throw InternalServerError.exception( | ||
| "Could not load task payload from deep storage for job [%s]. Check the overlord logs for any errors in uploading task payload to deep storage.", | ||
| from.getMetadata().getName() | ||
| ); | ||
| } | ||
| String task = IOUtils.toString(taskBody.get(), Charset.defaultCharset()); | ||
| return mapper.readValue(task, Task.class); | ||
| } | ||
|
|
||
| @Override | ||
| public K8sTaskId getTaskId(Job from) | ||
| { | ||
| Map<String, String> annotations = from.getSpec().getTemplate().getMetadata().getAnnotations(); | ||
| if (annotations == null) { | ||
| throw DruidException.defensive().build("No annotations found on pod spec for job [%s]", from.getMetadata().getName()); | ||
| } | ||
| String taskId = annotations.get(DruidK8sConstants.TASK_ID); | ||
| if (taskId == null) { | ||
| throw DruidException.defensive().build("No task_id annotation found on pod spec for job [%s]", from.getMetadata().getName()); | ||
| } | ||
| return new K8sTaskId(taskId); | ||
| } | ||
|
|
||
| @VisibleForTesting | ||
| abstract Job createJobFromPodSpec(PodSpec podSpec, Task task, PeonCommandContext context) throws IOException; | ||
|
|
||
|
|
@@ -219,15 +256,11 @@ void addEnvironmentVariables(Container mainContainer, PeonCommandContext context | |
| .build()); | ||
| } | ||
|
|
||
| mainContainer.getEnv().addAll(Lists.newArrayList( | ||
| List<EnvVar> envVars = Lists.newArrayList( | ||
| new EnvVarBuilder() | ||
| .withName(DruidK8sConstants.TASK_DIR_ENV) | ||
| .withValue(context.getTaskDir().getAbsolutePath()) | ||
| .build(), | ||
| new EnvVarBuilder() | ||
| .withName(DruidK8sConstants.TASK_JSON_ENV) | ||
| .withValue(taskContents) | ||
| .build(), | ||
| new EnvVarBuilder() | ||
| .withName(DruidK8sConstants.JAVA_OPTS) | ||
| .withValue(Joiner.on(" ").join(context.getJavaOpts())) | ||
|
|
@@ -244,7 +277,17 @@ void addEnvironmentVariables(Container mainContainer, PeonCommandContext context | |
| null, | ||
| "metadata.name" | ||
| )).build()).build() | ||
| )); | ||
| ); | ||
|
|
||
| if (taskContents.length() < DruidK8sConstants.MAX_ENV_VARIABLE_KBS) { | ||
| envVars.add( | ||
| new EnvVarBuilder() | ||
| .withName(DruidK8sConstants.TASK_JSON_ENV) | ||
| .withValue(taskContents) | ||
| .build() | ||
| ); | ||
| } | ||
| mainContainer.getEnv().addAll(envVars); | ||
| } | ||
|
|
||
| protected Container setupMainContainer( | ||
|
|
@@ -403,6 +446,9 @@ private List<String> generateCommand(Task task) | |
| command.add("--loadBroadcastSegments"); | ||
| command.add("true"); | ||
| } | ||
|
|
||
| command.add("--taskId"); | ||
| command.add(task.getId()); | ||
| log.info( | ||
| "Peon Command for K8s job: %s", | ||
| ForkingTaskRunner.getMaskedCommand(startupLoggingConfig.getMaskProperties(), command) | ||
|
|
@@ -433,5 +479,12 @@ static ResourceRequirements getResourceRequirements(ResourceRequirements require | |
| } | ||
| return requirements; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean shouldUseDeepStorageForTaskPayload(Task task) throws IOException | ||
| { | ||
| String compressedTaskPayload = Base64Compression.compressBase64(mapper.writeValueAsString(task)); | ||
| return compressedTaskPayload.length() > DruidK8sConstants.MAX_ENV_VARIABLE_KBS; | ||
| } | ||
| } | ||
|
|
||
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
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.
Uh oh!
There was an error while loading. Please reload this page.