-
Notifications
You must be signed in to change notification settings - Fork 224
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
Replace time.Time.String() with time.Time.Format() #1017
base: main
Are you sure you want to change the base?
Conversation
.github/workflows/draft-release.yaml
Outdated
@@ -6,6 +6,7 @@ on: | |||
- 'protocol/**' # Push events to matching protocol/foo/bar/v*, i.e. protocol/foo/bar/v1.0, protocol/foo/bar/v20.15.10 | |||
- 'observability/**' # Push events to matching observability/foo/bar/v* | |||
- 'sql/**' # Push events to matching sql/v* | |||
- 'binding/**' # Push events to matching binding/foo/bar/v* |
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.
nit: should be separate PR
README.md
Outdated
@@ -27,7 +27,7 @@ _Note:_ Supported go version: 1.14+ | |||
Add the module as dependency using go mod: | |||
|
|||
```shell | |||
go get github.com/cloudevents/sdk-go/v2@v2.4.1 | |||
go get github.com/cloudevents/sdk-go/v2@v2.5.0 |
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.
nit: should be separate PR (incl. the other ones)
/* | ||
Copyright 2021 The CloudEvents Authors | ||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
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.
nit: should be separate PR
v2/event/event_marshal.go
Outdated
stream.WriteString(eventContext.Time.String()) | ||
stream.WriteString(eventContext.Time.Format(time.RFC3339)) |
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 ran an example w/ Go 1.22 (same w/ Go 1.21) here: https://go.dev/play/p/NcMTqPu75fe
And I get:
2009-11-10 23:00:00 +0000 UTC m=+0.000000001
2009-11-10T23:00:00Z
Which could be considered a breaking change. WDYT?
cc/ @duglin
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'm ok with the breaking change. I'm more bothered that:
1 - it wasn't spec compliant before and no one noticed
2 - not a single testcase needed to be changed
I agree with splitting the upgrade stuff into a separate PR. But can we also get at least one testcase added that checks the format of the time
attribute and that it adheres to the CE spec (RFC3339) ?
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'll get to work on it! Thank you so much for the feedback!
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.
Cleaned up the PR. Currently working on test cases:)
a209c30
to
232dcc4
Compare
@MaryamTaj converted to draft, seems you're still working on this. Once ready for review, please just mark as "Ready for review" and ping us. |
@MaryamTaj any update on this? |
@duglin Hi Doug! I was running into some issues earlier, where all the tests pass locally but not on GitHub. I am going to try a new approach, and I'll let you know how it goes |
ok thanks for the update. |
@MaryamTaj any update on this? |
@duglin I think I'm running into a wall. I tried to resolve as many errors as I could. |
@MaryamTaj I push a commit - see what you think. |
ping @MaryamTaj |
@duglin Thank you so much for helping me out! I'm going through, and understanding how you resolved the issue. I will sign my commits to pass the DCO. |
Glad it's sorted out! Before we merge, can you please squash/clean up commits into one? |
@@ -13,7 +13,7 @@ import ( | |||
"time" | |||
|
|||
cloudevents "github.com/cloudevents/sdk-go/v2" | |||
"github.com/cloudevents/sdk-go/v2/types" | |||
// "github.com/cloudevents/sdk-go/v2/types" |
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.
why comment out and not remove?
@duglin do we consider this PR a breaking change for users? I understand our code was broken, so this would be a fix - but still could be an issue impacting downstream users? |
|
Yes it is a breaking change. Some options: I like 3. Also, I think we need a test that checks the serialization of the timestamp IS actually the right format, not just that the sent and received values look the same. Unless I'm missing a test that already covers this. |
Signed-off-by: MaryamTaj <[email protected]>
Signed-off-by: Doug Davis <[email protected]>
I signed off and squashed all the commits into one. I also went through the codebase. Would v2/types/timestamp_test.go check the serialization of the timestamp is actually the right format? |
I'm guessing no since you didn't need to change any test in there as part of this PR. At least some test should have failed as a result of your change... hence I think we need a new test that would pass w/o your change in v2/event/event_marshal.go but would fail with it.... then you can "fix" the test to fail w/o your change, and pass with it. |
Yes, the existing tests might not detect it because if the producer is updated with the new semantics, the consumer will see automatically the new behavior. A test showing a producer with the old semantics and a consumer with the new behavior should fail with this change IIUC. I also like option (3), but strictly speaking it requires a MAJOR version change in our semver scheme which doesn't feel justified. And my concern is that at the scale this SDK is used, consumers might not detect it right away? |
I agree that a major version bump doesn't feel right, especially if we want to consider this a "fix" rather than a new feature. One option is to do 2 and 3, meaning:
At least then people had warnings and could migrate to the new format (turn on the flag) in prep for the final step at their own pace. |
@@ -120,7 +121,7 @@ func WriteJson(in *Event, writer io.Writer) error { | |||
if eventContext.Time != nil { | |||
stream.WriteMore() | |||
stream.WriteObjectField("time") | |||
stream.WriteString(eventContext.Time.String()) | |||
stream.WriteString(eventContext.Time.Format(time.RFC3339Nano)) |
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.
Why are we using Nano here, and the tests don't?
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.
If I'm remembering correctly, it was because there were some tests that needed more precision than just "seconds".
Resolves #987
Earlier, we used time.Time.String() to marshal time into a string. According to the go time.Time documentation however, time.Time.String() is only suitable for debugging purposes. This PR replaces time.Time.String with time.Time.Format() with RFC3339 to provide a stable serialized representation of time.