mirror of
https://github.com/hanzoai/tasks.git
synced 2026-10-04 02:04:03 +00:00
**What changed?** gogo/protobuf has been replaced with Google's official go compiler. **Why?** gogo/protobuf has been deprecated for some time and the community is moving on, building new tools (like vtproto) atop google's v2 compiler. **How did you test it?** `make test` **Potential risks** 1. The change from embedded gogo-generated-structs to google-generated-pointers-to-structs created a risk of nil pointer exceptions. I've fixed all the ones our tests found but it's possible there are more lurking in the new code. 2. This change may cause our performance to decrease. Certainly encoding/deconding of proto objects will become slower, but the overuse of pointers by the google compiler may negatively affect our overall performance. We'll need to keep an eye on the GC stats 3. This breaks the HTTP API. We will not support [shortand payload encoding](https://github.com/temporalio/proposals/blob/master/api/http-api.md#payload-formatting) in this first pass; that will come once this initial work is in testing. **Breaking changes for developers** - `*time.Time` in proto structs will now be [timestamppb.Timestamp](https://pkg.go.dev/google.golang.org/[email protected]/types/known/timestamppb#section-documentation) - `*time.Duration` will now be [durationpb.Duration](https://pkg.go.dev/google.golang.org/protobuf/types/known/durationpb) - V2-generated structs embed locks, so you cannot dereference them. `go vet` will scream at you about this. If you need a copy, use `proto.Clone`. - If the performance of this sucks then I will either update our code generator to add shallow-clone methods or hand-roll the ones we need - Proto enums will, when formatted to JSON, now be in `SCREAMING_SNAKE_CASE` rather than `PascalCase`. We decided (in discussion with the SDK team) that now was as good a time as any to rip the bandage off. - Proto objects, or objects embedding protos, cannot be compared using `reflect.DeepEqual` or _anything_ that uses it. This includes `testify` and `mock` equality testers! - You will need to use the `common/testing/protorequire`, `common/testing/protoassert`, or `common/testing/protomock` packages instead. I've implemented proto-compatible matchers and assertions there for all cases I've encountered - If you need `reflect.DeepEqual` for any reason you can use `go.temporal.io/api/temporalproto.DeepEqual` instead Note that history loading will not be impacted by the JSON changes: I rewrote history loading to dynamically fix incoming history JSON data (like all our other sdks); you can find this code in [my fork of our go API](https://github.com/tdeebswihart/temporal-api-go/blob/master/internal/temporalhistoryv1/load.go) alongside its tests. **🚨Sharp Edges Introduced🚨** Beware `*timestamppb.Timestamp.AsTime()`. If you need to extract a time value from a proto time (timestamppb) **always** make sure to check whether it's nil first. When the proto object is `nil` `AsTime()` will return a non-zero time at the proto epoch: UTC midnight on January 1, 1970. I've made this mistake multiple times during this transition and each time it's been a pain to debug **Is hotfix candidate?** No.
45 lines
1.8 KiB
Bash
Executable File
45 lines
1.8 KiB
Bash
Executable File
#!/usr/bin/env sh
|
|
set -eu
|
|
PROTO_OUT=api
|
|
PROTO_ROOT=${PROTO_ROOT:-proto}
|
|
PROTO_OUT=api
|
|
PROTO_OPTS="paths=source_relative:${PROTO_OUT}"
|
|
|
|
SED='sed -i'
|
|
case $(go env GOOS) in
|
|
darwin*)
|
|
SED="sed -i ''"
|
|
;;
|
|
esac
|
|
|
|
# Compile protos
|
|
find "${PROTO_ROOT}/internal" -name "*.proto" | sort | xargs -I{} dirname {} | uniq | while read -r dir; do
|
|
protoc --fatal_warnings \
|
|
-I="${PROTO_ROOT}/internal" \
|
|
-I="${PROTO_ROOT}/api" \
|
|
-I="${PROTO_ROOT}/dependencies" \
|
|
--go_out="${PROTO_OPTS}" \
|
|
--go-grpc_out="${PROTO_OPTS}" \
|
|
--go-helpers_out="${PROTO_OPTS}" \
|
|
"${dir}"/*
|
|
done
|
|
grep -ERl "^//\s+(- )?protoc[ -]" ${PROTO_OUT} | xargs -I{} sh -c "${SED} -E -e '\@//[[:space:]]*(- )?protoc@d' {}"
|
|
mv -f "${PROTO_OUT}/temporal/server/api/"* "${PROTO_OUT}" && rm -rf "${PROTO_OUT}"/temporal
|
|
|
|
# The generated enums in go are just plain terrible, so we fix them
|
|
# by removing the typename prefixes. We already made good choices with our enum
|
|
# names, so this shouldn't be an issue
|
|
# Note that we have to special case one of them because we didn't make a good choice of name for it
|
|
# We turn off -e because grep will fail if it doesn't find anything, which is fine. We don't care.
|
|
set +e
|
|
grep -R '^enum ' "${PROTO_ROOT}" | cut -d ' ' -f2 | while read -r enum; do
|
|
grep -Rl "${enum}" "${PROTO_OUT}" \
|
|
| grep -E "\.go" \
|
|
| xargs -I {} sh -c "${SED} -e 's/${enum}_\(.*\) ${enum}/\1 ${enum}/g' -e 's/\.${enum}_\(.*\)/.\1/g' {}"
|
|
done
|
|
sh -c "${SED} -e 's/BuildId_\(.*\) BuildId_State/\1 BuildId_State/g;s/return BuildId_\(.*\)/return \1/g' ${PROTO_OUT}/persistence/v1/task_queues.pb.go"
|
|
set -e
|
|
# We rely on the old temporal CamelCase JSON enums for presentation, so we rewrite the String method
|
|
# on all generated enums
|
|
find . -name "*.pb.go" -print0 | xargs -0 enumrewriter
|