-
Notifications
You must be signed in to change notification settings - Fork 174
Add sdk name/version to task completions when unset or changed #2422
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
Add sdk name/version to task completions when unset or changed #2422
Conversation
@Test | ||
public void setsSdkNameAndVersionIfDifferentFromHistory() throws Throwable { |
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.
This test and the next I can't get to work because the setup in this suite isn't meant to work with more than one completion. I tried adjusting the mocks but it just led down dead end of the mock really not being suitable.
@Quinn-With-Two-Ns I can't find any tests that will allow me to really do what I want, which is just pass in some history and get a WFT response out that I can inspect, at this level. There are a bunch that operate at the workflow state machines level, but that's one level too deep. Any pointers would be welcome
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.
The tests in io/temporal/internal/statemachines
take in a history and you can inspect the result. All the tests there are focused on a particular state machine, but no reason you can't add tests that focus on the workflow task state machine.
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.
Problem is this logic isn't in the workflow task state machine, it's in ReplayWorkflowRunTaskHandler
, but, whatever. For the sake of making this easier to test with the existing stuff I'll just push it down and require one extra getter and just make sure it's set for completions with an integ test
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.
Ok, this is all fixed. The one remaining test at that level ensures the name/ver returned by state machines is actually attached to the response
if (!Strings.isNullOrEmpty(result.getWriteSdkVersion())) { | ||
metadata.setSdkVersion(result.getWriteSdkVersion()); | ||
} | ||
completedRequest.setSdkMetadata(metadata.build()); |
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.
Will this set an empty workflow task completed metadata even if there are no SDK flags and no SDK name/version to set? I'm worried it's put on task complete as is which means every event in history JSON dump will have {}
even if empty (there is difference between empty and null). I think this whole chunk of code should be surrounded by if (!result.getSdkFlags().isEmpty() || !Strings.isNullOrEmpty(result.getWriteSdkName()) || !Strings.isNullOrEmpty(result.getWriteSdkVersion())) {
.
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.
Yeah, it will do that, I'll change.
} | ||
flags.setSdkFlag(sdkFlag); | ||
} | ||
if (!Strings.isNullOrEmpty(completedEvent.getSdkMetadata().getSdkName())) { |
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.
Pardon my lack of Java proto knowledge, can you confirm (like some other lang proto impls) that a getter for a message returns an empty form of the message even if the underlying value is null?
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.
Yes it does
f643065
to
b2ddb5b
Compare
b2ddb5b
to
b0d54fe
Compare
.setSdkName(writeSdkName) | ||
.setSdkVersion(writeSdkVersion) |
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 am not sure proto builder setters for strings are null safe (a quick peek at some generated code shows that this may throw a NPE, should probably only call these setters if string is non-null and non-empty)
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.
God they aren't. That's absolutely silly.
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.
👍 May be showing a test coverage hole too. Alongside Quinn's suggestion of integration test, can we make sure there is some kind of test that would have failed if this code had not changed?
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.
Added the integ test but it'd require some very different test setup than what's available now to verify this particular scenario it seems. I don't have a good way to manually alter history (which I'd need to do) but still test this layer of the code. I think the other tests offer solid coverage
Can we add an integration test as well that tests this end to end , ideally the test workflow should contain multiple workflow tasks and evict the workflow from cache during the test |
What was changed
Write name and version to task completions
Why?
Parity
Checklist
Closes Update sdk-name and sdk-version in task-level metadata if changed #1838
How was this tested:
Added unit tests
Any docs updates needed?