Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
149dd782
Commit
149dd782
authored
Jan 11, 2017
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'built_in_template_variables'
parents
44b7a261
b475f913
Show whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
149 additions
and
94 deletions
+149
-94
pkg/tsdb/influxdb/query.go
+40
-9
pkg/tsdb/influxdb/query_part.go
+2
-23
pkg/tsdb/influxdb/query_part_test.go
+2
-23
pkg/tsdb/influxdb/query_test.go
+44
-1
pkg/tsdb/interval.go
+8
-3
pkg/tsdb/interval_test.go
+4
-4
public/app/core/components/query_part/query_part.ts
+1
-1
public/app/features/panel/metrics_panel_ctrl.ts
+8
-1
public/app/features/templating/specs/template_srv_specs.ts
+12
-0
public/app/features/templating/templateSrv.js
+10
-4
public/app/plugins/datasource/elasticsearch/datasource.js
+2
-9
public/app/plugins/datasource/elasticsearch/query_builder.js
+3
-3
public/app/plugins/datasource/influxdb/datasource.ts
+3
-3
public/app/plugins/datasource/influxdb/influx_query.ts
+1
-1
public/app/plugins/datasource/influxdb/specs/influx_query_specs.ts
+9
-9
No files found.
pkg/tsdb/influxdb/query.go
View file @
149dd782
...
...
@@ -2,7 +2,9 @@ package influxdb
import
(
"fmt"
"strconv"
"strings"
"time"
"regexp"
...
...
@@ -15,24 +17,53 @@ var (
)
func
(
query
*
Query
)
Build
(
queryContext
*
tsdb
.
QueryContext
)
(
string
,
error
)
{
if
query
.
UseRawQuery
&&
query
.
RawQuery
!=
""
{
q
:=
query
.
RawQuery
q
=
strings
.
Replace
(
q
,
"$timeFilter"
,
query
.
renderTimeFilter
(
queryContext
),
1
)
q
=
strings
.
Replace
(
q
,
"$interval"
,
tsdb
.
CalculateInterval
(
queryContext
.
TimeRange
),
1
)
var
res
string
return
q
,
nil
}
res
:
=
query
.
renderSelectors
(
queryContext
)
if
query
.
UseRawQuery
&&
query
.
RawQuery
!=
""
{
res
=
query
.
RawQuery
}
else
{
res
=
query
.
renderSelectors
(
queryContext
)
res
+=
query
.
renderMeasurement
()
res
+=
query
.
renderWhereClause
()
res
+=
query
.
renderTimeFilter
(
queryContext
)
res
+=
query
.
renderGroupBy
(
queryContext
)
}
interval
,
err
:=
getDefinedInterval
(
query
,
queryContext
)
if
err
!=
nil
{
return
""
,
err
}
res
=
strings
.
Replace
(
res
,
"$timeFilter"
,
query
.
renderTimeFilter
(
queryContext
),
1
)
res
=
strings
.
Replace
(
res
,
"$interval"
,
interval
.
Text
,
1
)
res
=
strings
.
Replace
(
res
,
"$__interval_ms"
,
strconv
.
FormatInt
(
interval
.
Value
.
Nanoseconds
()
/
int64
(
time
.
Millisecond
),
10
),
1
)
res
=
strings
.
Replace
(
res
,
"$__interval"
,
interval
.
Text
,
1
)
return
res
,
nil
}
func
getDefinedInterval
(
query
*
Query
,
queryContext
*
tsdb
.
QueryContext
)
(
*
tsdb
.
Interval
,
error
)
{
defaultInterval
:=
tsdb
.
CalculateInterval
(
queryContext
.
TimeRange
)
if
query
.
Interval
==
""
{
return
&
defaultInterval
,
nil
}
setInterval
:=
strings
.
Replace
(
strings
.
Replace
(
query
.
Interval
,
"<"
,
""
,
1
),
">"
,
""
,
1
)
parsedSetInterval
,
err
:=
time
.
ParseDuration
(
setInterval
)
if
err
!=
nil
{
return
nil
,
err
}
if
strings
.
Contains
(
query
.
Interval
,
">"
)
{
if
defaultInterval
.
Value
>
parsedSetInterval
{
return
&
defaultInterval
,
nil
}
}
return
&
tsdb
.
Interval
{
Value
:
parsedSetInterval
,
Text
:
setInterval
},
nil
}
func
(
query
*
Query
)
renderTags
()
[]
string
{
var
res
[]
string
for
i
,
tag
:=
range
query
.
Tags
{
...
...
pkg/tsdb/influxdb/query_part.go
View file @
149dd782
...
...
@@ -3,7 +3,6 @@ package influxdb
import
(
"fmt"
"strings"
"time"
"github.com/grafana/grafana/pkg/tsdb"
)
...
...
@@ -93,30 +92,10 @@ func fieldRenderer(query *Query, queryContext *tsdb.QueryContext, part *QueryPar
return
fmt
.
Sprintf
(
`"%s"`
,
part
.
Params
[
0
])
}
func
getDefinedInterval
(
query
*
Query
,
queryContext
*
tsdb
.
QueryContext
)
string
{
setInterval
:=
strings
.
Replace
(
strings
.
Replace
(
query
.
Interval
,
"<"
,
""
,
1
),
">"
,
""
,
1
)
defaultInterval
:=
tsdb
.
CalculateInterval
(
queryContext
.
TimeRange
)
if
strings
.
Contains
(
query
.
Interval
,
">"
)
{
parsedDefaultInterval
,
err
:=
time
.
ParseDuration
(
defaultInterval
)
parsedSetInterval
,
err2
:=
time
.
ParseDuration
(
setInterval
)
if
err
==
nil
&&
err2
==
nil
&&
parsedDefaultInterval
>
parsedSetInterval
{
return
defaultInterval
}
}
return
setInterval
}
func
functionRenderer
(
query
*
Query
,
queryContext
*
tsdb
.
QueryContext
,
part
*
QueryPart
,
innerExpr
string
)
string
{
for
i
,
param
:=
range
part
.
Params
{
if
param
==
"$interval"
||
param
==
"auto"
{
if
query
.
Interval
!=
""
{
part
.
Params
[
i
]
=
getDefinedInterval
(
query
,
queryContext
)
}
else
{
part
.
Params
[
i
]
=
tsdb
.
CalculateInterval
(
queryContext
.
TimeRange
)
}
if
part
.
Type
==
"time"
&&
param
==
"auto"
{
part
.
Params
[
i
]
=
"$__interval"
}
}
...
...
pkg/tsdb/influxdb/query_part_test.go
View file @
149dd782
...
...
@@ -42,7 +42,7 @@ func TestInfluxdbQueryPart(t *testing.T) {
So
(
err
,
ShouldBeNil
)
res
:=
part
.
Render
(
query
,
queryContext
,
""
)
So
(
res
,
ShouldEqual
,
"time(
200ms
)"
)
So
(
res
,
ShouldEqual
,
"time(
$interval
)"
)
})
Convey
(
"render time with auto"
,
func
()
{
...
...
@@ -50,28 +50,7 @@ func TestInfluxdbQueryPart(t *testing.T) {
So
(
err
,
ShouldBeNil
)
res
:=
part
.
Render
(
query
,
queryContext
,
""
)
So
(
res
,
ShouldEqual
,
"time(200ms)"
)
})
Convey
(
"render time interval >10s"
,
func
()
{
part
,
err
:=
NewQueryPart
(
"time"
,
[]
string
{
"$interval"
})
So
(
err
,
ShouldBeNil
)
query
.
Interval
=
">10s"
res
:=
part
.
Render
(
query
,
queryContext
,
""
)
So
(
res
,
ShouldEqual
,
"time(10s)"
)
})
Convey
(
"render time interval >1s and higher interval calculation"
,
func
()
{
part
,
err
:=
NewQueryPart
(
"time"
,
[]
string
{
"$interval"
})
queryContext
:=
&
tsdb
.
QueryContext
{
TimeRange
:
tsdb
.
NewTimeRange
(
"1y"
,
"now"
)}
So
(
err
,
ShouldBeNil
)
query
.
Interval
=
">1s"
res
:=
part
.
Render
(
query
,
queryContext
,
""
)
So
(
res
,
ShouldEqual
,
"time(168h)"
)
So
(
res
,
ShouldEqual
,
"time($__interval)"
)
})
Convey
(
"render spread"
,
func
()
{
...
...
pkg/tsdb/influxdb/query_test.go
View file @
149dd782
...
...
@@ -16,10 +16,15 @@ func TestInfluxdbQueryBuilder(t *testing.T) {
qp1
,
_
:=
NewQueryPart
(
"field"
,
[]
string
{
"value"
})
qp2
,
_
:=
NewQueryPart
(
"mean"
,
[]
string
{})
groupBy1
,
_
:=
NewQueryPart
(
"time"
,
[]
string
{
"$interval"
})
mathPartDivideBy100
,
_
:=
NewQueryPart
(
"math"
,
[]
string
{
"/ 100"
})
mathPartDivideByIntervalMs
,
_
:=
NewQueryPart
(
"math"
,
[]
string
{
"/ $__interval_ms"
})
groupBy1
,
_
:=
NewQueryPart
(
"time"
,
[]
string
{
"$__interval"
})
groupBy2
,
_
:=
NewQueryPart
(
"tag"
,
[]
string
{
"datacenter"
})
groupBy3
,
_
:=
NewQueryPart
(
"fill"
,
[]
string
{
"null"
})
groupByOldInterval
,
_
:=
NewQueryPart
(
"time"
,
[]
string
{
"$interval"
})
tag1
:=
&
Tag
{
Key
:
"hostname"
,
Value
:
"server1"
,
Operator
:
"="
}
tag2
:=
&
Tag
{
Key
:
"hostname"
,
Value
:
"server2"
,
Operator
:
"="
,
Condition
:
"OR"
}
...
...
@@ -55,6 +60,43 @@ func TestInfluxdbQueryBuilder(t *testing.T) {
So
(
rawQuery
,
ShouldEqual
,
`SELECT mean("value") FROM "cpu" WHERE "hostname" = 'server1' OR "hostname" = 'server2' AND time > now() - 5m GROUP BY time(5s), "datacenter" fill(null)`
)
})
Convey
(
"can build query with math part"
,
func
()
{
query
:=
&
Query
{
Selects
:
[]
*
Select
{{
*
qp1
,
*
qp2
,
*
mathPartDivideBy100
}},
Measurement
:
"cpu"
,
Interval
:
"5s"
,
}
rawQuery
,
err
:=
query
.
Build
(
queryContext
)
So
(
err
,
ShouldBeNil
)
So
(
rawQuery
,
ShouldEqual
,
`SELECT mean("value") / 100 FROM "cpu" WHERE time > now() - 5m`
)
})
Convey
(
"can build query with math part using $__interval_ms variable"
,
func
()
{
query
:=
&
Query
{
Selects
:
[]
*
Select
{{
*
qp1
,
*
qp2
,
*
mathPartDivideByIntervalMs
}},
Measurement
:
"cpu"
,
Interval
:
"5s"
,
}
rawQuery
,
err
:=
query
.
Build
(
queryContext
)
So
(
err
,
ShouldBeNil
)
So
(
rawQuery
,
ShouldEqual
,
`SELECT mean("value") / 5000 FROM "cpu" WHERE time > now() - 5m`
)
})
Convey
(
"can build query with old $interval variable"
,
func
()
{
query
:=
&
Query
{
Selects
:
[]
*
Select
{{
*
qp1
,
*
qp2
}},
Measurement
:
"cpu"
,
Policy
:
""
,
GroupBy
:
[]
*
QueryPart
{
groupByOldInterval
},
}
rawQuery
,
err
:=
query
.
Build
(
queryContext
)
So
(
err
,
ShouldBeNil
)
So
(
rawQuery
,
ShouldEqual
,
`SELECT mean("value") FROM "cpu" WHERE time > now() - 5m GROUP BY time(200ms)`
)
})
Convey
(
"can render time range"
,
func
()
{
query
:=
Query
{}
Convey
(
"render from: 2h to now-1h"
,
func
()
{
...
...
@@ -139,4 +181,5 @@ func TestInfluxdbQueryBuilder(t *testing.T) {
So
(
query
.
renderMeasurement
(),
ShouldEqual
,
` FROM "policy"./apa/`
)
})
})
}
pkg/tsdb/interval.go
View file @
149dd782
...
...
@@ -12,14 +12,19 @@ var (
day
time
.
Duration
=
time
.
Hour
*
24
*
365
)
func
CalculateInterval
(
timerange
*
TimeRange
)
string
{
type
Interval
struct
{
Text
string
Value
time
.
Duration
}
func
CalculateInterval
(
timerange
*
TimeRange
)
Interval
{
interval
:=
time
.
Duration
((
timerange
.
MustGetTo
()
.
UnixNano
()
-
timerange
.
MustGetFrom
()
.
UnixNano
())
/
defaultRes
)
if
interval
<
minInterval
{
return
formatDuration
(
minInterval
)
return
Interval
{
Text
:
formatDuration
(
minInterval
),
Value
:
interval
}
}
return
formatDuration
(
roundInterval
(
interval
))
return
Interval
{
Text
:
formatDuration
(
roundInterval
(
interval
)),
Value
:
interval
}
}
func
formatDuration
(
inter
time
.
Duration
)
string
{
...
...
pkg/tsdb/interval_test.go
View file @
149dd782
...
...
@@ -18,28 +18,28 @@ func TestInterval(t *testing.T) {
tr
:=
NewTimeRange
(
"5m"
,
"now"
)
interval
:=
CalculateInterval
(
tr
)
So
(
interval
,
ShouldEqual
,
"200ms"
)
So
(
interval
.
Text
,
ShouldEqual
,
"200ms"
)
})
Convey
(
"for 15min"
,
func
()
{
tr
:=
NewTimeRange
(
"15m"
,
"now"
)
interval
:=
CalculateInterval
(
tr
)
So
(
interval
,
ShouldEqual
,
"500ms"
)
So
(
interval
.
Text
,
ShouldEqual
,
"500ms"
)
})
Convey
(
"for 30min"
,
func
()
{
tr
:=
NewTimeRange
(
"30m"
,
"now"
)
interval
:=
CalculateInterval
(
tr
)
So
(
interval
,
ShouldEqual
,
"1s"
)
So
(
interval
.
Text
,
ShouldEqual
,
"1s"
)
})
Convey
(
"for 1h"
,
func
()
{
tr
:=
NewTimeRange
(
"1h"
,
"now"
)
interval
:=
CalculateInterval
(
tr
)
So
(
interval
,
ShouldEqual
,
"2s"
)
So
(
interval
.
Text
,
ShouldEqual
,
"2s"
)
})
Convey
(
"Round interval"
,
func
()
{
...
...
public/app/core/components/query_part/query_part.ts
View file @
149dd782
...
...
@@ -89,7 +89,7 @@ export function functionRenderer(part, innerExpr) {
var
paramType
=
part
.
def
.
params
[
index
];
if
(
paramType
.
type
===
'time'
)
{
if
(
value
===
'auto'
)
{
value
=
'$interval'
;
value
=
'$
__
interval'
;
}
}
if
(
paramType
.
quote
===
'single'
)
{
...
...
public/app/features/panel/metrics_panel_ctrl.ts
View file @
149dd782
...
...
@@ -191,6 +191,13 @@ class MetricsPanelCtrl extends PanelCtrl {
return
this
.
$q
.
when
([]);
}
// make shallow copy of scoped vars,
// and add built in variables interval and interval_ms
var
scopedVars
=
Object
.
assign
({},
this
.
panel
.
scopedVars
,
{
"__interval"
:
{
text
:
this
.
interval
,
value
:
this
.
interval
},
"__interval_ms"
:
{
text
:
this
.
intervalMs
,
value
:
this
.
intervalMs
},
});
var
metricsQuery
=
{
panelId
:
this
.
panel
.
id
,
range
:
this
.
range
,
...
...
@@ -200,7 +207,7 @@ class MetricsPanelCtrl extends PanelCtrl {
targets
:
this
.
panel
.
targets
,
format
:
this
.
panel
.
renderer
===
'png'
?
'png'
:
'json'
,
maxDataPoints
:
this
.
resolution
,
scopedVars
:
this
.
panel
.
scopedVars
,
scopedVars
:
scopedVars
,
cacheTimeout
:
this
.
panel
.
cacheTimeout
};
...
...
public/app/features/templating/specs/template_srv_specs.ts
View file @
149dd782
...
...
@@ -244,4 +244,16 @@ describe('templateSrv', function() {
expect
(
target
).
to
.
be
(
'Server: All, period: 13m'
);
});
});
describe
(
'built in interval variables'
,
function
()
{
beforeEach
(
function
()
{
initTemplateSrv
([]);
});
it
(
'should replace $__interval_ms with interval milliseconds'
,
function
()
{
var
target
=
_templateSrv
.
replace
(
'10 * $__interval_ms'
,
{
"__interval_ms"
:
{
text
:
"100"
,
value
:
"100"
}});
expect
(
target
).
to
.
be
(
'10 * 100'
);
});
});
});
public/app/features/templating/templateSrv.js
View file @
149dd782
...
...
@@ -17,6 +17,11 @@ function (angular, _, kbn) {
this
.
_grafanaVariables
=
{};
this
.
_adhocVariables
=
{};
// default built ins
this
.
_builtIns
=
{};
this
.
_builtIns
[
'__interval'
]
=
{
text
:
'1s'
,
value
:
'1s'
};
this
.
_builtIns
[
'__interval_ms'
]
=
{
text
:
'100'
,
value
:
'100'
};
this
.
init
=
function
(
variables
)
{
this
.
variables
=
variables
;
this
.
updateTemplateData
();
...
...
@@ -42,6 +47,7 @@ function (angular, _, kbn) {
this
.
_index
[
variable
.
name
]
=
variable
;
}
};
this
.
variableInitialized
=
function
(
variable
)
{
...
...
@@ -103,11 +109,11 @@ function (angular, _, kbn) {
return
this
.
distributeVariable
(
value
,
variable
.
name
);
}
default
:
{
if
(
typeof
value
===
'string'
)
{
return
value
;
}
if
(
_
.
isArray
(
value
))
{
return
'{'
+
value
.
join
(
','
)
+
'}'
;
}
return
value
;
}
}
};
...
...
@@ -135,7 +141,7 @@ function (angular, _, kbn) {
str
=
_
.
escape
(
str
);
this
.
_regex
.
lastIndex
=
0
;
return
str
.
replace
(
this
.
_regex
,
function
(
match
,
g1
,
g2
)
{
if
(
self
.
_index
[
g1
||
g2
])
{
if
(
self
.
_index
[
g1
||
g2
]
||
self
.
_builtIns
[
g1
||
g2
]
)
{
return
'<span class="template-variable">'
+
match
+
'</span>'
;
}
return
match
;
...
...
public/app/plugins/datasource/elasticsearch/datasource.js
View file @
149dd782
...
...
@@ -197,15 +197,9 @@ function (angular, _, moment, kbn, ElasticQueryBuilder, IndexPattern, ElasticRes
target
=
options
.
targets
[
i
];
if
(
target
.
hide
)
{
continue
;}
var
queryObj
=
this
.
queryBuilder
.
build
(
target
,
adhocFilters
);
var
queryString
=
templateSrv
.
replace
(
target
.
query
||
'*'
,
options
.
scopedVars
,
'lucene'
);
var
queryObj
=
this
.
queryBuilder
.
build
(
target
,
adhocFilters
,
queryString
);
var
esQuery
=
angular
.
toJson
(
queryObj
);
var
luceneQuery
=
target
.
query
||
'*'
;
luceneQuery
=
templateSrv
.
replace
(
luceneQuery
,
options
.
scopedVars
,
'lucene'
);
luceneQuery
=
angular
.
toJson
(
luceneQuery
);
// remove inner quotes
luceneQuery
=
luceneQuery
.
substr
(
1
,
luceneQuery
.
length
-
2
);
esQuery
=
esQuery
.
replace
(
"$lucene_query"
,
luceneQuery
);
var
searchType
=
(
queryObj
.
size
===
0
&&
this
.
esVersion
<
5
)
?
'count'
:
'query_then_fetch'
;
var
header
=
this
.
getQueryHeader
(
searchType
,
options
.
range
.
from
,
options
.
range
.
to
);
...
...
@@ -219,7 +213,6 @@ function (angular, _, moment, kbn, ElasticQueryBuilder, IndexPattern, ElasticRes
return
$q
.
when
([]);
}
payload
=
payload
.
replace
(
/
\$
interval/g
,
options
.
interval
);
payload
=
payload
.
replace
(
/
\$
timeFrom/g
,
options
.
range
.
from
.
valueOf
());
payload
=
payload
.
replace
(
/
\$
timeTo/g
,
options
.
range
.
to
.
valueOf
());
payload
=
templateSrv
.
replace
(
payload
,
options
.
scopedVars
);
...
...
public/app/plugins/datasource/elasticsearch/query_builder.js
View file @
149dd782
...
...
@@ -66,7 +66,7 @@ function (queryDef) {
esAgg
.
format
=
"epoch_millis"
;
if
(
esAgg
.
interval
===
'auto'
)
{
esAgg
.
interval
=
"$interval"
;
esAgg
.
interval
=
"$
__
interval"
;
}
if
(
settings
.
missing
)
{
...
...
@@ -121,7 +121,7 @@ function (queryDef) {
}
};
ElasticQueryBuilder
.
prototype
.
build
=
function
(
target
,
adhocFilters
)
{
ElasticQueryBuilder
.
prototype
.
build
=
function
(
target
,
adhocFilters
,
queryString
)
{
// make sure query has defaults;
target
.
metrics
=
target
.
metrics
||
[{
type
:
'count'
,
id
:
'1'
}];
target
.
dsType
=
'elasticsearch'
;
...
...
@@ -138,7 +138,7 @@ function (queryDef) {
{
"query_string"
:
{
"analyze_wildcard"
:
true
,
"query"
:
'$lucene_query'
"query"
:
queryString
,
}
}
]
...
...
public/app/plugins/datasource/influxdb/datasource.ts
View file @
149dd782
...
...
@@ -45,7 +45,7 @@ export default class InfluxDatasource {
query
(
options
)
{
var
timeFilter
=
this
.
getTimeFilter
(
options
);
var
scopedVars
=
options
.
scopedVars
?
_
.
cloneDeep
(
options
.
scopedVars
)
:
{}
;
var
scopedVars
=
options
.
scopedVars
;
var
targets
=
_
.
cloneDeep
(
options
.
targets
);
var
queryTargets
=
[];
var
queryModel
;
...
...
@@ -56,8 +56,8 @@ export default class InfluxDatasource {
queryTargets
.
push
(
target
);
// b
uild quer
y
scopedVars
.
interval
=
{
value
:
target
.
interval
||
options
.
interval
}
;
// b
ackward compatabilit
y
scopedVars
.
interval
=
scopedVars
.
__interval
;
queryModel
=
new
InfluxQuery
(
target
,
this
.
templateSrv
,
scopedVars
);
return
queryModel
.
render
(
true
);
...
...
public/app/plugins/datasource/influxdb/influx_query.ts
View file @
149dd782
...
...
@@ -23,7 +23,7 @@ export default class InfluxQuery {
target
.
resultFormat
=
target
.
resultFormat
||
'time_series'
;
target
.
tags
=
target
.
tags
||
[];
target
.
groupBy
=
target
.
groupBy
||
[
{
type
:
'time'
,
params
:
[
'$interval'
]},
{
type
:
'time'
,
params
:
[
'$
__
interval'
]},
{
type
:
'fill'
,
params
:
[
'null'
]},
];
target
.
select
=
target
.
select
||
[[
...
...
public/app/plugins/datasource/influxdb/specs/influx_query_specs.ts
View file @
149dd782
...
...
@@ -12,7 +12,7 @@ describe('InfluxQuery', function() {
},
templateSrv
,
{});
var
queryText
=
query
.
render
();
expect
(
queryText
).
to
.
be
(
'SELECT mean("value") FROM "cpu" WHERE $timeFilter GROUP BY time($interval) fill(null)'
);
expect
(
queryText
).
to
.
be
(
'SELECT mean("value") FROM "cpu" WHERE $timeFilter GROUP BY time($
__
interval) fill(null)'
);
});
});
...
...
@@ -24,7 +24,7 @@ describe('InfluxQuery', function() {
},
templateSrv
,
{});
var
queryText
=
query
.
render
();
expect
(
queryText
).
to
.
be
(
'SELECT mean("value") FROM "5m_avg"."cpu" WHERE $timeFilter GROUP BY time($interval) fill(null)'
);
expect
(
queryText
).
to
.
be
(
'SELECT mean("value") FROM "5m_avg"."cpu" WHERE $timeFilter GROUP BY time($
__
interval) fill(null)'
);
});
});
...
...
@@ -43,7 +43,7 @@ describe('InfluxQuery', function() {
},
templateSrv
,
{});
var
queryText
=
query
.
render
();
expect
(
queryText
).
to
.
be
(
'SELECT mean("value") /100 AS "text" FROM "cpu" WHERE $timeFilter GROUP BY time($interval) fill(null)'
);
expect
(
queryText
).
to
.
be
(
'SELECT mean("value") /100 AS "text" FROM "cpu" WHERE $timeFilter GROUP BY time($
__
interval) fill(null)'
);
});
});
...
...
@@ -58,7 +58,7 @@ describe('InfluxQuery', function() {
var
queryText
=
query
.
render
();
expect
(
queryText
).
to
.
be
(
'SELECT mean("value") FROM "cpu" WHERE "hostname" =
\'
server
\\\\
1
\'
AND $timeFilter'
+
' GROUP BY time($interval)'
);
+
' GROUP BY time($
__
interval)'
);
});
it
(
'should switch regex operator with tag value is regex'
,
function
()
{
...
...
@@ -69,7 +69,7 @@ describe('InfluxQuery', function() {
},
templateSrv
,
{});
var
queryText
=
query
.
render
();
expect
(
queryText
).
to
.
be
(
'SELECT mean("value") FROM "cpu" WHERE "app" =~ /e.*/ AND $timeFilter GROUP BY time($interval)'
);
expect
(
queryText
).
to
.
be
(
'SELECT mean("value") FROM "cpu" WHERE "app" =~ /e.*/ AND $timeFilter GROUP BY time($
__
interval)'
);
});
});
...
...
@@ -83,7 +83,7 @@ describe('InfluxQuery', function() {
var
queryText
=
query
.
render
();
expect
(
queryText
).
to
.
be
(
'SELECT mean("value") FROM "cpu" WHERE "hostname" =
\'
server1
\'
AND "app" =
\'
email
\'
AND '
+
'$timeFilter GROUP BY time($interval)'
);
'$timeFilter GROUP BY time($
__
interval)'
);
});
});
...
...
@@ -97,7 +97,7 @@ describe('InfluxQuery', function() {
var
queryText
=
query
.
render
();
expect
(
queryText
).
to
.
be
(
'SELECT mean("value") FROM "cpu" WHERE "hostname" =
\'
server1
\'
OR "hostname" =
\'
server2
\'
AND '
+
'$timeFilter GROUP BY time($interval)'
);
'$timeFilter GROUP BY time($
__
interval)'
);
});
});
...
...
@@ -124,7 +124,7 @@ describe('InfluxQuery', function() {
var
queryText
=
query
.
render
();
expect
(
queryText
).
to
.
be
(
'SELECT mean("value") FROM "cpu" WHERE $timeFilter '
+
'GROUP BY time($interval), "host"'
);
'GROUP BY time($
__
interval), "host"'
);
});
});
...
...
@@ -148,7 +148,7 @@ describe('InfluxQuery', function() {
groupBy
:
[{
type
:
'time'
},
{
type
:
'fill'
,
params
:
[
'0'
]}],
},
templateSrv
,
{});
var
queryText
=
query
.
render
();
expect
(
queryText
).
to
.
be
(
'SELECT "value" FROM "cpu" WHERE $timeFilter GROUP BY time($interval) fill(0)'
);
expect
(
queryText
).
to
.
be
(
'SELECT "value" FROM "cpu" WHERE $timeFilter GROUP BY time($
__
interval) fill(0)'
);
});
});
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment