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

Add support for UTC offset serialization/deserialization. #8

Open
wants to merge 14 commits into
base: main
Choose a base branch
from

Conversation

LinZhihao-723
Copy link
Member

References

Description

In our latest IR format, we decided to deprecate IANA timezone ID and represent timezone information using UTC offset (in milliseconds) directly. This PR introduces the necessary changes to achieve this goal:
For IR serialization, we provide an API for users to serialize a packet indicating the UTC offset changes. This can be used when the timezone of a stream changes. By default, the offset is 0 (which indicates the UTC timezone). The effect of this change is that each IR stream doesn't stick to one timezone anymore.
For IR deserialization, we use the deserializer to keep track of the current UTC offset. For each deserialized log event, the UTC offset is stored as a member along with log message and timestamp. The effect of this change is that the timezone information is associated with each individual log event now.
Notice that this PR doesn't deprecate the tzid in the stream initialization yet. This is because the tzid is not formally deprecated in the CLP core. We can have another PR to update the serializer API so it doesn't take a tzid for creation.

Validation performed

Add unit tests for new features. Ensure serialization -> deserialization works as expected.

@LinZhihao-723 LinZhihao-723 requested a review from davidlion July 10, 2024 20:05
Comment on lines 253 to 263
auto try_deserialize_utc_offset_changes(
BufferReader& ir_buf,
encoded_tag_t& tag,
Deserializer* deserializer
) -> IRErrorCode {
if (UtcOffsetChange != tag) {
return IRErrorCode::IRErrorCode_Success;
}

UtcOffset utc_offset{0};
while (UtcOffsetChange == tag) {
Copy link
Member

Choose a reason for hiding this comment

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

Lets just simplify this by taking out the while loop and drop the try part. If we find multiple offset change packets in a row it will get handled by the next log event while loop anyway, so lets just keep this function as simple as possible.

Copy link
Member

@davidlion davidlion left a comment

Choose a reason for hiding this comment

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

Notice that this PR doesn't deprecate the tzid in the stream initialization yet. This is because the tzid is not formally deprecated in the CLP core. We can have another PR to update the serializer API so it doesn't take a tzid for creation.

This is fair reasoning, but lets just drop the tzid support completely to simplify things as no one is depending on continued tzid support.

encoded_tag_t tag{};
epoch_time_ms_t timestamp{};
IRErrorCode err{};
std::optional<clp::UtcOffset> utc_offset;
Copy link
Member Author

Choose a reason for hiding this comment

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

Using std::optional for deserialized utc offsets, and set it only when we return success. This will ensure the state of deserializer is unchanged if an error happens.

Copy link
Member

Choose a reason for hiding this comment

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

Since it is possible to fail outside of deserialize_to_next_log_event (even when it returns success), this isn't actually a complete defense... We would need to only update the stored utc_offset after we decide to return an updated ir position.

@davidlion davidlion self-requested a review July 13, 2024 02:58
@kirkrodrigues
Copy link
Member

Shall we close this PR now that we're moving to the new IR format which works on the basis of IR units?

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