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

[cli] Emit JSON events for updates via --json flag #8275

Merged
merged 9 commits into from
Oct 26, 2021
Merged

Conversation

komalali
Copy link
Member

@komalali komalali commented Oct 20, 2021

Description

This PR adds a --json flag to up, destroy and refresh and streams json events to stdout when the flag is passed.

For preview, the existing functionality of outputting a JSON object at the end of preview is maintained. However, the streaming output can be extended to preview by using the PULUMI_ENABLE_STREAMING_JSON_PREVIEW environment variable.

I added some tests, ready for review.

Follow-up Work

Fixes #2390

Checklist

  • I have added tests that prove my fix is effective or that my feature works
  • Yes, there are changes in this PR that warrants bumping the Pulumi Service API version

@komalali komalali requested a review from a team October 20, 2021 23:01
Copy link
Member

@iwahbe iwahbe left a comment

Choose a reason for hiding this comment

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

I agree that we should add testing, and I have a couple of very minor nits.
In general, LGTM.

pkg/backend/display/display.go Show resolved Hide resolved
pkg/backend/display/json.go Outdated Show resolved Hide resolved
@komalali komalali force-pushed the komalali/json branch 2 times, most recently from ed8a13f to 75f7303 Compare October 21, 2021 03:47
@@ -169,7 +171,7 @@ func newDestroyCmd() *cobra.Command {
Scopes: cancellationScopes,
})

if res == nil && len(*targets) == 0 {
if res == nil && len(*targets) == 0 && !jsonDisplay {
Copy link
Member

Choose a reason for hiding this comment

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

Good catch. 👍


return encoder.Encode(apiEvent)
}

func startEventLogger(events <-chan engine.Event, done chan<- bool, opts Options) (<-chan engine.Event, chan<- bool) {
Copy link
Member

Choose a reason for hiding this comment

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

How does --json interact with the event logger? I'm guessing from the way things are factored that they will work together just fine.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah they work together just fine, and in fact the test uses the event log to ensure all events from the event log are present in the stdout output.

@komalali komalali merged commit 2f433d6 into master Oct 26, 2021
@komalali komalali deleted the komalali/json branch October 26, 2021 23:21
@sudocovik
Copy link

This feature is especially important for Automation API when you want to customize the output. No need to parse text.
Can we expect this in (hopefully near) future to arrive in Automation API?

@komalali
Copy link
Member Author

komalali commented Nov 5, 2021

@Covik This is already available in automation api via engine events. Depending on which language you are using they can be accessed by either an onEvent callback (python, nodejs, dotnet) on the Up, Preview, etc. methods or by a channel (go)

See: #6441, #6442, #6443, #6444

@sudocovik
Copy link

@komalali Pardon my ignorance to properly do the research.

Thanks for the information!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support --json on pulumi {update|destroy|preview|refresh}
4 participants