mirror of
https://github.com/grafana/grafana.git
synced 2025-02-14 17:43:35 -06:00
style(mqe): improve code
This commit is contained in:
parent
23387bd39b
commit
0a0f558c48
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user