-
Notifications
You must be signed in to change notification settings - Fork 2.4k
fix(template): always marshal Alerts time to JSON with time-secfrac part #3602
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
base: main
Are you sure you want to change the base?
fix(template): always marshal Alerts time to JSON with time-secfrac part #3602
Conversation
Signed-off-by: Pavel Vondrak <pavel.vondrak@hotmail.cz>
b05a675 to
eca5e9b
Compare
|
Hi! 👋 I'm afraid this doesn't look like a bug to me. Go uses RFC3339 when representing time in JSON, and in the specification milliseconds are optional as the definition of It sounds like the software you are using to deserialize webhooks might not be RFC3339 compliant? |
|
Hi George, thank you for your reply. I'm aware of the RFC3339 and you are totally right. I'm sorry for wrongly marking the PR as a "fix". Nevertheless, I still believe having a fixed datetime format is worth because: In Alertmanager:
In general
PS: I've always thought that optionality of secfrac part in the RFC is meant for systems and contexts which doesn't utilize such precision at all |
|
Hi! 👋 I think the decision of whether or not to force millisecond precision in notifications will have to be made by the maintainers. However, a strong argument for making this change is that notifications are then consistent with the Alertmanager APIs, as you said. To reply to your points:
|
|
Hi George, thank you for your reply. Regarding your replies to my points The core idea of this PR is in fact written in RFC3339 itself in section 5.3. Rarely Used Options suggesting the inclusion of time-secfrac based on usage (either always or never) and not by a timestamp value.
|
|
I think Section 5.3 of RFC3339 is also a good argument to do this. I'm not sure if swagger codegen can be configured to use nanosecond precision, so I think either Alertmanager should use millisecond precision in notifications (at the loss of some precision) of we figure out how to add nanosecond precision to the swagger codegen. |
Fixes behavior of marshalling
time.Timetype to JSON which completely omits milliseconds whentime.Timeobject contains zero milliseconds.The default marshalling behavior can cause issues during deserialization of sent webhook notifications.
Example:
Alert.StartsAt is equal to
time.Date(2023, 11, 14, 15, 49, 10, 0, time.UTC)Expected JSON value:
2023-11-14T15:49:10.000ZActual value:
2023-11-14T15:49:10Z