maintner: use more recent protobuf module
Switch from the older github.com/golang/protobuf module
to the newer google.golang.org/protobuf one.
Mostly a no-op, but this will change the formatting of
text protos a bit.
Change-Id: I2ac90ad5f882c6429ab7c81d55496adbb1008542
Reviewed-on: https://go-review.googlesource.com/c/build/+/617275
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
diff --git a/go.mod b/go.mod
index b70c6b6..20de1dd 100644
--- a/go.mod
+++ b/go.mod
@@ -27,7 +27,6 @@
github.com/gliderlabs/ssh v0.3.3
github.com/go-sql-driver/mysql v1.5.0
github.com/golang-migrate/migrate/v4 v4.15.0-beta.3
- github.com/golang/protobuf v1.5.3
github.com/google/go-cmp v0.6.0
github.com/google/go-github/v48 v48.1.0
github.com/google/safehtml v0.0.3-0.20220430015336-00016cfeca15
@@ -67,7 +66,6 @@
google.golang.org/appengine v1.6.8-0.20221117013220-504804fb50de
google.golang.org/genproto/googleapis/api v0.0.0-20240814211410-ddb44dafa142
google.golang.org/grpc v1.67.1
- google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.3.0
google.golang.org/protobuf v1.34.2
gopkg.in/inf.v0 v0.9.1
rsc.io/github v0.3.1-0.20240418182958-01bebb0c456a
@@ -106,6 +104,7 @@
github.com/golang/glog v1.2.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/mock v1.6.0 // indirect
+ github.com/golang/protobuf v1.5.3 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/google/flatbuffers v2.0.8+incompatible // indirect
github.com/google/go-querystring v1.1.0 // indirect
diff --git a/go.sum b/go.sum
index 79b851e..cf841f1 100644
--- a/go.sum
+++ b/go.sum
@@ -1358,8 +1358,6 @@
google.golang.org/grpc v1.67.1 h1:zWnc1Vrcno+lHZCOofnIMvycFcc0QRGIzm9dhnDX68E=
google.golang.org/grpc v1.67.1/go.mod h1:1gLDyUQU7CTLJI90u3nXZ9ekeghjeM7pTDZlqFNg2AA=
google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.1.0/go.mod h1:6Kw0yEErY5E/yWrBtf03jp27GLLJujG4z/JK95pnjjw=
-google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.3.0 h1:rNBFJjBCOgVr9pWD7rs/knKL4FRTKgpZmsRfV214zcA=
-google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.3.0/go.mod h1:Dk1tviKTvMCz5tvh7t+fh94dhmQVHuCt2OzJB3CTW9Y=
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
diff --git a/maintner/git.go b/maintner/git.go
index 84cf109..47b1157 100644
--- a/maintner/git.go
+++ b/maintner/git.go
@@ -18,10 +18,10 @@
"strings"
"time"
- "github.com/golang/protobuf/proto"
"golang.org/x/build/internal/envutil"
"golang.org/x/build/internal/foreach"
"golang.org/x/build/maintner/maintpb"
+ "google.golang.org/protobuf/proto"
)
// GitHash is a git commit in binary form (NOT hex form).
diff --git a/maintner/github.go b/maintner/github.go
index 41754ab..66141fa 100644
--- a/maintner/github.go
+++ b/maintner/github.go
@@ -21,14 +21,13 @@
"strings"
"time"
- "github.com/golang/protobuf/ptypes"
- "github.com/golang/protobuf/ptypes/timestamp"
"github.com/google/go-github/v48/github"
"github.com/gregjones/httpcache"
"golang.org/x/build/maintner/maintpb"
"golang.org/x/oauth2"
"golang.org/x/sync/errgroup"
"golang.org/x/time/rate"
+ "google.golang.org/protobuf/types/known/timestamppb"
)
// xFromCache is the synthetic response header added by the httpcache
@@ -525,9 +524,7 @@
p.OtherJson = []byte(e.OtherJSON)
}
if !e.Created.IsZero() {
- if tp, err := ptypes.TimestampProto(e.Created); err == nil {
- p.Created = tp
- }
+ p.Created = timestamppb.New(e.Created)
}
if e.Actor != nil {
p.ActorId = e.Actor.ID
@@ -549,7 +546,7 @@
}
if p.Created != nil {
- e.Created, _ = ptypes.Timestamp(p.Created)
+ e.Created = p.Created.AsTime()
}
if len(p.OtherJson) > 0 {
// TODO: parse it and see if we've since learned how
@@ -636,9 +633,7 @@
p.OtherJson = []byte(e.OtherJSON)
}
if !e.Created.IsZero() {
- if tp, err := ptypes.TimestampProto(e.Created); err == nil {
- p.Created = tp
- }
+ p.Created = timestamppb.New(e.Created)
}
if e.Actor != nil {
p.ActorId = e.Actor.ID
@@ -703,7 +698,7 @@
To: p.RenameTo,
}
if p.Created != nil {
- e.Created, _ = ptypes.Timestamp(p.Created)
+ e.Created = p.Created.AsTime()
}
if len(p.OtherJson) > 0 {
// TODO: parse it and see if we've since learned how
@@ -1039,15 +1034,11 @@
return d.diffTimeField(&m.ClosedAt, d.a.getClosedAt(), d.b.GetClosedAt())
}
-func (d githubIssueDiffer) diffTimeField(dst **timestamp.Timestamp, memTime, githubTime time.Time) bool {
+func (d githubIssueDiffer) diffTimeField(dst **timestamppb.Timestamp, memTime, githubTime time.Time) bool {
if githubTime.IsZero() || memTime.Equal(githubTime) {
return false
}
- tproto, err := ptypes.TimestampProto(githubTime)
- if err != nil {
- panic(err)
- }
- *dst = tproto
+ *dst = timestamppb.New(githubTime)
return true
}
@@ -1280,11 +1271,7 @@
return
}
- var err error
- gi.Created, err = ptypes.Timestamp(m.Created)
- if err != nil {
- panic(err)
- }
+ gi.Created = m.Created.AsTime()
}
if m.NotExist != gi.NotExist {
gi.NotExist = m.NotExist
@@ -1297,18 +1284,10 @@
// Mutation is stale
// (ignoring Created since it *should* never update)
if m.Updated != nil {
- t, err := ptypes.Timestamp(m.Updated)
- if err != nil {
- panic(err)
- }
- gi.Updated = t
+ gi.Updated = m.Updated.AsTime()
}
if m.ClosedAt != nil {
- t, err := ptypes.Timestamp(m.ClosedAt)
- if err != nil {
- panic(err)
- }
- gi.ClosedAt = t
+ gi.ClosedAt = m.ClosedAt.AsTime()
}
if m.User != nil {
gi.User = c.github.getUser(m.User)
@@ -1379,21 +1358,17 @@
gc.User = c.github.getUser(cmut.User)
}
if cmut.Created != nil {
- gc.Created, _ = ptypes.Timestamp(cmut.Created)
- gc.Created = gc.Created.UTC()
+ gc.Created = cmut.Created.AsTime().UTC()
}
if cmut.Updated != nil {
- gc.Updated, _ = ptypes.Timestamp(cmut.Updated)
- gc.Updated = gc.Updated.UTC()
+ gc.Updated = cmut.Updated.AsTime().UTC()
}
if cmut.Body != "" {
gc.Body = cmut.Body
}
}
if m.CommentStatus != nil && m.CommentStatus.ServerDate != nil {
- if serverDate, err := ptypes.Timestamp(m.CommentStatus.ServerDate); err == nil {
- gi.commentsSyncedAsOf = serverDate.UTC()
- }
+ gi.commentsSyncedAsOf = m.CommentStatus.ServerDate.AsTime().UTC()
}
for _, emut := range m.Event {
@@ -1411,9 +1386,7 @@
}
}
if m.EventStatus != nil && m.EventStatus.ServerDate != nil {
- if serverDate, err := ptypes.Timestamp(m.EventStatus.ServerDate); err == nil {
- gi.eventsSyncedAsOf = serverDate.UTC()
- }
+ gi.eventsSyncedAsOf = m.EventStatus.ServerDate.AsTime().UTC()
}
for _, rmut := range m.Review {
@@ -1431,9 +1404,7 @@
}
}
if m.ReviewStatus != nil && m.ReviewStatus.ServerDate != nil {
- if serverDate, err := ptypes.Timestamp(m.ReviewStatus.ServerDate); err == nil {
- gi.reviewsSyncedAsOf = serverDate.UTC()
- }
+ gi.reviewsSyncedAsOf = m.ReviewStatus.ServerDate.AsTime().UTC()
}
}
@@ -1970,14 +1941,8 @@
p.logf("bogus comment: %v", ic)
continue
}
- created, err := ptypes.TimestampProto(*ic.CreatedAt)
- if err != nil {
- continue
- }
- updated, err := ptypes.TimestampProto(*ic.UpdatedAt)
- if err != nil {
- continue
- }
+ created := timestamppb.New(*ic.CreatedAt)
+ updated := timestamppb.New(*ic.UpdatedAt)
since = *ic.UpdatedAt // for next round
id := int64(*ic.ID)
@@ -2014,8 +1979,9 @@
p.c.mu.RUnlock()
if res.NextPage == 0 {
- sdp, _ := ptypes.TimestampProto(serverDate)
- mut.GithubIssue.CommentStatus = &maintpb.GithubIssueSyncStatus{ServerDate: sdp}
+ mut.GithubIssue.CommentStatus = &maintpb.GithubIssueSyncStatus{
+ ServerDate: timestamppb.New(serverDate),
+ }
morePages = false
}
@@ -2114,8 +2080,9 @@
if err != nil {
return nil, nil, fmt.Errorf("invalid server Date response: %v", err)
}
- sdp, _ := ptypes.TimestampProto(serverDate.UTC())
- mut.GithubIssue.EventStatus = &maintpb.GithubIssueSyncStatus{ServerDate: sdp}
+ mut.GithubIssue.EventStatus = &maintpb.GithubIssueSyncStatus{
+ ServerDate: timestamppb.New(serverDate.UTC()),
+ }
return is, ghResp, err
},
@@ -2358,8 +2325,9 @@
if err != nil {
return nil, nil, fmt.Errorf("invalid server Date response: %v", err)
}
- sdp, _ := ptypes.TimestampProto(serverDate.UTC())
- mut.GithubIssue.ReviewStatus = &maintpb.GithubIssueSyncStatus{ServerDate: sdp}
+ mut.GithubIssue.ReviewStatus = &maintpb.GithubIssueSyncStatus{
+ ServerDate: timestamppb.New(serverDate.UTC()),
+ }
return is, ghResp, err
},
diff --git a/maintner/github_test.go b/maintner/github_test.go
index 4066eb8..da15e33 100644
--- a/maintner/github_test.go
+++ b/maintner/github_test.go
@@ -19,10 +19,9 @@
"testing"
"time"
- "github.com/golang/protobuf/ptypes"
- "github.com/golang/protobuf/ptypes/timestamp"
"github.com/google/go-github/v48/github"
"golang.org/x/build/maintner/maintpb"
+ "google.golang.org/protobuf/types/known/timestamppb"
)
func TestParseGithubEvents(t *testing.T) {
@@ -1058,12 +1057,8 @@
return t.UTC()
}
-func p3339(s string) *timestamp.Timestamp {
- tp, err := ptypes.TimestampProto(t3339(s))
- if err != nil {
- panic(err)
- }
- return tp
+func p3339(s string) *timestamppb.Timestamp {
+ return timestamppb.New(t3339(s))
}
func TestParseGithubRefs(t *testing.T) {
diff --git a/maintner/logger.go b/maintner/logger.go
index 3ee7ff3..f4ec1ca 100644
--- a/maintner/logger.go
+++ b/maintner/logger.go
@@ -13,9 +13,9 @@
"sync"
"time"
- "github.com/golang/protobuf/proto"
"golang.org/x/build/maintner/maintpb"
"golang.org/x/build/maintner/reclog"
+ "google.golang.org/protobuf/proto"
)
// A MutationLogger logs mutations.
diff --git a/maintner/maintner.go b/maintner/maintner.go
index 9000857..41b1fd9 100644
--- a/maintner/maintner.go
+++ b/maintner/maintner.go
@@ -19,9 +19,6 @@
"sync"
"time"
- "github.com/golang/protobuf/ptypes"
- "github.com/golang/protobuf/ptypes/timestamp"
-
"golang.org/x/build/maintner/maintpb"
"golang.org/x/sync/errgroup"
"golang.org/x/time/rate"
@@ -134,16 +131,6 @@
return nil
}
-// mustProtoFromTime turns a time.Time into a *timestamp.Timestamp or panics if
-// in is invalid.
-func mustProtoFromTime(in time.Time) *timestamp.Timestamp {
- tp, err := ptypes.TimestampProto(in)
- if err != nil {
- panic(err)
- }
- return tp
-}
-
// requires c.mu be held for writing
func (c *Corpus) str(s string) string {
if v, ok := c.strIntern[s]; ok {
diff --git a/maintner/maintner_test.go b/maintner/maintner_test.go
index f2dbddc..873ed29 100644
--- a/maintner/maintner_test.go
+++ b/maintner/maintner_test.go
@@ -14,10 +14,9 @@
"time"
"github.com/davecgh/go-spew/spew"
- "github.com/golang/protobuf/ptypes"
- google_protobuf "github.com/golang/protobuf/ptypes/timestamp"
"github.com/google/go-github/v48/github"
"golang.org/x/build/maintner/maintpb"
+ "google.golang.org/protobuf/types/known/timestamppb"
)
var u1 = &GitHubUser{
@@ -65,13 +64,13 @@
}
var t1, t2 time.Time
-var tp1, tp2 *google_protobuf.Timestamp
+var tp1, tp2 *timestamppb.Timestamp
func init() {
t1, _ = time.Parse(time.RFC3339, "2016-01-02T15:04:00Z")
t2, _ = time.Parse(time.RFC3339, "2016-01-02T15:30:00Z")
- tp1, _ = ptypes.TimestampProto(t1)
- tp2, _ = ptypes.TimestampProto(t2)
+ tp1 = timestamppb.New(t1)
+ tp2 = timestamppb.New(t2)
}
func singleIssueGitHubCorpus() *Corpus {
diff --git a/maintner/maintnerd/gcslog/gcslog.go b/maintner/maintnerd/gcslog/gcslog.go
index 3900119..9cdb14d 100644
--- a/maintner/maintnerd/gcslog/gcslog.go
+++ b/maintner/maintnerd/gcslog/gcslog.go
@@ -24,11 +24,11 @@
"time"
"cloud.google.com/go/storage"
- "github.com/golang/protobuf/proto"
"golang.org/x/build/maintner"
"golang.org/x/build/maintner/maintpb"
"golang.org/x/build/maintner/reclog"
"google.golang.org/api/iterator"
+ "google.golang.org/protobuf/proto"
)
// targetObjectSize is the goal maximum size for each log segment on
diff --git a/maintner/maintnerd/maintapi/api_test.go b/maintner/maintnerd/maintapi/api_test.go
index f83231d..b23bf56 100644
--- a/maintner/maintnerd/maintapi/api_test.go
+++ b/maintner/maintnerd/maintapi/api_test.go
@@ -15,7 +15,6 @@
"testing"
"time"
- "github.com/golang/protobuf/proto"
"github.com/google/go-cmp/cmp"
"golang.org/x/build/gerrit"
"golang.org/x/build/maintner"
@@ -23,6 +22,8 @@
"golang.org/x/build/maintner/maintnerd/apipb"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
+ "google.golang.org/protobuf/encoding/prototext"
+ "google.golang.org/protobuf/proto"
"google.golang.org/protobuf/testing/protocmp"
)
@@ -78,7 +79,7 @@
// Just for interactive debugging. This is using live data.
// The stable tests are in TestTryWorkItem and TestTryBotStatus.
- t.Logf("Current:\n%v", proto.MarshalTextString(res))
+ t.Logf("Current:\n%v", prototext.Format(res))
t1 := time.Now()
res2, err := s.GoFindTryWork(context.Background(), req)
diff --git a/maintner/maintq/maintq.go b/maintner/maintq/maintq.go
index 8d69095..64ffefd 100644
--- a/maintner/maintq/maintq.go
+++ b/maintner/maintq/maintq.go
@@ -18,10 +18,10 @@
"strings"
"time"
- "github.com/golang/protobuf/proto"
"golang.org/x/build/maintner/maintnerd/apipb"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
+ "google.golang.org/protobuf/encoding/prototext"
)
var (
@@ -117,7 +117,8 @@
if err != nil {
return err
}
- return printTextProto(res)
+ fmt.Print(prototext.Format(res))
+ return nil
}
func callListReleases(args []string) error {
@@ -128,7 +129,8 @@
if err != nil {
return err
}
- return printTextProto(res)
+ fmt.Print(prototext.Format(res))
+ return nil
}
func callGetDashboard(args []string) error {
@@ -151,10 +153,6 @@
if err != nil {
return err
}
- return printTextProto(res)
-}
-
-func printTextProto(m proto.Message) error {
- tm := proto.TextMarshaler{Compact: false}
- return tm.Marshal(os.Stdout, m)
+ fmt.Print(prototext.Format(res))
+ return nil
}
diff --git a/maintner/maintwatch/maintwatch.go b/maintner/maintwatch/maintwatch.go
index ce5dd1b..17065cd 100644
--- a/maintner/maintwatch/maintwatch.go
+++ b/maintner/maintwatch/maintwatch.go
@@ -10,12 +10,11 @@
"flag"
"fmt"
"log"
- "os"
"time"
- "github.com/golang/protobuf/proto"
"golang.org/x/build/maintner"
"golang.org/x/build/maintner/godata"
+ "google.golang.org/protobuf/encoding/prototext"
)
var server = flag.String("server", godata.Server, "maintner server's /logs URL")
@@ -23,7 +22,6 @@
func main() {
flag.Parse()
- tm := proto.TextMarshaler{Compact: false}
for {
err := maintner.TailNetworkMutationSource(context.Background(), *server, func(e maintner.MutationStreamEvent) error {
if e.Err != nil {
@@ -32,7 +30,7 @@
return nil
}
fmt.Println()
- tm.Marshal(os.Stdout, e.Mutation)
+ fmt.Print(prototext.Format(e.Mutation))
return nil
})
log.Printf("tail error: %v; restarting\n", err)
diff --git a/maintner/netsource.go b/maintner/netsource.go
index 5d8d9f2..128222a 100644
--- a/maintner/netsource.go
+++ b/maintner/netsource.go
@@ -23,10 +23,10 @@
"strings"
"time"
- "github.com/golang/protobuf/proto"
"golang.org/x/build/maintner/internal/robustio"
"golang.org/x/build/maintner/maintpb"
"golang.org/x/build/maintner/reclog"
+ "google.golang.org/protobuf/proto"
)
// NewNetworkMutationSource returns a mutation source from a master server.