Skip to content

Commit

Permalink
[cleanup] A bunch of cleanup (cloudprober#603)
Browse files Browse the repository at this point in the history
- Replace "github.com/golang/protobuf/proto" with "google.golang.org/protobuf/proto" everywhere except probes.go and targets.go as new package doesn't support proto extensions the same way.
- Replace  google log "glog" with "log".
  • Loading branch information
manugarg authored Oct 26, 2023
1 parent 5d41109 commit a054ed6
Show file tree
Hide file tree
Showing 43 changed files with 122 additions and 116 deletions.
13 changes: 7 additions & 6 deletions contrib/gcp/cmd/bigquery_probe.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,14 @@ package main
import (
"context"
"fmt"
"log"

"flag"
"github.com/golang/glog"
"github.com/golang/protobuf/proto"

"github.com/cloudprober/cloudprober/contrib/gcp/bigquery"
serverpb "github.com/cloudprober/cloudprober/probes/external/proto"
"github.com/cloudprober/cloudprober/probes/external/serverutils"
"google.golang.org/protobuf/proto"
)

var (
Expand All @@ -54,14 +55,14 @@ func main() {
flag.Parse()

if *projectID == "" {
glog.Exitf("--project_id must be specified")
log.Fatalf("--project_id must be specified")
}

dstTable := *table
ctx := context.Background()
runner, err := bigquery.NewRunner(ctx, *projectID)
if err != nil {
glog.Fatal(err)
log.Fatal(err)
}

if *serverMode {
Expand All @@ -70,7 +71,7 @@ func main() {
opts := parseProbeRequest(request)
if val, ok := opts["table"]; ok {
dstTable = val
glog.Infof("--table set to %q by ProbeRequest config", val)
log.Printf("--table set to %q by ProbeRequest config", val)
}
payload, err := bigquery.Probe(ctx, runner, dstTable)
reply.Payload = proto.String(payload)
Expand All @@ -82,7 +83,7 @@ func main() {

payload, err := bigquery.Probe(ctx, runner, dstTable)
if err != nil {
glog.Fatal(err)
log.Fatal(err)
}
fmt.Println(payload)

Expand Down
1 change: 1 addition & 0 deletions docs/content/docs/how-to/alerting/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ currently supports the following notification targets:
- [Opsgenie](/docs/config/alerting/#cloudprober_alerting_Opsgenie)
- [Slack](/docs/config/alerting/#cloudprober_alerting_Slack)
- [Command](/docs/config/alerting/#cloudprober_alerting_NotifyConfig)
- [HTTP](/docs/config/alerting/#cloudprober_alerting_NotifyConfig)
Configuration documentation (linked above) has more details on each of them.
Expand Down
2 changes: 1 addition & 1 deletion examples/external/redis_probe.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ import (

epb "github.com/cloudprober/cloudprober/probes/external/proto"
"github.com/cloudprober/cloudprober/probes/external/serverutils"
"github.com/golang/protobuf/proto"
"github.com/hoisie/redis"
"google.golang.org/protobuf/proto"
)

var server = flag.Bool("server", false, "Whether to run in server mode")
Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ require (
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.12.11
github.com/aws/aws-sdk-go-v2/service/cloudwatch v1.18.3
github.com/fullstorydev/grpcurl v1.8.7
github.com/golang/glog v1.1.2
github.com/golang/protobuf v1.5.3
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510
github.com/google/uuid v1.3.1
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,6 @@ github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2
github.com/goccy/go-json v0.9.11 h1:/pAaQDLHEoCq/5FFmSKBswWmK6H0e8g4159Kc/X/nqk=
github.com/goccy/go-json v0.9.11/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
github.com/golang/glog v1.1.2 h1:DVjP2PbBOzHyzA+dn3WhHIq4NdVu3Q+pvivFICf/7fo=
github.com/golang/glog v1.1.2/go.mod h1:zR+okUeTbrL6EL3xHUDxZuEtGv04p5shwip1+mL/rLQ=
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
10 changes: 5 additions & 5 deletions internal/rds/client/cmd/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ package main

import (
"fmt"
"log"
"strings"
"time"

"flag"

"github.com/golang/glog"
"github.com/golang/protobuf/proto"
"google.golang.org/protobuf/proto"

"github.com/cloudprober/cloudprober/internal/rds/client"
configpb "github.com/cloudprober/cloudprober/internal/rds/client/proto"
Expand All @@ -47,7 +47,7 @@ func main() {
flag.Parse()

if *project == "" {
glog.Exit("--project is a required paramater")
log.Fatal("--project is a required paramater")
}

serverName := *certServerName
Expand Down Expand Up @@ -90,7 +90,7 @@ func main() {
}
fParts := strings.SplitN(f, "=", 2)
if len(fParts) != 2 {
glog.Exitf("bad filter in --filters flag (%s): %s", *filtersF, f)
log.Fatalf("bad filter in --filters flag (%s): %s", *filtersF, f)
}
c.Request.Filter = append(c.Request.Filter, &pb.Filter{
Key: proto.String(fParts[0]),
Expand All @@ -100,7 +100,7 @@ func main() {

tgts, err := client.New(c, nil, &logger.Logger{})
if err != nil {
glog.Exit(err)
log.Fatal(err)
}
for {
fmt.Printf("%s\n", time.Now())
Expand Down
2 changes: 1 addition & 1 deletion internal/rds/gcp/rtc_variables.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ import (
pb "github.com/cloudprober/cloudprober/internal/rds/proto"
"github.com/cloudprober/cloudprober/internal/rds/server/filter"
"github.com/cloudprober/cloudprober/logger"
"github.com/golang/protobuf/proto"
"golang.org/x/oauth2/google"
runtimeconfig "google.golang.org/api/runtimeconfig/v1beta1"
"google.golang.org/protobuf/proto"
)

// rtcVar is an internal representation of the runtimeconfig (RTC) variables.
Expand Down
2 changes: 1 addition & 1 deletion internal/rds/gcp/rtc_variables_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import (
"time"

pb "github.com/cloudprober/cloudprober/internal/rds/proto"
"github.com/golang/protobuf/proto"
runtimeconfig "google.golang.org/api/runtimeconfig/v1beta1"
"google.golang.org/protobuf/proto"
)

type testVar struct {
Expand Down
4 changes: 2 additions & 2 deletions internal/rds/kubernetes/endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
pb "github.com/cloudprober/cloudprober/internal/rds/proto"
"github.com/cloudprober/cloudprober/internal/rds/server/filter"
"github.com/cloudprober/cloudprober/logger"
"github.com/golang/protobuf/proto"
"google.golang.org/protobuf/proto"
)

type epLister struct {
Expand Down Expand Up @@ -148,7 +148,7 @@ func (epi *epInfo) resources(portFilter *filter.RegexFilter, l *logger.Logger) (
resources = append(resources, &pb.Resource{
Name: proto.String(resName),
Ip: proto.String(addr.IP),
Port: proto.Int(port.Port),
Port: proto.Int32(int32(port.Port)),
Labels: labels,
})
}
Expand Down
2 changes: 1 addition & 1 deletion internal/rds/kubernetes/ingresses.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
pb "github.com/cloudprober/cloudprober/internal/rds/proto"
"github.com/cloudprober/cloudprober/internal/rds/server/filter"
"github.com/cloudprober/cloudprober/logger"
"github.com/golang/protobuf/proto"
"google.golang.org/protobuf/proto"
)

type ingressesLister struct {
Expand Down
2 changes: 1 addition & 1 deletion internal/rds/kubernetes/ingresses_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"testing"

pb "github.com/cloudprober/cloudprober/internal/rds/proto"
"github.com/golang/protobuf/proto"
"google.golang.org/protobuf/proto"
)

func testIngressInfo(k resourceKey, ingressIP, hostname string, labels map[string]string) *ingressInfo {
Expand Down
2 changes: 1 addition & 1 deletion internal/rds/kubernetes/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
pb "github.com/cloudprober/cloudprober/internal/rds/proto"
"github.com/cloudprober/cloudprober/internal/rds/server/filter"
"github.com/cloudprober/cloudprober/logger"
"github.com/golang/protobuf/proto"
"google.golang.org/protobuf/proto"
)

type servicesLister struct {
Expand Down
2 changes: 1 addition & 1 deletion internal/rds/kubernetes/services_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"testing"

pb "github.com/cloudprober/cloudprober/internal/rds/proto"
"github.com/golang/protobuf/proto"
"google.golang.org/protobuf/proto"
)

func testServiceInfo(name, ns, ip, publicIP, hostname string, labels map[string]string, ports []int) *serviceInfo {
Expand Down
16 changes: 8 additions & 8 deletions internal/rds/server/cmd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ package main
import (
"context"
"io/ioutil"
"log"
"net"

"flag"

"github.com/cloudprober/cloudprober/internal/rds/server"
configpb "github.com/cloudprober/cloudprober/internal/rds/server/proto"
"github.com/cloudprober/cloudprober/logger"
"github.com/golang/glog"
"github.com/golang/protobuf/proto"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
"google.golang.org/protobuf/encoding/prototext"
)

var (
Expand All @@ -33,16 +33,16 @@ func main() {
if *config != "" {
b, err := ioutil.ReadFile(*config)
if err != nil {
glog.Exit(err)
log.Fatal(err)
}
if err := proto.UnmarshalText(string(b), c); err != nil {
glog.Exitf("Error while parsing config protobuf %s: Err: %v", string(b), err)
if err := prototext.Unmarshal(b, c); err != nil {
log.Fatalf("Error while parsing config protobuf %s: Err: %v", string(b), err)
}
}

grpcLn, err := net.Listen("tcp", *addr)
if err != nil {
glog.Exitf("error while creating listener for default gRPC server: %v", err)
log.Fatalf("error while creating listener for default gRPC server: %v", err)
}

// Create a gRPC server for RDS service.
Expand All @@ -51,15 +51,15 @@ func main() {
if *tlsCertFile != "" {
creds, err := credentials.NewServerTLSFromFile(*tlsCertFile, *tlsKeyFile)
if err != nil {
glog.Exitf("error initializing gRPC server TLS credentials: %v", err)
log.Fatalf("error initializing gRPC server TLS credentials: %v", err)
}
serverOpts = append(serverOpts, grpc.Creds(creds))
}

grpcServer := grpc.NewServer(serverOpts...)
srv, err := server.New(context.Background(), c, nil, &logger.Logger{})
if err != nil {
glog.Exit(err)
log.Fatal(err)
}
srv.RegisterWithGRPC(grpcServer)

Expand Down
2 changes: 1 addition & 1 deletion internal/rds/server/filter/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"testing"

pb "github.com/cloudprober/cloudprober/internal/rds/proto"
"github.com/golang/protobuf/proto"
"google.golang.org/protobuf/proto"
)

func TestParseFilters(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion internal/rds/server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"testing"

pb "github.com/cloudprober/cloudprober/internal/rds/proto"
"github.com/golang/protobuf/proto"
"google.golang.org/protobuf/proto"
)

type testProvider struct {
Expand Down
2 changes: 1 addition & 1 deletion internal/servers/grpc/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ import (
"net"
"time"

"github.com/golang/protobuf/proto"
"google.golang.org/grpc"
"google.golang.org/grpc/health"
"google.golang.org/grpc/reflection"
"google.golang.org/protobuf/proto"

"github.com/cloudprober/cloudprober/config/runconfig"
configpb "github.com/cloudprober/cloudprober/internal/servers/grpc/proto"
Expand Down
2 changes: 1 addition & 1 deletion internal/servers/grpc/grpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ import (
pb "github.com/cloudprober/cloudprober/internal/servers/grpc/proto"
spb "github.com/cloudprober/cloudprober/internal/servers/grpc/proto"
"github.com/cloudprober/cloudprober/logger"
"github.com/golang/protobuf/proto"
"google.golang.org/grpc"
"google.golang.org/protobuf/proto"
)

var once sync.Once
Expand Down
9 changes: 4 additions & 5 deletions internal/servers/udp/cmd/udp.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,15 @@ package main

import (
"context"
"log"
"log/slog"

"github.com/cloudprober/cloudprober/internal/servers/udp"
configpb "github.com/cloudprober/cloudprober/internal/servers/udp/proto"
"github.com/cloudprober/cloudprober/logger"
"github.com/golang/protobuf/proto"
"google.golang.org/protobuf/proto"

"flag"

"github.com/golang/glog"
)

var (
Expand All @@ -46,7 +45,7 @@ func main() {
}
server, err := udp.New(context.Background(), config, logger.NewWithAttrs(slog.String("component", "UDP_"+*responseType)))
if err != nil {
glog.Fatalf("Error creating a new UDP server: %v", err)
log.Fatalf("Error creating a new UDP server: %v", err)
}
glog.Fatal(server.Start(context.Background(), nil))
log.Fatal(server.Start(context.Background(), nil))
}
2 changes: 1 addition & 1 deletion internal/servers/udp/udp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (

configpb "github.com/cloudprober/cloudprober/internal/servers/udp/proto"
"github.com/cloudprober/cloudprober/logger"
"github.com/golang/protobuf/proto"
"google.golang.org/protobuf/proto"
)

// Return true if the underlying error indicates a udp.Client timeout.
Expand Down
5 changes: 3 additions & 2 deletions metrics/payload/payload_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ import (

"github.com/cloudprober/cloudprober/metrics"
configpb "github.com/cloudprober/cloudprober/metrics/payload/proto"
"github.com/golang/protobuf/proto"
"google.golang.org/protobuf/encoding/prototext"
"google.golang.org/protobuf/proto"
)

var (
Expand All @@ -44,7 +45,7 @@ func parserForTest(t *testing.T, agg bool, additionalLabels string) *Parser {
`

var c configpb.OutputMetricsOptions
if err := proto.UnmarshalText(fmt.Sprintf(testConf, agg), &c); err != nil {
if err := prototext.Unmarshal([]byte(fmt.Sprintf(testConf, agg)), &c); err != nil {
t.Error(err)
}
if additionalLabels != "" {
Expand Down
Loading

0 comments on commit a054ed6

Please sign in to comment.