feat(mqe): simplify timestamp parsing

This commit is contained in:
bergquist 2016-11-17 08:42:09 +01:00
parent 9572f086ae
commit 23387bd39b
3 changed files with 17 additions and 13 deletions

View File

@ -67,7 +67,7 @@ func (e *MQEExecutor) Execute(ctx context.Context, queries tsdb.QuerySlice, quer
rawQueries = append(rawQueries, queries...)
}
asdf := &tsdb.QueryResult{}
queryResult := &tsdb.QueryResult{}
for _, v := range rawQueries {
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)
}
asdf.Series = append(asdf.Series, series.Series...)
queryResult.Series = append(queryResult.Series, series.Series...)
}
result.QueryResults = make(map[string]*tsdb.QueryResult)
result.QueryResults["A"] = asdf
result.QueryResults["A"] = queryResult
return result
}

View File

@ -4,7 +4,6 @@ import (
"encoding/json"
"io/ioutil"
"net/http"
"time"
null "gopkg.in/guregu/null.v3"
@ -32,9 +31,9 @@ type MQEResponse struct {
}
type ResponseTimeRange struct {
Start int64 `json:"start"`
End int64 `json:"end"`
Resolution time.Duration `json:"Resolution"`
Start int64 `json:"start"`
End int64 `json:"end"`
Resolution int64 `json:"Resolution"`
}
type MQEResponseSerie struct {
@ -84,10 +83,9 @@ func (parser *MQEResponseParser) Parse(res *http.Response) (*tsdb.QueryResult, e
Name: v.Name,
}
startTime := time.Unix(v.TimeRange.Start*1000, 0)
for i, l := range k.Values {
timestamp := startTime.Add(time.Duration(int64(v.TimeRange.Resolution) * int64(i)))
serie.Points = append(serie.Points, tsdb.NewTimePoint(l, float64(timestamp.UnixNano()/int64(time.Millisecond))))
for i, value := range k.Values {
timestamp := v.TimeRange.Start + int64(i)*v.TimeRange.Resolution
serie.Points = append(serie.Points, tsdb.NewTimePoint(value, float64(timestamp)))
}
series = append(series, serie)

View File

@ -27,7 +27,13 @@ func TestMQEResponseParser(t *testing.T) {
res, err := parser.Parse(response)
So(err, ShouldBeNil)
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",
"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": {