Skip to content

Commit

Permalink
Fix issues found by revive
Browse files Browse the repository at this point in the history
Signed-off-by: Gao Hongtao <hanahmily@gmail.com>
  • Loading branch information
hanahmily committed Dec 5, 2022
1 parent c3adea8 commit e8d655a
Show file tree
Hide file tree
Showing 135 changed files with 1,032 additions and 1,659 deletions.
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ linters-settings:
scope: toplevel
staticcheck:
go: "1.19"
checks: ["all", "-ST1000", "-ST1016", "-ST1020", "-ST1021", "-ST1022"]
stylecheck:
go: "1.19"
exhaustive:
Expand Down
19 changes: 16 additions & 3 deletions api/common/id.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,28 @@ import (
)

type (
// SeriesID identit fdf.
// SeriesID identity a series in a shard.
SeriesID uint64
ShardID uint32
ItemID uint64

// ShardID identity a shard in a tsdb.
ShardID uint32

// ItemID identity an item in a series.
ItemID uint64
)

// Marshal encodes series id to bytes.
func (s SeriesID) Marshal() []byte {
return convert.Uint64ToBytes(uint64(s))
}

// PositionKey is a context key to store the module position.
var PositionKey = contextPositionKey{}

type contextPositionKey struct{}

// Position is stored in the context.
// The logger could attach it for debugging.
type Position struct {
Module string
Database string
Expand All @@ -50,6 +58,7 @@ type Position struct {
KV string
}

// Labels converts Position to Prom Labels.
func (p Position) Labels() prometheus.Labels {
return prometheus.Labels{
"module": p.Module,
Expand All @@ -61,6 +70,7 @@ func (p Position) Labels() prometheus.Labels {
}
}

// SetPosition sets a position returned from fn to attach it to ctx, then return a new context.
func SetPosition(ctx context.Context, fn func(p Position) Position) context.Context {
val := ctx.Value(PositionKey)
var p Position
Expand All @@ -72,14 +82,17 @@ func SetPosition(ctx context.Context, fn func(p Position) Position) context.Cont
return context.WithValue(ctx, PositionKey, fn(p))
}

// Error wraps a error msg.
type Error struct {
msg string
}

// NewError returns a new Error.
func NewError(tpl string, args ...any) Error {
return Error{msg: fmt.Sprintf(tpl, args...)}
}

// Msg shows the string msg.
func (e Error) Msg() string {
return e.msg
}
8 changes: 8 additions & 0 deletions api/data/measure.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,29 @@ import (
"github.com/apache/skywalking-banyandb/pkg/bus"
)

// MeasureWriteKindVersion is the version tag of measure write kind.
var MeasureWriteKindVersion = common.KindVersion{
Version: "v1",
Kind: "measure-write",
}

// TopicMeasureWrite is the measure write topic.
var TopicMeasureWrite = bus.UniTopic(MeasureWriteKindVersion.String())

// MeasureQueryKindVersion is the version tag of measure query kind.
var MeasureQueryKindVersion = common.KindVersion{
Version: "v1",
Kind: "measure-query",
}

// TopicMeasureQuery is the measure query topic.
var TopicMeasureQuery = bus.BiTopic(MeasureQueryKindVersion.String())

// TopNQueryKindVersion is the version tag of top-n query kind.
var TopNQueryKindVersion = common.KindVersion{
Version: "v1",
Kind: "topN-query",
}

// TopicTopNQuery is the top-n query topic.
var TopicTopNQuery = bus.BiTopic(TopNQueryKindVersion.String())
5 changes: 5 additions & 0 deletions api/data/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,20 @@ import (
"github.com/apache/skywalking-banyandb/pkg/bus"
)

// StreamWriteKindVersion is the version tag of stream write kind.
var StreamWriteKindVersion = common.KindVersion{
Version: "v1",
Kind: "stream-write",
}

// TopicStreamWrite is the stream write topic.
var TopicStreamWrite = bus.UniTopic(StreamWriteKindVersion.String())

// StreamQueryKindVersion is the version tag of stream query kind.
var StreamQueryKindVersion = common.KindVersion{
Version: "v1",
Kind: "stream-query",
}

// TopicStreamQuery is the stream query topic.
var TopicStreamQuery = bus.BiTopic(StreamQueryKindVersion.String())
6 changes: 6 additions & 0 deletions api/event/measure.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,21 @@ import (
)

var (
// MeasureShardEventKindVersion is the version tag of measure shard event kind.
MeasureShardEventKindVersion = common.KindVersion{
Version: "v1",
Kind: "measure-event-shard",
}

// MeasureTopicShardEvent is the measure shard event publishing topic.
MeasureTopicShardEvent = bus.UniTopic(MeasureShardEventKindVersion.String())

// MeasureEntityEventKindVersion is the version tag of measure entity kind.
MeasureEntityEventKindVersion = common.KindVersion{
Version: "v1",
Kind: "measure-event-entity",
}

// MeasureTopicEntityEvent is the measure entity event publishing topic.
MeasureTopicEntityEvent = bus.UniTopic(MeasureEntityEventKindVersion.String())
)
6 changes: 6 additions & 0 deletions api/event/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,21 @@ import (
)

var (
// StreamShardEventKindVersion is the version tag of stream shard entity kind.
StreamShardEventKindVersion = common.KindVersion{
Version: "v1",
Kind: "stream-event-shard",
}

// StreamTopicShardEvent is the stream entity event publishing topic.
StreamTopicShardEvent = bus.UniTopic(StreamShardEventKindVersion.String())

// StreamEntityEventKindVersion is the version tag of stream entity kind.
StreamEntityEventKindVersion = common.KindVersion{
Version: "v1",
Kind: "stream-event-entity",
}

// StreamTopicEntityEvent is the stream entity event publishing topic.
StreamTopicEntityEvent = bus.UniTopic(StreamEntityEventKindVersion.String())
)
2 changes: 1 addition & 1 deletion banyand/kv/kv.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func TSSWithMemTableSize(sizeInBytes int64) TimeSeriesOptions {
}

// Iterator allows iterating the kv tables.
// TODO: use generic to provide a unique iterator
// TODO: use generic to provide a unique iterator.
type Iterator interface {
Next()
Rewind()
Expand Down
2 changes: 1 addition & 1 deletion banyand/liaison/grpc/registry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ func setupForRegistry() func() {
Expect(err).NotTo(HaveOccurred())
flags = append(flags, "--metadata-root-path="+metaPath, "--etcd-listen-client-url="+listenClientURL,
"--etcd-listen-peer-url="+listenPeerURL)
deferFunc := test.SetUpModules(
deferFunc := test.SetupModules(
flags,
repo,
pipeline,
Expand Down
2 changes: 1 addition & 1 deletion banyand/measure/measure.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// specific language governing permissions and limitations
// under the License.

// Package measures implements a time-series-based storage which is consists of a sequence of data points.
// Package measure implements a time-series-based storage which is consists of a sequence of data points.
// Each data point contains tags and fields. They arrive in a fixed interval. A data point could be updated
// by one with the identical entity(series_id) and timestamp.
package measure
Expand Down
2 changes: 1 addition & 1 deletion banyand/measure/measure_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func setUp() (*services, func()) {
listenClientURL, listenPeerURL, err := test.NewEtcdListenUrls()
gomega.Expect(err).NotTo(gomega.HaveOccurred())
flags = append(flags, "--etcd-listen-client-url="+listenClientURL, "--etcd-listen-peer-url="+listenPeerURL)
moduleDeferFunc := test.SetUpModules(
moduleDeferFunc := test.SetupModules(
flags,
repo,
pipeline,
Expand Down
9 changes: 5 additions & 4 deletions banyand/metadata/metadata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ package metadata

import (
"context"
"os"
"testing"

"github.com/stretchr/testify/assert"

commonv1 "github.com/apache/skywalking-banyandb/api/proto/banyandb/common/v1"
databasev1 "github.com/apache/skywalking-banyandb/api/proto/banyandb/database/v1"
"github.com/apache/skywalking-banyandb/pkg/logger"
testhelper "github.com/apache/skywalking-banyandb/pkg/test"
"github.com/apache/skywalking-banyandb/pkg/test/flags"
test "github.com/apache/skywalking-banyandb/pkg/test/stream"
)
Expand All @@ -43,14 +43,15 @@ func Test_service_RulesBySubject(t *testing.T) {
ctx := context.TODO()
s, _ := NewService(ctx)
is.NotNil(s)
rootDir := test.RandomTempDir()
err := s.FlagSet().Parse([]string{"--metadata-root-path=" + rootDir})
rootDir, deferFn, err := testhelper.NewSpace()
is.NoError(err)
err = s.FlagSet().Parse([]string{"--metadata-root-path=" + rootDir})
is.NoError(err)
err = s.PreRun()
is.NoError(err)
defer func() {
s.GracefulStop()
_ = os.RemoveAll(rootDir)
deferFn()
}()

err = test.PreloadSchema(s.SchemaRegistry())
Expand Down
17 changes: 9 additions & 8 deletions banyand/metadata/schema/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,17 @@ import (
)

var (
// ErrGRPCResourceNotFound indicates the resource doesn't exist.
ErrGRPCResourceNotFound = statusGRPCResourceNotFound.Err()

statusGRPCInvalidArgument = status.New(codes.InvalidArgument, "banyandb: input is invalid")
ErrGRPCInvalidArgument = statusGRPCInvalidArgument.Err()
statusGRPCResourceNotFound = status.New(codes.NotFound, "banyandb: resource not found")
ErrGRPCResourceNotFound = statusGRPCResourceNotFound.Err()
statusGRPCAlreadyExists = status.New(codes.AlreadyExists, "banyandb: resource already exists")
ErrGRPCAlreadyExists = statusGRPCAlreadyExists.Err()
errGRPCAlreadyExists = statusGRPCAlreadyExists.Err()
statusDataLoss = status.New(codes.DataLoss, "banyandb: resource corrupts.")
ErrGRPCDataLoss = statusDataLoss.Err()
errGRPCDataLoss = statusDataLoss.Err()
)

func IsNotFound(err error) bool {
return errors.Is(err, ErrGRPCResourceNotFound)
}

// BadRequest creates a gRPC error with error details with type BadRequest,
// which describes violations in a client request.
func BadRequest(field, desc string) error {
Expand All @@ -51,3 +48,7 @@ func BadRequest(field, desc string) error {
st, _ := statusGRPCInvalidArgument.WithDetails(br)
return st.Err()
}

func isNotFound(err error) bool {
return errors.Is(err, ErrGRPCResourceNotFound)
}
Loading

0 comments on commit e8d655a

Please sign in to comment.