From 572bb7daf12831cc5840f41441437eaf74d69df1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B3=93=E9=80=B8?= Date: Tue, 28 May 2024 19:11:59 +0800 Subject: [PATCH 1/2] handle pulllogsMeta is nil --- log_store.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/log_store.go b/log_store.go index 477aa235..d4ef39dd 100644 --- a/log_store.go +++ b/log_store.go @@ -503,6 +503,9 @@ func (s *LogStore) GetLogsBytes(shardID int, cursor, endCursor string, // Deprecated: use GetLogsBytesWithQuery instead func (s *LogStore) GetLogsBytesV2(plr *PullLogRequest) ([]byte, string, error) { out, plm, err := s.GetLogsBytesWithQuery(plr) + if err != nil { + return nil, "", err + } return out, plm.NextCursor, err } @@ -655,6 +658,9 @@ func (s *LogStore) PullLogs(shardID int, cursor, endCursor string, // Deprecated: use PullLogsWithQuery instead func (s *LogStore) PullLogsV2(plr *PullLogRequest) (*LogGroupList, string, error) { gl, plm, err := s.PullLogsWithQuery(plr) + if err != nil { + return nil, "", err + } return gl, plm.NextCursor, err } From 842f534594c9d8893173564af4a66961bf064bf3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B3=93=E9=80=B8?= Date: Tue, 28 May 2024 22:58:13 +0800 Subject: [PATCH 2/2] add UT --- logstore_test.go | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/logstore_test.go b/logstore_test.go index cf110412..0d504161 100644 --- a/logstore_test.go +++ b/logstore_test.go @@ -229,6 +229,45 @@ func (s *LogstoreTestSuite) TestPullLogs() { s.Nil(err) } +func (s *LogstoreTestSuite) TestGetLogByteWithError() { + c := &LogContent{ + Key: proto.String("error code"), + Value: proto.String("InternalServerError"), + } + l := &Log{ + Time: proto.Uint32(uint32(time.Now().Unix())), + Contents: []*LogContent{ + c, + }, + } + lg := &LogGroup{ + Topic: proto.String("demo topic"), + Source: proto.String("10.230.201.117"), + Logs: []*Log{ + l, + }, + } + + shards, err := s.Logstore.ListShards() + s.True(len(shards) > 0) + + err = s.Logstore.PutLogs(lg) + s.Nil(err) + + cursor, err := s.Logstore.GetCursor(0, "begin") + s.Nil(err) + endCursor, err := s.Logstore.GetCursor(0, "end") + s.Nil(err) + + _, _, err = s.Logstore.GetLogsBytes(1000, cursor, "", 10) + s.Contains(err.Error(), "ShardNotExist") + s.NotNil(err) + + _, _, err = s.Logstore.GetLogsBytes(1000, cursor, endCursor, 10) + s.Contains(err.Error(), "ShardNotExist") + s.NotNil(err) +} + func (s *LogstoreTestSuite) TestGetLogs() { idx, err := s.Logstore.GetIndex() if err != nil {