mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -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"
|
"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
|
||||||
|
@ -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 _, body := range data.Body {
|
||||||
for _, k := range v.Series {
|
for _, mqeSerie := range body.Series {
|
||||||
serie := &tsdb.TimeSeries{
|
serie := &tsdb.TimeSeries{Name: body.Name}
|
||||||
Name: v.Name,
|
|
||||||
}
|
|
||||||
|
|
||||||
for i, value := range k.Values {
|
for i, value := range mqeSerie.Values {
|
||||||
timestamp := v.TimeRange.Start + int64(i)*v.TimeRange.Resolution
|
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
|
||||||
|
Loading…
Reference in New Issue
Block a user