Skip to content
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

Add interval to gethistogram #306

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions client_interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ type ClientInterface interface {
PullLogsWithQuery(plr *PullLogRequest) (gl *LogGroupList, plm *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)
GetHistogramsV2(project, logstore string, ghr *GetHistogramRequest) (*GetHistogramsResponse, error)
// GetLogs query logs with [from, to) time range
GetLogs(project, logstore string, topic string, from int64, to int64, queryExp string,
maxLineNum int64, offset int64, reverse bool) (*GetLogsResponse, error)
Expand All @@ -316,6 +317,7 @@ type ClientInterface interface {

// GetHistogramsToCompleted query logs with [from, to) time range to completed
GetHistogramsToCompleted(project, logstore string, topic string, from int64, to int64, queryExp string) (*GetHistogramsResponse, error)
GetHistogramsToCompletedV2(project, logstore string, ghr *GetHistogramRequest) (*GetHistogramsResponse, error)
// GetLogsToCompleted query logs with [from, to) time range to completed
GetLogsToCompleted(project, logstore string, topic string, from int64, to int64, queryExp string, maxLineNum int64, offset int64, reverse bool) (*GetLogsResponse, error)
// GetLogsToCompletedV2 query logs with [from, to) time range to completed
Expand Down
10 changes: 10 additions & 0 deletions client_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,12 +247,22 @@ func (c *Client) GetHistograms(project, logstore string, topic string, from int6
return ls.GetHistograms(topic, from, to, queryExp)
}

func (c *Client) GetHistogramsV2(project, logstore string, ghr *GetHistogramRequest) (*GetHistogramsResponse, error) {
ls := convertLogstore(c, project, logstore)
return ls.GetHistogramsV2(ghr)
}

// GetHistogramsToCompleted query logs with [from, to) time range to completed
func (c *Client) GetHistogramsToCompleted(project, logstore string, topic string, from int64, to int64, queryExp string) (*GetHistogramsResponse, error) {
ls := convertLogstore(c, project, logstore)
return ls.GetHistogramsToCompleted(topic, from, to, queryExp)
}

func (c *Client) GetHistogramsToCompletedV2(project, logstore string, ghr *GetHistogramRequest) (*GetHistogramsResponse, error) {
ls := convertLogstore(c, project, logstore)
return ls.GetHistogramsToCompletedV2(ghr)
}

// GetLogs query logs with [from, to) time range
func (c *Client) GetLogs(project, logstore string, topic string, from int64, to int64, queryExp string,
maxLineNum int64, offset int64, reverse bool) (*GetLogsResponse, error) {
Expand Down
30 changes: 24 additions & 6 deletions log_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -650,18 +650,22 @@ func (s *LogStore) PullLogsWithQuery(plr *PullLogRequest) (gl *LogGroupList, plm

// GetHistograms query logs with [from, to) time range
func (s *LogStore) GetHistograms(topic string, from int64, to int64, queryExp string) (*GetHistogramsResponse, error) {
return s.GetHistogramsV2(&GetHistogramRequest{
Topic: topic,
From: from,
To: to,
Query: queryExp,
})
}

func (s *LogStore) GetHistogramsV2(ghr *GetHistogramRequest) (*GetHistogramsResponse, error) {

h := map[string]string{
"x-log-bodyrawsize": "0",
"Accept": "application/json",
}

urlVal := url.Values{}
urlVal.Add("type", "histogram")
urlVal.Add("from", strconv.Itoa(int(from)))
urlVal.Add("to", strconv.Itoa(int(to)))
urlVal.Add("topic", topic)
urlVal.Add("query", queryExp)
urlVal := ghr.ToURLParams()

uri := fmt.Sprintf("/logstores/%s?%s", s.Name, urlVal.Encode())
r, err := request(s.project, "GET", uri, h, nil)
Expand Down Expand Up @@ -866,6 +870,20 @@ func (s *LogStore) GetHistogramsToCompleted(topic string, from int64, to int64,
return res, err
}

func (s *LogStore) GetHistogramsToCompletedV2(ghr *GetHistogramRequest) (*GetHistogramsResponse, error) {
var res *GetHistogramsResponse
var err error
f := func() (bool, error) {
res, err = s.GetHistogramsV2(ghr)
if err == nil {
return res.IsComplete(), nil
}
return false, err
}
s.getToCompleted(f)
return res, err
}

// GetLogsV2 query logs with [from, to) time range
func (s *LogStore) GetLogsV2(req *GetLogRequest) (*GetLogsResponse, error) {
resp, httpRsp, err := s.getLogsV3Internal(req)
Expand Down
19 changes: 19 additions & 0 deletions model.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,25 @@ func (glr *GetLogRequest) ToURLParams() url.Values {
return urlVal
}

type GetHistogramRequest struct {
Topic string `json:"topic"`
From int64 `json:"from"`
To int64 `json:"to"`
Query string `json:"query"`
Interval int32 `json:"interval"`
}

func (ghr *GetHistogramRequest) ToURLParams() url.Values {
urlVal := url.Values{}
urlVal.Add("type", "histogram")
urlVal.Add("from", strconv.Itoa(int(ghr.From)))
urlVal.Add("to", strconv.Itoa(int(ghr.To)))
urlVal.Add("topic", ghr.Topic)
urlVal.Add("query", ghr.Query)
urlVal.Add("interval", strconv.Itoa(int(ghr.Interval)))
return urlVal
}

type PullLogRequest struct {
Project string
Logstore string
Expand Down
20 changes: 20 additions & 0 deletions token_auto_update_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -881,6 +881,16 @@ func (c *TokenAutoUpdateClient) GetHistograms(project, logstore string, topic st
return
}

func (c *TokenAutoUpdateClient) GetHistogramsV2(project, logstore string, ghr *GetHistogramRequest) (h *GetHistogramsResponse, err error) {
for i := 0; i < c.maxTryTimes; i++ {
h, err = c.logClient.GetHistogramsV2(project, logstore, ghr)
if !c.processError(err) {
return
}
}
return
}

func (c *TokenAutoUpdateClient) GetHistogramsToCompleted(project, logstore string, topic string, from int64, to int64, queryExp string) (h *GetHistogramsResponse, err error) {
for i := 0; i < c.maxTryTimes; i++ {
h, err = c.logClient.GetHistogramsToCompleted(project, logstore, topic, from, to, queryExp)
Expand All @@ -891,6 +901,16 @@ func (c *TokenAutoUpdateClient) GetHistogramsToCompleted(project, logstore strin
return
}

func (c *TokenAutoUpdateClient) GetHistogramsToCompletedV2(project, logstore string, ghr *GetHistogramRequest) (h *GetHistogramsResponse, err error) {
for i := 0; i < c.maxTryTimes; i++ {
h, err = c.logClient.GetHistogramsToCompletedV2(project, logstore, ghr)
if !c.processError(err) {
return
}
}
return
}

func (c *TokenAutoUpdateClient) GetLogsV2(project, logstore string, req *GetLogRequest) (r *GetLogsResponse, err error) {
for i := 0; i < c.maxTryTimes; i++ {
r, err = c.logClient.GetLogsV2(project, logstore, req)
Expand Down
Loading