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

Make workflow show output json usable for replay #110

Merged
merged 5 commits into from
Mar 29, 2023
Merged

Conversation

feedmeapples
Copy link
Contributor

@feedmeapples feedmeapples commented Feb 11, 2023

What was changed

Made workflow show --output json produce replayable history

Depends on temporalio/tctl-kit#39

Why?

Allows exporting replayable history with syntax

workflow show --output json -w workflow_id > ~/history.json

Checklist

  1. Closes

  2. How was this tested:

E2E test here #171

  1. Any docs updates needed?

@feedmeapples feedmeapples marked this pull request as draft February 11, 2023 07:04
@feedmeapples feedmeapples marked this pull request as ready for review February 23, 2023 00:10
@feedmeapples feedmeapples changed the title Support exporting history for replay Make workflow show output json good for replay Feb 23, 2023
FlagInputSTQDefinition = "Optional Query input, in JSON format.\nFor multiple parameters, concatenate them and separate by space."
FlagInputFileSTQDefinition = "Passes optional Query input from a JSON file.\nIf there are multiple JSON, concatenate them and separate by space or newline.\n" + "Input from the command line will overwrite file input."
FlagInputSTQDefinition = "Optional Query input, in JSON format.\nFor multiple parameters, concatenate them and separate by space."
FlagInputFileSTQDefinition = "Passes optional Query input from a JSON file.\nIf there are multiple JSON, concatenate them and separate by space or newline.\n" + "Input from the command line will overwrite file input."
Copy link
Member

Choose a reason for hiding this comment

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

nit: why aren't we using multiline strings here for better readability?

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'll change in a new PR

cc @DJSanti

Comment on lines 295 to 300
var lastEvent historypb.HistoryEvent // used for print result of this run
var lastEvent historypb.HistoryEvent
Copy link
Member

Choose a reason for hiding this comment

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

Why remove the comment?

Copy link
Contributor Author

@feedmeapples feedmeapples Feb 23, 2023

Choose a reason for hiding this comment

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

if lastEvent usage changes later in code then the comment needs to be updated as well. Figured it's better to give a good name to the variable than commenting it (i think the name is already good, or another option executionResult )

Copy link
Contributor Author

Choose a reason for hiding this comment

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

changed to wfResult, should clarify the variable better and not need the comment?

hIter := sdkClient.GetWorkflowHistory(tcCtx, wid, rid, watch, enumspb.HISTORY_EVENT_FILTER_TYPE_ALL_EVENT)
iter := &historyIterator{iter: hIter, maxFieldLength: maxFieldLength, lastEvent: &lastEvent}
err = output.PrintIterator(c, iter, po)
iter := sdkClient.GetWorkflowHistory(tcCtx, wid, rid, watch, enumspb.HISTORY_EVENT_FILTER_TYPE_ALL_EVENT)
Copy link
Member

Choose a reason for hiding this comment

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

Watch and JSON aren't compatible, can we ensure they're not both set?

history := &historypb.History{}
history.Events = events

common.PrettyPrintJSONObject(history)
Copy link
Member

Choose a reason for hiding this comment

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

Just verifying that this will not generate pretty output when stdout is not a TTY.

Copy link
Member

@bergundy bergundy left a comment

Choose a reason for hiding this comment

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

This requires tests.

@feedmeapples feedmeapples force-pushed the export-history branch 2 times, most recently from 97ce5b8 to c00c2f4 Compare March 23, 2023 22:14
@bergundy bergundy changed the title Make workflow show output json good for replay Make workflow show output json usable for replay Mar 24, 2023
Copy link
Member

@bergundy bergundy left a comment

Choose a reason for hiding this comment

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

I mostly want to see a test for this but otherwise LGTM.

@feedmeapples
Copy link
Contributor Author

feedmeapples commented Mar 25, 2023

I mostly want to see a test for this but otherwise LGTM.

added a test here #171 separately as it requires temporaltest to exist in the server repo (and to not block the current PR). One more #170

@bergundy
Copy link
Member

I’d rather use the cli for the test server so we utilize it as much as possible

@feedmeapples
Copy link
Contributor Author

feedmeapples commented Mar 28, 2023

I’d rather use the cli for the test server so we utilize it as much as possible

i'm split between these options:

Ideally i would like integration tests to directly cover CLI dev server, the commands and options. To test one thing at a time instead of implicitly proxy testing CLI server in unrelated tests. I see your point though

update: changing to SDK based dev server

workflow/workflow_commands.go Outdated Show resolved Hide resolved
if err != nil {
fmt.Printf("Error when try to print pretty: %v", err)
fmt.Println(o)
fmt.Fprintf(w, "Error when try to print pretty: %v", err)
Copy link
Member

Choose a reason for hiding this comment

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

All fmt.Printf should be fmt.Fprintf. No?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes! i'll send separately to not mix

Co-authored-by: Alex Shtin <alex@shtin.com>
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.

3 participants