Skip to content

Commit

Permalink
scripts: upgrade protobuf dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
nicks committed May 11, 2022
1 parent 2b2478a commit 14d7af9
Show file tree
Hide file tree
Showing 24 changed files with 861 additions and 837 deletions.
3 changes: 2 additions & 1 deletion Dockerfile.toast
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ RUN apk add --no-cache \
# Newer versions of protoc-gen-go are stricter with the `go_package` argument, which is invalid in the K8s protobufs
# so we're currently locked to an older version as there's no way to suppress the error
# see https://github.com/golang/protobuf/issues/1316
RUN go install 'github.com/golang/protobuf/protoc-gen-go@v1.4.3'
RUN go install 'google.golang.org/protobuf/cmd/protoc-gen-go@v1.28.0'
RUN go install 'google.golang.org/grpc/cmd/protoc-gen-go-grpc@v1.2.0'
RUN go install 'github.com/google/wire/cmd/wire@v0.5.0'
RUN go install 'golang.org/x/tools/cmd/goimports@latest'
ARG GRPC_GATEWAY_VERSION="v1.16.0"
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ require (
github.com/ghodss/yaml v1.0.0
github.com/go-logr/logr v1.2.3
github.com/gogo/protobuf v1.3.2
github.com/golang/protobuf v1.5.2
github.com/google/go-cmp v0.5.8
github.com/google/uuid v1.3.0
github.com/google/wire v0.5.0
Expand Down Expand Up @@ -144,6 +143,7 @@ require (
github.com/gogo/googleapis v1.4.0 // indirect
github.com/golang-jwt/jwt/v4 v4.0.0 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/btree v1.0.1 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
Expand Down Expand Up @@ -264,5 +264,5 @@ replace (
go.opentelemetry.io/otel/trace => go.opentelemetry.io/otel/trace v0.20.0
go.opentelemetry.io/proto/otlp => go.opentelemetry.io/proto/otlp v0.7.0

k8s.io/apimachinery => github.com/tilt-dev/apimachinery v0.23.6-tilt-20220503
k8s.io/apimachinery => github.com/tilt-dev/apimachinery v0.23.6-tilt-20220511
)
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1546,8 +1546,8 @@ github.com/tetafro/godot v0.3.7/go.mod h1:/7NLHhv08H1+8DNj0MElpAACw1ajsCuf3TKNQx
github.com/tetafro/godot v0.4.2/go.mod h1:/7NLHhv08H1+8DNj0MElpAACw1ajsCuf3TKNQxA5S+0=
github.com/theupdateframework/notary v0.6.1 h1:7wshjstgS9x9F5LuB1L5mBI2xNMObWqjz+cjWoom6l0=
github.com/theupdateframework/notary v0.6.1/go.mod h1:MOfgIfmox8s7/7fduvB2xyPPMJCrjRLRizA8OFwpnKY=
github.com/tilt-dev/apimachinery v0.23.6-tilt-20220503 h1:Sz9yMKYXuCtngycEc+CAl0In28ng34SsPRbtS1MnDkQ=
github.com/tilt-dev/apimachinery v0.23.6-tilt-20220503/go.mod h1:BEuFMMBaIbcOqVIJqNZJXGFTP4W6AycEpb5+m/97hrM=
github.com/tilt-dev/apimachinery v0.23.6-tilt-20220511 h1:jnJqSPTJlKqiVlA4zy/fLgXlS1lTr88XCkeTIYC+9PU=
github.com/tilt-dev/apimachinery v0.23.6-tilt-20220511/go.mod h1:BEuFMMBaIbcOqVIJqNZJXGFTP4W6AycEpb5+m/97hrM=
github.com/tilt-dev/browser v0.0.1 h1:e+mFToX6A7pkMlGFrXW5VLvS7qS0HVbcXqmR0uPrWUA=
github.com/tilt-dev/browser v0.0.1/go.mod h1:2DaMt8P8xEqDFzxaAbraOig5iUmQdd1wtO1Tb6tODHA=
github.com/tilt-dev/buildkit v0.8.3-tilt-20220505 h1:a8aO6YvW5JQ7MW4ZI7qhFmSE+T7rUxNA2AbP53Qm+ZA=
Expand Down
4 changes: 1 addition & 3 deletions internal/cloud/io_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"testing"
"time"

"github.com/golang/protobuf/ptypes"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"google.golang.org/protobuf/types/known/timestamppb"
Expand Down Expand Up @@ -51,8 +50,7 @@ func TestWriteSnapshotTo(t *testing.T) {
}
}

startTime, err := ptypes.TimestampProto(now)
require.NoError(t, err)
startTime := timestamppb.New(now)
snapshot.View.TiltStartTime = startTime

err = WriteSnapshotTo(ctx, snapshot, buf)
Expand Down
17 changes: 11 additions & 6 deletions internal/hud/server/logs_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import (
"context"
"io"

"github.com/golang/protobuf/jsonpb"
"github.com/gorilla/websocket"
"github.com/pkg/errors"
"google.golang.org/protobuf/encoding/protojson"

"github.com/tilt-dev/tilt/internal/hud"
"github.com/tilt-dev/tilt/internal/hud/webview"
Expand All @@ -26,8 +26,8 @@ import (

type WebsocketReader struct {
conn WebsocketConn
marshaller jsonpb.Marshaler
unmarshaller jsonpb.Unmarshaler
marshaller protojson.MarshalOptions
unmarshaller protojson.UnmarshalOptions
persistent bool // whether to keep listening on websocket, or close after first message
handler ViewHandler
}
Expand All @@ -40,8 +40,8 @@ func newWebsocketReaderForLogs(conn WebsocketConn, persistent bool, resources []
func newWebsocketReader(conn WebsocketConn, persistent bool, handler ViewHandler) *WebsocketReader {
return &WebsocketReader{
conn: conn,
marshaller: jsonpb.Marshaler{},
unmarshaller: jsonpb.Unmarshaler{},
marshaller: protojson.MarshalOptions{},
unmarshaller: protojson.UnmarshalOptions{},
persistent: persistent,
handler: handler,
}
Expand Down Expand Up @@ -163,8 +163,13 @@ func (wsr *WebsocketReader) Listen(ctx context.Context) error {
}

func (wsr *WebsocketReader) handleTextMessage(_ context.Context, reader io.Reader) error {
content, err := io.ReadAll(reader)
if err != nil {
return errors.Wrap(err, "Reading websocket message")
}

v := &proto_webview.View{}
err := wsr.unmarshaller.Unmarshal(reader, v)
err = wsr.unmarshaller.Unmarshal(content, v)
if err != nil {
return errors.Wrap(err, "Unmarshalling websocket message")
}
Expand Down
8 changes: 5 additions & 3 deletions internal/hud/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import (
"net/http"
_ "net/http/pprof"

"google.golang.org/protobuf/encoding/protojson"
"google.golang.org/protobuf/types/known/timestamppb"

"github.com/tilt-dev/tilt/pkg/apis/core/v1alpha1"

"github.com/golang/protobuf/jsonpb"
"github.com/google/uuid"
"github.com/gorilla/mux"
_ "github.com/gorilla/websocket"
Expand Down Expand Up @@ -170,11 +170,13 @@ func (s *HeadsUpServer) SnapshotJSON(w http.ResponseWriter, req *http.Request) {
}

w.Header().Set("Content-Type", "application/json")
var m jsonpb.Marshaler
err = m.Marshal(w, snapshot)
var m protojson.MarshalOptions
content, err := m.Marshal(snapshot)
if err != nil {
http.Error(w, fmt.Sprintf("Error rendering view payload: %v", err), http.StatusInternalServerError)
return
}
_, _ = w.Write(content)
}

func (s *HeadsUpServer) HandleAnalyticsOpt(w http.ResponseWriter, req *http.Request) {
Expand Down
5 changes: 2 additions & 3 deletions internal/hud/server/websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@ import (
"time"

"github.com/grpc-ecosystem/grpc-gateway/runtime"
"google.golang.org/protobuf/types/known/timestamppb"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/util/workqueue"
ctrlclient "sigs.k8s.io/controller-runtime/pkg/client"

"github.com/golang/protobuf/ptypes/timestamp"

"github.com/tilt-dev/tilt/internal/hud/server/gorilla"
"github.com/tilt-dev/tilt/internal/hud/webview"
"github.com/tilt-dev/tilt/internal/store"
Expand Down Expand Up @@ -71,7 +70,7 @@ type WebsocketSubscriber struct {
dirtyUISession *v1alpha1.UISession
dirtyClusters map[string]*v1alpha1.Cluster

tiltStartTime *timestamp.Timestamp
tiltStartTime *timestamppb.Timestamp
clientCheckpoint logstore.Checkpoint
}

Expand Down
5 changes: 2 additions & 3 deletions internal/hud/server/websocket_reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,10 @@ func (f *websocketReaderFixture) start() {
}

func (f *websocketReaderFixture) sendView(v *proto_webview.View) {
buf := &bytes.Buffer{}
err := f.wsr.marshaller.Marshal(buf, v)
content, err := f.wsr.marshaller.Marshal(v)
assert.NoError(f.t, err)

f.conn.newMessageToRead(buf)
f.conn.newMessageToRead(bytes.NewReader(content))
}

func (f *websocketReaderFixture) assertHandlerCallCount(n int) {
Expand Down
12 changes: 3 additions & 9 deletions internal/hud/webview/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"sort"
"strings"

"github.com/golang/protobuf/ptypes"
"github.com/pkg/errors"
"google.golang.org/protobuf/types/known/timestamppb"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
Expand Down Expand Up @@ -89,10 +89,7 @@ func CompleteView(ctx context.Context, client ctrlclient.Client, st store.RStore

// We grandfather in TiltStartTime from the old protocol,
// because it tells the UI to reload.
start, err := ptypes.TimestampProto(s.TiltStartTime)
if err != nil {
return nil, err
}
start := timestamppb.New(s.TiltStartTime)
ret.TiltStartTime = start
ret.IsComplete = true

Expand All @@ -116,10 +113,7 @@ func LogUpdate(st store.RStore, checkpoint logstore.Checkpoint) (*proto_webview.

// We grandfather in TiltStartTime from the old protocol,
// because it tells the UI to reload.
start, err := ptypes.TimestampProto(s.TiltStartTime)
if err != nil {
return nil, err
}
start := timestamppb.New(s.TiltStartTime)
ret.TiltStartTime = start

return ret, nil
Expand Down
Loading

0 comments on commit 14d7af9

Please sign in to comment.