-
Notifications
You must be signed in to change notification settings - Fork 113
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support spl #251
Support spl #251
Changes from 5 commits
7f48d43
cf8f58e
459259f
41c4f15
f87046b
974fbee
2df118b
0bfb0a3
5fb7474
6f14df2
4fae389
2ab20cc
bb74901
9d2f400
bb4079f
b816f96
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -264,14 +264,14 @@ type ClientInterface interface { | |
// The nextCursor is the next curosr can be used to read logs at next time. | ||
GetLogsBytes(project, logstore string, shardID int, cursor, endCursor string, | ||
logGroupMaxCount int) (out []byte, nextCursor string, err error) | ||
GetLogsBytesV2(plr *PullLogRequest) (out []byte, nextCursor string, err error) | ||
GetLogsBytesV2(plr *PullLogRequest) (out []byte, pullLogMeta *PullLogMeta, err error) | ||
// PullLogs gets logs from shard specified by shardId according cursor and endCursor. | ||
// The logGroupMaxCount is the max number of logGroup could be returned. | ||
// The nextCursor is the next cursor can be used to read logs at next time. | ||
// @note if you want to pull logs continuous, set endCursor = "" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. GetLogsBytesV2 也是要废弃的吧?注解 |
||
PullLogs(project, logstore string, shardID int, cursor, endCursor string, | ||
logGroupMaxCount int) (gl *LogGroupList, nextCursor string, err error) | ||
PullLogsV2(plr *PullLogRequest) (gl *LogGroupList, nextCursor string, err error) | ||
PullLogsV2(plr *PullLogRequest) (gl *LogGroupList, pullLogMeta *PullLogMeta, err error) | ||
// GetHistograms query logs with [from, to) time range | ||
GetHistograms(project, logstore string, topic string, from int64, to int64, queryExp string) (*GetHistogramsResponse, error) | ||
// GetLogs query logs with [from, to) time range | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -445,13 +445,13 @@ func (s *LogStore) GetLogsBytes(shardID int, cursor, endCursor string, | |
EndCursor: endCursor, | ||
LogGroupMaxCount: logGroupMaxCount, | ||
} | ||
return s.GetLogsBytesV2(plr) | ||
return convertByteV1(s.GetLogsBytesV2(plr)) | ||
} | ||
|
||
// GetLogsBytes gets logs binary data from shard specified by shardId according cursor and endCursor. | ||
// The logGroupMaxCount is the max number of logGroup could be returned. | ||
// The nextCursor is the next curosr can be used to read logs at next time. | ||
func (s *LogStore) GetLogsBytesV2(plr *PullLogRequest) (out []byte, nextCursor string, err error) { | ||
func (s *LogStore) GetLogsBytesV2(plr *PullLogRequest) (out []byte, pullLogMeta *PullLogMeta, err error) { | ||
h := map[string]string{ | ||
"x-log-bodyrawsize": "0", | ||
"Accept": "application/x-protobuf", | ||
|
@@ -463,12 +463,12 @@ func (s *LogStore) GetLogsBytesV2(plr *PullLogRequest) (out []byte, nextCursor s | |
|
||
r, err := request(s.project, "GET", uri, h, nil) | ||
AVloger marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if err != nil { | ||
return nil, "", err | ||
return | ||
} | ||
defer r.Body.Close() | ||
buf, err := ioutil.ReadAll(r.Body) | ||
if err != nil { | ||
return nil, "", err | ||
return | ||
} | ||
|
||
if r.StatusCode != http.StatusOK { | ||
|
@@ -500,22 +500,47 @@ func (s *LogStore) GetLogsBytesV2(plr *PullLogRequest) (out []byte, nextCursor s | |
err = fmt.Errorf("can't find 'x-log-cursor' header") | ||
return | ||
} | ||
nextCursor = v[0] | ||
pullLogMeta = &PullLogMeta{ | ||
RawDataSize: -1, | ||
RawDataCount: -1, | ||
} | ||
|
||
pullLogMeta.NextCursor = v[0] | ||
|
||
v, ok = r.Header["X-Log-Bodyrawsize"] | ||
if !ok || len(v) == 0 { | ||
err = fmt.Errorf("can't find 'x-log-bodyrawsize' header") | ||
return | ||
} | ||
bodyRawSize, err := strconv.Atoi(v[0]) | ||
pullLogMeta.DataSize, err = strconv.Atoi(v[0]) | ||
if err != nil { | ||
return nil, "", err | ||
return | ||
} | ||
|
||
out = make([]byte, bodyRawSize) | ||
if bodyRawSize != 0 { | ||
out = make([]byte, pullLogMeta.DataSize) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. L520/L521换一下顺序 |
||
if pullLogMeta.DataSize != 0 { | ||
len := 0 | ||
if len, err = lz4.UncompressBlock(buf, out); err != nil || len != bodyRawSize { | ||
if len, err = lz4.UncompressBlock(buf, out); err != nil || len != pullLogMeta.DataSize { | ||
return | ||
} | ||
} | ||
// If it is not in scan mode, exit early | ||
if plr.PullMode != "scan_on_stream" { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 最好这样改: |
||
return | ||
} | ||
//datasize before data processing | ||
v = r.Header["X-Log-Rawdatasize"] | ||
if len(v) > 0 { | ||
pullLogMeta.RawDataSize, err = strconv.Atoi(v[0]) | ||
if err != nil { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. header非法或取不到,需要返回用户更容易理解的信息 可以参考以前的:
|
||
return | ||
} | ||
} | ||
//lines before data processing | ||
v = r.Header["X-Log-Rawdatacount"] | ||
if len(v) > 0 { | ||
pullLogMeta.RawDataCount, err = strconv.Atoi(v[0]) | ||
if err != nil { | ||
return | ||
} | ||
} | ||
|
@@ -546,22 +571,22 @@ func (s *LogStore) PullLogs(shardID int, cursor, endCursor string, | |
EndCursor: endCursor, | ||
LogGroupMaxCount: logGroupMaxCount, | ||
} | ||
return s.PullLogsV2(plr) | ||
return convertGlV1(s.PullLogsV2(plr)) | ||
} | ||
|
||
func (s *LogStore) PullLogsV2(plr *PullLogRequest) (gl *LogGroupList, nextCursor string, err error) { | ||
func (s *LogStore) PullLogsV2(plr *PullLogRequest) (gl *LogGroupList, pullLogMeta *PullLogMeta, err error) { | ||
|
||
out, nextCursor, err := s.GetLogsBytesV2(plr) | ||
out, pullLogMeta, err := s.GetLogsBytesV2(plr) | ||
if err != nil { | ||
return nil, "", err | ||
return nil, nil, err | ||
} | ||
|
||
gl, err = LogsBytesDecode(out) | ||
if err != nil { | ||
return nil, "", err | ||
return nil, nil, err | ||
} | ||
|
||
return gl, nextCursor, nil | ||
return | ||
} | ||
|
||
// GetHistograms query logs with [from, to) time range | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
一下 去掉