mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
feat(mqe): simplify timestamp parsing
This commit is contained in:
parent
9572f086ae
commit
23387bd39b
@ -67,7 +67,7 @@ func (e *MQEExecutor) Execute(ctx context.Context, queries tsdb.QuerySlice, quer
|
|||||||
rawQueries = append(rawQueries, queries...)
|
rawQueries = append(rawQueries, queries...)
|
||||||
}
|
}
|
||||||
|
|
||||||
asdf := &tsdb.QueryResult{}
|
queryResult := &tsdb.QueryResult{}
|
||||||
for _, v := range rawQueries {
|
for _, v := range rawQueries {
|
||||||
glog.Info("Mqe executor", "query", v)
|
glog.Info("Mqe executor", "query", v)
|
||||||
|
|
||||||
@ -83,11 +83,11 @@ func (e *MQEExecutor) Execute(ctx context.Context, queries tsdb.QuerySlice, quer
|
|||||||
return result.WithError(err)
|
return result.WithError(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
asdf.Series = append(asdf.Series, series.Series...)
|
queryResult.Series = append(queryResult.Series, series.Series...)
|
||||||
}
|
}
|
||||||
|
|
||||||
result.QueryResults = make(map[string]*tsdb.QueryResult)
|
result.QueryResults = make(map[string]*tsdb.QueryResult)
|
||||||
result.QueryResults["A"] = asdf
|
result.QueryResults["A"] = queryResult
|
||||||
|
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,6 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
|
||||||
|
|
||||||
null "gopkg.in/guregu/null.v3"
|
null "gopkg.in/guregu/null.v3"
|
||||||
|
|
||||||
@ -32,9 +31,9 @@ type MQEResponse struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type ResponseTimeRange struct {
|
type ResponseTimeRange struct {
|
||||||
Start int64 `json:"start"`
|
Start int64 `json:"start"`
|
||||||
End int64 `json:"end"`
|
End int64 `json:"end"`
|
||||||
Resolution time.Duration `json:"Resolution"`
|
Resolution int64 `json:"Resolution"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type MQEResponseSerie struct {
|
type MQEResponseSerie struct {
|
||||||
@ -84,10 +83,9 @@ func (parser *MQEResponseParser) Parse(res *http.Response) (*tsdb.QueryResult, e
|
|||||||
Name: v.Name,
|
Name: v.Name,
|
||||||
}
|
}
|
||||||
|
|
||||||
startTime := time.Unix(v.TimeRange.Start*1000, 0)
|
for i, value := range k.Values {
|
||||||
for i, l := range k.Values {
|
timestamp := v.TimeRange.Start + int64(i)*v.TimeRange.Resolution
|
||||||
timestamp := startTime.Add(time.Duration(int64(v.TimeRange.Resolution) * int64(i)))
|
serie.Points = append(serie.Points, tsdb.NewTimePoint(value, float64(timestamp)))
|
||||||
serie.Points = append(serie.Points, tsdb.NewTimePoint(l, float64(timestamp.UnixNano()/int64(time.Millisecond))))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
series = append(series, serie)
|
series = append(series, serie)
|
||||||
|
@ -27,7 +27,13 @@ func TestMQEResponseParser(t *testing.T) {
|
|||||||
res, err := parser.Parse(response)
|
res, err := parser.Parse(response)
|
||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
So(len(res.Series), ShouldEqual, 2)
|
So(len(res.Series), ShouldEqual, 2)
|
||||||
So(len(res.Series[0].Points), ShouldEqual, 11)
|
So(len(res.Series[0].Points), ShouldEqual, 14)
|
||||||
|
|
||||||
|
startTime := 1479287280000
|
||||||
|
for i := 0; i < 11; i++ {
|
||||||
|
So(res.Series[0].Points[i][0].Float64, ShouldEqual, i+1)
|
||||||
|
So(res.Series[0].Points[i][1].Float64, ShouldEqual, startTime+(i*30000))
|
||||||
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -47,7 +53,7 @@ func init() {
|
|||||||
"app": "demoapp",
|
"app": "demoapp",
|
||||||
"host": "staples-lab-1"
|
"host": "staples-lab-1"
|
||||||
},
|
},
|
||||||
"values": [1,2,3,4,5,6,7,8,9,10,11]
|
"values": [1,2,3,4,5,6,7,8,9,10,11, null, null, null]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"tagset": {
|
"tagset": {
|
||||||
|
Loading…
Reference in New Issue
Block a user