diff --git a/backend/prome/query.go b/backend/prome/query.go index e658a020..2158e980 100644 --- a/backend/prome/query.go +++ b/backend/prome/query.go @@ -207,13 +207,15 @@ func (pd *PromeDataSource) QueryData(inputs vos.DataQueryParam) []*vos.DataQuery startT := tsToUtcTs(inputs.Start) endT := tsToUtcTs(inputs.End) - // TODO 前端传入分辨率还是后端计算,grafana和prometheus ui都是前端传入 - delta := (inputs.End - inputs.Start) / 3600 - if delta <= 0 { - delta = 1 + resolution := time.Second * time.Duration(inputs.Step) + if inputs.Step == 0 { + // step==0 说明要自己算 grafana和prometheus ui都是前端传入 + delta := (inputs.End - inputs.Start) / 3600 + if delta <= 0 { + delta = 1 + } + resolution = time.Second * time.Duration(delta*DEFAULT_STEP) } - resolution := time.Second * time.Duration(delta*DEFAULT_STEP) - q, err := pd.QueryEngine.NewRangeQuery(pd.Queryable, qlStrFinal, startT, endT, resolution) if err != nil { logger.Errorf("[prome_query_error][QueryData_error_may_be_parse_ql_error][args:%+v][err:%+v]", input, err) @@ -253,7 +255,8 @@ func (pd *PromeDataSource) QueryData(inputs vos.DataQueryParam) []*vos.DataQuery pNum := len(m.Points) for _, p := range m.Points { tmpP := &vos.Point{ - Timestamp: p.T, + // 毫秒时间时间戳转 秒时间戳 + Timestamp: p.T / 1e3, Value: vos.JsonFloat(p.V), } oneResp.Values = append(oneResp.Values, tmpP) @@ -266,7 +269,7 @@ func (pd *PromeDataSource) QueryData(inputs vos.DataQueryParam) []*vos.DataQuery } tagStr = strings.TrimRight(tagStr, ",") oneResp.Tags = tagStr - oneResp.Resolution = delta * DEFAULT_STEP + oneResp.Resolution = int64(resolution / time.Second) oneResp.PNum = pNum respD = append(respD, oneResp) diff --git a/vos/query.go b/vos/query.go index a211b722..16b97e87 100644 --- a/vos/query.go +++ b/vos/query.go @@ -31,6 +31,7 @@ type DataQueryParam struct { Limit int `json:"limit"` Start int64 `json:"start"` End int64 `json:"end"` + Step int64 `json:"step"` } type DataQueryInstantParam struct {