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
53312852
Commit
53312852
authored
Mar 22, 2016
by
bergquist
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tests(influxdb): adds tests for influxdb response
parent
2d59112c
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
86 additions
and
18 deletions
+86
-18
public/app/plugins/datasource/influxdb/datasource.ts
+5
-18
public/app/plugins/datasource/influxdb/response_parser.ts
+23
-0
public/app/plugins/datasource/influxdb/specs/response_parser_specs.ts
+58
-0
No files found.
public/app/plugins/datasource/influxdb/datasource.ts
View file @
53312852
...
@@ -6,6 +6,7 @@ import _ from 'lodash';
...
@@ -6,6 +6,7 @@ import _ from 'lodash';
import
*
as
dateMath
from
'app/core/utils/datemath'
;
import
*
as
dateMath
from
'app/core/utils/datemath'
;
import
InfluxSeries
from
'./influx_series'
;
import
InfluxSeries
from
'./influx_series'
;
import
InfluxQuery
from
'./influx_query'
;
import
InfluxQuery
from
'./influx_query'
;
import
ResponseParser
from
'./response_parser'
;
/** @ngInject */
/** @ngInject */
export
function
InfluxDatasource
(
instanceSettings
,
$q
,
backendSrv
,
templateSrv
)
{
export
function
InfluxDatasource
(
instanceSettings
,
$q
,
backendSrv
,
templateSrv
)
{
...
@@ -22,6 +23,7 @@ export function InfluxDatasource(instanceSettings, $q, backendSrv, templateSrv)
...
@@ -22,6 +23,7 @@ export function InfluxDatasource(instanceSettings, $q, backendSrv, templateSrv)
this
.
interval
=
(
instanceSettings
.
jsonData
||
{}).
timeInterval
;
this
.
interval
=
(
instanceSettings
.
jsonData
||
{}).
timeInterval
;
this
.
supportAnnotations
=
true
;
this
.
supportAnnotations
=
true
;
this
.
supportMetrics
=
true
;
this
.
supportMetrics
=
true
;
this
.
responseParser
=
new
ResponseParser
();
this
.
query
=
function
(
options
)
{
this
.
query
=
function
(
options
)
{
var
timeFilter
=
getTimeFilter
(
options
);
var
timeFilter
=
getTimeFilter
(
options
);
...
@@ -101,7 +103,7 @@ export function InfluxDatasource(instanceSettings, $q, backendSrv, templateSrv)
...
@@ -101,7 +103,7 @@ export function InfluxDatasource(instanceSettings, $q, backendSrv, templateSrv)
});
});
};
};
this
.
metricFindQuery
=
function
(
query
)
{
this
.
metricFindQuery
=
function
(
query
,
queryType
)
{
var
interpolated
;
var
interpolated
;
try
{
try
{
interpolated
=
templateSrv
.
replace
(
query
,
null
,
'regex'
);
interpolated
=
templateSrv
.
replace
(
query
,
null
,
'regex'
);
...
@@ -109,23 +111,8 @@ export function InfluxDatasource(instanceSettings, $q, backendSrv, templateSrv)
...
@@ -109,23 +111,8 @@ export function InfluxDatasource(instanceSettings, $q, backendSrv, templateSrv)
return
$q
.
reject
(
err
);
return
$q
.
reject
(
err
);
}
}
return
this
.
_seriesQuery
(
interpolated
).
then
(
function
(
results
)
{
return
this
.
_seriesQuery
(
interpolated
)
if
(
!
results
||
results
.
results
.
length
===
0
)
{
return
[];
}
.
then
(
_
.
curry
(
this
.
responseParser
.
parse
)(
queryType
));
var
influxResults
=
results
.
results
[
0
];
if
(
!
influxResults
.
series
)
{
return
[];
}
var
series
=
influxResults
.
series
[
0
];
return
_
.
map
(
series
.
values
,
function
(
value
)
{
if
(
_
.
isArray
(
value
))
{
return
{
text
:
value
[
0
]
};
}
else
{
return
{
text
:
value
};
}
});
});
};
};
this
.
_seriesQuery
=
function
(
query
)
{
this
.
_seriesQuery
=
function
(
query
)
{
...
...
public/app/plugins/datasource/influxdb/response_parser.ts
0 → 100644
View file @
53312852
///<reference path="../../../headers/common.d.ts" />
import
_
from
'lodash'
;
export
default
class
ResponseParser
{
parse
(
queryType
,
results
)
{
if
(
!
results
||
results
.
results
.
length
===
0
)
{
return
[];
}
var
influxResults
=
results
.
results
[
0
];
if
(
!
influxResults
.
series
)
{
return
[];
}
var
series
=
influxResults
.
series
[
0
];
return
_
.
map
(
series
.
values
,
function
(
value
)
{
if
(
_
.
isArray
(
value
))
{
return
{
text
:
value
[
0
]
};
}
else
{
return
{
text
:
value
};
}
});
}
}
public/app/plugins/datasource/influxdb/specs/response_parser_specs.ts
0 → 100644
View file @
53312852
import
_
from
'lodash'
;
import
{
describe
,
beforeEach
,
it
,
sinon
,
expect
}
from
'test/lib/common'
;
import
ResponseParser
from
'../response_parser'
;
describe
.
only
(
"influxdb response parser"
,
()
=>
{
describe
(
"SHOW_TAGS response"
,
()
=>
{
this
.
parser
=
new
ResponseParser
();
describe
(
"response from 0.10.0"
,
()
=>
{
var
response
=
{
"results"
:
[
{
"series"
:
[
{
"name"
:
"hostnameTagValues"
,
"columns"
:
[
"hostname"
],
"values"
:
[
[
"server1"
],
[
"server2"
]
]
}
]
}
]
};
var
result
=
this
.
parser
.
parse
(
'SHOW_TAGS'
,
response
);
it
(
"should get two responses"
,
()
=>
{
expect
(
_
.
size
(
result
)).
to
.
be
(
2
);
expect
(
result
[
0
].
text
).
to
.
be
(
"server1"
);
expect
(
result
[
1
].
text
).
to
.
be
(
"server2"
);
});
});
});
describe
(
"SHOW_FIELDS response"
,
()
=>
{
describe
(
"response from 0.10.0"
,
()
=>
{
var
response
=
{
"results"
:
[
{
"series"
:
[
{
"name"
:
"measurements"
,
"columns"
:
[
"name"
],
"values"
:
[
[
"cpu"
],
[
"derivative"
],
[
"logins.count"
],
[
"logs"
],
[
"payment.ended"
],
[
"payment.started"
]
]
}
]
}
]
};
var
result
=
this
.
parser
.
parse
(
'SHOW_FIELDS'
,
response
);
it
(
"should get two responses"
,
()
=>
{
expect
(
_
.
size
(
result
)).
to
.
be
(
6
);
});
});
});
});
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