You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by GitBox <gi...@apache.org> on 2021/07/12 19:51:10 UTC
[GitHub] [skywalking-banyandb] lujiajing1126 commented on a change in pull request #15: Trace series module
lujiajing1126 commented on a change in pull request #15:
URL: https://github.com/apache/skywalking-banyandb/pull/15#discussion_r667800504
##########
File path: banyand/series/trace/query.go
##########
@@ -0,0 +1,253 @@
+// Licensed to Apache Software Foundation (ASF) under one or more contributor
+// license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright
+// ownership. Apache Software Foundation (ASF) licenses this file to you under
+// the Apache License, Version 2.0 (the "License"); you may
+// not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package trace
+
+import (
+ "encoding/hex"
+ "time"
+
+ flatbuffers "github.com/google/flatbuffers/go"
+ "github.com/pkg/errors"
+ "go.uber.org/multierr"
+
+ "github.com/apache/skywalking-banyandb/api/common"
+ "github.com/apache/skywalking-banyandb/api/data"
+ v1 "github.com/apache/skywalking-banyandb/api/fbs/v1"
+ "github.com/apache/skywalking-banyandb/banyand/kv"
+ "github.com/apache/skywalking-banyandb/banyand/series"
+ "github.com/apache/skywalking-banyandb/pkg/convert"
+ "github.com/apache/skywalking-banyandb/pkg/fb"
+ "github.com/apache/skywalking-banyandb/pkg/partition"
+)
+
+func (t *traceSeries) FetchTrace(traceID string, opt series.ScanOptions) (trace data.Trace, err error) {
+ if traceID == "" {
+ return trace, ErrInvalidTraceID
+ }
+ traceIDBytes := []byte(traceID)
+ traceIDShardID := partition.ShardID(traceIDBytes, t.shardNum)
+ bb, errTraceID := t.reader.TimeSeriesReader(traceIDShardID, traceIndex, 0, 0).GetAll(traceIDBytes)
+ if errTraceID != nil {
+ return trace, errTraceID
+ }
+ t.l.Debug().Uint("shard_id", traceIDShardID).
+ Str("trace_id", traceID).
+ Hex("trace_id_bytes", traceIDBytes).
+ Int("chunk_num", len(bb)).Msg("fetch Trace by trace_id")
+ if len(bb) < 1 {
+ return trace, nil
+ }
+ chunkIDs := make([]common.ChunkID, len(bb))
+ for i, b := range bb {
+ chunkIDs[i] = b
+ }
+ entities, errEntity := t.FetchEntity(chunkIDs, opt)
+ if errEntity != nil {
+ return trace, errEntity
+ }
+ return data.Trace{
+ KindVersion: data.TraceKindVersion,
+ Entities: entities,
+ }, err
+}
+
+func (t *traceSeries) ScanEntity(startTime, endTime uint64, opt series.ScanOptions) ([]data.Entity, error) {
+ total := opt.Limit
+ if total < 1 {
+ total = 10
+ }
+ states := make([]byte, 0, 2)
+ switch opt.State {
+ case series.TraceStateSuccess:
+ states = append(states, StateSuccess)
+ case series.TraceStateError:
+ states = append(states, StateError)
+ default:
Review comment:
I guess I've added a default `TraceState`. Do I need to remove this default field?
##########
File path: banyand/queue/local.go
##########
@@ -21,7 +21,7 @@ import (
"go.uber.org/multierr"
"github.com/apache/skywalking-banyandb/banyand/discovery"
- "github.com/apache/skywalking-banyandb/banyand/internal/bus"
+ bus2 "github.com/apache/skywalking-banyandb/pkg/bus"
Review comment:
why `bus2`?
##########
File path: banyand/series/trace/common_test.go
##########
@@ -0,0 +1,270 @@
+// Licensed to Apache Software Foundation (ASF) under one or more contributor
+// license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright
+// ownership. Apache Software Foundation (ASF) licenses this file to you under
+// the Apache License, Version 2.0 (the "License"); you may
+// not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package trace
+
+import (
+ "bytes"
+ "context"
+ "sort"
+ "testing"
+ "time"
+
+ flatbuffers "github.com/google/flatbuffers/go"
+ "github.com/stretchr/testify/assert"
+
+ "github.com/apache/skywalking-banyandb/api/common"
+ "github.com/apache/skywalking-banyandb/api/data"
+ v1 "github.com/apache/skywalking-banyandb/api/fbs/v1"
+ "github.com/apache/skywalking-banyandb/banyand/storage"
+ "github.com/apache/skywalking-banyandb/pkg/convert"
+ "github.com/apache/skywalking-banyandb/pkg/fb"
+ "github.com/apache/skywalking-banyandb/pkg/logger"
+ "github.com/apache/skywalking-banyandb/pkg/partition"
+)
+
+var _ sort.Interface = (ByEntityID)(nil)
+
+type ByEntityID []data.Entity
+
+func (b ByEntityID) Len() int {
+ return len(b)
+}
+
+func (b ByEntityID) Less(i, j int) bool {
+ return bytes.Compare(b[i].EntityId(), b[j].EntityId()) < 0
+}
+
+func (b ByEntityID) Swap(i, j int) {
+ b[i], b[j] = b[j], b[i]
+}
+
+func setup(t *testing.T) (*traceSeries, func()) {
+ _ = logger.Bootstrap()
+ db, err := storage.NewDB(context.TODO(), nil)
+ assert.NoError(t, err)
+ assert.NoError(t, db.FlagSet().Parse(nil))
+ svc, err := NewService(context.TODO(), db, nil)
+ assert.NoError(t, err)
+ assert.NoError(t, svc.PreRun())
+ assert.NoError(t, db.PreRun())
+ traceSVC := svc.(*service)
+ b := flatbuffers.NewBuilder(0)
+ name := b.CreateString("sw")
+ group := b.CreateString("default")
+ v1.MetadataStart(b)
+ v1.MetadataAddName(b, name)
+ v1.MetadataAddGroup(b, group)
+ b.Finish(v1.MetadataEnd(b))
+ meta := new(v1.Metadata)
+ meta.Init(b.Bytes, b.Offset())
+ ts, err := traceSVC.getSeries(common.Metadata{
+ Spec: v1.GetRootAsMetadata(b.FinishedBytes(), 0),
+ })
+ assert.NoError(t, err)
+ return ts, db.GracefulStop
+}
+
+type seriesEntity struct {
+ seriesID string
+ entity entity
+}
+
+type wantEntity struct {
+ entityID string
+ dataBinary []byte
+ fieldsSize int
+}
+
+var gap = uint64(500 * time.Millisecond)
+
+func testData(ts uint64) []seriesEntity {
+
+ return []seriesEntity{
+ {
+ seriesID: "webapp_10.0.0.1",
+ entity: getEntityWithTS("1", []byte{11}, ts,
+ "trace_id-xxfff.111323",
+ 0,
+ "webapp_id",
+ "10.0.0.1_id",
+ "/home_id",
+ "webapp",
+ "10.0.0.1",
+ "/home",
+ 300,
+ 1622933202000000000,
+ ),
+ },
+ {
+ seriesID: "gateway_10.0.0.2",
+ entity: getEntityWithTS("2", []byte{12}, ts+gap,
+ "trace_id-xxfff.111323a",
+ 1,
+ ),
+ },
+ {
+ seriesID: "httpserver_10.0.0.3",
+ entity: getEntityWithTS("3", []byte{13}, ts+2*gap,
+ "trace_id-xxfff.111323",
+ 1,
+ "httpserver_id",
+ "10.0.0.3_id",
+ "/home_id",
+ "httpserver",
+ "10.0.0.3",
+ "/home",
+ 300,
+ 1622933202000000000,
+ "GET",
+ "200",
+ ),
+ },
+ {
+ seriesID: "database_10.0.0.4",
+ entity: getEntityWithTS("4", []byte{14}, ts+3*gap,
+ "trace_id-xxfff.111323",
+ 0,
+ "database_id",
+ "10.0.0.4_id",
+ "/home_id",
+ "database",
+ "10.0.0.4",
+ "/home",
+ 300,
+ 1622933202000000000,
+ nil,
+ nil,
+ "MySQL",
+ "10.1.1.4",
+ ),
+ },
+ {
+ seriesID: "mq_10.0.0.5",
+ entity: getEntityWithTS("5", []byte{15}, ts+4*gap,
+ "trace_id-zzpp.111323",
+ 0,
+ "mq_id",
+ "10.0.0.5_id",
+ "/home_id",
+ "mq",
+ "10.0.0.5",
+ "/home",
+ 300,
+ 1622933202000000000,
+ nil,
+ nil,
+ nil,
+ nil,
+ "test_topic",
+ "10.0.0.5",
+ ),
+ },
+ {
+ seriesID: "database_10.0.0.6",
+ entity: getEntityWithTS("6", []byte{16}, ts+5*gap,
+ "trace_id-zzpp.111323",
+ 1,
+ "database_id",
+ "10.0.0.6_id",
+ "/home_id",
+ "database",
+ "10.0.0.6",
+ "/home",
+ 300,
+ 1622933202000000000,
+ nil,
+ nil,
+ "MySQL",
+ "10.1.1.6",
+ ),
+ },
+ {
+ seriesID: "mq_10.0.0.7",
+ entity: getEntityWithTS("7", []byte{17}, ts+6*gap,
+ "trace_id-zzpp.111323",
+ 0,
+ "nq_id",
+ "10.0.0.7_id",
+ "/home_id",
+ "mq",
+ "10.0.0.7",
+ "/home",
+ 300,
+ 1622933202000000000,
+ nil,
+ nil,
+ nil,
+ nil,
+ "test_topic",
+ "10.0.0.7",
+ ),
+ },
+ }
+}
+
+type entity struct {
+ id string
+ binary []byte
+ ts uint64
+ items []interface{}
+}
+
+func getEntity(id string, binary []byte, items ...interface{}) entity {
+ return entity{
+ id: id,
+ binary: binary,
+ items: items,
+ }
+}
+
+func getEntityWithTS(id string, binary []byte, ts uint64, items ...interface{}) entity {
Review comment:
As I understood, we have to pass items in strict order since we have to keep the same order as defined in the schema, right?
##########
File path: banyand/liaison/grpc/grpc.go
##########
@@ -35,10 +39,33 @@ type Server struct {
log *logger.Logger
ser *grpclib.Server
pipeline queue.Queue
+ repo discovery.ServiceRepo
}
-func NewServer(ctx context.Context, pipeline queue.Queue) *Server {
- return &Server{pipeline: pipeline}
+func (s *Server) Rev(message bus.Message) (resp bus.Message) {
+ data, ok := message.Data().([]byte)
+ if !ok {
+ s.log.Warn().Msg("invalid event data type")
+ return
+ }
+ shardEvent := v1.GetRootAsShardEvent(data, 0)
Review comment:
I am curious how can we ensure that the data received is `ShardEvent`?
##########
File path: banyand/liaison/grpc/grpc.go
##########
@@ -35,10 +39,33 @@ type Server struct {
log *logger.Logger
ser *grpclib.Server
pipeline queue.Queue
+ repo discovery.ServiceRepo
}
-func NewServer(ctx context.Context, pipeline queue.Queue) *Server {
- return &Server{pipeline: pipeline}
+func (s *Server) Rev(message bus.Message) (resp bus.Message) {
+ data, ok := message.Data().([]byte)
+ if !ok {
+ s.log.Warn().Msg("invalid event data type")
+ return
+ }
+ shardEvent := v1.GetRootAsShardEvent(data, 0)
Review comment:
I am curious how can we ensure that the data received can be deserialized to `ShardEvent`?
##########
File path: banyand/series/trace/common_test.go
##########
@@ -0,0 +1,270 @@
+// Licensed to Apache Software Foundation (ASF) under one or more contributor
+// license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright
+// ownership. Apache Software Foundation (ASF) licenses this file to you under
+// the Apache License, Version 2.0 (the "License"); you may
+// not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package trace
+
+import (
+ "bytes"
+ "context"
+ "sort"
+ "testing"
+ "time"
+
+ flatbuffers "github.com/google/flatbuffers/go"
+ "github.com/stretchr/testify/assert"
+
+ "github.com/apache/skywalking-banyandb/api/common"
+ "github.com/apache/skywalking-banyandb/api/data"
+ v1 "github.com/apache/skywalking-banyandb/api/fbs/v1"
+ "github.com/apache/skywalking-banyandb/banyand/storage"
+ "github.com/apache/skywalking-banyandb/pkg/convert"
+ "github.com/apache/skywalking-banyandb/pkg/fb"
+ "github.com/apache/skywalking-banyandb/pkg/logger"
+ "github.com/apache/skywalking-banyandb/pkg/partition"
+)
+
+var _ sort.Interface = (ByEntityID)(nil)
+
+type ByEntityID []data.Entity
+
+func (b ByEntityID) Len() int {
+ return len(b)
+}
+
+func (b ByEntityID) Less(i, j int) bool {
+ return bytes.Compare(b[i].EntityId(), b[j].EntityId()) < 0
+}
+
+func (b ByEntityID) Swap(i, j int) {
+ b[i], b[j] = b[j], b[i]
+}
+
+func setup(t *testing.T) (*traceSeries, func()) {
+ _ = logger.Bootstrap()
+ db, err := storage.NewDB(context.TODO(), nil)
+ assert.NoError(t, err)
+ assert.NoError(t, db.FlagSet().Parse(nil))
+ svc, err := NewService(context.TODO(), db, nil)
+ assert.NoError(t, err)
+ assert.NoError(t, svc.PreRun())
+ assert.NoError(t, db.PreRun())
+ traceSVC := svc.(*service)
+ b := flatbuffers.NewBuilder(0)
+ name := b.CreateString("sw")
+ group := b.CreateString("default")
+ v1.MetadataStart(b)
+ v1.MetadataAddName(b, name)
+ v1.MetadataAddGroup(b, group)
+ b.Finish(v1.MetadataEnd(b))
+ meta := new(v1.Metadata)
+ meta.Init(b.Bytes, b.Offset())
+ ts, err := traceSVC.getSeries(common.Metadata{
+ Spec: v1.GetRootAsMetadata(b.FinishedBytes(), 0),
+ })
+ assert.NoError(t, err)
+ return ts, db.GracefulStop
+}
+
+type seriesEntity struct {
+ seriesID string
+ entity entity
+}
+
+type wantEntity struct {
+ entityID string
+ dataBinary []byte
+ fieldsSize int
+}
+
+var gap = uint64(500 * time.Millisecond)
+
+func testData(ts uint64) []seriesEntity {
+
+ return []seriesEntity{
+ {
+ seriesID: "webapp_10.0.0.1",
+ entity: getEntityWithTS("1", []byte{11}, ts,
+ "trace_id-xxfff.111323",
+ 0,
+ "webapp_id",
+ "10.0.0.1_id",
+ "/home_id",
+ "webapp",
+ "10.0.0.1",
+ "/home",
+ 300,
+ 1622933202000000000,
+ ),
+ },
+ {
+ seriesID: "gateway_10.0.0.2",
+ entity: getEntityWithTS("2", []byte{12}, ts+gap,
+ "trace_id-xxfff.111323a",
+ 1,
+ ),
+ },
+ {
+ seriesID: "httpserver_10.0.0.3",
+ entity: getEntityWithTS("3", []byte{13}, ts+2*gap,
+ "trace_id-xxfff.111323",
+ 1,
+ "httpserver_id",
+ "10.0.0.3_id",
+ "/home_id",
+ "httpserver",
+ "10.0.0.3",
+ "/home",
+ 300,
+ 1622933202000000000,
+ "GET",
+ "200",
+ ),
+ },
+ {
+ seriesID: "database_10.0.0.4",
+ entity: getEntityWithTS("4", []byte{14}, ts+3*gap,
+ "trace_id-xxfff.111323",
+ 0,
+ "database_id",
+ "10.0.0.4_id",
+ "/home_id",
+ "database",
+ "10.0.0.4",
+ "/home",
+ 300,
+ 1622933202000000000,
+ nil,
+ nil,
+ "MySQL",
+ "10.1.1.4",
+ ),
+ },
+ {
+ seriesID: "mq_10.0.0.5",
+ entity: getEntityWithTS("5", []byte{15}, ts+4*gap,
+ "trace_id-zzpp.111323",
+ 0,
+ "mq_id",
+ "10.0.0.5_id",
+ "/home_id",
+ "mq",
+ "10.0.0.5",
+ "/home",
+ 300,
+ 1622933202000000000,
+ nil,
+ nil,
+ nil,
+ nil,
+ "test_topic",
+ "10.0.0.5",
+ ),
+ },
+ {
+ seriesID: "database_10.0.0.6",
+ entity: getEntityWithTS("6", []byte{16}, ts+5*gap,
+ "trace_id-zzpp.111323",
+ 1,
+ "database_id",
+ "10.0.0.6_id",
+ "/home_id",
+ "database",
+ "10.0.0.6",
+ "/home",
+ 300,
+ 1622933202000000000,
+ nil,
+ nil,
+ "MySQL",
+ "10.1.1.6",
+ ),
+ },
+ {
+ seriesID: "mq_10.0.0.7",
+ entity: getEntityWithTS("7", []byte{17}, ts+6*gap,
+ "trace_id-zzpp.111323",
+ 0,
+ "nq_id",
+ "10.0.0.7_id",
+ "/home_id",
+ "mq",
+ "10.0.0.7",
+ "/home",
+ 300,
+ 1622933202000000000,
+ nil,
+ nil,
+ nil,
+ nil,
+ "test_topic",
+ "10.0.0.7",
+ ),
+ },
+ }
+}
+
+type entity struct {
+ id string
+ binary []byte
+ ts uint64
+ items []interface{}
+}
+
+func getEntity(id string, binary []byte, items ...interface{}) entity {
+ return entity{
+ id: id,
+ binary: binary,
+ items: items,
+ }
+}
+
+func getEntityWithTS(id string, binary []byte, ts uint64, items ...interface{}) entity {
Review comment:
As I understood, we have to pass items in strict order since we have to keep the same order as what is defined in the schema, right?
##########
File path: banyand/series/schema/sw/trace_series.json
##########
@@ -33,7 +37,11 @@
"type": "String"
},
{
- "name": "state",
+ "name": "duration",
Review comment:
Finally we have `duration`!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org