Files
tasks/develop/protoc.sh
Prathyush PVandStephan Behnke 2317be7056 Send raw history events from history to frontend service (#7342)
## What changed?
Change to send raw history blobs from history service to frontend
service. History service returns a new proto message that has a repeated
bytes history field.
This response is wire compatible with the original response which has
temporal.api.history.v1.History type for this field. This allows history
service to not deserialize events from this data blob. This considerably
reduces CPU usage.

History service still needs event_id and version decoded from history
events. For this we use a new proto message StrippedHistoryEvent which
has these two fields only. It takes considerably less CPU to decode
events to this struct.

## Why?
We have seen incidents of high history CPU usage when large number of
GetWorkflowExecutionHistory calls are made to workflows which has large
history. With this change we can reduce the CPU burden on history
service during this API call.

## How did you test it?
Existing unit and functional tests.

## Potential risks

## Documentation

## Is hotfix candidate?
2025-03-25 15:43:26 -07:00

51 lines
1.8 KiB
Bash
Executable File

#!/usr/bin/env bash
set -eu -o pipefail
color() { printf "\e[1;36m%s\e[0m\n" "$*"; }
api=$PROTO_OUT
new=$api.new
color "Generating protos..."
rm -rf "$new" && mkdir -p "$new"
$PROTOGEN \
--descriptor_set_in="$API_BINPB" \
--root="$PROTO_ROOT"/internal \
--rewrite-enum=BuildId_State:BuildId \
--output="$new" \
-p go-grpc_out=paths=source_relative:"$new" \
-p go-helpers_out=paths=source_relative:"$new"
color "Run goimports for proto files..."
$GOIMPORTS -w "$new"
color "Generate proto mocks..."
find "$new" -name service.pb.go -o -name service_grpc.pb.go | while read -r src; do
dst=$(echo "$src" | sed -e 's,service/,servicemock/,' -e 's,[.]go$,.mock.go,')
pkg=$(basename "$(dirname "$(dirname "$dst")")")
$MOCKGEN -copyright_file LICENSE -package "$pkg" -source "$src" -destination "$dst"
# Since we're generating mocks from files in incorrect locations, mockgen
# writes incorrect imports. Fix them manually. The awkward sed/rm invocation
# is to work on linux and macos.
sed -i.replaced "s,$new/temporal/server/,," "$dst"
rm -f "$dst.replaced"
done
color "Update license headers for proto files..."
go run ./cmd/tools/copyright/licensegen.go --scanDir "$new"
color "Modify history service server interface..."
sed -i.bak -e \
's/GetWorkflowExecutionHistory(context\.Context, \*GetWorkflowExecutionHistoryRequest) (\*GetWorkflowExecutionHistoryResponse, error)/GetWorkflowExecutionHistory(context.Context, *GetWorkflowExecutionHistoryRequest) (*GetWorkflowExecutionHistoryResponseWithRaw, error)/g' \
"$new"/temporal/server/api/historyservice/v1/service_grpc.pb.go && rm "$new"/temporal/server/api/historyservice/v1/service_grpc.pb.go.bak
color "Moving proto files into place..."
old=$api.old
[[ -d "$api" ]] && mv -f "$api" "$old"
mkdir -p "$api"
mv -f "$new"/temporal/server/api/* "$api"/
rm -rf "$new" "$old"