-
Notifications
You must be signed in to change notification settings - Fork 26
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
Adds CloudSdk parameter for setting structured logs value #426
Changes from 5 commits
a1e5deb
c66ce8b
04ecfbd
747fdb6
1a46a29
1c83d0b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,7 +59,7 @@ | |
*/ | ||
public class CloudSdk { | ||
|
||
public static final CloudSdkVersion MINIMUM_VERSION = new CloudSdkVersion("145.0.0"); | ||
public static final CloudSdkVersion MINIMUM_VERSION = new CloudSdkVersion("159.0.0"); | ||
|
||
private static final Logger logger = Logger.getLogger(CloudSdk.class.getName()); | ||
private static final Joiner WHITESPACE_JOINER = Joiner.on(" "); | ||
|
@@ -79,22 +79,26 @@ public class CloudSdk { | |
private final ProcessRunner processRunner; | ||
private final String appCommandMetricsEnvironment; | ||
private final String appCommandMetricsEnvironmentVersion; | ||
@Nullable | ||
private final File appCommandCredentialFile; | ||
private final String appCommandOutputFormat; | ||
private final String appCommandShowStructuredLogs; | ||
private final WaitingProcessOutputLineListener runDevAppServerWaitListener; | ||
|
||
private CloudSdk(Path sdkPath, Path javaHomePath, String appCommandMetricsEnvironment, | ||
String appCommandMetricsEnvironmentVersion, | ||
private CloudSdk(Path sdkPath, Path javaHomePath, | ||
@Nullable String appCommandMetricsEnvironment, | ||
@Nullable String appCommandMetricsEnvironmentVersion, | ||
@Nullable File appCommandCredentialFile, | ||
String appCommandOutputFormat, ProcessRunner processRunner, | ||
@Nullable String appCommandOutputFormat, | ||
@Nullable String appCommandShowStructuredLogs, | ||
ProcessRunner processRunner, | ||
WaitingProcessOutputLineListener runDevAppServerWaitListener) { | ||
this.sdkPath = sdkPath; | ||
this.javaHomePath = javaHomePath; | ||
this.appCommandMetricsEnvironment = appCommandMetricsEnvironment; | ||
this.appCommandMetricsEnvironmentVersion = appCommandMetricsEnvironmentVersion; | ||
this.appCommandCredentialFile = appCommandCredentialFile; | ||
this.appCommandOutputFormat = appCommandOutputFormat; | ||
this.appCommandShowStructuredLogs = appCommandShowStructuredLogs; | ||
this.processRunner = processRunner; | ||
this.runDevAppServerWaitListener = runDevAppServerWaitListener; | ||
|
||
|
@@ -165,9 +169,20 @@ private void runGcloudCommand(List<String> args, File workingDirectory, String.. | |
command.addAll(args); | ||
command.addAll(GcloudArgs.get("format", appCommandOutputFormat)); | ||
|
||
Map<String, String> environment = Maps.newHashMap(); | ||
if (appCommandCredentialFile != null) { | ||
command.addAll(GcloudArgs.get("credential-file-override", appCommandCredentialFile)); | ||
} | ||
|
||
logCommand(command); | ||
processRunner.setEnvironment(getGcloudCommandEnvironment()); | ||
processRunner.setWorkingDirectory(workingDirectory); | ||
processRunner.run(command.toArray(new String[command.size()])); | ||
} | ||
|
||
@VisibleForTesting | ||
Map<String, String> getGcloudCommandEnvironment() { | ||
Map<String, String> environment = Maps.newHashMap(); | ||
if (appCommandCredentialFile != null) { | ||
environment.put("CLOUDSDK_APP_USE_GSUTIL", "0"); | ||
} | ||
if (appCommandMetricsEnvironment != null) { | ||
|
@@ -176,6 +191,9 @@ private void runGcloudCommand(List<String> args, File workingDirectory, String.. | |
if (appCommandMetricsEnvironmentVersion != null) { | ||
environment.put("CLOUDSDK_METRICS_ENVIRONMENT_VERSION", appCommandMetricsEnvironmentVersion); | ||
} | ||
if (appCommandShowStructuredLogs != null) { | ||
environment.put("CLOUDSDK_CORE_SHOW_STRUCTURED_LOGS", appCommandShowStructuredLogs); | ||
} | ||
// This is to ensure IDE credentials get correctly passed to the gcloud commands, in Windows. | ||
// It's a temporary workaround until a fix is released. | ||
// https://github.com/GoogleCloudPlatform/google-cloud-intellij/issues/985 | ||
|
@@ -185,10 +203,7 @@ private void runGcloudCommand(List<String> args, File workingDirectory, String.. | |
|
||
environment.put("CLOUDSDK_CORE_DISABLE_PROMPTS", "1"); | ||
|
||
logCommand(command); | ||
processRunner.setEnvironment(environment); | ||
processRunner.setWorkingDirectory(workingDirectory); | ||
processRunner.run(command.toArray(new String[command.size()])); | ||
return environment; | ||
} | ||
|
||
// Runs a gcloud command synchronously, with a new ProcessRunner. This method is intended to be | ||
|
@@ -525,9 +540,9 @@ public static class Builder { | |
private Path sdkPath; | ||
private String appCommandMetricsEnvironment; | ||
private String appCommandMetricsEnvironmentVersion; | ||
@Nullable | ||
private File appCommandCredentialFile; | ||
private String appCommandOutputFormat; | ||
private String appCommandShowStructuredLogs; | ||
private boolean async = false; | ||
private List<ProcessOutputLineListener> stdOutLineListeners = new ArrayList<>(); | ||
private List<ProcessOutputLineListener> stdErrLineListeners = new ArrayList<>(); | ||
|
@@ -584,6 +599,15 @@ public Builder appCommandOutputFormat(String appCommandOutputFormat) { | |
return this; | ||
} | ||
|
||
/** | ||
* Sets structured json logs for the stderr output. Supported values include 'never' (default), | ||
* 'always', 'terminal', etc. | ||
*/ | ||
public Builder appCommandShowStructuredLogs(String appCommandShowStructuredLogs) { | ||
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. Name is unwieldy. Maybe just "useStructuredLogs"? 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 mimics the gcloud config var name 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 agree the name isn't the best though; 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. Given that, I agree that "show" beats "use". However, I still think "appCommand" is unnecessary. 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 I'm not denying though that this whole thing could be refactored to avoid this, but I don't think this PR is the place for it 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. actually it looks @loosebazooka has some code in the experimental package that addresses all of this. |
||
this.appCommandShowStructuredLogs = appCommandShowStructuredLogs; | ||
return this; | ||
} | ||
|
||
/** | ||
* Whether to run commands asynchronously. | ||
*/ | ||
|
@@ -713,7 +737,7 @@ public CloudSdk build() { | |
|
||
return new CloudSdk(sdkPath, javaHomePath, appCommandMetricsEnvironment, | ||
appCommandMetricsEnvironmentVersion, appCommandCredentialFile, appCommandOutputFormat, | ||
processRunner, runDevAppServerWaitListener); | ||
appCommandShowStructuredLogs, processRunner, runDevAppServerWaitListener); | ||
} | ||
|
||
/** | ||
|
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.
Is this Nullable? I don't see a null check in the constructor. Ditto sdkPath and javaHomePath.
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.
they are not nullable
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.
actually they may be nullable depending on which command is invoked..
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.
@elharo. PTAL. I added an @nullable to javaHomePath as that is the only one of those that is truly nullable.