mirror of
https://github.com/prometheus/prometheus.git
synced 2025-02-21 03:16:00 -08:00
Fix DataTable tests and missing value key warning (#10422)
* Fix DataTable tests and missing value key warning Fixes issues introduced in https://github.com/prometheus/prometheus/pull/10376 Signed-off-by: Julius Volz <julius.volz@gmail.com> * Fix more DataTable brokenness Signed-off-by: Julius Volz <julius.volz@gmail.com>
This commit is contained in:
parent
2c3d45c88a
commit
7f238e6a04
|
@ -1,13 +1,13 @@
|
||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import { shallow } from 'enzyme';
|
import { shallow } from 'enzyme';
|
||||||
import DataTable, { QueryResult } from './DataTable';
|
import DataTable, { DataTableProps } from './DataTable';
|
||||||
import { Alert, Table } from 'reactstrap';
|
import { Alert, Table } from 'reactstrap';
|
||||||
import SeriesName from './SeriesName';
|
import SeriesName from './SeriesName';
|
||||||
|
|
||||||
describe('DataTable', () => {
|
describe('DataTable', () => {
|
||||||
describe('when data is null', () => {
|
describe('when data is null', () => {
|
||||||
it('renders an alert', () => {
|
it('renders an alert', () => {
|
||||||
const table = shallow(<DataTable data={null} />);
|
const table = shallow(<DataTable useLocalTime={false} data={null} />);
|
||||||
const alert = table.find(Alert);
|
const alert = table.find(Alert);
|
||||||
expect(Object.keys(alert.props())).toHaveLength(7);
|
expect(Object.keys(alert.props())).toHaveLength(7);
|
||||||
expect(alert.prop('color')).toEqual('light');
|
expect(alert.prop('color')).toEqual('light');
|
||||||
|
@ -17,11 +17,12 @@ describe('DataTable', () => {
|
||||||
|
|
||||||
describe('when data.result is empty', () => {
|
describe('when data.result is empty', () => {
|
||||||
it('renders an alert', () => {
|
it('renders an alert', () => {
|
||||||
const dataTableProps: QueryResult = {
|
const dataTableProps: DataTableProps = {
|
||||||
data: {
|
data: {
|
||||||
resultType: 'vector',
|
resultType: 'vector',
|
||||||
result: [],
|
result: [],
|
||||||
},
|
},
|
||||||
|
useLocalTime: false,
|
||||||
};
|
};
|
||||||
const table = shallow(<DataTable {...dataTableProps} />);
|
const table = shallow(<DataTable {...dataTableProps} />);
|
||||||
const alert = table.find(Alert);
|
const alert = table.find(Alert);
|
||||||
|
@ -32,7 +33,7 @@ describe('DataTable', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('when resultType is a vector with values', () => {
|
describe('when resultType is a vector with values', () => {
|
||||||
const dataTableProps: QueryResult = {
|
const dataTableProps: DataTableProps = {
|
||||||
data: {
|
data: {
|
||||||
resultType: 'vector',
|
resultType: 'vector',
|
||||||
result: [
|
result: [
|
||||||
|
@ -54,6 +55,7 @@ describe('DataTable', () => {
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
useLocalTime: false,
|
||||||
};
|
};
|
||||||
const dataTable = shallow(<DataTable {...dataTableProps} />);
|
const dataTable = shallow(<DataTable {...dataTableProps} />);
|
||||||
|
|
||||||
|
@ -75,7 +77,7 @@ describe('DataTable', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('when resultType is a vector with too many values', () => {
|
describe('when resultType is a vector with too many values', () => {
|
||||||
const dataTableProps: QueryResult = {
|
const dataTableProps: DataTableProps = {
|
||||||
data: {
|
data: {
|
||||||
resultType: 'vector',
|
resultType: 'vector',
|
||||||
result: Array.from(Array(10001).keys()).map((i) => {
|
result: Array.from(Array(10001).keys()).map((i) => {
|
||||||
|
@ -89,6 +91,7 @@ describe('DataTable', () => {
|
||||||
};
|
};
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
|
useLocalTime: false,
|
||||||
};
|
};
|
||||||
const dataTable = shallow(<DataTable {...dataTableProps} />);
|
const dataTable = shallow(<DataTable {...dataTableProps} />);
|
||||||
|
|
||||||
|
@ -104,7 +107,7 @@ describe('DataTable', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('when resultType is vector and size is more than maximum limit of formatting', () => {
|
describe('when resultType is vector and size is more than maximum limit of formatting', () => {
|
||||||
const dataTableProps: QueryResult = {
|
const dataTableProps: DataTableProps = {
|
||||||
data: {
|
data: {
|
||||||
resultType: 'vector',
|
resultType: 'vector',
|
||||||
result: Array.from(Array(1001).keys()).map((i) => {
|
result: Array.from(Array(1001).keys()).map((i) => {
|
||||||
|
@ -118,6 +121,7 @@ describe('DataTable', () => {
|
||||||
};
|
};
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
|
useLocalTime: false,
|
||||||
};
|
};
|
||||||
const dataTable = shallow(<DataTable {...dataTableProps} />);
|
const dataTable = shallow(<DataTable {...dataTableProps} />);
|
||||||
|
|
||||||
|
@ -130,7 +134,7 @@ describe('DataTable', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('when result type is a matrix', () => {
|
describe('when result type is a matrix', () => {
|
||||||
const dataTableProps: QueryResult = {
|
const dataTableProps: DataTableProps = {
|
||||||
data: {
|
data: {
|
||||||
resultType: 'matrix',
|
resultType: 'matrix',
|
||||||
result: [
|
result: [
|
||||||
|
@ -226,6 +230,7 @@ describe('DataTable', () => {
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
useLocalTime: false,
|
||||||
};
|
};
|
||||||
const dataTable = shallow(<DataTable {...dataTableProps} />);
|
const dataTable = shallow(<DataTable {...dataTableProps} />);
|
||||||
it('renders rows', () => {
|
it('renders rows', () => {
|
||||||
|
@ -233,35 +238,19 @@ describe('DataTable', () => {
|
||||||
const rows = table.find('tr');
|
const rows = table.find('tr');
|
||||||
expect(table.find('tr')).toHaveLength(3);
|
expect(table.find('tr')).toHaveLength(3);
|
||||||
const row = rows.at(0);
|
const row = rows.at(0);
|
||||||
expect(row.text()).toEqual(`<SeriesName />9 @1572097950.93
|
expect(row.text()).toEqual(
|
||||||
10 @1572097965.931
|
`<SeriesName />9 @1572097950.9310 @1572097965.93111 @1572097980.92912 @1572097995.93113 @1572098010.93214 @1572098025.93315 @1572098040.9316 @1572098055.9317 @1572098070.9318 @1572098085.93619 @1572098100.93620 @1572098115.93321 @1572098130.93222 @1572098145.93223 @1572098160.93324 @1572098175.93425 @1572098190.93726 @1572098205.93427 @1572098220.93328 @1572098235.934`
|
||||||
11 @1572097980.929
|
);
|
||||||
12 @1572097995.931
|
|
||||||
13 @1572098010.932
|
|
||||||
14 @1572098025.933
|
|
||||||
15 @1572098040.93
|
|
||||||
16 @1572098055.93
|
|
||||||
17 @1572098070.93
|
|
||||||
18 @1572098085.936
|
|
||||||
19 @1572098100.936
|
|
||||||
20 @1572098115.933
|
|
||||||
21 @1572098130.932
|
|
||||||
22 @1572098145.932
|
|
||||||
23 @1572098160.933
|
|
||||||
24 @1572098175.934
|
|
||||||
25 @1572098190.937
|
|
||||||
26 @1572098205.934
|
|
||||||
27 @1572098220.933
|
|
||||||
28 @1572098235.934`);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('when resultType is a scalar', () => {
|
describe('when resultType is a scalar', () => {
|
||||||
const dataTableProps: QueryResult = {
|
const dataTableProps: DataTableProps = {
|
||||||
data: {
|
data: {
|
||||||
resultType: 'scalar',
|
resultType: 'scalar',
|
||||||
result: [1572098246.599, '5'],
|
result: [1572098246.599, '5'],
|
||||||
},
|
},
|
||||||
|
useLocalTime: false,
|
||||||
};
|
};
|
||||||
const dataTable = shallow(<DataTable {...dataTableProps} />);
|
const dataTable = shallow(<DataTable {...dataTableProps} />);
|
||||||
it('renders a scalar row', () => {
|
it('renders a scalar row', () => {
|
||||||
|
@ -272,11 +261,12 @@ describe('DataTable', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('when resultType is a string', () => {
|
describe('when resultType is a string', () => {
|
||||||
const dataTableProps: QueryResult = {
|
const dataTableProps: DataTableProps = {
|
||||||
data: {
|
data: {
|
||||||
resultType: 'string',
|
resultType: 'string',
|
||||||
result: 'string',
|
result: 'string',
|
||||||
},
|
},
|
||||||
|
useLocalTime: false,
|
||||||
};
|
};
|
||||||
const dataTable = shallow(<DataTable {...dataTableProps} />);
|
const dataTable = shallow(<DataTable {...dataTableProps} />);
|
||||||
it('renders a string row', () => {
|
it('renders a string row', () => {
|
||||||
|
|
|
@ -7,7 +7,7 @@ import { Metric } from '../../types/types';
|
||||||
|
|
||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
|
|
||||||
export interface QueryResult {
|
export interface DataTableProps {
|
||||||
data:
|
data:
|
||||||
| null
|
| null
|
||||||
| {
|
| {
|
||||||
|
@ -50,7 +50,7 @@ const limitSeries = <S extends InstantSample | RangeSamples>(series: S[]): S[] =
|
||||||
return series;
|
return series;
|
||||||
};
|
};
|
||||||
|
|
||||||
const DataTable: FC<QueryResult> = ({ data, useLocalTime }) => {
|
const DataTable: FC<DataTableProps> = ({ data, useLocalTime }) => {
|
||||||
if (data === null) {
|
if (data === null) {
|
||||||
return <Alert color="light">No data queried yet</Alert>;
|
return <Alert color="light">No data queried yet</Alert>;
|
||||||
}
|
}
|
||||||
|
@ -78,18 +78,18 @@ const DataTable: FC<QueryResult> = ({ data, useLocalTime }) => {
|
||||||
limited = rows.length !== data.result.length;
|
limited = rows.length !== data.result.length;
|
||||||
break;
|
break;
|
||||||
case 'matrix':
|
case 'matrix':
|
||||||
rows = (limitSeries(data.result) as RangeSamples[]).map((s, index) => {
|
rows = (limitSeries(data.result) as RangeSamples[]).map((s, seriesIdx) => {
|
||||||
const valuesAndTimes = s.values.map((v) => {
|
const valuesAndTimes = s.values.map((v, valIdx) => {
|
||||||
const printedDatetime = moment.unix(v[0]).toISOString(useLocalTime);
|
const printedDatetime = moment.unix(v[0]).toISOString(useLocalTime);
|
||||||
return (
|
return (
|
||||||
<React.Fragment>
|
<React.Fragment key={valIdx}>
|
||||||
{v[1]} @{<span title={printedDatetime}>{v[0]}</span>}
|
{v[1]} @{<span title={printedDatetime}>{v[0]}</span>}
|
||||||
<br />
|
<br />
|
||||||
</React.Fragment>
|
</React.Fragment>
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
return (
|
return (
|
||||||
<tr style={{ whiteSpace: 'pre' }} key={index}>
|
<tr style={{ whiteSpace: 'pre' }} key={seriesIdx}>
|
||||||
<td>
|
<td>
|
||||||
<SeriesName labels={s.metric} format={doFormat} />
|
<SeriesName labels={s.metric} format={doFormat} />
|
||||||
</td>
|
</td>
|
||||||
|
|
Loading…
Reference in a new issue