Skip to content

Commit

Permalink
Replace deprecated github.com/golang/protobuf package
Browse files Browse the repository at this point in the history
This replaces usage of proto.{Float64,Int32,Int64,String,Uint32,Uint64},
which doesn't break the interface.

And remove usage of proto.MarshalTextString in wrap_test.go

Updates: #1175

Signed-off-by: Shengjing Zhu <zhsj@debian.org>
  • Loading branch information
zhsj committed Dec 22, 2022
1 parent e29ed9f commit 50863b4
Show file tree
Hide file tree
Showing 13 changed files with 33 additions and 56 deletions.
6 changes: 2 additions & 4 deletions prometheus/counter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,9 @@ import (
"testing"
"time"

//nolint:staticcheck // Ignore SA1019. Need to keep deprecated package for compatibility.
"github.com/golang/protobuf/proto"
"google.golang.org/protobuf/types/known/timestamppb"

dto "github.com/prometheus/client_model/go"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/types/known/timestamppb"
)

func TestCounterAdd(t *testing.T) {
Expand Down
9 changes: 3 additions & 6 deletions prometheus/desc.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,12 @@ import (
"sort"
"strings"

"github.com/cespare/xxhash/v2"

"github.com/prometheus/client_golang/prometheus/internal"

//nolint:staticcheck // Ignore SA1019. Need to keep deprecated package for compatibility.
"github.com/golang/protobuf/proto"
"github.com/prometheus/common/model"

"github.com/cespare/xxhash/v2"
dto "github.com/prometheus/client_model/go"
"github.com/prometheus/common/model"
"google.golang.org/protobuf/proto"
)

// Desc is the descriptor used by every Prometheus Metric. It is essentially
Expand Down
7 changes: 3 additions & 4 deletions prometheus/go_collector_latest.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,10 @@ import (
"strings"
"sync"

//nolint:staticcheck // Ignore SA1019. Need to keep deprecated package for compatibility.
"github.com/golang/protobuf/proto"
dto "github.com/prometheus/client_model/go"

"github.com/prometheus/client_golang/prometheus/internal"

dto "github.com/prometheus/client_model/go"
"google.golang.org/protobuf/proto"
)

const (
Expand Down
5 changes: 2 additions & 3 deletions prometheus/histogram.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@ import (
"sync/atomic"
"time"

//nolint:staticcheck // Ignore SA1019. Need to keep deprecated package for compatibility.
"github.com/golang/protobuf/proto"

dto "github.com/prometheus/client_model/go"

"google.golang.org/protobuf/proto"
)

// nativeHistogramBounds for the frac of observed values. Only relevant for
Expand Down
6 changes: 2 additions & 4 deletions prometheus/histogram_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,11 @@ import (
"testing/quick"
"time"

//nolint:staticcheck // Ignore SA1019. Need to keep deprecated package for compatibility.
"github.com/golang/protobuf/proto"
"google.golang.org/protobuf/types/known/timestamppb"

"github.com/prometheus/client_golang/prometheus/internal"

dto "github.com/prometheus/client_model/go"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/types/known/timestamppb"
)

func benchmarkHistogramObserve(w int, b *testing.B) {
Expand Down
6 changes: 2 additions & 4 deletions prometheus/metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,9 @@ import (
"strings"
"time"

//nolint:staticcheck // Ignore SA1019. Need to keep deprecated package for compatibility.
"github.com/golang/protobuf/proto"
"github.com/prometheus/common/model"

dto "github.com/prometheus/client_model/go"
"github.com/prometheus/common/model"
"google.golang.org/protobuf/proto"
)

var separatorByteSlice = []byte{model.SeparatorByte} // For convenient use with xxhash.
Expand Down
4 changes: 2 additions & 2 deletions prometheus/metric_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ import (
"math"
"testing"

//nolint:staticcheck // Ignore SA1019. Need to keep deprecated package for compatibility.
"github.com/golang/protobuf/proto"
dto "github.com/prometheus/client_model/go"

"google.golang.org/protobuf/proto"
)

func TestBuildFQName(t *testing.T) {
Expand Down
10 changes: 4 additions & 6 deletions prometheus/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,12 @@ import (
"sync"
"unicode/utf8"

"github.com/cespare/xxhash/v2"
//nolint:staticcheck // Ignore SA1019. Need to keep deprecated package for compatibility.
"github.com/golang/protobuf/proto"
"github.com/prometheus/common/expfmt"
"github.com/prometheus/client_golang/prometheus/internal"

"github.com/cespare/xxhash/v2"
dto "github.com/prometheus/client_model/go"

"github.com/prometheus/client_golang/prometheus/internal"
"github.com/prometheus/common/expfmt"
"google.golang.org/protobuf/proto"
)

const (
Expand Down
10 changes: 4 additions & 6 deletions prometheus/registry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,12 @@ import (
"testing"
"time"

dto "github.com/prometheus/client_model/go"

//nolint:staticcheck // Ignore SA1019. Need to keep deprecated package for compatibility.
"github.com/golang/protobuf/proto"
"github.com/prometheus/common/expfmt"

"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"

dto "github.com/prometheus/client_model/go"
"github.com/prometheus/common/expfmt"
"google.golang.org/protobuf/proto"
)

// uncheckedCollector wraps a Collector but its Describe method yields no Desc.
Expand Down
7 changes: 3 additions & 4 deletions prometheus/summary.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,10 @@ import (
"sync/atomic"
"time"

"github.com/beorn7/perks/quantile"
//nolint:staticcheck // Ignore SA1019. Need to keep deprecated package for compatibility.
"github.com/golang/protobuf/proto"

dto "github.com/prometheus/client_model/go"

"github.com/beorn7/perks/quantile"
"google.golang.org/protobuf/proto"
)

// quantileLabel is used for the label that defines the quantile in a
Expand Down
6 changes: 2 additions & 4 deletions prometheus/value.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,11 @@ import (
"time"
"unicode/utf8"

//nolint:staticcheck // Ignore SA1019. Need to keep deprecated package for compatibility.
"github.com/golang/protobuf/proto"
"google.golang.org/protobuf/types/known/timestamppb"

"github.com/prometheus/client_golang/prometheus/internal"

dto "github.com/prometheus/client_model/go"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/types/known/timestamppb"
)

// ValueType is an enumeration of metric types that represent a simple value.
Expand Down
6 changes: 2 additions & 4 deletions prometheus/wrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,10 @@ import (
"fmt"
"sort"

//nolint:staticcheck // Ignore SA1019. Need to keep deprecated package for compatibility.
"github.com/golang/protobuf/proto"
"github.com/prometheus/client_golang/prometheus/internal"

dto "github.com/prometheus/client_model/go"

"github.com/prometheus/client_golang/prometheus/internal"
"google.golang.org/protobuf/proto"
)

// WrapRegistererWith returns a Registerer wrapping the provided
Expand Down
7 changes: 2 additions & 5 deletions prometheus/wrap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ import (
"strings"
"testing"

//nolint:staticcheck // Ignore SA1019. Need to keep deprecated package for compatibility.
"github.com/golang/protobuf/proto"

dto "github.com/prometheus/client_model/go"
)

Expand Down Expand Up @@ -304,10 +301,10 @@ func TestWrap(t *testing.T) {
var want, got []string

for i, mf := range wantMF {
want = append(want, fmt.Sprintf("%3d: %s", i, proto.MarshalTextString(mf)))
want = append(want, fmt.Sprintf("%3d: %s", i, mf))
}
for i, mf := range gotMF {
got = append(got, fmt.Sprintf("%3d: %s", i, proto.MarshalTextString(mf)))
got = append(got, fmt.Sprintf("%3d: %s", i, mf))
}

t.Fatalf(
Expand Down

0 comments on commit 50863b4

Please sign in to comment.