Skip to content

Commit

Permalink
Update from github.com/golang/protobuf to google.golang.org/protobuf (#…
Browse files Browse the repository at this point in the history
…382)

The old module, github.com/golang/protobuf, has been deprecated a while,
and the newer API has a slightly improved interface for the timestamp
type as well, avoiding a potential error that needs to be handled (that
we've traditionally ignored anyway in our own code).

Note there is a remaining caller of the old module in Google's appengine
module, which gets vendored in unnecessarily via x/oauth2 (golang/oauth2#615).

In passing, update the protoc-gen-go tool as well to the version hosted
in the new repository.

Depends on pganalyze/collector-snapshot#30
  • Loading branch information
lfittl authored Feb 28, 2023
1 parent a5ab6c1 commit 08cb680
Show file tree
Hide file tree
Showing 73 changed files with 1,256 additions and 1,710 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ docker_release:
output/pganalyze_collector/snapshot.pb.go: $(PROTOBUF_FILES)
ifdef PROTOC_VERSION
mkdir -p $(PWD)/bin
GOBIN=$(PWD)/bin go install github.com/golang/protobuf/protoc-gen-go
protoc --go_out=Mgoogle/protobuf/timestamp.proto=github.com/golang/protobuf/ptypes/timestamp:output/pganalyze_collector -I protobuf $(PROTOBUF_FILES)
GOBIN=$(PWD)/bin go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
protoc --go_out=. --go_opt=module=github.com/pganalyze/collector -I protobuf $(PROTOBUF_FILES)
else
@echo '👷 Warning: protoc not found, skipping protocol buffer regeneration (to install protoc check Makefile instructions in install_protoc step)'
endif
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ require (
github.com/go-ini/ini v1.62.0
github.com/go-ole/go-ole v0.0.0-20160708033836-be49f7c07711 // indirect
github.com/golang-jwt/jwt/v4 v4.1.0 // indirect
github.com/golang/protobuf v1.4.2
github.com/golang/protobuf v1.4.2 // indirect
github.com/gopherjs/gopherjs v0.0.0-20181103185306-d547d1d9531e // indirect
github.com/gorhill/cronexpr v0.0.0-20160318121724-f0984319b442
github.com/guregu/null v0.0.0-20160228005316-41961cea0328
Expand Down
13 changes: 6 additions & 7 deletions output/compact.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ import (
"strings"
"time"

"github.com/golang/protobuf/jsonpb"
"github.com/golang/protobuf/proto"
"github.com/golang/protobuf/ptypes"
"github.com/pganalyze/collector/output/pganalyze_collector"
"github.com/pganalyze/collector/state"
"github.com/pganalyze/collector/util"
uuid "github.com/satori/go.uuid"
"google.golang.org/protobuf/encoding/protojson"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/types/known/timestamppb"
)

func uploadAndSubmitCompactSnapshot(ctx context.Context, s pganalyze_collector.CompactSnapshot, grant state.Grant, server *state.Server, collectionOpts state.CollectionOpts, logger *util.Logger, collectedAt time.Time, quiet bool, kind string) error {
Expand All @@ -31,7 +31,7 @@ func uploadAndSubmitCompactSnapshot(ctx context.Context, s pganalyze_collector.C
s.SnapshotVersionMinor = 0
s.CollectorVersion = util.CollectorNameAndVersion
s.SnapshotUuid = snapshotUUID.String()
s.CollectedAt, _ = ptypes.TimestampProto(collectedAt)
s.CollectedAt = timestamppb.New(collectedAt)

data, err = proto.Marshal(&s)
if err != nil {
Expand Down Expand Up @@ -82,13 +82,12 @@ func debugCompactOutputAsJSON(logger *util.Logger, compressedData bytes.Buffer)
}

var out bytes.Buffer
var marshaler jsonpb.Marshaler
dataJSON, err := marshaler.MarshalToString(s)
dataJSON, err := protojson.Marshal(s)
if err != nil {
logger.PrintError("Failed to transform protocol buffers to JSON: %s", err)
return
}
json.Indent(&out, []byte(dataJSON), "", "\t")
json.Indent(&out, dataJSON, "", "\t")
logger.PrintInfo("Dry run - data that would have been sent will be output on stdout:\n")
fmt.Printf("%s\n", out.String())
}
Expand Down
13 changes: 6 additions & 7 deletions output/full.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ import (
"strings"
"time"

"github.com/golang/protobuf/jsonpb"
"github.com/golang/protobuf/proto"
"github.com/golang/protobuf/ptypes"
"github.com/pganalyze/collector/output/pganalyze_collector"
snapshot "github.com/pganalyze/collector/output/pganalyze_collector"
"github.com/pganalyze/collector/output/transform"
"github.com/pganalyze/collector/state"
"github.com/pganalyze/collector/util"
uuid "github.com/satori/go.uuid"
"google.golang.org/protobuf/encoding/protojson"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/types/known/timestamppb"
)

func SendFull(ctx context.Context, server *state.Server, collectionOpts state.CollectionOpts, logger *util.Logger, newState state.PersistedState, diffState state.DiffState, transientState state.TransientState, collectedIntervalSecs uint32) error {
Expand All @@ -46,7 +46,7 @@ func submitFull(ctx context.Context, s snapshot.FullSnapshot, server *state.Serv
s.SnapshotVersionMinor = 0
s.CollectorVersion = util.CollectorNameAndVersion
s.SnapshotUuid = snapshotUUID.String()
s.CollectedAt, _ = ptypes.TimestampProto(collectedAt)
s.CollectedAt = timestamppb.New(collectedAt)
s.CollectorLogSnapshotDisabled = server.CollectionStatus.LogSnapshotDisabled
s.CollectorLogSnapshotDisabledReason = server.CollectionStatus.LogSnapshotDisabledReason

Expand Down Expand Up @@ -99,13 +99,12 @@ func debugOutputAsJSON(logger *util.Logger, compressedData bytes.Buffer) {
}

var out bytes.Buffer
var marshaler jsonpb.Marshaler
dataJSON, err := marshaler.MarshalToString(s)
dataJSON, err := protojson.Marshal(s)
if err != nil {
logger.PrintError("Failed to transform protocol buffers to JSON: %s", err)
return
}
json.Indent(&out, []byte(dataJSON), "", "\t")
json.Indent(&out, dataJSON, "", "\t")
logger.PrintInfo("Dry run - data that would have been sent will be output on stdout:\n")
fmt.Printf("%s\n", out.String())
}
Expand Down
13 changes: 6 additions & 7 deletions output/pganalyze_collector/bloat_report.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 7 additions & 8 deletions output/pganalyze_collector/buffercache_report.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 08cb680

Please sign in to comment.