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>
This commit is contained in:
Damien Neil 2024-10-01 13:15:23 -07:00
Родитель 0b78e172e8
Коммит c4345a7cbf
13 изменённых файлов: 50 добавлений и 107 удалений

3
go.mod
Просмотреть файл

@ -27,7 +27,6 @@ require (
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 @@ require (
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 @@ require (
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

2
go.sum
Просмотреть файл

@ -1358,8 +1358,6 @@ google.golang.org/grpc v1.45.0/go.mod h1:lN7owxKUQEqMfSyQikvvk5tf/6zMPsrK+ONuO11
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=

Просмотреть файл

@ -18,10 +18,10 @@ import (
"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).

Просмотреть файл

@ -21,14 +21,13 @@ import (
"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 @@ func (e *GitHubReview) Proto() *maintpb.GithubReview {
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 @@ func (r *GitHubRepo) newGithubReview(p *maintpb.GithubReview) *GitHubReview {
}
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 @@ func (e *GitHubIssueEvent) Proto() *maintpb.GithubIssueEvent {
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 @@ func (r *GitHubRepo) newGithubEvent(p *maintpb.GithubIssueEvent) *GitHubIssueEve
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 @@ func (d githubIssueDiffer) diffClosedAt(m *maintpb.GithubIssueMutation) bool {
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 @@ func (c *Corpus) processGithubIssueMutation(m *maintpb.GithubIssueMutation) {
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 @@ func (c *Corpus) processGithubIssueMutation(m *maintpb.GithubIssueMutation) {
// 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 @@ func (c *Corpus) processGithubIssueMutation(m *maintpb.GithubIssueMutation) {
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 @@ func (c *Corpus) processGithubIssueMutation(m *maintpb.GithubIssueMutation) {
}
}
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 @@ func (c *Corpus) processGithubIssueMutation(m *maintpb.GithubIssueMutation) {
}
}
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 @@ func (p *githubRepoPoller) syncCommentsOnIssue(ctx context.Context, issueNum int
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 @@ func (p *githubRepoPoller) syncCommentsOnIssue(ctx context.Context, issueNum int
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 @@ func (p *githubRepoPoller) syncEventsOnIssue(ctx context.Context, issueNum int32
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 @@ func (p *githubRepoPoller) syncReviewsOnPullRequest(ctx context.Context, issueNu
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
},

Просмотреть файл

@ -19,10 +19,9 @@ import (
"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 @@ func t3339(s string) time.Time {
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) {

Просмотреть файл

@ -13,9 +13,9 @@ import (
"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.

Просмотреть файл

@ -19,9 +19,6 @@ import (
"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 @@ func (c *Corpus) Check() error {
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 {

Просмотреть файл

@ -14,10 +14,9 @@ import (
"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 @@ func (mt mutationTest) test(t *testing.T, muts ...*maintpb.Mutation) {
}
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 {

Просмотреть файл

@ -24,11 +24,11 @@ import (
"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

Просмотреть файл

@ -15,7 +15,6 @@ import (
"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 @@ import (
"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 @@ func TestFindTryWork(t *testing.T) {
// 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)

Просмотреть файл

@ -18,10 +18,10 @@ import (
"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 @@ func callTryWork(args []string) error {
if err != nil {
return err
}
return printTextProto(res)
fmt.Print(prototext.Format(res))
return nil
}
func callListReleases(args []string) error {
@ -128,7 +129,8 @@ func callListReleases(args []string) error {
if err != nil {
return err
}
return printTextProto(res)
fmt.Print(prototext.Format(res))
return nil
}
func callGetDashboard(args []string) error {
@ -151,10 +153,6 @@ func callGetDashboard(args []string) error {
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
}

Просмотреть файл

@ -10,12 +10,11 @@ import (
"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 @@ var server = flag.String("server", godata.Server, "maintner server's /logs URL")
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 @@ func main() {
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)

Просмотреть файл

@ -23,10 +23,10 @@ import (
"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.