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
4f04eaec
Commit
4f04eaec
authored
Nov 30, 2015
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(influxdb): moved query builder tests
parent
5a2b9b1f
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
68 additions
and
182 deletions
+68
-182
public/app/plugins/datasource/influxdb/query_builder.js
+0
-72
public/app/plugins/datasource/influxdb/specs/influx_query_specs.ts
+68
-0
public/app/plugins/datasource/influxdb/specs/query_builder_specs.ts
+0
-110
No files found.
public/app/plugins/datasource/influxdb/query_builder.js
View file @
4f04eaec
...
@@ -93,77 +93,5 @@ function (_) {
...
@@ -93,77 +93,5 @@ function (_) {
return
query
;
return
query
;
};
};
p
.
_getGroupByTimeInterval
=
function
(
interval
)
{
if
(
interval
===
'auto'
)
{
return
'$interval'
;
}
return
interval
;
};
p
.
_buildQuery
=
function
()
{
var
target
=
this
.
target
;
if
(
!
target
.
measurement
)
{
throw
"Metric measurement is missing"
;
}
if
(
!
target
.
fields
)
{
target
.
fields
=
[{
name
:
'value'
,
func
:
target
.
function
||
'mean'
}];
}
var
query
=
'SELECT '
;
var
i
;
for
(
i
=
0
;
i
<
target
.
fields
.
length
;
i
++
)
{
var
field
=
target
.
fields
[
i
];
if
(
i
>
0
)
{
query
+=
', '
;
}
query
+=
field
.
func
+
'("'
+
field
.
name
+
'")'
;
if
(
field
.
mathExpr
)
{
query
+=
field
.
mathExpr
;
}
if
(
field
.
asExpr
)
{
query
+=
' AS "'
+
field
.
asExpr
+
'"'
;
}
else
{
query
+=
' AS "'
+
field
.
name
+
'"'
;
}
}
var
measurement
=
target
.
measurement
;
if
(
!
measurement
.
match
(
'^/.*/'
)
&&
!
measurement
.
match
(
/^merge
\(
.*
\)
/
))
{
measurement
=
'"'
+
measurement
+
'"'
;
}
query
+=
' FROM '
+
measurement
+
' WHERE '
;
var
conditions
=
_
.
map
(
target
.
tags
,
function
(
tag
,
index
)
{
return
renderTagCondition
(
tag
,
index
);
});
query
+=
conditions
.
join
(
' '
);
query
+=
(
conditions
.
length
>
0
?
' AND '
:
''
)
+
'$timeFilter'
;
query
+=
' GROUP BY'
;
for
(
i
=
0
;
i
<
target
.
groupBy
.
length
;
i
++
)
{
var
group
=
target
.
groupBy
[
i
];
if
(
group
.
type
===
'time'
)
{
query
+=
' time('
+
this
.
_getGroupByTimeInterval
(
group
.
interval
)
+
')'
;
}
else
{
query
+=
', "'
+
group
.
key
+
'"'
;
}
}
if
(
target
.
fill
)
{
query
+=
' fill('
+
target
.
fill
+
')'
;
}
target
.
query
=
query
;
return
query
;
};
p
.
_modifyRawQuery
=
function
()
{
return
this
.
target
.
query
.
replace
(
";"
,
""
);
};
return
InfluxQueryBuilder
;
return
InfluxQueryBuilder
;
});
});
public/app/plugins/datasource/influxdb/specs/influx_query_specs.ts
View file @
4f04eaec
...
@@ -34,6 +34,74 @@ describe('InfluxQuery', function() {
...
@@ -34,6 +34,74 @@ describe('InfluxQuery', function() {
});
});
});
});
describe
(
'series with single tag only'
,
function
()
{
it
(
'should generate correct query'
,
function
()
{
var
query
=
new
InfluxQuery
({
measurement
:
'cpu'
,
groupBy
:
[{
type
:
'time'
,
params
:
[
'auto'
]}],
tags
:
[{
key
:
'hostname'
,
value
:
'server1'
}]
});
var
queryText
=
query
.
render
();
expect
(
queryText
).
to
.
be
(
'SELECT mean("value") FROM "cpu" WHERE "hostname" =
\'
server1
\'
AND $timeFilter'
+
' GROUP BY time($interval)'
);
});
it
(
'should switch regex operator with tag value is regex'
,
function
()
{
var
query
=
new
InfluxQuery
({
measurement
:
'cpu'
,
groupBy
:
[{
type
:
'time'
,
params
:
[
'auto'
]}],
tags
:
[{
key
:
'app'
,
value
:
'/e.*/'
}]
});
var
queryText
=
query
.
render
();
expect
(
queryText
).
to
.
be
(
'SELECT mean("value") FROM "cpu" WHERE "app" =~ /e.*/ AND $timeFilter GROUP BY time($interval)'
);
});
});
describe
(
'series with multiple tags only'
,
function
()
{
it
(
'should generate correct query'
,
function
()
{
var
query
=
new
InfluxQuery
({
measurement
:
'cpu'
,
groupBy
:
[{
type
:
'time'
,
params
:
[
'auto'
]}],
tags
:
[{
key
:
'hostname'
,
value
:
'server1'
},
{
key
:
'app'
,
value
:
'email'
,
condition
:
"AND"
}]
});
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)'
);
});
});
describe
(
'series with tags OR condition'
,
function
()
{
it
(
'should generate correct query'
,
function
()
{
var
query
=
new
InfluxQuery
({
measurement
:
'cpu'
,
groupBy
:
[{
type
:
'time'
,
params
:
[
'auto'
]}],
tags
:
[{
key
:
'hostname'
,
value
:
'server1'
},
{
key
:
'hostname'
,
value
:
'server2'
,
condition
:
"OR"
}]
});
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)'
);
});
});
describe
(
'series with groupByTag'
,
function
()
{
it
(
'should generate correct query'
,
function
()
{
var
query
=
new
InfluxQuery
({
measurement
:
'cpu'
,
tags
:
[],
groupBy
:
[{
type
:
'time'
,
interval
:
'auto'
},
{
type
:
'tag'
,
params
:
[
'host'
]}],
});
var
queryText
=
query
.
render
();
expect
(
queryText
).
to
.
be
(
'SELECT mean("value") FROM "cpu" WHERE $timeFilter '
+
'GROUP BY time($interval), "host"'
);
});
});
describe
(
'render series without group by'
,
function
()
{
describe
(
'render series without group by'
,
function
()
{
it
(
'should generate correct query'
,
function
()
{
it
(
'should generate correct query'
,
function
()
{
var
query
=
new
InfluxQuery
({
var
query
=
new
InfluxQuery
({
...
...
public/app/plugins/datasource/influxdb/specs/query_builder_specs.ts
View file @
4f04eaec
...
@@ -6,116 +6,6 @@ declare var InfluxQueryBuilder: any;
...
@@ -6,116 +6,6 @@ declare var InfluxQueryBuilder: any;
describe
(
'InfluxQueryBuilder'
,
function
()
{
describe
(
'InfluxQueryBuilder'
,
function
()
{
describe
(
'series with mesurement only'
,
function
()
{
it
(
'should generate correct query'
,
function
()
{
var
builder
=
new
InfluxQueryBuilder
({
measurement
:
'cpu'
,
groupBy
:
[{
type
:
'time'
,
interval
:
'auto'
}]
});
var
query
=
builder
.
build
();
expect
(
query
).
to
.
be
(
'SELECT mean("value") AS "value" FROM "cpu" WHERE $timeFilter GROUP BY time($interval)'
);
});
});
describe
(
'series with math expr and as expr'
,
function
()
{
it
(
'should generate correct query'
,
function
()
{
var
builder
=
new
InfluxQueryBuilder
({
measurement
:
'cpu'
,
fields
:
[{
name
:
'test'
,
func
:
'max'
,
mathExpr
:
'*2'
,
asExpr
:
'new_name'
}],
groupBy
:
[{
type
:
'time'
,
interval
:
'auto'
}]
});
var
query
=
builder
.
build
();
expect
(
query
).
to
.
be
(
'SELECT max("test")*2 AS "new_name" FROM "cpu" WHERE $timeFilter GROUP BY time($interval)'
);
});
});
describe
(
'series with single tag only'
,
function
()
{
it
(
'should generate correct query'
,
function
()
{
var
builder
=
new
InfluxQueryBuilder
({
measurement
:
'cpu'
,
groupBy
:
[{
type
:
'time'
,
interval
:
'auto'
}],
tags
:
[{
key
:
'hostname'
,
value
:
'server1'
}]
});
var
query
=
builder
.
build
();
expect
(
query
).
to
.
be
(
'SELECT mean("value") AS "value" FROM "cpu" WHERE "hostname" =
\'
server1
\'
AND $timeFilter'
+
' GROUP BY time($interval)'
);
});
it
(
'should switch regex operator with tag value is regex'
,
function
()
{
var
builder
=
new
InfluxQueryBuilder
({
measurement
:
'cpu'
,
groupBy
:
[{
type
:
'time'
,
interval
:
'auto'
}],
tags
:
[{
key
:
'app'
,
value
:
'/e.*/'
}]
});
var
query
=
builder
.
build
();
expect
(
query
).
to
.
be
(
'SELECT mean("value") AS "value" FROM "cpu" WHERE "app" =~ /e.*/ AND $timeFilter GROUP BY time($interval)'
);
});
});
describe
(
'series with multiple fields'
,
function
()
{
it
(
'should generate correct query'
,
function
()
{
var
builder
=
new
InfluxQueryBuilder
({
measurement
:
'cpu'
,
tags
:
[],
groupBy
:
[{
type
:
'time'
,
interval
:
'auto'
}],
fields
:
[{
name
:
'tx_in'
,
func
:
'sum'
},
{
name
:
'tx_out'
,
func
:
'mean'
}]
});
var
query
=
builder
.
build
();
expect
(
query
).
to
.
be
(
'SELECT sum("tx_in") AS "tx_in", mean("tx_out") AS "tx_out" '
+
'FROM "cpu" WHERE $timeFilter GROUP BY time($interval)'
);
});
});
describe
(
'series with multiple tags only'
,
function
()
{
it
(
'should generate correct query'
,
function
()
{
var
builder
=
new
InfluxQueryBuilder
({
measurement
:
'cpu'
,
groupBy
:
[{
type
:
'time'
,
interval
:
'auto'
}],
tags
:
[{
key
:
'hostname'
,
value
:
'server1'
},
{
key
:
'app'
,
value
:
'email'
,
condition
:
"AND"
}]
});
var
query
=
builder
.
build
();
expect
(
query
).
to
.
be
(
'SELECT mean("value") AS "value" FROM "cpu" WHERE "hostname" =
\'
server1
\'
AND "app" =
\'
email
\'
AND '
+
'$timeFilter GROUP BY time($interval)'
);
});
});
describe
(
'series with tags OR condition'
,
function
()
{
it
(
'should generate correct query'
,
function
()
{
var
builder
=
new
InfluxQueryBuilder
({
measurement
:
'cpu'
,
groupBy
:
[{
type
:
'time'
,
interval
:
'auto'
}],
tags
:
[{
key
:
'hostname'
,
value
:
'server1'
},
{
key
:
'hostname'
,
value
:
'server2'
,
condition
:
"OR"
}]
});
var
query
=
builder
.
build
();
expect
(
query
).
to
.
be
(
'SELECT mean("value") AS "value" FROM "cpu" WHERE "hostname" =
\'
server1
\'
OR "hostname" =
\'
server2
\'
AND '
+
'$timeFilter GROUP BY time($interval)'
);
});
});
describe
(
'series with groupByTag'
,
function
()
{
it
(
'should generate correct query'
,
function
()
{
var
builder
=
new
InfluxQueryBuilder
({
measurement
:
'cpu'
,
tags
:
[],
groupBy
:
[{
type
:
'time'
,
interval
:
'auto'
},
{
type
:
'tag'
,
key
:
'host'
}],
});
var
query
=
builder
.
build
();
expect
(
query
).
to
.
be
(
'SELECT mean("value") AS "value" FROM "cpu" WHERE $timeFilter '
+
'GROUP BY time($interval), "host"'
);
});
});
describe
(
'when building explore queries'
,
function
()
{
describe
(
'when building explore queries'
,
function
()
{
it
(
'should only have measurement condition in tag keys query given query with measurement'
,
function
()
{
it
(
'should only have measurement condition in tag keys query given query with measurement'
,
function
()
{
...
...
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