You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by lu...@apache.org on 2022/08/07 15:58:31 UTC

[skywalking-banyandb] 02/02: fix warning and lint

This is an automated email from the ASF dual-hosted git repository.

lujiajing pushed a commit to branch feature/update-go-1-19
in repository https://gitbox.apache.org/repos/asf/skywalking-banyandb.git

commit 43bd1f3b1c5595bd5114dedffd85768e6f423aae
Author: Megrez Lu <lu...@gmail.com>
AuthorDate: Sun Aug 7 23:58:16 2022 +0800

    fix warning and lint
---
 banyand/measure/measure_write_test.go | 4 ++--
 banyand/query/processor_test.go       | 4 ++--
 banyand/stream/stream_query_test.go   | 4 ++--
 banyand/tsdb/tsdb.go                  | 8 +++-----
 go.mod                                | 2 +-
 pkg/query/logical/common_test.go      | 6 +++---
 pkg/test/measure/traffic/traffic.go   | 1 +
 pkg/test/space.go                     | 5 ++---
 pkg/test/stream/traffic/traffic.go    | 7 ++++---
 9 files changed, 20 insertions(+), 21 deletions(-)

diff --git a/banyand/measure/measure_write_test.go b/banyand/measure/measure_write_test.go
index ec2f3eb..159de0b 100644
--- a/banyand/measure/measure_write_test.go
+++ b/banyand/measure/measure_write_test.go
@@ -22,9 +22,9 @@ import (
 	"encoding/json"
 	"time"
 
-	"github.com/golang/protobuf/jsonpb"
 	. "github.com/onsi/ginkgo/v2"
 	. "github.com/onsi/gomega"
+	"google.golang.org/protobuf/encoding/protojson"
 	"google.golang.org/protobuf/types/known/timestamppb"
 
 	commonv1 "github.com/apache/skywalking-banyandb/api/proto/banyandb/common/v1"
@@ -133,7 +133,7 @@ func writeDataWithBaseTime(baseTime time.Time, dataFile string, measure measure.
 		Expect(errMarshal).ShouldNot(HaveOccurred())
 		dataPointValue := &measurev1.DataPointValue{}
 		dataPointValue.Timestamp = timestamppb.New(baseTime.Add(time.Duration(i) * time.Minute))
-		Expect(jsonpb.UnmarshalString(string(rawDataPointValue), dataPointValue)).ShouldNot(HaveOccurred())
+		Expect(protojson.Unmarshal(rawDataPointValue, dataPointValue)).ShouldNot(HaveOccurred())
 		errInner := measure.Write(dataPointValue)
 		Expect(errInner).ShouldNot(HaveOccurred())
 	}
diff --git a/banyand/query/processor_test.go b/banyand/query/processor_test.go
index b72908b..e8bc07e 100644
--- a/banyand/query/processor_test.go
+++ b/banyand/query/processor_test.go
@@ -26,9 +26,9 @@ import (
 	"strconv"
 	"time"
 
-	"github.com/golang/protobuf/jsonpb"
 	. "github.com/onsi/ginkgo/v2"
 	. "github.com/onsi/gomega"
+	"google.golang.org/protobuf/encoding/protojson"
 	"google.golang.org/protobuf/types/known/timestamppb"
 
 	"github.com/apache/skywalking-banyandb/api/data"
@@ -158,7 +158,7 @@ func setUpStreamQueryData(dataFile string, stream stream.Stream) (baseTime time.
 		rawSearchTagFamily, errMarshal := json.Marshal(template)
 		Expect(errMarshal).ShouldNot(HaveOccurred())
 		searchTagFamily := &modelv1.TagFamilyForWrite{}
-		Expect(jsonpb.UnmarshalString(string(rawSearchTagFamily), searchTagFamily)).Should(Succeed())
+		Expect(protojson.Unmarshal(rawSearchTagFamily, searchTagFamily)).Should(Succeed())
 		e := &streamv1.ElementValue{
 			ElementId: strconv.Itoa(i),
 			Timestamp: timestamppb.New(baseTime.Add(500 * time.Millisecond * time.Duration(i))),
diff --git a/banyand/stream/stream_query_test.go b/banyand/stream/stream_query_test.go
index b0092c1..9735e4f 100644
--- a/banyand/stream/stream_query_test.go
+++ b/banyand/stream/stream_query_test.go
@@ -28,10 +28,10 @@ import (
 	"strconv"
 	"time"
 
-	"github.com/golang/protobuf/jsonpb"
 	. "github.com/onsi/ginkgo/v2"
 	. "github.com/onsi/gomega"
 	"github.com/pkg/errors"
+	"google.golang.org/protobuf/encoding/protojson"
 	"google.golang.org/protobuf/types/known/timestamppb"
 
 	"github.com/apache/skywalking-banyandb/api/common"
@@ -990,7 +990,7 @@ func setupQueryData(dataFile string, stream *stream) (baseTime time.Time) {
 		rawSearchTagFamily, errMarshal := json.Marshal(template)
 		Expect(errMarshal).ShouldNot(HaveOccurred())
 		searchTagFamily := &modelv1.TagFamilyForWrite{}
-		Expect(jsonpb.UnmarshalString(string(rawSearchTagFamily), searchTagFamily)).ShouldNot(HaveOccurred())
+		Expect(protojson.Unmarshal(rawSearchTagFamily, searchTagFamily)).ShouldNot(HaveOccurred())
 		e := &streamv1.ElementValue{
 			ElementId: strconv.Itoa(i),
 			Timestamp: timestamppb.New(baseTime.Add(500 * time.Millisecond * time.Duration(i))),
diff --git a/banyand/tsdb/tsdb.go b/banyand/tsdb/tsdb.go
index 34e84d2..20d8e6e 100644
--- a/banyand/tsdb/tsdb.go
+++ b/banyand/tsdb/tsdb.go
@@ -21,8 +21,6 @@ import (
 	"context"
 	"fmt"
 	"io"
-	"io/fs"
-	"io/ioutil"
 	"os"
 	"strconv"
 	"strings"
@@ -182,9 +180,9 @@ func OpenDatabase(ctx context.Context, opts DatabaseOpts) (Database, error) {
 		blockSize:   blockSize,
 	}
 	db.logger.Info().Str("path", opts.Location).Msg("initialized")
-	var entries []fs.FileInfo
+	var entries []os.DirEntry
 	var err error
-	if entries, err = ioutil.ReadDir(opts.Location); err != nil {
+	if entries, err = os.ReadDir(opts.Location); err != nil {
 		return nil, errors.Wrap(err, "failed to read directory contents failed")
 	}
 	thisContext := context.WithValue(ctx, logger.ContextKey, db.logger)
@@ -262,7 +260,7 @@ func loadDatabase(ctx context.Context, db *database) (Database, error) {
 type WalkFn func(suffix, absolutePath string) error
 
 func WalkDir(root, prefix string, walkFn WalkFn) error {
-	files, err := ioutil.ReadDir(root)
+	files, err := os.ReadDir(root)
 	if err != nil {
 		return errors.Wrapf(err, "failed to walk the database path: %s", root)
 	}
diff --git a/go.mod b/go.mod
index d9dd2d8..3b5b9d7 100644
--- a/go.mod
+++ b/go.mod
@@ -9,7 +9,7 @@ require (
 	github.com/dgraph-io/badger/v3 v3.2011.1
 	github.com/dgraph-io/ristretto v0.1.0
 	github.com/golang/mock v1.6.0
-	github.com/golang/protobuf v1.5.2
+	github.com/golang/protobuf v1.5.2 // indirect
 	github.com/google/go-cmp v0.5.8
 	github.com/google/uuid v1.3.0
 	github.com/klauspost/compress v1.15.6
diff --git a/pkg/query/logical/common_test.go b/pkg/query/logical/common_test.go
index cc616ea..8a61618 100644
--- a/pkg/query/logical/common_test.go
+++ b/pkg/query/logical/common_test.go
@@ -27,9 +27,9 @@ import (
 	"testing"
 	"time"
 
-	"github.com/golang/protobuf/jsonpb"
 	"github.com/stretchr/testify/assert"
 	"github.com/stretchr/testify/require"
+	"google.golang.org/protobuf/encoding/protojson"
 	"google.golang.org/protobuf/types/known/timestamppb"
 
 	commonv1 "github.com/apache/skywalking-banyandb/api/proto/banyandb/common/v1"
@@ -63,7 +63,7 @@ func setupQueryData(testing *testing.T, dataFile string, stream stream.Stream) (
 		rawSearchTagFamily, errMarshal := json.Marshal(template)
 		t.NoError(errMarshal)
 		searchTagFamily := &modelv1.TagFamilyForWrite{}
-		t.NoError(jsonpb.UnmarshalString(string(rawSearchTagFamily), searchTagFamily))
+		t.NoError(protojson.Unmarshal(rawSearchTagFamily, searchTagFamily))
 		e := &streamv1.ElementValue{
 			ElementId: strconv.Itoa(i),
 			Timestamp: timestamppb.New(baseTime.Add(500 * time.Millisecond * time.Duration(i))),
@@ -216,7 +216,7 @@ func setupMeasureQueryData(testing *testing.T, dataFile string, measure measure.
 		if dataPointValue.Timestamp == nil {
 			dataPointValue.Timestamp = timestamppb.New(baseTime.Add(time.Duration(i) * time.Minute))
 		}
-		t.NoError(jsonpb.UnmarshalString(string(rawDataPointValue), dataPointValue))
+		t.NoError(protojson.Unmarshal(rawDataPointValue, dataPointValue))
 		errInner := measure.Write(dataPointValue)
 		t.NoError(errInner)
 	}
diff --git a/pkg/test/measure/traffic/traffic.go b/pkg/test/measure/traffic/traffic.go
index 6d87c55..b7f746b 100644
--- a/pkg/test/measure/traffic/traffic.go
+++ b/pkg/test/measure/traffic/traffic.go
@@ -14,6 +14,7 @@
 // KIND, either express or implied.  See the License for the
 // specific language governing permissions and limitations
 // under the License.
+
 package traffic
 
 import (
diff --git a/pkg/test/space.go b/pkg/test/space.go
index 8fafdb3..9e9e64a 100644
--- a/pkg/test/space.go
+++ b/pkg/test/space.go
@@ -19,7 +19,6 @@ package test
 
 import (
 	"fmt"
-	"io/ioutil"
 	"os"
 
 	"github.com/stretchr/testify/require"
@@ -27,7 +26,7 @@ import (
 
 func Space(t *require.Assertions) (tempDir string, deferFunc func()) {
 	var tempDirErr error
-	tempDir, tempDirErr = ioutil.TempDir("", "banyandb-test-*")
+	tempDir, tempDirErr = os.MkdirTemp("", "banyandb-test-*")
 	t.Nil(tempDirErr)
 	return tempDir, func() {
 		if err := os.RemoveAll(tempDir); err != nil {
@@ -37,7 +36,7 @@ func Space(t *require.Assertions) (tempDir string, deferFunc func()) {
 }
 
 func NewSpace() (tempDir string, deferFunc func(), err error) {
-	tempDir, err = ioutil.TempDir("", "banyandb-test-*")
+	tempDir, err = os.MkdirTemp("", "banyandb-test-*")
 	return tempDir, func() {
 		if err = os.RemoveAll(tempDir); err != nil {
 			_, _ = fmt.Fprintf(os.Stderr, "Error while removing dir: %v\n", err)
diff --git a/pkg/test/stream/traffic/traffic.go b/pkg/test/stream/traffic/traffic.go
index d57645b..93ac164 100644
--- a/pkg/test/stream/traffic/traffic.go
+++ b/pkg/test/stream/traffic/traffic.go
@@ -14,6 +14,7 @@
 // KIND, either express or implied.  See the License for the
 // specific language governing permissions and limitations
 // under the License.
+
 package traffic
 
 import (
@@ -30,7 +31,7 @@ import (
 	"time"
 
 	"github.com/dgraph-io/ristretto/z"
-	"github.com/golang/protobuf/jsonpb"
+	"google.golang.org/protobuf/encoding/protojson"
 	"google.golang.org/protobuf/proto"
 	"google.golang.org/protobuf/types/known/timestamppb"
 
@@ -44,7 +45,7 @@ import (
 
 var (
 	//go:embed searchable_template.json
-	content string
+	content []byte
 	l       = logger.GetLogger("test_stream_traffic")
 )
 
@@ -56,7 +57,7 @@ type TestCase struct {
 
 func SendWrites(ts TestCase) (*z.Closer, error) {
 	searchTagFamily := &modelv1.TagFamilyForWrite{}
-	err := jsonpb.UnmarshalString(content, searchTagFamily)
+	err := protojson.Unmarshal(content, searchTagFamily)
 	if err != nil {
 		l.Err(err).Msg("unmarshal template")
 		return nil, err