@@ -2,10 +2,13 @@ package sls
2
2
3
3
import (
4
4
"encoding/json"
5
+ "fmt"
5
6
"net/http"
6
7
"net/url"
7
8
"strconv"
8
9
"strings"
10
+
11
+ "github.com/go-kit/kit/log/level"
9
12
)
10
13
11
14
// GetLogRequest for GetLogsV2
@@ -75,10 +78,11 @@ func (plr *PullLogRequest) ToURLParams() url.Values {
75
78
}
76
79
77
80
type PullLogMeta struct {
78
- NextCursor string
79
- Netflow int
80
- RawSize int
81
- Count int
81
+ NextCursor string
82
+ Netflow int
83
+ RawSize int
84
+ Count int
85
+ readLastCursor string // int64 string, eg: "1732154287213232020"
82
86
// these fields are only present when query is set
83
87
RawSizeBeforeQuery int // processed raw size before query
84
88
Lines int // result lines after query
@@ -375,3 +379,50 @@ type ListStoreViewsResponse struct {
375
379
Count int `json:"count"`
376
380
StoreViews []string `json:"storeviews"`
377
381
}
382
+
383
+ type logGroupIdentity struct {
384
+ cursor string
385
+ shard int
386
+ }
387
+
388
+ // GetLogGroupId returns the log group id (shard|cursor)
389
+ // If id is unknown, returns empty string
390
+ func (l * LogGroup ) GetLogGroupId () string {
391
+ if l .identity == nil {
392
+ return ""
393
+ }
394
+ return fmt .Sprintf ("%d|%s" , l .identity .shard , l .identity .cursor )
395
+ }
396
+
397
+ // index must be less than len(LogGroup.Logs)
398
+ // if no log id found, the returned log id is empty string
399
+ func (l * LogGroup ) GetLogId (index int ) string {
400
+ if index > len (l .Logs ) {
401
+ return ""
402
+ }
403
+ logGroupId := l .GetLogGroupId ()
404
+ if logGroupId == "" {
405
+ return ""
406
+ }
407
+ return fmt .Sprintf ("%s|%d|%d" , logGroupId , len (l .Logs ), index )
408
+ }
409
+
410
+ func (l * LogGroupList ) addIdIfPossible (readLastCursor string , shard int ) error {
411
+ lastCursorInt , err := strconv .ParseInt (readLastCursor , 10 , 64 )
412
+ if err != nil {
413
+ if IsDebugLevelMatched (1 ) {
414
+ level .Error (Logger ).Log ("msg" , "decode readLastCursor failed" ,
415
+ "cursor" , readLastCursor , "err" , err )
416
+ }
417
+ return err
418
+ }
419
+ cursor := lastCursorInt - int64 (len (l .LogGroups )) + 1
420
+ for i := 0 ; i < len (l .LogGroups ); i ++ {
421
+ l .LogGroups [i ].identity = & logGroupIdentity {
422
+ cursor : encodeCursor (cursor ),
423
+ shard : shard ,
424
+ }
425
+ cursor ++
426
+ }
427
+ return nil
428
+ }
0 commit comments