Skip to content

Commit

Permalink
Merge pull request #276 from AVloger/hotfix/handle_plm_nil
Browse files Browse the repository at this point in the history
handle pulllogsMeta is nils
  • Loading branch information
AVloger authored May 29, 2024
2 parents 878e9de + 842f534 commit 52078e0
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
6 changes: 6 additions & 0 deletions log_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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
}

Expand Down
39 changes: 39 additions & 0 deletions logstore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 52078e0

Please sign in to comment.