Skip to content

Commit 24b6f23

Browse files
authoredAug 30, 2023
add getlogsV3ToComplete (aliyun#227)
1 parent 386a0d0 commit 24b6f23

6 files changed

+69
-0
lines changed
 

‎client_interface.go

+2
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,8 @@ type ClientInterface interface {
287287
GetLogsToCompleted(project, logstore string, topic string, from int64, to int64, queryExp string, maxLineNum int64, offset int64, reverse bool) (*GetLogsResponse, error)
288288
// GetLogsToCompletedV2 query logs with [from, to) time range to completed
289289
GetLogsToCompletedV2(project, logstore string, req *GetLogRequest) (*GetLogsResponse, error)
290+
// GetLogsToCompletedV3 query logs with [from, to) time range to completed
291+
GetLogsToCompletedV3(project, logstore string, req *GetLogRequest) (*GetLogsV3Response, error)
290292

291293
// #################### Index Operations #####################
292294
// CreateIndex ...

‎client_store.go

+6
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,12 @@ func (c *Client) GetLogsToCompletedV2(project, logstore string, req *GetLogReque
280280
return ls.GetLogsToCompletedV2(req)
281281
}
282282

283+
// GetLogsToCompletedV3 ...
284+
func (c *Client) GetLogsToCompletedV3(project, logstore string, req *GetLogRequest) (*GetLogsV3Response, error) {
285+
ls := convertLogstore(c, project, logstore)
286+
return ls.GetLogsToCompletedV3(req)
287+
}
288+
283289
// GetLogLinesV2 ...
284290
func (c *Client) GetLogLinesV2(project, logstore string, req *GetLogRequest) (*GetLogLinesResponse, error) {
285291
ls := convertLogstore(c, project, logstore)

‎client_store_test.go

+32
Original file line numberDiff line numberDiff line change
@@ -112,3 +112,35 @@ func (s *LostoreTestSuite) TestSplitShardDefault() {
112112
assert.True(s.T(), id3 != -1)
113113
assert.Equal(s.T(), 4, num3)
114114
}
115+
116+
func (s *LostoreTestSuite) TestGetLogsV3ToCompleted() {
117+
key := "key"
118+
value := "val"
119+
n := uint32(time.Now().Unix())
120+
lg := &LogGroup{
121+
Logs: []*Log{
122+
{
123+
Time: &n,
124+
Contents: []*LogContent{
125+
{
126+
Key: &key,
127+
Value: &value,
128+
},
129+
},
130+
},
131+
},
132+
}
133+
project := s.projectName
134+
logstore := s.logstoreName
135+
err := s.client.PostLogStoreLogs(project, logstore, lg, nil)
136+
s.Require().NoError(err)
137+
time.Sleep(time.Second * 10)
138+
resp, err := s.client.GetLogsToCompletedV3(project, logstore, &GetLogRequest{
139+
From: time.Now().Unix() - 30000,
140+
To: time.Now().Unix(),
141+
Lines: 100,
142+
Topic: "",
143+
})
144+
s.Require().NoError(err)
145+
s.GreaterOrEqual(resp.Meta.Count, int64(1))
146+
}

‎log_store.go

+15
Original file line numberDiff line numberDiff line change
@@ -752,6 +752,21 @@ func (s *LogStore) GetLogsToCompletedV2(req *GetLogRequest) (*GetLogsResponse, e
752752
return res, err
753753
}
754754

755+
// GetLogsToCompletedV3 query logs with [from, to) time range to completed
756+
func (s *LogStore) GetLogsToCompletedV3(req *GetLogRequest) (*GetLogsV3Response, error) {
757+
var res *GetLogsV3Response
758+
var err error
759+
f := func() (bool, error) {
760+
res, err = s.GetLogsV3(req)
761+
if err == nil {
762+
return res.IsComplete(), nil
763+
}
764+
return false, err
765+
}
766+
s.getToCompleted(f)
767+
return res, err
768+
}
769+
755770
// GetHistogramsToCompleted query logs with [from, to) time range to completed
756771
func (s *LogStore) GetHistogramsToCompleted(topic string, from int64, to int64, queryExp string) (*GetHistogramsResponse, error) {
757772
var res *GetHistogramsResponse

‎model.go

+4
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,10 @@ type GetLogsV3Response struct {
207207
Logs []map[string]string `json:"data"`
208208
}
209209

210+
func (resp *GetLogsV3Response) IsComplete() bool {
211+
return strings.ToLower(resp.Meta.Progress) == "complete"
212+
}
213+
210214
// GetLogLinesResponse defines response from GetLogLines call
211215
// note: GetLogLinesResponse.Logs is nil when use GetLogLinesResponse
212216
type GetLogLinesResponse struct {

‎token_auto_update_client.go

+10
Original file line numberDiff line numberDiff line change
@@ -874,6 +874,16 @@ func (c *TokenAutoUpdateClient) GetLogsToCompletedV2(project, logstore string, r
874874
return
875875
}
876876

877+
func (c *TokenAutoUpdateClient) GetLogsToCompletedV3(project, logstore string, req *GetLogRequest) (r *GetLogsV3Response, err error) {
878+
for i := 0; i < c.maxTryTimes; i++ {
879+
r, err = c.logClient.GetLogsToCompletedV3(project, logstore, req)
880+
if !c.processError(err) {
881+
return
882+
}
883+
}
884+
return
885+
}
886+
877887
func (c *TokenAutoUpdateClient) GetLogLinesV2(project, logstore string, req *GetLogRequest) (r *GetLogLinesResponse, err error) {
878888
for i := 0; i < c.maxTryTimes; i++ {
879889
r, err = c.logClient.GetLogLinesV2(project, logstore, req)

0 commit comments

Comments
 (0)
Please sign in to comment.