style(mqe): improve code

This commit is contained in:
bergquist 2016-11-17 08:48:13 +01:00
parent 23387bd39b
commit 0a0f558c48
2 changed files with 16 additions and 14 deletions

View File

@ -14,6 +14,16 @@ import (
"github.com/grafana/grafana/pkg/tsdb"
)
/*
TODO:
* response serie names
* response serie names with tags
* response serie names with wildcards
* real caching
*/
type MQEExecutor struct {
*tsdb.DataSourceInfo
QueryParser *MQEQueryParser

View File

@ -13,11 +13,6 @@ import (
"github.com/grafana/grafana/pkg/tsdb"
)
// wildcard as alias
// add host to alias
// add app to alias
// regular alias
func NewResponseParser() *MQEResponseParser {
return &MQEResponseParser{
log: log.New("tsdb.mqe"),
@ -68,7 +63,7 @@ func (parser *MQEResponseParser) Parse(res *http.Response) (*tsdb.QueryResult, e
var data *MQEResponse = &MQEResponse{}
err = json.Unmarshal(body, data)
if err != nil {
parser.log.Info("Failed to unmarshal graphite response", "error", err, "status", res.Status, "body", string(body))
parser.log.Info("Failed to unmarshal mqe response", "error", err, "status", res.Status, "body", string(body))
return nil, err
}
@ -77,20 +72,17 @@ func (parser *MQEResponseParser) Parse(res *http.Response) (*tsdb.QueryResult, e
}
var series tsdb.TimeSeriesSlice
for _, v := range data.Body {
for _, k := range v.Series {
serie := &tsdb.TimeSeries{
Name: v.Name,
}
for _, body := range data.Body {
for _, mqeSerie := range body.Series {
serie := &tsdb.TimeSeries{Name: body.Name}
for i, value := range k.Values {
timestamp := v.TimeRange.Start + int64(i)*v.TimeRange.Resolution
for i, value := range mqeSerie.Values {
timestamp := body.TimeRange.Start + int64(i)*body.TimeRange.Resolution
serie.Points = append(serie.Points, tsdb.NewTimePoint(value, float64(timestamp)))
}
series = append(series, serie)
}
}
return &tsdb.QueryResult{Series: series}, nil