mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
feat(mqe): renames app tag into cluster
This commit is contained in:
@@ -14,12 +14,12 @@ type QueryParser struct{}
|
||||
|
||||
func (qp *QueryParser) Parse(model *simplejson.Json, dsInfo *models.DataSource, queryContext *tsdb.QueryContext) (*Query, error) {
|
||||
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.UseRawQuery = model.Get("rawQuery").MustBool(false)
|
||||
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{})
|
||||
|
||||
var metrics []Metric
|
||||
|
||||
@@ -19,7 +19,7 @@ func TestMQEQueryParser(t *testing.T) {
|
||||
Convey("can parse simple mqe model", func() {
|
||||
json := `
|
||||
{
|
||||
"apps": [],
|
||||
"cluster": [],
|
||||
"hosts": [
|
||||
"staples-lab-1"
|
||||
],
|
||||
@@ -39,7 +39,7 @@ func TestMQEQueryParser(t *testing.T) {
|
||||
So(err, ShouldBeNil)
|
||||
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.Metrics[0].Metric, ShouldEqual, "os.cpu.all*")
|
||||
})
|
||||
@@ -47,7 +47,7 @@ func TestMQEQueryParser(t *testing.T) {
|
||||
Convey("can parse multi serie mqe model", func() {
|
||||
json := `
|
||||
{
|
||||
"apps": [
|
||||
"cluster": [
|
||||
"demoapp"
|
||||
],
|
||||
"hosts": [
|
||||
@@ -63,7 +63,7 @@ func TestMQEQueryParser(t *testing.T) {
|
||||
],
|
||||
"rawQuery": "",
|
||||
"refId": "A",
|
||||
"addAppToAlias": true,
|
||||
"addClusterToAlias": true,
|
||||
"addHostToAlias": true
|
||||
}
|
||||
`
|
||||
@@ -73,7 +73,7 @@ func TestMQEQueryParser(t *testing.T) {
|
||||
query, err := parser.Parse(modelJson, dsInfo, queryContext)
|
||||
So(err, ShouldBeNil)
|
||||
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[1].Metric, ShouldEqual, "os.disk.sda.io_time")
|
||||
})
|
||||
@@ -81,9 +81,9 @@ func TestMQEQueryParser(t *testing.T) {
|
||||
Convey("can parse raw query", func() {
|
||||
json := `
|
||||
{
|
||||
"addAppToAlias": true,
|
||||
"addClusterToAlias": true,
|
||||
"addHostToAlias": true,
|
||||
"apps": [],
|
||||
"cluster": [],
|
||||
"hosts": [
|
||||
"staples-lab-1"
|
||||
],
|
||||
@@ -99,9 +99,7 @@ func TestMQEQueryParser(t *testing.T) {
|
||||
],
|
||||
"rawQuery": true,
|
||||
"query": "raw-query",
|
||||
"refId": "A",
|
||||
"addAppToAlias": true,
|
||||
"addHostToAlias": true
|
||||
"refId": "A"
|
||||
}
|
||||
`
|
||||
modelJson, err := simplejson.NewJson([]byte(json))
|
||||
@@ -112,7 +110,7 @@ func TestMQEQueryParser(t *testing.T) {
|
||||
|
||||
So(query.UseRawQuery, ShouldBeTrue)
|
||||
So(query.RawQuery, ShouldEqual, "raw-query")
|
||||
So(query.AddAppToAlias, ShouldBeTrue)
|
||||
So(query.AddClusterToAlias, ShouldBeTrue)
|
||||
So(query.AddHostToAlias, ShouldBeTrue)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -78,7 +78,7 @@ func (parser *ResponseParser) Parse(res *http.Response, queryRef *Query) ([]*tsd
|
||||
|
||||
//append predefined tags to seriename
|
||||
for key, value := range mqeSerie.Tagset {
|
||||
if key == "app" && queryRef.AddAppToAlias {
|
||||
if key == "cluster" && queryRef.AddClusterToAlias {
|
||||
namePrefix += value + " "
|
||||
}
|
||||
if key == "host" && queryRef.AddHostToAlias {
|
||||
|
||||
@@ -21,8 +21,8 @@ func TestMQEResponseParser(t *testing.T) {
|
||||
|
||||
Convey("Can parse response", func() {
|
||||
queryRef := &Query{
|
||||
AddAppToAlias: true,
|
||||
AddHostToAlias: true,
|
||||
AddClusterToAlias: true,
|
||||
AddHostToAlias: true,
|
||||
}
|
||||
|
||||
response := &http.Response{
|
||||
@@ -55,14 +55,14 @@ func init() {
|
||||
"series": [
|
||||
{
|
||||
"tagset": {
|
||||
"app": "demoapp",
|
||||
"cluster": "demoapp",
|
||||
"host": "staples-lab-1"
|
||||
},
|
||||
"values": [1,2,3,4,5,6,7,8,9,10,11, null, null, null]
|
||||
},
|
||||
{
|
||||
"tagset": {
|
||||
"app": "demoapp",
|
||||
"cluster": "demoapp",
|
||||
"host": "staples-lab-2"
|
||||
},
|
||||
"values": [11,10,9,8,7,6,5,4,3,2,1]
|
||||
@@ -77,7 +77,7 @@ func init() {
|
||||
],
|
||||
"metadata": {
|
||||
"description": {
|
||||
"app": [
|
||||
"cluster": [
|
||||
"demoapp"
|
||||
],
|
||||
"host": [
|
||||
|
||||
@@ -17,11 +17,11 @@ type Metric struct {
|
||||
}
|
||||
|
||||
type Query struct {
|
||||
Metrics []Metric
|
||||
Hosts []string
|
||||
Apps []string
|
||||
AddAppToAlias bool
|
||||
AddHostToAlias bool
|
||||
Metrics []Metric
|
||||
Hosts []string
|
||||
Cluster []string
|
||||
AddClusterToAlias bool
|
||||
AddHostToAlias bool
|
||||
|
||||
TimeRange *tsdb.TimeRange
|
||||
UseRawQuery bool
|
||||
@@ -91,7 +91,7 @@ func (q *Query) Build(availableSeries []string) ([]QueryToSend, error) {
|
||||
}
|
||||
|
||||
func (q *Query) buildWhereClause() string {
|
||||
hasApps := len(q.Apps) > 0
|
||||
hasApps := len(q.Cluster) > 0
|
||||
hasHosts := len(q.Hosts) > 0
|
||||
|
||||
where := ""
|
||||
@@ -100,8 +100,8 @@ func (q *Query) buildWhereClause() string {
|
||||
}
|
||||
|
||||
if hasApps {
|
||||
apps := strings.Join(q.Apps, "', '")
|
||||
where += fmt.Sprintf("app in ('%s')", apps)
|
||||
apps := strings.Join(q.Cluster, "', '")
|
||||
where += fmt.Sprintf("cluster in ('%s')", apps)
|
||||
}
|
||||
|
||||
if hasHosts && hasApps {
|
||||
|
||||
@@ -31,19 +31,19 @@ func TestWildcardExpansion(t *testing.T) {
|
||||
Metric{Metric: "os.cpu.2.idle", Alias: ""},
|
||||
Metric{Metric: "os.cpu.1.idle", Alias: "cpu"},
|
||||
},
|
||||
Hosts: []string{"staples-lab-1", "staples-lab-2"},
|
||||
Apps: []string{"demoapp-1", "demoapp-2"},
|
||||
AddAppToAlias: false,
|
||||
AddHostToAlias: false,
|
||||
TimeRange: &tsdb.TimeRange{Now: now, From: "5m", To: "now"},
|
||||
Hosts: []string{"staples-lab-1", "staples-lab-2"},
|
||||
Cluster: []string{"demoapp-1", "demoapp-2"},
|
||||
AddClusterToAlias: false,
|
||||
AddHostToAlias: false,
|
||||
TimeRange: &tsdb.TimeRange{Now: now, From: "5m", To: "now"},
|
||||
}
|
||||
|
||||
expandeQueries, err := query.Build(availableMetrics)
|
||||
So(err, ShouldBeNil)
|
||||
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[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[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[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 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 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() {
|
||||
@@ -51,10 +51,10 @@ func TestWildcardExpansion(t *testing.T) {
|
||||
Metrics: []Metric{
|
||||
Metric{Metric: "os.cpu*", Alias: ""},
|
||||
},
|
||||
Hosts: []string{"staples-lab-1"},
|
||||
AddAppToAlias: false,
|
||||
AddHostToAlias: false,
|
||||
TimeRange: &tsdb.TimeRange{Now: now, From: "5m", To: "now"},
|
||||
Hosts: []string{"staples-lab-1"},
|
||||
AddClusterToAlias: false,
|
||||
AddHostToAlias: false,
|
||||
TimeRange: &tsdb.TimeRange{Now: now, From: "5m", To: "now"},
|
||||
}
|
||||
|
||||
expandeQueries, err := query.Build(availableMetrics)
|
||||
|
||||
Reference in New Issue
Block a user