Commit ca6a6675 by bergquist

feat(mqe): renames app tag into cluster

parent f8871f9e
...@@ -14,12 +14,12 @@ type QueryParser struct{} ...@@ -14,12 +14,12 @@ type QueryParser struct{}
func (qp *QueryParser) Parse(model *simplejson.Json, dsInfo *models.DataSource, queryContext *tsdb.QueryContext) (*Query, error) { func (qp *QueryParser) Parse(model *simplejson.Json, dsInfo *models.DataSource, queryContext *tsdb.QueryContext) (*Query, error) {
query := &Query{TimeRange: queryContext.TimeRange} query := &Query{TimeRange: queryContext.TimeRange}
query.AddAppToAlias = model.Get("addAppToAlias").MustBool(false) query.AddClusterToAlias = model.Get("addClusterToAlias").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)
query.RawQuery = model.Get("query").MustString("") query.RawQuery = model.Get("query").MustString("")
query.Apps = model.Get("apps").MustStringArray([]string{}) query.Cluster = model.Get("cluster").MustStringArray([]string{})
query.Hosts = model.Get("hosts").MustStringArray([]string{}) query.Hosts = model.Get("hosts").MustStringArray([]string{})
var metrics []Metric var metrics []Metric
......
...@@ -19,7 +19,7 @@ func TestMQEQueryParser(t *testing.T) { ...@@ -19,7 +19,7 @@ func TestMQEQueryParser(t *testing.T) {
Convey("can parse simple mqe model", func() { Convey("can parse simple mqe model", func() {
json := ` json := `
{ {
"apps": [], "cluster": [],
"hosts": [ "hosts": [
"staples-lab-1" "staples-lab-1"
], ],
...@@ -39,7 +39,7 @@ func TestMQEQueryParser(t *testing.T) { ...@@ -39,7 +39,7 @@ func TestMQEQueryParser(t *testing.T) {
So(err, ShouldBeNil) So(err, ShouldBeNil)
So(query.UseRawQuery, ShouldBeFalse) So(query.UseRawQuery, ShouldBeFalse)
So(len(query.Apps), ShouldEqual, 0) So(len(query.Cluster), ShouldEqual, 0)
So(query.Hosts[0], ShouldEqual, "staples-lab-1") So(query.Hosts[0], ShouldEqual, "staples-lab-1")
So(query.Metrics[0].Metric, ShouldEqual, "os.cpu.all*") So(query.Metrics[0].Metric, ShouldEqual, "os.cpu.all*")
}) })
...@@ -47,7 +47,7 @@ func TestMQEQueryParser(t *testing.T) { ...@@ -47,7 +47,7 @@ func TestMQEQueryParser(t *testing.T) {
Convey("can parse multi serie mqe model", func() { Convey("can parse multi serie mqe model", func() {
json := ` json := `
{ {
"apps": [ "cluster": [
"demoapp" "demoapp"
], ],
"hosts": [ "hosts": [
...@@ -63,7 +63,7 @@ func TestMQEQueryParser(t *testing.T) { ...@@ -63,7 +63,7 @@ func TestMQEQueryParser(t *testing.T) {
], ],
"rawQuery": "", "rawQuery": "",
"refId": "A", "refId": "A",
"addAppToAlias": true, "addClusterToAlias": true,
"addHostToAlias": true "addHostToAlias": true
} }
` `
...@@ -73,7 +73,7 @@ func TestMQEQueryParser(t *testing.T) { ...@@ -73,7 +73,7 @@ func TestMQEQueryParser(t *testing.T) {
query, err := parser.Parse(modelJson, dsInfo, queryContext) 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.Cluster[0], ShouldEqual, "demoapp")
So(query.Metrics[0].Metric, ShouldEqual, "os.cpu.all.active_percentage") So(query.Metrics[0].Metric, ShouldEqual, "os.cpu.all.active_percentage")
So(query.Metrics[1].Metric, ShouldEqual, "os.disk.sda.io_time") So(query.Metrics[1].Metric, ShouldEqual, "os.disk.sda.io_time")
}) })
...@@ -81,9 +81,9 @@ func TestMQEQueryParser(t *testing.T) { ...@@ -81,9 +81,9 @@ func TestMQEQueryParser(t *testing.T) {
Convey("can parse raw query", func() { Convey("can parse raw query", func() {
json := ` json := `
{ {
"addAppToAlias": true, "addClusterToAlias": true,
"addHostToAlias": true, "addHostToAlias": true,
"apps": [], "cluster": [],
"hosts": [ "hosts": [
"staples-lab-1" "staples-lab-1"
], ],
...@@ -99,9 +99,7 @@ func TestMQEQueryParser(t *testing.T) { ...@@ -99,9 +99,7 @@ func TestMQEQueryParser(t *testing.T) {
], ],
"rawQuery": true, "rawQuery": true,
"query": "raw-query", "query": "raw-query",
"refId": "A", "refId": "A"
"addAppToAlias": true,
"addHostToAlias": true
} }
` `
modelJson, err := simplejson.NewJson([]byte(json)) modelJson, err := simplejson.NewJson([]byte(json))
...@@ -112,7 +110,7 @@ func TestMQEQueryParser(t *testing.T) { ...@@ -112,7 +110,7 @@ func TestMQEQueryParser(t *testing.T) {
So(query.UseRawQuery, ShouldBeTrue) So(query.UseRawQuery, ShouldBeTrue)
So(query.RawQuery, ShouldEqual, "raw-query") So(query.RawQuery, ShouldEqual, "raw-query")
So(query.AddAppToAlias, ShouldBeTrue) So(query.AddClusterToAlias, ShouldBeTrue)
So(query.AddHostToAlias, ShouldBeTrue) So(query.AddHostToAlias, ShouldBeTrue)
}) })
}) })
......
...@@ -78,7 +78,7 @@ func (parser *ResponseParser) Parse(res *http.Response, queryRef *Query) ([]*tsd ...@@ -78,7 +78,7 @@ func (parser *ResponseParser) Parse(res *http.Response, queryRef *Query) ([]*tsd
//append predefined tags to seriename //append predefined tags to seriename
for key, value := range mqeSerie.Tagset { for key, value := range mqeSerie.Tagset {
if key == "app" && queryRef.AddAppToAlias { if key == "cluster" && queryRef.AddClusterToAlias {
namePrefix += value + " " namePrefix += value + " "
} }
if key == "host" && queryRef.AddHostToAlias { if key == "host" && queryRef.AddHostToAlias {
......
...@@ -21,8 +21,8 @@ func TestMQEResponseParser(t *testing.T) { ...@@ -21,8 +21,8 @@ func TestMQEResponseParser(t *testing.T) {
Convey("Can parse response", func() { Convey("Can parse response", func() {
queryRef := &Query{ queryRef := &Query{
AddAppToAlias: true, AddClusterToAlias: true,
AddHostToAlias: true, AddHostToAlias: true,
} }
response := &http.Response{ response := &http.Response{
...@@ -55,14 +55,14 @@ func init() { ...@@ -55,14 +55,14 @@ func init() {
"series": [ "series": [
{ {
"tagset": { "tagset": {
"app": "demoapp", "cluster": "demoapp",
"host": "staples-lab-1" "host": "staples-lab-1"
}, },
"values": [1,2,3,4,5,6,7,8,9,10,11, null, null, null] "values": [1,2,3,4,5,6,7,8,9,10,11, null, null, null]
}, },
{ {
"tagset": { "tagset": {
"app": "demoapp", "cluster": "demoapp",
"host": "staples-lab-2" "host": "staples-lab-2"
}, },
"values": [11,10,9,8,7,6,5,4,3,2,1] "values": [11,10,9,8,7,6,5,4,3,2,1]
...@@ -77,7 +77,7 @@ func init() { ...@@ -77,7 +77,7 @@ func init() {
], ],
"metadata": { "metadata": {
"description": { "description": {
"app": [ "cluster": [
"demoapp" "demoapp"
], ],
"host": [ "host": [
......
...@@ -17,11 +17,11 @@ type Metric struct { ...@@ -17,11 +17,11 @@ type Metric struct {
} }
type Query struct { type Query struct {
Metrics []Metric Metrics []Metric
Hosts []string Hosts []string
Apps []string Cluster []string
AddAppToAlias bool AddClusterToAlias bool
AddHostToAlias bool AddHostToAlias bool
TimeRange *tsdb.TimeRange TimeRange *tsdb.TimeRange
UseRawQuery bool UseRawQuery bool
...@@ -91,7 +91,7 @@ func (q *Query) Build(availableSeries []string) ([]QueryToSend, error) { ...@@ -91,7 +91,7 @@ func (q *Query) Build(availableSeries []string) ([]QueryToSend, error) {
} }
func (q *Query) buildWhereClause() string { func (q *Query) buildWhereClause() string {
hasApps := len(q.Apps) > 0 hasApps := len(q.Cluster) > 0
hasHosts := len(q.Hosts) > 0 hasHosts := len(q.Hosts) > 0
where := "" where := ""
...@@ -100,8 +100,8 @@ func (q *Query) buildWhereClause() string { ...@@ -100,8 +100,8 @@ func (q *Query) buildWhereClause() string {
} }
if hasApps { if hasApps {
apps := strings.Join(q.Apps, "', '") apps := strings.Join(q.Cluster, "', '")
where += fmt.Sprintf("app in ('%s')", apps) where += fmt.Sprintf("cluster in ('%s')", apps)
} }
if hasHosts && hasApps { if hasHosts && hasApps {
......
...@@ -31,19 +31,19 @@ func TestWildcardExpansion(t *testing.T) { ...@@ -31,19 +31,19 @@ func TestWildcardExpansion(t *testing.T) {
Metric{Metric: "os.cpu.2.idle", Alias: ""}, Metric{Metric: "os.cpu.2.idle", Alias: ""},
Metric{Metric: "os.cpu.1.idle", Alias: "cpu"}, Metric{Metric: "os.cpu.1.idle", Alias: "cpu"},
}, },
Hosts: []string{"staples-lab-1", "staples-lab-2"}, Hosts: []string{"staples-lab-1", "staples-lab-2"},
Apps: []string{"demoapp-1", "demoapp-2"}, Cluster: []string{"demoapp-1", "demoapp-2"},
AddAppToAlias: false, AddClusterToAlias: false,
AddHostToAlias: false, AddHostToAlias: false,
TimeRange: &tsdb.TimeRange{Now: now, From: "5m", To: "now"}, TimeRange: &tsdb.TimeRange{Now: now, From: "5m", To: "now"},
} }
expandeQueries, err := query.Build(availableMetrics) expandeQueries, err := query.Build(availableMetrics)
So(err, ShouldBeNil) So(err, ShouldBeNil)
So(len(expandeQueries), ShouldEqual, 3) So(len(expandeQueries), ShouldEqual, 3)
So(expandeQueries[0].RawQuery, ShouldEqual, fmt.Sprintf("`os.cpu.3.idle` where app in ('demoapp-1', 'demoapp-2') and host in ('staples-lab-1', 'staples-lab-2') from %v to %v", from, to)) So(expandeQueries[0].RawQuery, ShouldEqual, fmt.Sprintf("`os.cpu.3.idle` where cluster in ('demoapp-1', 'demoapp-2') and host in ('staples-lab-1', 'staples-lab-2') from %v to %v", from, to))
So(expandeQueries[1].RawQuery, ShouldEqual, fmt.Sprintf("`os.cpu.2.idle` where app in ('demoapp-1', 'demoapp-2') and host in ('staples-lab-1', 'staples-lab-2') from %v to %v", from, to)) So(expandeQueries[1].RawQuery, ShouldEqual, fmt.Sprintf("`os.cpu.2.idle` where cluster in ('demoapp-1', 'demoapp-2') and host in ('staples-lab-1', 'staples-lab-2') from %v to %v", from, to))
So(expandeQueries[2].RawQuery, ShouldEqual, fmt.Sprintf("`os.cpu.1.idle` {cpu} where app in ('demoapp-1', 'demoapp-2') and host in ('staples-lab-1', 'staples-lab-2') from %v to %v", from, to)) So(expandeQueries[2].RawQuery, ShouldEqual, fmt.Sprintf("`os.cpu.1.idle` {cpu} where cluster in ('demoapp-1', 'demoapp-2') and host in ('staples-lab-1', 'staples-lab-2') from %v to %v", from, to))
}) })
Convey("Containg wildcard series", func() { Convey("Containg wildcard series", func() {
...@@ -51,10 +51,10 @@ func TestWildcardExpansion(t *testing.T) { ...@@ -51,10 +51,10 @@ func TestWildcardExpansion(t *testing.T) {
Metrics: []Metric{ Metrics: []Metric{
Metric{Metric: "os.cpu*", Alias: ""}, Metric{Metric: "os.cpu*", Alias: ""},
}, },
Hosts: []string{"staples-lab-1"}, Hosts: []string{"staples-lab-1"},
AddAppToAlias: false, AddClusterToAlias: false,
AddHostToAlias: false, AddHostToAlias: false,
TimeRange: &tsdb.TimeRange{Now: now, From: "5m", To: "now"}, TimeRange: &tsdb.TimeRange{Now: now, From: "5m", To: "now"},
} }
expandeQueries, err := query.Build(availableMetrics) expandeQueries, err := query.Build(availableMetrics)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment