Skip to content
This repository has been archived by the owner on Aug 24, 2022. It is now read-only.

PMM-9377 upgrade to grpc-gateway v2 #348

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions agentlocal/agent_local.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,22 @@ package agentlocal
import (
"bytes"
"context"
_ "expvar" // register /debug/vars
_ "expvar"
idoqo marked this conversation as resolved.
Show resolved Hide resolved
"html/template"
"log"
"net"
"net/http"
_ "net/http/pprof" // register /debug/pprof
_ "net/http/pprof"
idoqo marked this conversation as resolved.
Show resolved Hide resolved
"os"
"strconv"
"strings"
"sync"
"time"

grpc_gateway "github.com/grpc-ecosystem/grpc-gateway/runtime"
grpc_gateway "github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
"github.com/percona/pmm/api/agentlocalpb"
"github.com/percona/pmm/api/agentpb"
pmmerrors "github.com/percona/pmm/utils/errors"
"github.com/percona/pmm/version"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/collectors"
Expand All @@ -44,6 +45,7 @@ import (
"google.golang.org/grpc/credentials/insecure"
"google.golang.org/grpc/reflection"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/encoding/protojson"
"google.golang.org/protobuf/types/known/durationpb"

"github.com/percona/pmm-agent/config"
Expand Down Expand Up @@ -271,11 +273,17 @@ func (s *Server) runJSONServer(ctx context.Context, grpcAddress string) {

proxyMux := grpc_gateway.NewServeMux(
grpc_gateway.WithMarshalerOption(grpc_gateway.MIMEWildcard, &grpc_gateway.JSONPb{
EmitDefaults: true,
Indent: " ",
OrigName: true,
MarshalOptions: protojson.MarshalOptions{
EmitUnpopulated: true,
Indent: " ",
UseProtoNames: true,
},
UnmarshalOptions: protojson.UnmarshalOptions{
DiscardUnknown: true,
},
}),
)
grpc_gateway.WithErrorHandler(pmmerrors.PMMHTTPErrorHandler))

opts := []grpc.DialOption{
grpc.WithTransportCredentials(insecure.NewCredentials()),
grpc.WithBlock(),
Expand Down
6 changes: 3 additions & 3 deletions commands/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func checkStatus(configFilepath string, l *logrus.Entry) (string, bool) {
case *agent_local.StatusDefault:
msg := fmt.Sprintf("HTTP code %d", err.Code())
if err.Payload != nil {
msg = fmt.Sprintf("%s (gRPC code %d, HTTP code %d)", err.Payload.Error, err.Payload.Code, err.Code())
msg = fmt.Sprintf("%s (gRPC code %d, HTTP code %d)", err.Payload.Message, err.Payload.Code, err.Code())
}
fmt.Printf("pmm-agent is running, but status check failed: %s.\n", msg)
os.Exit(1)
Expand Down Expand Up @@ -140,7 +140,7 @@ func register(cfg *config.Config, l *logrus.Entry) {
if err != nil {
msg := err.Error()
if e, _ := err.(*node.RegisterNodeDefault); e != nil {
msg = e.Payload.Error + ""
msg = e.Payload.Message + ""
switch e.Code() {
case http.StatusConflict:
msg += " If you want override node, use --force option"
Expand All @@ -167,7 +167,7 @@ func reload(l *logrus.Entry) {
err := localReload()
l.Debugf("Reload error: %#v", err)
if err, _ := err.(*agent_local.ReloadDefault); err != nil && err.Code() == int(codes.FailedPrecondition) {
fmt.Printf("Failed to reload configuration: %s.\n", err.Payload.Error)
fmt.Printf("Failed to reload configuration: %s.\n", err.Payload.Message)
os.Exit(1)
}

Expand Down
7 changes: 3 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ require (
github.com/go-openapi/runtime v0.24.0
github.com/go-sql-driver/mysql v1.6.0
github.com/golang/protobuf v1.5.2
github.com/grpc-ecosystem/grpc-gateway v1.16.0
github.com/grpc-ecosystem/grpc-gateway/v2 v2.10.0
github.com/hashicorp/go-version v1.4.0
github.com/lib/pq v1.10.5
github.com/percona/exporter_shared v0.7.3
github.com/percona/go-mysql v0.0.0-20200630114833-b77f37c0bfa2
github.com/percona/percona-toolkit v3.2.1+incompatible
github.com/percona/pmm v0.0.0-20220505164356-d8b4097358e1
github.com/percona/pmm v0.0.0-20220518061335-59b17db5e3cc
github.com/pganalyze/pg_query_go v1.0.3
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.12.1
github.com/prometheus/client_golang v1.12.2
github.com/prometheus/common v0.34.0
github.com/sirupsen/logrus v1.8.1
github.com/stretchr/objx v0.4.0
Expand Down Expand Up @@ -61,7 +61,6 @@ require (
github.com/go-stack/stack v1.8.1 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/snappy v0.0.1 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.10.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/klauspost/compress v1.13.6 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
Expand Down
9 changes: 5 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69
github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe h1:lXe2qZdvpiX5WZkZR4hgp4KJVfY3nMkvmwbVkpv1rVY=
github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe/go.mod h1:8vg3r2VgvsThLBIFL93Qb5yWzgyZWhEmBwUJWevAkK0=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
github.com/golang/glog v1.0.0 h1:nfP3RFugxnNRyKgeWd4oI1nYvXpxrx8ck8ZrcizshdQ=
github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
github.com/golang/groupcache v0.0.0-20191227052852-215e87163ea7/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
Expand Down Expand Up @@ -232,7 +233,6 @@ github.com/google/uuid v1.1.2 h1:EVhdT+1Kseyi1/pUmXKaFxYsDNy9RQYkMWRH68J/W7Y=
github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg=
github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk=
github.com/grpc-ecosystem/grpc-gateway v1.16.0 h1:gmcG1KaJ57LophUzW0Hy8NmPhnMZb4M0+kPpLofRdBo=
github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.10.0 h1:ESEyqQqXXFIcImj/BE8oKEX37Zsuceb2cZI+EL/zNCY=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.10.0/go.mod h1:XnLCLFp3tjoZJszVKjfpyAK6J8sYIcQXWQxmqLWF21I=
Expand Down Expand Up @@ -319,8 +319,8 @@ github.com/percona/go-mysql v0.0.0-20200630114833-b77f37c0bfa2 h1:0tQBti5FIrKfH3
github.com/percona/go-mysql v0.0.0-20200630114833-b77f37c0bfa2/go.mod h1:/SGLf9OMxlnK6jq4mkFiImBcJXXk5jwD+lDrwDaGXcw=
github.com/percona/percona-toolkit v3.2.1+incompatible h1:5jLvtZKcu9fDmaLRB8qA4bLR727t5iYyguHJJQTk9w0=
github.com/percona/percona-toolkit v3.2.1+incompatible/go.mod h1:netQWdWMaF1cnmwiIS+i5uyaqNXz46yNeM6HKkR6yeI=
github.com/percona/pmm v0.0.0-20220505164356-d8b4097358e1 h1:Iil3UzE49DPn4keMZ4apU396bzRJRQZvNGJc8jWRp08=
github.com/percona/pmm v0.0.0-20220505164356-d8b4097358e1/go.mod h1:k7HS59HPX33tmrSZGiNzUTYuLr0+a49F3BEZ48MAbuo=
github.com/percona/pmm v0.0.0-20220518061335-59b17db5e3cc h1:VrYuHDdtB12vhXZiKetQPEzXy3BFoYlu0fYpuyxbT0s=
github.com/percona/pmm v0.0.0-20220518061335-59b17db5e3cc/go.mod h1:e5xncX628/vtPf/BzjxwWO3/09jvQ3CSqik00Qrj8bY=
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
Expand All @@ -332,8 +332,9 @@ github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5Fsn
github.com/prometheus/client_golang v1.1.0/go.mod h1:I1FGZT9+L76gKKOs5djB6ezCbFQP1xR9D75/vuwEF3g=
github.com/prometheus/client_golang v1.7.1/go.mod h1:PY5Wy2awLA44sXw4AOSfFBetzPP4j5+D6mVACh+pe2M=
github.com/prometheus/client_golang v1.11.0/go.mod h1:Z6t4BnS23TR94PD6BsDNk8yVqroYurpAkEiz0P2BEV0=
github.com/prometheus/client_golang v1.12.1 h1:ZiaPsmm9uiBeaSMRznKsCDNtPCS0T3JVDGF+06gjBzk=
github.com/prometheus/client_golang v1.12.1/go.mod h1:3Z9XVyYiZYEO+YQWt3RD2R3jrbd179Rt297l4aS6nDY=
github.com/prometheus/client_golang v1.12.2 h1:51L9cDoUHVrXx4zWYlcLQIZ+d+VXHgqnYKkIuq4g/34=
github.com/prometheus/client_golang v1.12.2/go.mod h1:3Z9XVyYiZYEO+YQWt3RD2R3jrbd179Rt297l4aS6nDY=
github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo=
github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
Expand Down