Skip to content

Commit 8944afb

Browse files
committed
feat: getHistogram v3 use post
1 parent 270ed16 commit 8944afb

File tree

5 files changed

+67
-0
lines changed

5 files changed

+67
-0
lines changed

client_interface.go

+1
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,7 @@ type ClientInterface interface {
303303
// GetHistograms query logs with [from, to) time range
304304
GetHistograms(project, logstore string, topic string, from int64, to int64, queryExp string) (*GetHistogramsResponse, error)
305305
GetHistogramsV2(project, logstore string, ghr *GetHistogramRequest) (*GetHistogramsResponse, error)
306+
GetHistogramsV3(project, logstore string, ghr *GetHistogramRequest) (*GetHistogramsResponse, error)
306307
// GetLogs query logs with [from, to) time range
307308
GetLogs(project, logstore string, topic string, from int64, to int64, queryExp string,
308309
maxLineNum int64, offset int64, reverse bool) (*GetLogsResponse, error)

client_store.go

+5
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,11 @@ func (c *Client) GetHistogramsV2(project, logstore string, ghr *GetHistogramRequ
253253
return ls.GetHistogramsV2(ghr)
254254
}
255255

256+
func (c *Client) GetHistogramsV3(project, logstore string, ghr *GetHistogramRequest) (*GetHistogramsResponse, error) {
257+
ls := convertLogstore(c, project, logstore)
258+
return ls.GetHistogramsV3(ghr)
259+
}
260+
256261
// GetHistogramsToCompleted query logs with [from, to) time range to completed
257262
func (c *Client) GetHistogramsToCompleted(project, logstore string, topic string, from int64, to int64, queryExp string) (*GetHistogramsResponse, error) {
258263
ls := convertLogstore(c, project, logstore)

log_store.go

+47
Original file line numberDiff line numberDiff line change
@@ -716,6 +716,53 @@ func (s *LogStore) GetHistogramsV2(ghr *GetHistogramRequest) (*GetHistogramsResp
716716
return &getHistogramsResponse, nil
717717
}
718718

719+
func (s *LogStore) GetHistogramsV3(ghr *GetHistogramRequest) (*GetHistogramsResponse, error) {
720+
721+
h := map[string]string{
722+
"x-log-bodyrawsize": "0",
723+
"Accept": "application/json",
724+
"Content-Type": "application/json",
725+
}
726+
727+
reqBody, err := ghr.ToJsonBody()
728+
if err != nil {
729+
return nil, err
730+
}
731+
732+
uri := fmt.Sprintf("/logstores/%s/histograms", s.Name)
733+
r, err := request(s.project, "POST", uri, h, reqBody)
734+
if err != nil {
735+
return nil, NewClientError(err)
736+
}
737+
defer r.Body.Close()
738+
body, _ := ioutil.ReadAll(r.Body)
739+
if r.StatusCode != http.StatusOK {
740+
err := new(Error)
741+
if jErr := json.Unmarshal(body, err); jErr != nil {
742+
return nil, NewBadResponseError(string(body), r.Header, r.StatusCode)
743+
}
744+
return nil, err
745+
}
746+
747+
histograms := []SingleHistogram{}
748+
err = json.Unmarshal(body, &histograms)
749+
if err != nil {
750+
return nil, NewBadResponseError(string(body), r.Header, r.StatusCode)
751+
}
752+
753+
count, err := strconv.ParseInt(r.Header.Get(GetLogsCountHeader), 10, 64)
754+
if err != nil {
755+
return nil, err
756+
}
757+
getHistogramsResponse := GetHistogramsResponse{
758+
Progress: r.Header[ProgressHeader][0],
759+
Count: count,
760+
Histograms: histograms,
761+
}
762+
763+
return &getHistogramsResponse, nil
764+
}
765+
719766
// GetLogLines query logs with [from, to) time range
720767
func (s *LogStore) GetLogLines(topic string, from int64, to int64, queryExp string,
721768
maxLineNum int64, offset int64, reverse bool) (*GetLogLinesResponse, error) {

model.go

+4
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ func (ghr *GetHistogramRequest) ToURLParams() url.Values {
6363
return urlVal
6464
}
6565

66+
func (ghr *GetHistogramRequest) ToJsonBody() ([]byte, error) {
67+
return json.Marshal(ghr)
68+
}
69+
6670
type PullLogRequest struct {
6771
Project string
6872
Logstore string

token_auto_update_client.go

+10
Original file line numberDiff line numberDiff line change
@@ -901,6 +901,16 @@ func (c *TokenAutoUpdateClient) GetHistogramsV2(project, logstore string, ghr *G
901901
return
902902
}
903903

904+
func (c *TokenAutoUpdateClient) GetHistogramsV3(project, logstore string, ghr *GetHistogramRequest) (h *GetHistogramsResponse, err error) {
905+
for i := 0; i < c.maxTryTimes; i++ {
906+
h, err = c.logClient.GetHistogramsV3(project, logstore, ghr)
907+
if !c.processError(err) {
908+
return
909+
}
910+
}
911+
return
912+
}
913+
904914
func (c *TokenAutoUpdateClient) GetHistogramsToCompleted(project, logstore string, topic string, from int64, to int64, queryExp string) (h *GetHistogramsResponse, err error) {
905915
for i := 0; i < c.maxTryTimes; i++ {
906916
h, err = c.logClient.GetHistogramsToCompleted(project, logstore, topic, from, to, queryExp)

0 commit comments

Comments
 (0)