Skip to content

Conversation

stephanos
Copy link
Contributor

@stephanos stephanos commented Aug 20, 2025

What changed?

Allow customizing the DataBlob encoding type via env variable.

Why?

Allow to switch from protobuf to JSON encoding for human-readable format to aid in debugging.

How did you test it?

  • built
  • run locally and tested manually
  • covered by existing tests
  • added new unit test(s)
  • added new functional test(s)

Potential risks

No behaviour change is expected.

@stephanos stephanos force-pushed the customizable-serialization branch 10 times, most recently from cf59fcf to 840ae27 Compare August 22, 2025 15:53
@stephanos stephanos changed the title Customizable DataBlob codec Customizable DataBlob encoding type Aug 22, 2025
@stephanos stephanos force-pushed the customizable-serialization branch 4 times, most recently from ca150aa to c70e7e4 Compare August 25, 2025 16:21
@@ -13,6 +13,7 @@ This document describes the project's testing setup, utilities and best practice
- `TEMPORAL_TEST_LOG_FORMAT`: Controls the output format for test logs. Available options: `json` or `console`
- `TEMPORAL_TEST_LOG_LEVEL`: Sets the verbosity level for test logging. Available levels: `debug`, `info`, `warn`, `error`, `fatal`
- `TEMPORAL_TEST_OTEL_OUTPUT`: Enables OpenTelemetry (OTEL) trace output for failed tests to the provided file path.
- `TEMPORAL_TEST_DATA_ENCODING`: If set, overrides the default data blob encoding. Available options: `json`, `proto3`.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Documentation.

@stephanos stephanos force-pushed the customizable-serialization branch 14 times, most recently from 528435d to b43ad9f Compare September 3, 2025 23:02
@stephanos stephanos force-pushed the customizable-serialization branch from b43ad9f to d02dff7 Compare September 3, 2025 23:04
func QueueStateFromBlob(data *commonpb.DataBlob) (*persistencespb.QueueState, error) {
result := &persistencespb.QueueState{}
return result, Decode(data, result)
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

^ moved all this into serializer.go.

SerializeEvents(batch []*historypb.HistoryEvent) (*commonpb.DataBlob, error)
DeserializeEvents(data *commonpb.DataBlob) ([]*historypb.HistoryEvent, error)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved deserialize methods to own interface.

func NewSerializer() Serializer {
return &serializerImpl{}
return NewSerializerWithEncoding(EncodingTypeFromEnv())
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The benefit from this approach that it'll always be the one from the env which I think is beneficial since there's no question of whether or not the env var takes effect.

@stephanos stephanos force-pushed the customizable-serialization branch 5 times, most recently from 069cc12 to bffaf1b Compare September 4, 2025 21:33
@@ -73,29 +78,25 @@ func (u *HistoryBranchUtilImpl) NewHistoryBranch(
func (u *HistoryBranchUtilImpl) ParseHistoryBranchInfo(
branchToken []byte,
) (*persistencespb.HistoryBranch, error) {
return serialization.HistoryBranchFromBlob(&commonpb.DataBlob{Data: branchToken, EncodingType: enumspb.ENCODING_TYPE_PROTO3})
Copy link
Contributor Author

Choose a reason for hiding this comment

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

So this was problematic since it hard-coded the encoding type as we are not storing it. I changed the interface instead to accept []byte and use the encoding type of the current serializer. This way it can also be JSON, if that's configured.

historyEvents, err := h.payloadSerializer.DeserializeEvents(&commonpb.DataBlob{
EncodingType: enumspb.ENCODING_TYPE_PROTO3,
Data: request.GetRequest().GetEvents().GetData(),
EncodingType: cmp.Or(eventsBlob.GetEncodingType(), enumspb.ENCODING_TYPE_PROTO3),
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 this so it uses the stored encoding type, but if not defined falls back to the hard-coded one. It was too risky too remove this entirely since I don't know if it's safe to assume that all have an encoding type specified.

@stephanos stephanos force-pushed the customizable-serialization branch 3 times, most recently from f0a8bd6 to a9939a2 Compare September 10, 2025 20:09
func TestNewServerWithJSONEncoding(t *testing.T) {
t.Setenv(serialization.SerializerDataEncodingEnvVar, "json")
startAndVerifyServer(t)
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Only new test I added. Basic validation of JSON encoding; that's why I extended startAndStopServer to do more than just start up.

@stephanos stephanos force-pushed the customizable-serialization branch 3 times, most recently from 2e73bfc to 6fd2bbb Compare September 10, 2025 20:17
@stephanos stephanos force-pushed the customizable-serialization branch from 6fd2bbb to ed60ec6 Compare September 10, 2025 20:18
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.

1 participant