Skip to content

feat: getHistogram v3 use post #311

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions client_interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ type ClientInterface interface {
// 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)
GetHistogramsV3(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 Down
5 changes: 5 additions & 0 deletions client_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,11 @@ func (c *Client) GetHistogramsV2(project, logstore string, ghr *GetHistogramRequ
return ls.GetHistogramsV2(ghr)
}

func (c *Client) GetHistogramsV3(project, logstore string, ghr *GetHistogramRequest) (*GetHistogramsResponse, error) {
ls := convertLogstore(c, project, logstore)
return ls.GetHistogramsV3(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)
Expand Down
47 changes: 47 additions & 0 deletions log_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,53 @@ func (s *LogStore) GetHistogramsV2(ghr *GetHistogramRequest) (*GetHistogramsResp
return &getHistogramsResponse, nil
}

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

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

reqBody, err := ghr.ToJsonBody()
if err != nil {
return nil, err
}

uri := fmt.Sprintf("/logstores/%s/histograms", s.Name)
r, err := request(s.project, "POST", uri, h, reqBody)
if err != nil {
return nil, NewClientError(err)
}
defer r.Body.Close()
body, _ := ioutil.ReadAll(r.Body)
if r.StatusCode != http.StatusOK {
err := new(Error)
if jErr := json.Unmarshal(body, err); jErr != nil {
return nil, NewBadResponseError(string(body), r.Header, r.StatusCode)
}
return nil, err
}

histograms := []SingleHistogram{}
err = json.Unmarshal(body, &histograms)
if err != nil {
return nil, NewBadResponseError(string(body), r.Header, r.StatusCode)
}

count, err := strconv.ParseInt(r.Header.Get(GetLogsCountHeader), 10, 64)
if err != nil {
return nil, err
}
getHistogramsResponse := GetHistogramsResponse{
Progress: r.Header[ProgressHeader][0],
Count: count,
Histograms: histograms,
}

return &getHistogramsResponse, nil
}

// GetLogLines query logs with [from, to) time range
func (s *LogStore) GetLogLines(topic string, from int64, to int64, queryExp string,
maxLineNum int64, offset int64, reverse bool) (*GetLogLinesResponse, error) {
Expand Down
4 changes: 4 additions & 0 deletions model.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ func (ghr *GetHistogramRequest) ToURLParams() url.Values {
return urlVal
}

func (ghr *GetHistogramRequest) ToJsonBody() ([]byte, error) {
return json.Marshal(ghr)
}

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

func (c *TokenAutoUpdateClient) GetHistogramsV3(project, logstore string, ghr *GetHistogramRequest) (h *GetHistogramsResponse, err error) {
for i := 0; i < c.maxTryTimes; i++ {
h, err = c.logClient.GetHistogramsV3(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 Down
Loading