Browse Source

style(mqe): improve code

bergquist 9 years ago
parent
commit
0a0f558c48
2 changed files with 16 additions and 14 deletions
  1. 10 0
      pkg/tsdb/mqe/mqe.go
  2. 6 14
      pkg/tsdb/mqe/response_parser.go

+ 10 - 0
pkg/tsdb/mqe/mqe.go

@@ -14,6 +14,16 @@ import (
 	"github.com/grafana/grafana/pkg/tsdb"
 	"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 {
 type MQEExecutor struct {
 	*tsdb.DataSourceInfo
 	*tsdb.DataSourceInfo
 	QueryParser    *MQEQueryParser
 	QueryParser    *MQEQueryParser

+ 6 - 14
pkg/tsdb/mqe/response_parser.go

@@ -13,11 +13,6 @@ import (
 	"github.com/grafana/grafana/pkg/tsdb"
 	"github.com/grafana/grafana/pkg/tsdb"
 )
 )
 
 
-// wildcard as alias
-// add host to alias
-// add app to alias
-// regular alias
-
 func NewResponseParser() *MQEResponseParser {
 func NewResponseParser() *MQEResponseParser {
 	return &MQEResponseParser{
 	return &MQEResponseParser{
 		log: log.New("tsdb.mqe"),
 		log: log.New("tsdb.mqe"),
@@ -68,7 +63,7 @@ func (parser *MQEResponseParser) Parse(res *http.Response) (*tsdb.QueryResult, e
 	var data *MQEResponse = &MQEResponse{}
 	var data *MQEResponse = &MQEResponse{}
 	err = json.Unmarshal(body, data)
 	err = json.Unmarshal(body, data)
 	if err != nil {
 	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
 		return nil, err
 	}
 	}
 
 
@@ -77,20 +72,17 @@ func (parser *MQEResponseParser) Parse(res *http.Response) (*tsdb.QueryResult, e
 	}
 	}
 
 
 	var series tsdb.TimeSeriesSlice
 	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)))
 				serie.Points = append(serie.Points, tsdb.NewTimePoint(value, float64(timestamp)))
 			}
 			}
 
 
 			series = append(series, serie)
 			series = append(series, serie)
 		}
 		}
-
 	}
 	}
 
 
 	return &tsdb.QueryResult{Series: series}, nil
 	return &tsdb.QueryResult{Series: series}, nil