You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by ha...@apache.org on 2022/05/16 22:08:42 UTC

[skywalking-banyandb] branch liaison-stream created (now ea7ad36)

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

hanahmily pushed a change to branch liaison-stream
in repository https://gitbox.apache.org/repos/asf/skywalking-banyandb.git


      at ea7ad36  Fix invalid default time range

This branch includes the following new commits:

     new ea7ad36  Fix invalid default time range

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[skywalking-banyandb] 01/01: Fix invalid default time range

Posted by ha...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

hanahmily pushed a commit to branch liaison-stream
in repository https://gitbox.apache.org/repos/asf/skywalking-banyandb.git

commit ea7ad36a52b505ac1475f94fadf0769008d85a77
Author: Gao Hongtao <ha...@gmail.com>
AuthorDate: Mon May 16 22:06:23 2022 +0000

    Fix invalid default time range
    
    Signed-off-by: Gao Hongtao <ha...@gmail.com>
---
 banyand/liaison/grpc/stream.go | 10 +++-------
 pkg/timestamp/nano.go          |  8 ++++++++
 pkg/timestamp/nano_test.go     |  4 ++++
 3 files changed, 15 insertions(+), 7 deletions(-)

diff --git a/banyand/liaison/grpc/stream.go b/banyand/liaison/grpc/stream.go
index 158fc39..d22471b 100644
--- a/banyand/liaison/grpc/stream.go
+++ b/banyand/liaison/grpc/stream.go
@@ -24,10 +24,8 @@ import (
 
 	"google.golang.org/grpc/codes"
 	"google.golang.org/grpc/status"
-	"google.golang.org/protobuf/types/known/timestamppb"
 
 	"github.com/apache/skywalking-banyandb/api/data"
-	modelv1 "github.com/apache/skywalking-banyandb/api/proto/banyandb/model/v1"
 	streamv1 "github.com/apache/skywalking-banyandb/api/proto/banyandb/stream/v1"
 	"github.com/apache/skywalking-banyandb/banyand/tsdb"
 	"github.com/apache/skywalking-banyandb/pkg/bus"
@@ -73,11 +71,9 @@ func (s *streamService) Write(stream streamv1.StreamService_WriteServer) error {
 }
 
 func (s *streamService) Query(_ context.Context, entityCriteria *streamv1.QueryRequest) (*streamv1.QueryResponse, error) {
-	if timeRange := entityCriteria.GetTimeRange(); timeRange == nil {
-		entityCriteria.TimeRange = &modelv1.TimeRange{
-			Begin: timestamppb.New(time.Unix(0, 0)),
-			End:   timestamppb.New(time.Unix(0, timestamp.MaxNanoTime)),
-		}
+	timeRange := entityCriteria.GetTimeRange()
+	if timeRange == nil {
+		entityCriteria.TimeRange = timestamp.DefaultTimeRange
 	}
 	if err := timestamp.CheckTimeRange(entityCriteria.GetTimeRange()); err != nil {
 		return nil, status.Errorf(codes.InvalidArgument, "%v is invalid :%s", entityCriteria.GetTimeRange(), err)
diff --git a/pkg/timestamp/nano.go b/pkg/timestamp/nano.go
index 8a0312d..085d471 100644
--- a/pkg/timestamp/nano.go
+++ b/pkg/timestamp/nano.go
@@ -70,6 +70,14 @@ var (
 	minNanoTime = time.Unix(0, MinNanoTime).UTC()
 	maxNanoTime = time.Unix(0, MaxNanoTime).UTC()
 
+	MaxMilliTime       = time.UnixMilli(maxNanoTime.UnixMilli())
+	MaxMilliPbTime     = timestamppb.New(MaxMilliTime)
+	DefaultBeginPbTime = timestamppb.New(time.Unix(0, 0))
+	DefaultTimeRange   = &modelv1.TimeRange{
+		Begin: DefaultBeginPbTime,
+		End:   MaxMilliPbTime,
+	}
+
 	ErrTimeOutOfRange     = errors.Errorf("time is out of range %d - %d", MinNanoTime, MaxNanoTime)
 	ErrTimeNotMillisecond = errors.Errorf("time is not millisecond precision")
 	ErrTimeEmpty          = errors.Errorf("time is empty")
diff --git a/pkg/timestamp/nano_test.go b/pkg/timestamp/nano_test.go
index f2e41ca..6b601ba 100644
--- a/pkg/timestamp/nano_test.go
+++ b/pkg/timestamp/nano_test.go
@@ -31,3 +31,7 @@ func TestMToN(t *testing.T) {
 	assert.Equal(t, n.UnixMilli(), m.UnixMilli())
 	assert.GreaterOrEqual(t, n.Nanosecond(), m.Nanosecond())
 }
+
+func TestDefaultTimeRange(t *testing.T) {
+	assert.NoError(t, timestamp.CheckTimeRange(timestamp.DefaultTimeRange))
+}