WIP: more boilerplate

This commit is contained in:
bergquist 2016-11-11 12:35:09 +01:00
parent bd3259d07a
commit 118e2a6364
3 changed files with 85 additions and 0 deletions

View File

@ -0,0 +1,12 @@
package mqe
import (
"github.com/grafana/grafana/pkg/components/simplejson"
"github.com/grafana/grafana/pkg/tsdb"
)
type MQEQueryParser struct{}
func (qp *MQEQueryParser) Parse(model *simplejson.Json, dsInfo *tsdb.DataSourceInfo) (*MQEQuery, error) {
return nil, nil
}

View File

@ -0,0 +1,67 @@
package mqe
import (
"testing"
"github.com/grafana/grafana/pkg/components/simplejson"
"github.com/grafana/grafana/pkg/tsdb"
. "github.com/smartystreets/goconvey/convey"
)
func TestMQEQueryParser(t *testing.T) {
Convey("MQE query parser", t, func() {
parser := &MQEQueryParser{}
dsInfo := &tsdb.DataSourceInfo{
JsonData: simplejson.New(),
}
Convey("can parse simple mqe model", func() {
json := `
{
"apps": [],
"hosts": [
"staples-lab-1"
],
"metric": "$metric_cpu",
"metrics": [
{
"metric": "$metric_cpu"
}
],
"rawQuery": "",
"refId": "A"
}
`
modelJson, err := simplejson.NewJson([]byte(json))
So(err, ShouldBeNil)
res, err := parser.Parse(modelJson, dsInfo)
So(err, ShouldBeNil)
So(res.Interval, ShouldEqual, ">20s")
})
Convey("can parse multi serie mqe model", func() {
json := `
{
"apps": [],
"hosts": [
"staples-lab-1"
],
"metrics": [
{
"metric": "os.cpu.all.active_percentage"
},
{
"metric": "os.disk.sda.io_time"
}
],
"rawQuery": "",
"refId": "A",
"addAppToAlias": true,
"addHostToAlias": true
}
`
})
})
}

View File

@ -1 +1,7 @@
package mqe package mqe
type MQEQuery struct {
Metrics []string
Hosts []string
Apps []string
}