mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
feat(mqe): add timerange to query
This commit is contained in:
parent
fa8213d8d5
commit
9572f086ae
@ -7,9 +7,8 @@ import (
|
|||||||
|
|
||||||
type MQEQueryParser struct{}
|
type MQEQueryParser struct{}
|
||||||
|
|
||||||
func (qp *MQEQueryParser) Parse(model *simplejson.Json, dsInfo *tsdb.DataSourceInfo) (*MQEQuery, error) {
|
func (qp *MQEQueryParser) Parse(model *simplejson.Json, dsInfo *tsdb.DataSourceInfo, queryContext *tsdb.QueryContext) (*MQEQuery, error) {
|
||||||
query := &MQEQuery{}
|
query := &MQEQuery{TimeRange: queryContext.TimeRange}
|
||||||
|
|
||||||
query.AddAppToAlias = model.Get("addAppToAlias").MustBool(false)
|
query.AddAppToAlias = model.Get("addAppToAlias").MustBool(false)
|
||||||
query.AddHostToAlias = model.Get("addHostToAlias").MustBool(false)
|
query.AddHostToAlias = model.Get("addHostToAlias").MustBool(false)
|
||||||
query.UseRawQuery = model.Get("rawQuery").MustBool(false)
|
query.UseRawQuery = model.Get("rawQuery").MustBool(false)
|
||||||
|
@ -12,9 +12,8 @@ func TestMQEQueryParser(t *testing.T) {
|
|||||||
Convey("MQE query parser", t, func() {
|
Convey("MQE query parser", t, func() {
|
||||||
parser := &MQEQueryParser{}
|
parser := &MQEQueryParser{}
|
||||||
|
|
||||||
dsInfo := &tsdb.DataSourceInfo{
|
dsInfo := &tsdb.DataSourceInfo{JsonData: simplejson.New()}
|
||||||
JsonData: simplejson.New(),
|
queryContext := &tsdb.QueryContext{}
|
||||||
}
|
|
||||||
|
|
||||||
Convey("can parse simple mqe model", func() {
|
Convey("can parse simple mqe model", func() {
|
||||||
json := `
|
json := `
|
||||||
@ -35,7 +34,7 @@ func TestMQEQueryParser(t *testing.T) {
|
|||||||
modelJson, err := simplejson.NewJson([]byte(json))
|
modelJson, err := simplejson.NewJson([]byte(json))
|
||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
|
|
||||||
query, err := parser.Parse(modelJson, dsInfo)
|
query, err := parser.Parse(modelJson, dsInfo, queryContext)
|
||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
So(query.UseRawQuery, ShouldBeFalse)
|
So(query.UseRawQuery, ShouldBeFalse)
|
||||||
|
|
||||||
@ -70,7 +69,7 @@ func TestMQEQueryParser(t *testing.T) {
|
|||||||
modelJson, err := simplejson.NewJson([]byte(json))
|
modelJson, err := simplejson.NewJson([]byte(json))
|
||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
|
|
||||||
query, err := parser.Parse(modelJson, dsInfo)
|
query, err := parser.Parse(modelJson, dsInfo, queryContext)
|
||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
So(query.UseRawQuery, ShouldBeFalse)
|
So(query.UseRawQuery, ShouldBeFalse)
|
||||||
So(query.Apps[0], ShouldEqual, "demoapp")
|
So(query.Apps[0], ShouldEqual, "demoapp")
|
||||||
@ -107,7 +106,7 @@ func TestMQEQueryParser(t *testing.T) {
|
|||||||
modelJson, err := simplejson.NewJson([]byte(json))
|
modelJson, err := simplejson.NewJson([]byte(json))
|
||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
|
|
||||||
query, err := parser.Parse(modelJson, dsInfo)
|
query, err := parser.Parse(modelJson, dsInfo, queryContext)
|
||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
|
|
||||||
So(query.UseRawQuery, ShouldBeTrue)
|
So(query.UseRawQuery, ShouldBeTrue)
|
||||||
|
@ -35,12 +35,12 @@ var (
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
glog = log.New("tsdb.mqe")
|
glog = log.New("tsdb.mqe")
|
||||||
tsdb.RegisterExecutor("mqe", NewMQEExecutor)
|
tsdb.RegisterExecutor("mqe-datasource", NewMQEExecutor)
|
||||||
|
|
||||||
HttpClient = tsdb.GetDefaultClient()
|
HttpClient = tsdb.GetDefaultClient()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *MQEExecutor) Execute(ctx context.Context, queries tsdb.QuerySlice, context *tsdb.QueryContext) *tsdb.BatchResult {
|
func (e *MQEExecutor) Execute(ctx context.Context, queries tsdb.QuerySlice, queryContext *tsdb.QueryContext) *tsdb.BatchResult {
|
||||||
result := &tsdb.BatchResult{}
|
result := &tsdb.BatchResult{}
|
||||||
|
|
||||||
availableSeries, err := NewTokenClient().GetTokenData(ctx, e.DataSourceInfo)
|
availableSeries, err := NewTokenClient().GetTokenData(ctx, e.DataSourceInfo)
|
||||||
@ -48,11 +48,9 @@ func (e *MQEExecutor) Execute(ctx context.Context, queries tsdb.QuerySlice, cont
|
|||||||
return result.WithError(err)
|
return result.WithError(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
glog.Info("available series", availableSeries)
|
|
||||||
|
|
||||||
var mqeQueries []*MQEQuery
|
var mqeQueries []*MQEQuery
|
||||||
for _, v := range queries {
|
for _, v := range queries {
|
||||||
q, err := e.QueryParser.Parse(v.Model, e.DataSourceInfo)
|
q, err := e.QueryParser.Parse(v.Model, e.DataSourceInfo, queryContext)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result.WithError(err)
|
return result.WithError(err)
|
||||||
}
|
}
|
||||||
@ -88,6 +86,7 @@ func (e *MQEExecutor) Execute(ctx context.Context, queries tsdb.QuerySlice, cont
|
|||||||
asdf.Series = append(asdf.Series, series.Series...)
|
asdf.Series = append(asdf.Series, series.Series...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
result.QueryResults = make(map[string]*tsdb.QueryResult)
|
||||||
result.QueryResults["A"] = asdf
|
result.QueryResults["A"] = asdf
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
Loading…
Reference in New Issue
Block a user