Skip to content

Commit

Permalink
feat(mqe): simplify timestamp parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
bergquist committed Nov 17, 2016
1 parent 9572f08 commit 23387bd
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
6 changes: 3 additions & 3 deletions pkg/tsdb/mqe/mqe.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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
}
Expand Down
14 changes: 6 additions & 8 deletions pkg/tsdb/mqe/response_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"encoding/json"
"io/ioutil"
"net/http"
"time"

null "gopkg.in/guregu/null.v3"

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down
10 changes: 8 additions & 2 deletions pkg/tsdb/mqe/response_parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
})
})
}
Expand All @@ -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": {
Expand Down

0 comments on commit 23387bd

Please sign in to comment.