Parcourir la source

WIP: more boilerplate

bergquist il y a 9 ans
Parent
commit
118e2a6364
3 fichiers modifiés avec 85 ajouts et 0 suppressions
  1. 12 0
      pkg/tsdb/mqe/model_parser.go
  2. 67 0
      pkg/tsdb/mqe/model_parser_test.go
  3. 6 0
      pkg/tsdb/mqe/types.go

+ 12 - 0
pkg/tsdb/mqe/model_parser.go

@@ -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
+}

+ 67 - 0
pkg/tsdb/mqe/model_parser_test.go

@@ -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
+      }
+      `
+		})
+	})
+}

+ 6 - 0
pkg/tsdb/mqe/types.go

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