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
c83975f2
Unverified
Commit
c83975f2
authored
Nov 21, 2017
by
Carl Bergquist
Committed by
GitHub
Nov 21, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #9936 from grafana/js-to-ts-migration
Js to ts migration
parents
b1de1e6f
25f63e05
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
144 additions
and
152 deletions
+144
-152
public/app/plugins/datasource/influxdb/influx_series.d.ts
+0
-2
public/app/plugins/datasource/influxdb/influx_series.ts
+38
-37
public/app/plugins/datasource/influxdb/response_parser.ts
+0
-2
public/app/plugins/datasource/influxdb/specs/influx_query.jest.ts
+30
-32
public/app/plugins/datasource/influxdb/specs/influx_series.jest.ts
+49
-50
public/app/plugins/datasource/influxdb/specs/query_part.jest.ts
+8
-11
public/app/plugins/datasource/influxdb/specs/response_parser.jest.ts
+19
-18
No files found.
public/app/plugins/datasource/influxdb/influx_series.d.ts
deleted
100644 → 0
View file @
b1de1e6f
declare
var
test
:
any
;
export
default
test
;
public/app/plugins/datasource/influxdb/influx_series.
j
s
→
public/app/plugins/datasource/influxdb/influx_series.
t
s
View file @
c83975f2
define
([
'lodash'
,
'app/core/table_model'
,
],
function
(
_
,
TableModel
)
{
'use strict'
;
function
InfluxSeries
(
options
)
{
import
_
from
'lodash'
;
import
TableModel
from
'app/core/table_model'
;
export
default
class
InfluxSeries
{
series
:
any
;
alias
:
any
;
annotation
:
any
;
constructor
(
options
)
{
this
.
series
=
options
.
series
;
this
.
alias
=
options
.
alias
;
this
.
annotation
=
options
.
annotation
;
}
var
p
=
InfluxSeries
.
prototype
;
p
.
getTimeSeries
=
function
()
{
getTimeSeries
()
{
var
output
=
[];
var
self
=
this
;
var
i
,
j
;
if
(
self
.
series
.
length
===
0
)
{
if
(
this
.
series
.
length
===
0
)
{
return
output
;
}
_
.
each
(
self
.
series
,
function
(
series
)
{
_
.
each
(
this
.
series
,
(
series
)
=>
{
var
columns
=
series
.
columns
.
length
;
var
tags
=
_
.
map
(
series
.
tags
,
function
(
value
,
key
)
{
return
key
+
': '
+
value
;
...
...
@@ -35,8 +34,8 @@ function (_, TableModel) {
seriesName
=
seriesName
+
'.'
+
columnName
;
}
if
(
self
.
alias
)
{
seriesName
=
self
.
_getSeriesName
(
series
,
j
);
if
(
this
.
alias
)
{
seriesName
=
this
.
_getSeriesName
(
series
,
j
);
}
else
if
(
series
.
tags
)
{
seriesName
=
seriesName
+
' {'
+
tags
.
join
(
', '
)
+
'}'
;
}
...
...
@@ -53,9 +52,9 @@ function (_, TableModel) {
});
return
output
;
}
;
}
p
.
_getSeriesName
=
function
(
series
,
index
)
{
_getSeriesName
(
series
,
index
)
{
var
regex
=
/
\$(\w
+
)
|
\[\[([\s\S]
+
?)\]\]
/g
;
var
segments
=
series
.
name
.
split
(
'.'
);
...
...
@@ -72,30 +71,29 @@ function (_, TableModel) {
if
(
!
series
.
tags
)
{
return
match
;
}
return
series
.
tags
[
tag
];
});
}
;
}
p
.
getAnnotations
=
function
()
{
getAnnotations
()
{
var
list
=
[];
var
self
=
this
;
_
.
each
(
this
.
series
,
function
(
series
)
{
_
.
each
(
this
.
series
,
(
series
)
=>
{
var
titleCol
=
null
;
var
timeCol
=
null
;
var
tagsCol
=
[];
var
textCol
=
null
;
_
.
each
(
series
.
columns
,
function
(
column
,
index
)
{
_
.
each
(
series
.
columns
,
(
column
,
index
)
=>
{
if
(
column
===
'time'
)
{
timeCol
=
index
;
return
;
}
if
(
column
===
'sequence_number'
)
{
return
;
}
if
(
!
titleCol
)
{
titleCol
=
index
;
}
if
(
column
===
self
.
annotation
.
titleColumn
)
{
titleCol
=
index
;
return
;
}
if
(
_
.
includes
((
self
.
annotation
.
tagsColumn
||
''
).
replace
(
' '
,
''
).
split
(
","
),
column
))
{
tagsCol
.
push
(
index
);
return
;
}
if
(
column
===
self
.
annotation
.
textColumn
)
{
textCol
=
index
;
return
;
}
if
(
column
===
this
.
annotation
.
titleColumn
)
{
titleCol
=
index
;
return
;
}
if
(
_
.
includes
((
this
.
annotation
.
tagsColumn
||
''
).
replace
(
' '
,
''
).
split
(
","
),
column
))
{
tagsCol
.
push
(
index
);
return
;
}
if
(
column
===
this
.
annotation
.
textColumn
)
{
textCol
=
index
;
return
;
}
});
_
.
each
(
series
.
values
,
function
(
value
)
{
_
.
each
(
series
.
values
,
(
value
)
=>
{
var
data
=
{
annotation
:
self
.
annotation
,
annotation
:
this
.
annotation
,
time
:
+
new
Date
(
value
[
timeCol
]),
title
:
value
[
titleCol
],
// Remove empty values, then split in different tags for comma separated values
...
...
@@ -108,18 +106,17 @@ function (_, TableModel) {
});
return
list
;
}
;
}
p
.
getTable
=
function
()
{
var
table
=
new
TableModel
.
default
();
var
self
=
this
;
getTable
()
{
var
table
=
new
TableModel
();
var
i
,
j
;
if
(
self
.
series
.
length
===
0
)
{
if
(
this
.
series
.
length
===
0
)
{
return
table
;
}
_
.
each
(
self
.
series
,
function
(
series
,
seriesIndex
)
{
_
.
each
(
this
.
series
,
(
series
,
seriesIndex
)
=>
{
if
(
seriesIndex
===
0
)
{
table
.
columns
.
push
({
text
:
'Time'
,
type
:
'time'
});
...
...
@@ -151,7 +148,11 @@ function (_, TableModel) {
});
return
table
;
};
}
}
return
InfluxSeries
;
});
public/app/plugins/datasource/influxdb/response_parser.ts
View file @
c83975f2
///<reference path="../../../headers/common.d.ts" />
import
_
from
'lodash'
;
export
default
class
ResponseParser
{
...
...
public/app/plugins/datasource/influxdb/specs/influx_query
_specs
.ts
→
public/app/plugins/datasource/influxdb/specs/influx_query
.jest
.ts
View file @
c83975f2
import
{
describe
,
it
,
expect
}
from
'test/lib/common'
;
import
InfluxQuery
from
'../influx_query'
;
describe
(
'InfluxQuery'
,
function
()
{
...
...
@@ -12,7 +10,7 @@ describe('InfluxQuery', function() {
},
templateSrv
,
{});
var
queryText
=
query
.
render
();
expect
(
queryText
).
to
.
b
e
(
'SELECT mean("value") FROM "cpu" WHERE $timeFilter GROUP BY time($__interval) fill(null)'
);
expect
(
queryText
).
to
B
e
(
'SELECT mean("value") FROM "cpu" WHERE $timeFilter GROUP BY time($__interval) fill(null)'
);
});
});
...
...
@@ -24,7 +22,7 @@ describe('InfluxQuery', function() {
},
templateSrv
,
{});
var
queryText
=
query
.
render
();
expect
(
queryText
).
to
.
b
e
(
'SELECT mean("value") FROM "5m_avg"."cpu" WHERE $timeFilter GROUP BY time($__interval) fill(null)'
);
expect
(
queryText
).
to
B
e
(
'SELECT mean("value") FROM "5m_avg"."cpu" WHERE $timeFilter GROUP BY time($__interval) fill(null)'
);
});
});
...
...
@@ -43,7 +41,7 @@ describe('InfluxQuery', function() {
},
templateSrv
,
{});
var
queryText
=
query
.
render
();
expect
(
queryText
).
to
.
b
e
(
'SELECT mean("value") /100 AS "text" FROM "cpu" WHERE $timeFilter GROUP BY time($__interval) fill(null)'
);
expect
(
queryText
).
to
B
e
(
'SELECT mean("value") /100 AS "text" FROM "cpu" WHERE $timeFilter GROUP BY time($__interval) fill(null)'
);
});
});
...
...
@@ -57,7 +55,7 @@ describe('InfluxQuery', function() {
var
queryText
=
query
.
render
();
expect
(
queryText
).
to
.
b
e
(
'SELECT mean("value") FROM "cpu" WHERE ("hostname" =
\'
server
\\\\
1
\'
) AND $timeFilter'
expect
(
queryText
).
to
B
e
(
'SELECT mean("value") FROM "cpu" WHERE ("hostname" =
\'
server
\\\\
1
\'
) AND $timeFilter'
+
' GROUP BY time($__interval)'
);
});
...
...
@@ -69,7 +67,7 @@ describe('InfluxQuery', function() {
},
templateSrv
,
{});
var
queryText
=
query
.
render
();
expect
(
queryText
).
to
.
b
e
(
'SELECT mean("value") FROM "cpu" WHERE ("app" =~ /e.*/) AND $timeFilter GROUP BY time($__interval)'
);
expect
(
queryText
).
to
B
e
(
'SELECT mean("value") FROM "cpu" WHERE ("app" =~ /e.*/) AND $timeFilter GROUP BY time($__interval)'
);
});
});
...
...
@@ -82,7 +80,7 @@ describe('InfluxQuery', function() {
},
templateSrv
,
{});
var
queryText
=
query
.
render
();
expect
(
queryText
).
to
.
b
e
(
'SELECT mean("value") FROM "cpu" WHERE ("hostname" =
\'
server1
\'
AND "app" =
\'
email
\'
) AND '
+
expect
(
queryText
).
to
B
e
(
'SELECT mean("value") FROM "cpu" WHERE ("hostname" =
\'
server1
\'
AND "app" =
\'
email
\'
) AND '
+
'$timeFilter GROUP BY time($__interval)'
);
});
});
...
...
@@ -96,7 +94,7 @@ describe('InfluxQuery', function() {
},
templateSrv
,
{});
var
queryText
=
query
.
render
();
expect
(
queryText
).
to
.
b
e
(
'SELECT mean("value") FROM "cpu" WHERE ("hostname" =
\'
server1
\'
OR "hostname" =
\'
server2
\'
) AND '
+
expect
(
queryText
).
to
B
e
(
'SELECT mean("value") FROM "cpu" WHERE ("hostname" =
\'
server1
\'
OR "hostname" =
\'
server2
\'
) AND '
+
'$timeFilter GROUP BY time($__interval)'
);
});
});
...
...
@@ -110,7 +108,7 @@ describe('InfluxQuery', function() {
},
templateSrv
,
{});
var
queryText
=
query
.
render
();
expect
(
queryText
).
to
.
b
e
(
'SELECT mean("value") FROM "cpu" WHERE ("value" > 5) AND $timeFilter'
);
expect
(
queryText
).
to
B
e
(
'SELECT mean("value") FROM "cpu" WHERE ("value" > 5) AND $timeFilter'
);
});
});
...
...
@@ -123,7 +121,7 @@ describe('InfluxQuery', function() {
},
templateSrv
,
{});
var
queryText
=
query
.
render
();
expect
(
queryText
).
to
.
b
e
(
'SELECT mean("value") FROM "cpu" WHERE $timeFilter GROUP BY time($__interval), "host"'
);
expect
(
queryText
).
to
B
e
(
'SELECT mean("value") FROM "cpu" WHERE $timeFilter GROUP BY time($__interval), "host"'
);
});
});
...
...
@@ -135,7 +133,7 @@ describe('InfluxQuery', function() {
groupBy
:
[],
},
templateSrv
,
{});
var
queryText
=
query
.
render
();
expect
(
queryText
).
to
.
b
e
(
'SELECT "value" FROM "cpu" WHERE $timeFilter'
);
expect
(
queryText
).
to
B
e
(
'SELECT "value" FROM "cpu" WHERE $timeFilter'
);
});
});
...
...
@@ -147,7 +145,7 @@ describe('InfluxQuery', function() {
groupBy
:
[{
type
:
'time'
},
{
type
:
'fill'
,
params
:
[
'0'
]}],
},
templateSrv
,
{});
var
queryText
=
query
.
render
();
expect
(
queryText
).
to
.
b
e
(
'SELECT "value" FROM "cpu" WHERE $timeFilter GROUP BY time($__interval) fill(0)'
);
expect
(
queryText
).
to
B
e
(
'SELECT "value" FROM "cpu" WHERE $timeFilter GROUP BY time($__interval) fill(0)'
);
});
});
...
...
@@ -160,10 +158,10 @@ describe('InfluxQuery', function() {
},
templateSrv
,
{});
query
.
addGroupBy
(
'tag(host)'
);
expect
(
query
.
target
.
groupBy
.
length
).
to
.
b
e
(
3
);
expect
(
query
.
target
.
groupBy
[
1
].
type
).
to
.
b
e
(
'tag'
);
expect
(
query
.
target
.
groupBy
[
1
].
params
[
0
]).
to
.
b
e
(
'host'
);
expect
(
query
.
target
.
groupBy
[
2
].
type
).
to
.
b
e
(
'fill'
);
expect
(
query
.
target
.
groupBy
.
length
).
to
B
e
(
3
);
expect
(
query
.
target
.
groupBy
[
1
].
type
).
to
B
e
(
'tag'
);
expect
(
query
.
target
.
groupBy
[
1
].
params
[
0
]).
to
B
e
(
'host'
);
expect
(
query
.
target
.
groupBy
[
2
].
type
).
to
B
e
(
'fill'
);
});
it
(
'should add tag last if no fill'
,
function
()
{
...
...
@@ -173,8 +171,8 @@ describe('InfluxQuery', function() {
},
templateSrv
,
{});
query
.
addGroupBy
(
'tag(host)'
);
expect
(
query
.
target
.
groupBy
.
length
).
to
.
b
e
(
1
);
expect
(
query
.
target
.
groupBy
[
0
].
type
).
to
.
b
e
(
'tag'
);
expect
(
query
.
target
.
groupBy
.
length
).
to
B
e
(
1
);
expect
(
query
.
target
.
groupBy
[
0
].
type
).
to
B
e
(
'tag'
);
});
});
...
...
@@ -188,8 +186,8 @@ describe('InfluxQuery', function() {
},
templateSrv
,
{});
query
.
addSelectPart
(
query
.
selectModels
[
0
],
'mean'
);
expect
(
query
.
target
.
select
[
0
].
length
).
to
.
b
e
(
2
);
expect
(
query
.
target
.
select
[
0
][
1
].
type
).
to
.
b
e
(
'mean'
);
expect
(
query
.
target
.
select
[
0
].
length
).
to
B
e
(
2
);
expect
(
query
.
target
.
select
[
0
][
1
].
type
).
to
B
e
(
'mean'
);
});
it
(
'should replace sum by mean'
,
function
()
{
...
...
@@ -199,8 +197,8 @@ describe('InfluxQuery', function() {
},
templateSrv
,
{});
query
.
addSelectPart
(
query
.
selectModels
[
0
],
'sum'
);
expect
(
query
.
target
.
select
[
0
].
length
).
to
.
b
e
(
2
);
expect
(
query
.
target
.
select
[
0
][
1
].
type
).
to
.
b
e
(
'sum'
);
expect
(
query
.
target
.
select
[
0
].
length
).
to
B
e
(
2
);
expect
(
query
.
target
.
select
[
0
][
1
].
type
).
to
B
e
(
'sum'
);
});
it
(
'should add math before alias'
,
function
()
{
...
...
@@ -210,8 +208,8 @@ describe('InfluxQuery', function() {
},
templateSrv
,
{});
query
.
addSelectPart
(
query
.
selectModels
[
0
],
'math'
);
expect
(
query
.
target
.
select
[
0
].
length
).
to
.
b
e
(
4
);
expect
(
query
.
target
.
select
[
0
][
2
].
type
).
to
.
b
e
(
'math'
);
expect
(
query
.
target
.
select
[
0
].
length
).
to
B
e
(
4
);
expect
(
query
.
target
.
select
[
0
][
2
].
type
).
to
B
e
(
'math'
);
});
it
(
'should add math last'
,
function
()
{
...
...
@@ -221,8 +219,8 @@ describe('InfluxQuery', function() {
},
templateSrv
,
{});
query
.
addSelectPart
(
query
.
selectModels
[
0
],
'math'
);
expect
(
query
.
target
.
select
[
0
].
length
).
to
.
b
e
(
3
);
expect
(
query
.
target
.
select
[
0
][
2
].
type
).
to
.
b
e
(
'math'
);
expect
(
query
.
target
.
select
[
0
].
length
).
to
B
e
(
3
);
expect
(
query
.
target
.
select
[
0
][
2
].
type
).
to
B
e
(
'math'
);
});
it
(
'should replace math'
,
function
()
{
...
...
@@ -232,8 +230,8 @@ describe('InfluxQuery', function() {
},
templateSrv
,
{});
query
.
addSelectPart
(
query
.
selectModels
[
0
],
'math'
);
expect
(
query
.
target
.
select
[
0
].
length
).
to
.
b
e
(
3
);
expect
(
query
.
target
.
select
[
0
][
2
].
type
).
to
.
b
e
(
'math'
);
expect
(
query
.
target
.
select
[
0
].
length
).
to
B
e
(
3
);
expect
(
query
.
target
.
select
[
0
][
2
].
type
).
to
B
e
(
'math'
);
});
it
(
'should add math when one only query part'
,
function
()
{
...
...
@@ -243,8 +241,8 @@ describe('InfluxQuery', function() {
},
templateSrv
,
{});
query
.
addSelectPart
(
query
.
selectModels
[
0
],
'math'
);
expect
(
query
.
target
.
select
[
0
].
length
).
to
.
b
e
(
2
);
expect
(
query
.
target
.
select
[
0
][
1
].
type
).
to
.
b
e
(
'math'
);
expect
(
query
.
target
.
select
[
0
].
length
).
to
B
e
(
2
);
expect
(
query
.
target
.
select
[
0
][
1
].
type
).
to
B
e
(
'math'
);
});
describe
(
'when render adhoc filters'
,
function
()
{
...
...
@@ -256,7 +254,7 @@ describe('InfluxQuery', function() {
{
key
:
'key2'
,
operator
:
'!='
,
value
:
'value2'
},
]);
expect
(
queryText
).
to
.
b
e
(
'"key1" =
\'
value1
\'
AND "key2" !=
\'
value2
\'
'
);
expect
(
queryText
).
to
B
e
(
'"key1" =
\'
value1
\'
AND "key2" !=
\'
value2
\'
'
);
});
});
...
...
public/app/plugins/datasource/influxdb/specs/influx_series
_specs
.ts
→
public/app/plugins/datasource/influxdb/specs/influx_series
.jest
.ts
View file @
c83975f2
import
{
describe
,
it
,
expect
}
from
'test/lib/common'
;
import
InfluxSeries
from
'../influx_series'
;
describe
(
'when generating timeseries from influxdb response'
,
function
()
{
...
...
@@ -19,24 +18,24 @@ describe('when generating timeseries from influxdb response', function() {
var
series
=
new
InfluxSeries
(
options
);
var
result
=
series
.
getTimeSeries
();
expect
(
result
.
length
).
to
.
b
e
(
3
);
expect
(
result
[
0
].
target
).
to
.
b
e
(
'cpu.mean {app: test, server: server1}'
);
expect
(
result
[
0
].
datapoints
[
0
][
0
]).
to
.
b
e
(
10
);
expect
(
result
[
0
].
datapoints
[
0
][
1
]).
to
.
b
e
(
1431946625000
);
expect
(
result
[
0
].
datapoints
[
1
][
0
]).
to
.
b
e
(
20
);
expect
(
result
[
0
].
datapoints
[
1
][
1
]).
to
.
b
e
(
1431946626000
);
expect
(
result
[
1
].
target
).
to
.
b
e
(
'cpu.max {app: test, server: server1}'
);
expect
(
result
[
1
].
datapoints
[
0
][
0
]).
to
.
b
e
(
11
);
expect
(
result
[
1
].
datapoints
[
0
][
1
]).
to
.
b
e
(
1431946625000
);
expect
(
result
[
1
].
datapoints
[
1
][
0
]).
to
.
b
e
(
21
);
expect
(
result
[
1
].
datapoints
[
1
][
1
]).
to
.
b
e
(
1431946626000
);
expect
(
result
[
2
].
target
).
to
.
b
e
(
'cpu.min {app: test, server: server1}'
);
expect
(
result
[
2
].
datapoints
[
0
][
0
]).
to
.
b
e
(
9
);
expect
(
result
[
2
].
datapoints
[
0
][
1
]).
to
.
b
e
(
1431946625000
);
expect
(
result
[
2
].
datapoints
[
1
][
0
]).
to
.
b
e
(
19
);
expect
(
result
[
2
].
datapoints
[
1
][
1
]).
to
.
b
e
(
1431946626000
);
expect
(
result
.
length
).
to
B
e
(
3
);
expect
(
result
[
0
].
target
).
to
B
e
(
'cpu.mean {app: test, server: server1}'
);
expect
(
result
[
0
].
datapoints
[
0
][
0
]).
to
B
e
(
10
);
expect
(
result
[
0
].
datapoints
[
0
][
1
]).
to
B
e
(
1431946625000
);
expect
(
result
[
0
].
datapoints
[
1
][
0
]).
to
B
e
(
20
);
expect
(
result
[
0
].
datapoints
[
1
][
1
]).
to
B
e
(
1431946626000
);
expect
(
result
[
1
].
target
).
to
B
e
(
'cpu.max {app: test, server: server1}'
);
expect
(
result
[
1
].
datapoints
[
0
][
0
]).
to
B
e
(
11
);
expect
(
result
[
1
].
datapoints
[
0
][
1
]).
to
B
e
(
1431946625000
);
expect
(
result
[
1
].
datapoints
[
1
][
0
]).
to
B
e
(
21
);
expect
(
result
[
1
].
datapoints
[
1
][
1
]).
to
B
e
(
1431946626000
);
expect
(
result
[
2
].
target
).
to
B
e
(
'cpu.min {app: test, server: server1}'
);
expect
(
result
[
2
].
datapoints
[
0
][
0
]).
to
B
e
(
9
);
expect
(
result
[
2
].
datapoints
[
0
][
1
]).
to
B
e
(
1431946625000
);
expect
(
result
[
2
].
datapoints
[
1
][
0
]).
to
B
e
(
19
);
expect
(
result
[
2
].
datapoints
[
1
][
1
]).
to
B
e
(
1431946626000
);
});
});
...
...
@@ -47,9 +46,9 @@ describe('when generating timeseries from influxdb response', function() {
var
series
=
new
InfluxSeries
(
options
);
var
result
=
series
.
getTimeSeries
();
expect
(
result
[
0
].
target
).
to
.
b
e
(
'new series'
);
expect
(
result
[
1
].
target
).
to
.
b
e
(
'new series'
);
expect
(
result
[
2
].
target
).
to
.
b
e
(
'new series'
);
expect
(
result
[
0
].
target
).
to
B
e
(
'new series'
);
expect
(
result
[
1
].
target
).
to
B
e
(
'new series'
);
expect
(
result
[
2
].
target
).
to
B
e
(
'new series'
);
});
});
...
...
@@ -60,9 +59,9 @@ describe('when generating timeseries from influxdb response', function() {
var
series
=
new
InfluxSeries
(
options
);
var
result
=
series
.
getTimeSeries
();
expect
(
result
[
0
].
target
).
to
.
b
e
(
'alias: cpu -> server1 (cpu)'
);
expect
(
result
[
1
].
target
).
to
.
b
e
(
'alias: cpu -> server1 (cpu)'
);
expect
(
result
[
2
].
target
).
to
.
b
e
(
'alias: cpu -> server1 (cpu)'
);
expect
(
result
[
0
].
target
).
to
B
e
(
'alias: cpu -> server1 (cpu)'
);
expect
(
result
[
1
].
target
).
to
B
e
(
'alias: cpu -> server1 (cpu)'
);
expect
(
result
[
2
].
target
).
to
B
e
(
'alias: cpu -> server1 (cpu)'
);
});
});
...
...
@@ -90,8 +89,8 @@ describe('when generating timeseries from influxdb response', function() {
var
series
=
new
InfluxSeries
(
options
);
var
result
=
series
.
getTimeSeries
();
expect
(
result
[
0
].
target
).
to
.
b
e
(
'cpu {app: test, server: server1}'
);
expect
(
result
[
1
].
target
).
to
.
b
e
(
'cpu {app: test2, server: server2}'
);
expect
(
result
[
0
].
target
).
to
B
e
(
'cpu {app: test, server: server1}'
);
expect
(
result
[
1
].
target
).
to
B
e
(
'cpu {app: test2, server: server2}'
);
});
});
...
...
@@ -122,18 +121,18 @@ describe('when generating timeseries from influxdb response', function() {
var
series
=
new
InfluxSeries
(
options
);
var
result
=
series
.
getTimeSeries
();
expect
(
result
.
length
).
to
.
b
e
(
2
);
expect
(
result
[
0
].
target
).
to
.
b
e
(
'cpu.mean {app: test, server: server1}'
);
expect
(
result
[
0
].
datapoints
[
0
][
0
]).
to
.
b
e
(
10
);
expect
(
result
[
0
].
datapoints
[
0
][
1
]).
to
.
b
e
(
1431946625000
);
expect
(
result
[
0
].
datapoints
[
1
][
0
]).
to
.
b
e
(
12
);
expect
(
result
[
0
].
datapoints
[
1
][
1
]).
to
.
b
e
(
1431946626000
);
expect
(
result
[
1
].
target
).
to
.
b
e
(
'cpu.mean {app: test2, server: server2}'
);
expect
(
result
[
1
].
datapoints
[
0
][
0
]).
to
.
b
e
(
15
);
expect
(
result
[
1
].
datapoints
[
0
][
1
]).
to
.
b
e
(
1431946625000
);
expect
(
result
[
1
].
datapoints
[
1
][
0
]).
to
.
b
e
(
16
);
expect
(
result
[
1
].
datapoints
[
1
][
1
]).
to
.
b
e
(
1431946626000
);
expect
(
result
.
length
).
to
B
e
(
2
);
expect
(
result
[
0
].
target
).
to
B
e
(
'cpu.mean {app: test, server: server1}'
);
expect
(
result
[
0
].
datapoints
[
0
][
0
]).
to
B
e
(
10
);
expect
(
result
[
0
].
datapoints
[
0
][
1
]).
to
B
e
(
1431946625000
);
expect
(
result
[
0
].
datapoints
[
1
][
0
]).
to
B
e
(
12
);
expect
(
result
[
0
].
datapoints
[
1
][
1
]).
to
B
e
(
1431946626000
);
expect
(
result
[
1
].
target
).
to
B
e
(
'cpu.mean {app: test2, server: server2}'
);
expect
(
result
[
1
].
datapoints
[
0
][
0
]).
to
B
e
(
15
);
expect
(
result
[
1
].
datapoints
[
0
][
1
]).
to
B
e
(
1431946625000
);
expect
(
result
[
1
].
datapoints
[
1
][
0
]).
to
B
e
(
16
);
expect
(
result
[
1
].
datapoints
[
1
][
1
]).
to
B
e
(
1431946626000
);
});
});
...
...
@@ -143,7 +142,7 @@ describe('when generating timeseries from influxdb response', function() {
var
series
=
new
InfluxSeries
(
options
);
var
result
=
series
.
getTimeSeries
();
expect
(
result
[
0
].
target
).
to
.
b
e
(
'new series'
);
expect
(
result
[
0
].
target
).
to
B
e
(
'new series'
);
});
});
...
...
@@ -154,8 +153,8 @@ describe('when generating timeseries from influxdb response', function() {
var
series
=
new
InfluxSeries
(
options
);
var
result
=
series
.
getTimeSeries
();
expect
(
result
[
0
].
target
).
to
.
b
e
(
'alias: cpu -> server1 (cpu)'
);
expect
(
result
[
1
].
target
).
to
.
b
e
(
'alias: cpu -> server2 (cpu)'
);
expect
(
result
[
0
].
target
).
to
B
e
(
'alias: cpu -> server1 (cpu)'
);
expect
(
result
[
1
].
target
).
to
B
e
(
'alias: cpu -> server2 (cpu)'
);
});
});
...
...
@@ -180,7 +179,7 @@ describe('when generating timeseries from influxdb response', function() {
var
series
=
new
InfluxSeries
(
options
);
var
result
=
series
.
getTimeSeries
();
expect
(
result
[
0
].
target
).
to
.
b
e
(
'alias: prod -> count'
);
expect
(
result
[
0
].
target
).
to
B
e
(
'alias: prod -> count'
);
});
});
...
...
@@ -201,9 +200,9 @@ describe('when generating timeseries from influxdb response', function() {
var
series
=
new
InfluxSeries
(
options
);
var
table
=
series
.
getTable
();
expect
(
table
.
type
).
to
.
b
e
(
'table'
);
expect
(
table
.
columns
.
length
).
to
.
b
e
(
5
);
expect
(
table
.
rows
[
0
]).
to
.
eq
l
([
1431946625000
,
'Africa'
,
'server2'
,
23
,
10
]);
expect
(
table
.
type
).
to
B
e
(
'table'
);
expect
(
table
.
columns
.
length
).
to
B
e
(
5
);
expect
(
table
.
rows
[
0
]).
to
Equa
l
([
1431946625000
,
'Africa'
,
'server2'
,
23
,
10
]);
});
});
...
...
@@ -228,7 +227,7 @@ describe('when generating timeseries from influxdb response', function() {
var
series
=
new
InfluxSeries
(
options
);
var
annotations
=
series
.
getAnnotations
();
expect
(
annotations
[
0
].
tags
.
length
).
to
.
b
e
(
0
);
expect
(
annotations
[
0
].
tags
.
length
).
to
B
e
(
0
);
});
});
...
...
@@ -254,9 +253,9 @@ describe('when generating timeseries from influxdb response', function() {
var
series
=
new
InfluxSeries
(
options
);
var
annotations
=
series
.
getAnnotations
();
expect
(
annotations
[
0
].
tags
.
length
).
to
.
b
e
(
2
);
expect
(
annotations
[
0
].
tags
[
0
]).
to
.
b
e
(
'America'
);
expect
(
annotations
[
0
].
tags
[
1
]).
to
.
b
e
(
'backend'
);
expect
(
annotations
[
0
].
tags
.
length
).
to
B
e
(
2
);
expect
(
annotations
[
0
].
tags
[
0
]).
to
B
e
(
'America'
);
expect
(
annotations
[
0
].
tags
[
1
]).
to
B
e
(
'backend'
);
});
});
});
...
...
public/app/plugins/datasource/influxdb/specs/query_part
_specs
.ts
→
public/app/plugins/datasource/influxdb/specs/query_part
.jest
.ts
View file @
c83975f2
import
{
describe
,
it
,
expect
}
from
'test/lib/common'
;
import
queryPart
from
'../query_part'
;
describe
(
'InfluxQueryPart'
,
()
=>
{
...
...
@@ -12,8 +9,8 @@ describe('InfluxQueryPart', () => {
params
:
[
'10s'
],
});
expect
(
part
.
text
).
to
.
b
e
(
'derivative(10s)'
);
expect
(
part
.
render
(
'mean(value)'
)).
to
.
b
e
(
'derivative(mean(value), 10s)'
);
expect
(
part
.
text
).
to
B
e
(
'derivative(10s)'
);
expect
(
part
.
render
(
'mean(value)'
)).
to
B
e
(
'derivative(mean(value), 10s)'
);
});
it
(
'should nest spread function'
,
()
=>
{
...
...
@@ -21,8 +18,8 @@ describe('InfluxQueryPart', () => {
type
:
'spread'
});
expect
(
part
.
text
).
to
.
b
e
(
'spread()'
);
expect
(
part
.
render
(
'value'
)).
to
.
b
e
(
'spread(value)'
);
expect
(
part
.
text
).
to
B
e
(
'spread()'
);
expect
(
part
.
render
(
'value'
)).
to
B
e
(
'spread(value)'
);
});
it
(
'should handle suffix parts'
,
()
=>
{
...
...
@@ -31,8 +28,8 @@ describe('InfluxQueryPart', () => {
params
:
[
'/ 100'
],
});
expect
(
part
.
text
).
to
.
b
e
(
'math(/ 100)'
);
expect
(
part
.
render
(
'mean(value)'
)).
to
.
b
e
(
'mean(value) / 100'
);
expect
(
part
.
text
).
to
B
e
(
'math(/ 100)'
);
expect
(
part
.
render
(
'mean(value)'
)).
to
B
e
(
'mean(value) / 100'
);
});
it
(
'should handle alias parts'
,
()
=>
{
...
...
@@ -41,8 +38,8 @@ describe('InfluxQueryPart', () => {
params
:
[
'test'
],
});
expect
(
part
.
text
).
to
.
b
e
(
'alias(test)'
);
expect
(
part
.
render
(
'mean(value)'
)).
to
.
b
e
(
'mean(value) AS "test"'
);
expect
(
part
.
text
).
to
B
e
(
'alias(test)'
);
expect
(
part
.
render
(
'mean(value)'
)).
to
B
e
(
'mean(value) AS "test"'
);
});
});
...
...
public/app/plugins/datasource/influxdb/specs/response_parser
_specs
.ts
→
public/app/plugins/datasource/influxdb/specs/response_parser
.jest
.ts
View file @
c83975f2
import
_
from
'lodash'
;
import
{
describe
,
it
,
expect
}
from
'test/lib/common'
;
import
ResponseParser
from
'../response_parser'
;
describe
(
"influxdb response parser"
,
()
=>
{
this
.
parser
=
new
ResponseParser
();
describe
(
'influxdb response parser'
,
()
=>
{
const
parser
=
new
ResponseParser
();
describe
(
"SHOW TAG response"
,
()
=>
{
var
query
=
'SHOW TAG KEYS FROM "cpu"'
;
var
response
=
{
...
...
@@ -20,10 +21,10 @@ describe("influxdb response parser", () => {
]
};
var
result
=
this
.
parser
.
parse
(
query
,
response
);
var
result
=
parser
.
parse
(
query
,
response
);
it
(
"expects three results"
,
()
=>
{
expect
(
_
.
size
(
result
)).
to
.
b
e
(
3
);
expect
(
_
.
size
(
result
)).
to
B
e
(
3
);
});
});
...
...
@@ -45,12 +46,12 @@ describe("influxdb response parser", () => {
]
};
var
result
=
this
.
parser
.
parse
(
query
,
response
);
var
result
=
parser
.
parse
(
query
,
response
);
it
(
"should get two responses"
,
()
=>
{
expect
(
_
.
size
(
result
)).
to
.
b
e
(
2
);
expect
(
result
[
0
].
text
).
to
.
b
e
(
"server1"
);
expect
(
result
[
1
].
text
).
to
.
b
e
(
"server2"
);
expect
(
_
.
size
(
result
)).
to
B
e
(
2
);
expect
(
result
[
0
].
text
).
to
B
e
(
"server1"
);
expect
(
result
[
1
].
text
).
to
B
e
(
"server2"
);
});
});
...
...
@@ -80,13 +81,13 @@ describe("influxdb response parser", () => {
]
};
var
result
=
this
.
parser
.
parse
(
query
,
response
);
var
result
=
parser
.
parse
(
query
,
response
);
it
(
"should get two responses"
,
()
=>
{
expect
(
_
.
size
(
result
)).
to
.
b
e
(
3
);
expect
(
result
[
0
].
text
).
to
.
b
e
(
'site'
);
expect
(
result
[
1
].
text
).
to
.
b
e
(
'api'
);
expect
(
result
[
2
].
text
).
to
.
b
e
(
'webapi'
);
expect
(
_
.
size
(
result
)).
to
B
e
(
3
);
expect
(
result
[
0
].
text
).
to
B
e
(
'site'
);
expect
(
result
[
1
].
text
).
to
B
e
(
'api'
);
expect
(
result
[
2
].
text
).
to
B
e
(
'webapi'
);
});
});
});
...
...
@@ -110,9 +111,9 @@ describe("influxdb response parser", () => {
]
};
var
result
=
this
.
parser
.
parse
(
query
,
response
);
var
result
=
parser
.
parse
(
query
,
response
);
it
(
"should get two responses"
,
()
=>
{
expect
(
_
.
size
(
result
)).
to
.
b
e
(
6
);
expect
(
_
.
size
(
result
)).
to
B
e
(
6
);
});
});
...
...
@@ -131,10 +132,10 @@ describe("influxdb response parser", () => {
]
};
var
result
=
this
.
parser
.
parse
(
query
,
response
);
var
result
=
parser
.
parse
(
query
,
response
);
it
(
"should get two responses"
,
()
=>
{
expect
(
_
.
size
(
result
)).
to
.
b
e
(
1
);
expect
(
_
.
size
(
result
)).
to
B
e
(
1
);
});
});
});
...
...
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