When the time exceeds the limit, adjust the end time (#409)
This commit is contained in:
parent
227652ec8f
commit
38e060f704
|
@ -114,18 +114,19 @@ func xcludeResp(iter ident.TagIterator) *dataobj.XcludeResp {
|
|||
return ret
|
||||
}
|
||||
|
||||
func aggregateResp(data []*dataobj.TsdbQueryResponse, opts dataobj.QueryDataForUI) []*dataobj.TsdbQueryResponse {
|
||||
if len(data) < 2 {
|
||||
return data
|
||||
}
|
||||
|
||||
// resample the data
|
||||
func resampleResp(data []*dataobj.TsdbQueryResponse, opts dataobj.QueryDataForUI) []*dataobj.TsdbQueryResponse {
|
||||
for _, v := range data {
|
||||
if len(v.Values) <= MAX_PONINTS {
|
||||
continue
|
||||
}
|
||||
v.Values = resample(v.Values, opts.Start, opts.End, int64(opts.Step), opts.ConsolFunc)
|
||||
}
|
||||
return data
|
||||
}
|
||||
|
||||
func aggregateResp(data []*dataobj.TsdbQueryResponse, opts dataobj.QueryDataForUI) []*dataobj.TsdbQueryResponse {
|
||||
// aggregateResp
|
||||
if opts.AggrFunc == "" {
|
||||
if len(data) < 2 || opts.AggrFunc == "" {
|
||||
return data
|
||||
}
|
||||
|
||||
|
@ -188,6 +189,7 @@ func aggregateResp(data []*dataobj.TsdbQueryResponse, opts dataobj.QueryDataForU
|
|||
}
|
||||
|
||||
func resample(data []*dataobj.RRDData, start, end, step int64, consolFunc string) []*dataobj.RRDData {
|
||||
|
||||
l := int((end - start) / step)
|
||||
if l <= 0 {
|
||||
return []*dataobj.RRDData{}
|
||||
|
|
|
@ -155,6 +155,8 @@ func (p *Client) QueryDataForUI(input dataobj.QueryDataForUI) []*dataobj.TsdbQue
|
|||
return nil
|
||||
}
|
||||
|
||||
ret = resampleResp(ret, input)
|
||||
|
||||
return aggregateResp(ret, input)
|
||||
}
|
||||
|
||||
|
@ -484,9 +486,8 @@ func (cfg M3dbSection) validateQueryDataForUI(in *dataobj.QueryDataForUI) (err e
|
|||
}
|
||||
|
||||
if cfg.DaysLimit > 0 {
|
||||
if t := in.End - cfg.timeLimit; in.Start < t {
|
||||
// return fmt.Errorf("query time reange in invalid, daysLimit(%d/%d)", days, cfg.DaysLimit)
|
||||
in.Start = t
|
||||
if t := in.Start + cfg.timeLimit; in.End > t {
|
||||
in.End = t
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue