mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
influxdb: influxql: fix table-format data processing with renamed time field (#41052)
This commit is contained in:
parent
05c18c330f
commit
24db1efa9d
@ -171,19 +171,24 @@ export default class InfluxSeries {
|
||||
return table;
|
||||
}
|
||||
|
||||
// the order is:
|
||||
// - first the first item from the value-array (this is often (always?) the timestamp)
|
||||
// - then all the tag-values
|
||||
// - then the rest of the value-array
|
||||
//
|
||||
// we have to keep this order both in table.columns and table.rows
|
||||
|
||||
each(this.series, (series: any, seriesIndex: number) => {
|
||||
if (seriesIndex === 0) {
|
||||
j = 0;
|
||||
// Check that the first column is indeed 'time'
|
||||
if (series.columns[0] === 'time') {
|
||||
// Push this now before the tags and with the right type
|
||||
table.columns.push({ text: 'Time', type: FieldType.time });
|
||||
j++;
|
||||
}
|
||||
const firstCol = series.columns[0];
|
||||
// Check the first column's name, if it is `time`, we
|
||||
// mark it as having the type time
|
||||
const firstTableCol = firstCol === 'time' ? { text: 'Time', type: FieldType.time } : { text: firstCol };
|
||||
table.columns.push(firstTableCol);
|
||||
each(keys(series.tags), (key) => {
|
||||
table.columns.push({ text: key });
|
||||
});
|
||||
for (; j < series.columns.length; j++) {
|
||||
for (j = 1; j < series.columns.length; j++) {
|
||||
table.columns.push({ text: series.columns[j] });
|
||||
}
|
||||
}
|
||||
|
@ -1,3 +1,4 @@
|
||||
import produce from 'immer';
|
||||
import InfluxSeries from '../influx_series';
|
||||
|
||||
describe('when generating timeseries from influxdb response', () => {
|
||||
@ -300,5 +301,62 @@ describe('when generating timeseries from influxdb response', () => {
|
||||
expect(annotations[0].tags[1]).toBe('backend');
|
||||
});
|
||||
});
|
||||
|
||||
describe('given a time-column in the json-response', () => {
|
||||
const options = {
|
||||
alias: '',
|
||||
series: [
|
||||
{
|
||||
name: 'cpu',
|
||||
tags: { cpu: 'cpu1' },
|
||||
columns: ['time', 'usage_idle'],
|
||||
values: [[1481549440372, 42]],
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
it('the column-names should be correct if the time-column is not renamed', () => {
|
||||
const series = new InfluxSeries(options);
|
||||
const table = series.getTable();
|
||||
|
||||
expect(table.columns).toStrictEqual([
|
||||
{
|
||||
text: 'Time',
|
||||
type: 'time',
|
||||
},
|
||||
{
|
||||
text: 'cpu',
|
||||
},
|
||||
{
|
||||
text: 'usage_idle',
|
||||
},
|
||||
]);
|
||||
|
||||
expect(table.rows).toStrictEqual([[1481549440372, 'cpu1', 42]]);
|
||||
});
|
||||
|
||||
it('the column-names should be correct if the time-column is renamed', () => {
|
||||
const renamedOptions = produce(options, (draft) => {
|
||||
// we rename the time-column to `zeit`
|
||||
draft.series[0].columns[0] = 'zeit';
|
||||
});
|
||||
const series = new InfluxSeries(renamedOptions);
|
||||
const table = series.getTable();
|
||||
|
||||
expect(table.columns).toStrictEqual([
|
||||
{
|
||||
text: 'zeit',
|
||||
},
|
||||
{
|
||||
text: 'cpu',
|
||||
},
|
||||
{
|
||||
text: 'usage_idle',
|
||||
},
|
||||
]);
|
||||
|
||||
expect(table.rows).toStrictEqual([[1481549440372, 'cpu1', 42]]);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user