Merge pull request #585 from influxdata/legend
Remove identifier (host) from timeSeriesToDygraph converterpull/584/merge
commit
c879c9a723
|
@ -0,0 +1,88 @@
|
||||||
|
import timeSeriesToDygraph from 'src/utils/timeSeriesToDygraph';
|
||||||
|
|
||||||
|
describe('timeSeriesToDygraph', () => {
|
||||||
|
it('parses a raw InfluxDB response into a dygraph friendly data format', () => {
|
||||||
|
const influxResponse = [
|
||||||
|
{
|
||||||
|
"response":
|
||||||
|
{
|
||||||
|
"results": [
|
||||||
|
{
|
||||||
|
"series": [
|
||||||
|
{
|
||||||
|
"name":"m1",
|
||||||
|
"columns": ["time","f1"],
|
||||||
|
"values": [[1000, 1],[2000, 2]],
|
||||||
|
},
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"series": [
|
||||||
|
{
|
||||||
|
"name":"m1",
|
||||||
|
"columns": ["time","f2"],
|
||||||
|
"values": [[2000, 3],[4000, 4]],
|
||||||
|
},
|
||||||
|
]
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
const actual = timeSeriesToDygraph(influxResponse);
|
||||||
|
|
||||||
|
const expected = {
|
||||||
|
fields: [
|
||||||
|
'time',
|
||||||
|
`m1.f1`,
|
||||||
|
`m1.f2`,
|
||||||
|
],
|
||||||
|
timeSeries: [
|
||||||
|
[new Date(1000), 1, null],
|
||||||
|
[new Date(2000), 2, 3],
|
||||||
|
[new Date(4000), null, 4],
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
|
expect(actual).to.deep.equal(expected);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('can sort numerical timestamps correctly', () => {
|
||||||
|
const influxResponse = [
|
||||||
|
{
|
||||||
|
"response":
|
||||||
|
{
|
||||||
|
"results": [
|
||||||
|
{
|
||||||
|
"series": [
|
||||||
|
{
|
||||||
|
"name":"m1",
|
||||||
|
"columns": ["time","f1"],
|
||||||
|
"values": [[100, 1],[3000, 3],[200, 2]],
|
||||||
|
},
|
||||||
|
]
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
|
||||||
|
const actual = timeSeriesToDygraph(influxResponse);
|
||||||
|
|
||||||
|
const expected = {
|
||||||
|
fields: [
|
||||||
|
'time',
|
||||||
|
'm1.f1',
|
||||||
|
],
|
||||||
|
timeSeries: [
|
||||||
|
[new Date(100), 1],
|
||||||
|
[new Date(200), 2],
|
||||||
|
[new Date(3000), 3],
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
|
expect(actual).to.deep.equal(expected);
|
||||||
|
});
|
||||||
|
});
|
|
@ -60,7 +60,7 @@ export default function AutoRefresh(ComposedComponent) {
|
||||||
const newSeries = [];
|
const newSeries = [];
|
||||||
queries.forEach(({host, database, rp, text}) => {
|
queries.forEach(({host, database, rp, text}) => {
|
||||||
_fetchTimeSeries(host, database, rp, text).then((resp) => {
|
_fetchTimeSeries(host, database, rp, text).then((resp) => {
|
||||||
newSeries.push({identifier: host, response: resp.data});
|
newSeries.push({response: resp.data});
|
||||||
count += 1;
|
count += 1;
|
||||||
if (count === queries.length) {
|
if (count === queries.length) {
|
||||||
this.setState({
|
this.setState({
|
||||||
|
|
|
@ -131,6 +131,7 @@ export default React.createClass({
|
||||||
|
|
||||||
const timeSeries = this.getTimeSeries();
|
const timeSeries = this.getTimeSeries();
|
||||||
const {fields, yRange} = this.props;
|
const {fields, yRange} = this.props;
|
||||||
|
|
||||||
dygraph.updateOptions({
|
dygraph.updateOptions({
|
||||||
labels: fields,
|
labels: fields,
|
||||||
file: timeSeries,
|
file: timeSeries,
|
||||||
|
|
|
@ -26,7 +26,7 @@ export default function timeSeriesToDygraph(raw = []) {
|
||||||
*/
|
*/
|
||||||
const dateToFieldValue = {};
|
const dateToFieldValue = {};
|
||||||
|
|
||||||
raw.forEach(({identifier = '', response}) => {
|
raw.forEach(({response}) => {
|
||||||
// If a response is an empty result set or a query returned an error
|
// If a response is an empty result set or a query returned an error
|
||||||
// from InfluxDB, don't try and parse.
|
// from InfluxDB, don't try and parse.
|
||||||
if (response.results.length) {
|
if (response.results.length) {
|
||||||
|
@ -83,8 +83,7 @@ export default function timeSeriesToDygraph(raw = []) {
|
||||||
}).sort().join('');
|
}).sort().join('');
|
||||||
|
|
||||||
columns.slice(1).forEach((fieldName) => {
|
columns.slice(1).forEach((fieldName) => {
|
||||||
const identString = identifier ? `(${identifier})` : '';
|
const effectiveFieldName = `${measurementName}.${fieldName}${tags}`;
|
||||||
const effectiveFieldName = `${measurementName}.${fieldName}${tags}${identString}`;
|
|
||||||
|
|
||||||
// Given a field name, identify which column in the timeSeries result should hold the field's value
|
// Given a field name, identify which column in the timeSeries result should hold the field's value
|
||||||
// ex given this timeSeries [Date, 10, 20, 30] field index at 2 would correspond to value 20
|
// ex given this timeSeries [Date, 10, 20, 30] field index at 2 would correspond to value 20
|
||||||
|
@ -112,8 +111,7 @@ export default function timeSeriesToDygraph(raw = []) {
|
||||||
}
|
}
|
||||||
|
|
||||||
const fieldName = columns[index];
|
const fieldName = columns[index];
|
||||||
const identString = identifier ? `(${identifier})` : '';
|
const effectiveFieldName = `${measurementName}.${fieldName}${tags}`;
|
||||||
const effectiveFieldName = `${measurementName}.${fieldName}${tags}${identString}`;
|
|
||||||
dateToFieldValue[dateString][effectiveFieldName] = value;
|
dateToFieldValue[dateString][effectiveFieldName] = value;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue