Skip to content
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

Merged
merged 6 commits into from
Jun 26, 2017

Conversation

etanshaul
Copy link
Contributor

@etanshaul etanshaul commented Jun 21, 2017

fixes #425

This new parameter mimics the new gcloud configuration for providing the structured error logs environment variable setting CLOUDSDK_CORE_SHOW_STRUCTURED_LOGS.

gcloud accepts a string value for this: terminal, log, always, never

Setting this to terminal, or always, produces json output for messages coming from the cloudsdk according to the verbosity value currently set.

Example (consumed from IntelliJ):

Without structured logs set (defaulted to never):
image

Same error, with verbosity defaulted to error, and the structure logs parameter set to log:
image

@etanshaul etanshaul changed the title Structured logs Adds CloudSdk parameters for setting structured logs value Jun 21, 2017
@etanshaul etanshaul changed the title Adds CloudSdk parameters for setting structured logs value Adds CloudSdk parameter for setting structured logs value Jun 21, 2017
@codecov-io
Copy link

codecov-io commented Jun 21, 2017

Codecov Report

Merging #426 into master will increase coverage by 0.64%.
The diff coverage is 50%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #426      +/-   ##
==========================================
+ Coverage   65.13%   65.78%   +0.64%     
==========================================
  Files          64       64              
  Lines        1761     1768       +7     
  Branches      272      274       +2     
==========================================
+ Hits         1147     1163      +16     
+ Misses        499      485      -14     
- Partials      115      120       +5
Impacted Files Coverage Δ
...oogle/cloud/tools/appengine/cloudsdk/CloudSdk.java 43.38% <50%> (+4.89%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f2941d0...1c83d0b. Read the comment docs.

@patflynn
Copy link
Contributor

this environment variable has always been present in cloud sdk?

@etanshaul
Copy link
Contributor Author

No it was added as part of the structured error changes. It made the 159 release.

@patflynn
Copy link
Contributor

Do we need to update the minimum cloud sdk version?

@etanshaul
Copy link
Contributor Author

No, not necessarily. Setting this env var on an earlier version of the SDK will have no effect.

Copy link
Contributor

@elharo elharo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tests?

* Sets structured json logs for the stderr output. Supported values include 'never' (default),
* 'always', 'terminal', etc.
*/
public Builder appCommandShowStructuredLogs(String appCommandShowStructuredLogs) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Name is unwieldy. Maybe just "useStructuredLogs"?

Copy link
Contributor Author

@etanshaul etanshaul Jun 21, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the name mimics the gcloud config var name show_structured_logs. This is the patter we've been using here for the other parameters. But of course this can be debated.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree the name isn't the best though; useStructuredLogs doesn't help much though because if you look at the values it accepts, the name should be something like setStructuredLogsScope or something like that

Copy link
Contributor

Choose a reason for hiding this comment

The 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.

Copy link
Contributor Author

@etanshaul etanshaul Jun 21, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the appCommand prefix, while ugly, is to show clearly that the scope of the parameter is for gcloud command execution (e.g. CloudSdk#runAppCommand as opposed to a dev server command or appcfg etc. which are also executed from the CloudSdk class

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.

@patflynn
Copy link
Contributor

hmm. If a client wants to show structured logs it's likely because they want to parse them. I'm not really a big fan of the parameter silently being ignored dependent on the user's Cloud SDK version. We have a pretty good notification UI for when the Cloud SDK needs to be updated for our plugins to work, I'd be OK with forcing them to come up to the version we need.

@elharo
Copy link
Contributor

elharo commented Jun 21, 2017

I agree we should update the minimum SDK version.

@etanshaul
Copy link
Contributor Author

@patflynn @elharo, bumped the min sdk version to 159

@etanshaul
Copy link
Contributor Author

I'm looking into how I can add unit tests for this.

@etanshaul
Copy link
Contributor Author

@elharo @patflynn see 1a46a29 for unit tests

@etanshaul
Copy link
Contributor Author

@patflynn @elharo, any other changes you'd like for this?

String appCommandOutputFormat, ProcessRunner processRunner,
@Nullable String appCommandOutputFormat,
@Nullable String appCommandShowStructuredLogs,
ProcessRunner processRunner,
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

they are not nullable

Copy link
Contributor Author

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..

Copy link
Contributor Author

@etanshaul etanshaul Jun 23, 2017

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.

patflynn
patflynn previously approved these changes Jun 23, 2017
@etanshaul
Copy link
Contributor Author

@patflynn or @elharo can I please get another review / approval? my last commit auto dismissed the last approval

@etanshaul etanshaul merged commit aaa59dd into master Jun 26, 2017
@etanshaul etanshaul deleted the structured-logs branch June 26, 2017 14:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support gcloud structured logging
5 participants