-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Add log dir creation in ProcessRuntime #3114
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -38,6 +38,7 @@ | |
| import org.apache.pulsar.functions.secretsproviderconfigurator.SecretsProviderConfigurator; | ||
| import org.apache.pulsar.functions.utils.Utils; | ||
|
|
||
| import java.io.File; | ||
| import java.io.IOException; | ||
| import java.io.InputStream; | ||
| import java.util.List; | ||
|
|
@@ -70,6 +71,7 @@ class ProcessRuntime implements Runtime { | |
| private final SecretsProviderConfigurator secretsProviderConfigurator; | ||
| private final String extraDependenciesDir; | ||
| private static final long GRPC_TIMEOUT_SECS = 5; | ||
| private final String funcLogDir; | ||
|
|
||
| ProcessRuntime(InstanceConfig instanceConfig, | ||
| String instanceFile, | ||
|
|
@@ -86,6 +88,7 @@ class ProcessRuntime implements Runtime { | |
| this.metricsPort = Utils.findAvailablePort(); | ||
| this.expectedHealthCheckInterval = expectedHealthCheckInterval; | ||
| this.secretsProviderConfigurator = secretsProviderConfigurator; | ||
| this.funcLogDir = RuntimeUtils.genFunctionLogFolder(logDirectory, instanceConfig); | ||
| String logConfigFile = null; | ||
| String secretsProviderClassName = secretsProviderConfigurator.getSecretsProviderClassName(instanceConfig.getFunctionDetails()); | ||
| String secretsProviderConfig = null; | ||
|
|
@@ -131,6 +134,19 @@ class ProcessRuntime implements Runtime { | |
| @Override | ||
| public void start() { | ||
| java.lang.Runtime.getRuntime().addShutdownHook(new Thread(() -> process.destroy())); | ||
|
|
||
| // Note: we create the expected log folder before the function process logger attempts to create it | ||
| // This is because if multiple instances are launched they can encounter a race condition creation of the dir. | ||
| log.info("Creating function log directory {}", funcLogDir); | ||
| boolean success = createFolder(funcLogDir); | ||
|
|
||
| if (!success) { | ||
| log.error("Log folder could not be created : {}", funcLogDir); | ||
| throw new RuntimeException("Log folder creation error"); | ||
| } | ||
|
|
||
| log.info("Created function log directory {}", funcLogDir); | ||
|
|
||
| startProcess(); | ||
| if (channel == null && stub == null) { | ||
| channel = ManagedChannelBuilder.forAddress("127.0.0.1", instancePort) | ||
|
|
@@ -335,6 +351,11 @@ public boolean isAlive() { | |
| return true; | ||
| } | ||
|
|
||
| private boolean createFolder(final String path) { | ||
| final boolean success = new File(path).mkdirs(); | ||
|
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. We should only attempt to create directories if they are not present
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. I think this is fine since new File(path).mkdirs() is idempotent |
||
| return success; | ||
| } | ||
|
|
||
| private void tryExtractingDeathException() { | ||
| InputStream errorStream = process.getErrorStream(); | ||
| try { | ||
|
|
||
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
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.
So what if the directory is already there? Shouldn't throw exception because directory is already there
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.
I think this is fine since new File(path).mkdirs() is idempotent