2019-11-12 02:15:20 -08:00
|
|
|
import * as React from 'react';
|
2020-02-03 06:14:25 -08:00
|
|
|
import { mount, ReactWrapper } from 'enzyme';
|
2019-11-12 02:15:20 -08:00
|
|
|
import { act } from 'react-dom/test-utils';
|
2020-02-03 06:14:25 -08:00
|
|
|
import { Table } from 'reactstrap';
|
|
|
|
|
|
|
|
import TSDBStatus from './TSDBStatus';
|
2019-11-13 05:58:45 -08:00
|
|
|
import { TSDBMap } from './TSDBStatus';
|
2020-10-22 08:22:32 -07:00
|
|
|
import { PathPrefixContext } from '../../contexts/PathPrefixContext';
|
2019-11-12 02:15:20 -08:00
|
|
|
|
|
|
|
const fakeTSDBStatusResponse: {
|
|
|
|
status: string;
|
|
|
|
data: TSDBMap;
|
|
|
|
} = {
|
|
|
|
status: 'success',
|
|
|
|
data: {
|
2020-09-29 13:05:33 -07:00
|
|
|
headStats: {
|
|
|
|
numSeries: 508,
|
2021-01-06 22:41:32 -08:00
|
|
|
numLabelPairs: 1234,
|
2020-09-29 13:05:33 -07:00
|
|
|
chunkCount: 937,
|
|
|
|
minTime: 1591516800000,
|
|
|
|
maxTime: 1598896800143,
|
|
|
|
},
|
2019-11-12 02:15:20 -08:00
|
|
|
labelValueCountByLabelName: [
|
|
|
|
{
|
|
|
|
name: '__name__',
|
|
|
|
value: 5,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
seriesCountByMetricName: [
|
|
|
|
{
|
|
|
|
name: 'scrape_duration_seconds',
|
|
|
|
value: 1,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'scrape_samples_scraped',
|
|
|
|
value: 1,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
memoryInBytesByLabelName: [
|
|
|
|
{
|
|
|
|
name: '__name__',
|
|
|
|
value: 103,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
seriesCountByLabelValuePair: [
|
|
|
|
{
|
|
|
|
name: 'instance=localhost:9100',
|
|
|
|
value: 5,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2021-03-26 12:47:54 -07:00
|
|
|
const fakeEmptyTSDBStatusResponse: {
|
|
|
|
status: string;
|
|
|
|
data: TSDBMap;
|
|
|
|
} = {
|
|
|
|
status: 'success',
|
|
|
|
data: {
|
|
|
|
headStats: {
|
|
|
|
numSeries: 0,
|
|
|
|
numLabelPairs: 0,
|
|
|
|
chunkCount: 0,
|
|
|
|
minTime: 9223372036854776000,
|
|
|
|
maxTime: -9223372036854776000,
|
|
|
|
},
|
|
|
|
labelValueCountByLabelName: [],
|
|
|
|
seriesCountByMetricName: [],
|
|
|
|
memoryInBytesByLabelName: [],
|
|
|
|
seriesCountByLabelValuePair: [],
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2021-03-28 02:11:00 -07:00
|
|
|
const fakeInvalidTimestampTSDBStatusResponse: {
|
|
|
|
status: string;
|
|
|
|
data: TSDBMap;
|
|
|
|
} = {
|
|
|
|
status: 'success',
|
|
|
|
data: {
|
|
|
|
headStats: {
|
|
|
|
numSeries: 1,
|
|
|
|
numLabelPairs: 0,
|
|
|
|
chunkCount: 0,
|
|
|
|
minTime: 9223372036854776000,
|
|
|
|
maxTime: -9223372036854776000,
|
|
|
|
},
|
|
|
|
labelValueCountByLabelName: [],
|
|
|
|
seriesCountByMetricName: [],
|
|
|
|
memoryInBytesByLabelName: [],
|
|
|
|
seriesCountByLabelValuePair: [],
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2019-11-12 02:15:20 -08:00
|
|
|
describe('TSDB Stats', () => {
|
|
|
|
beforeEach(() => {
|
2019-11-13 05:58:45 -08:00
|
|
|
fetchMock.resetMocks();
|
2019-11-12 02:15:20 -08:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('Table Data Validation', () => {
|
|
|
|
it('Table Test', async () => {
|
|
|
|
const tables = [
|
2020-09-29 13:05:33 -07:00
|
|
|
fakeTSDBStatusResponse.data.labelValueCountByLabelName,
|
|
|
|
fakeTSDBStatusResponse.data.seriesCountByMetricName,
|
|
|
|
fakeTSDBStatusResponse.data.memoryInBytesByLabelName,
|
|
|
|
fakeTSDBStatusResponse.data.seriesCountByLabelValuePair,
|
2019-11-12 02:15:20 -08:00
|
|
|
];
|
|
|
|
|
2019-11-13 05:58:45 -08:00
|
|
|
const mock = fetchMock.mockResponse(JSON.stringify(fakeTSDBStatusResponse));
|
|
|
|
let page: any;
|
2019-11-12 02:15:20 -08:00
|
|
|
await act(async () => {
|
2020-10-22 08:22:32 -07:00
|
|
|
page = mount(
|
|
|
|
<PathPrefixContext.Provider value="/path/prefix">
|
|
|
|
<TSDBStatus />
|
|
|
|
</PathPrefixContext.Provider>
|
|
|
|
);
|
2019-11-12 02:15:20 -08:00
|
|
|
});
|
|
|
|
page.update();
|
|
|
|
|
2020-11-03 05:51:48 -08:00
|
|
|
expect(mock).toHaveBeenCalledWith('/path/prefix/api/v1/status/tsdb', {
|
2020-02-03 06:14:25 -08:00
|
|
|
cache: 'no-store',
|
2020-01-20 07:50:32 -08:00
|
|
|
credentials: 'same-origin',
|
|
|
|
});
|
2019-11-12 02:15:20 -08:00
|
|
|
|
2021-09-03 08:41:20 -07:00
|
|
|
const headStats = page.find(Table).at(0).find('tbody').find('td');
|
2021-01-06 22:41:32 -08:00
|
|
|
['508', '937', '1234', '2020-06-07T08:00:00.000Z (1591516800000)', '2020-08-31T18:00:00.143Z (1598896800143)'].forEach(
|
2020-09-29 13:05:33 -07:00
|
|
|
(value, i) => {
|
|
|
|
expect(headStats.at(i).text()).toEqual(value);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2019-11-12 02:15:20 -08:00
|
|
|
for (let i = 0; i < tables.length; i++) {
|
2020-09-29 13:05:33 -07:00
|
|
|
const data = tables[i];
|
2019-11-13 05:58:45 -08:00
|
|
|
const table = page
|
2019-11-12 02:15:20 -08:00
|
|
|
.find(Table)
|
2020-09-29 13:05:33 -07:00
|
|
|
.at(i + 1)
|
2019-11-12 02:15:20 -08:00
|
|
|
.find('tbody');
|
2019-11-13 05:58:45 -08:00
|
|
|
const rows = table.find('tr');
|
2019-11-12 02:15:20 -08:00
|
|
|
for (let i = 0; i < data.length; i++) {
|
|
|
|
const firstRowColumns = rows
|
|
|
|
.at(i)
|
|
|
|
.find('td')
|
2019-11-13 05:58:45 -08:00
|
|
|
.map((column: ReactWrapper) => column.text());
|
2019-11-12 02:15:20 -08:00
|
|
|
expect(rows.length).toBe(data.length);
|
|
|
|
expect(firstRowColumns[0]).toBe(data[i].name);
|
|
|
|
expect(firstRowColumns[1]).toBe(data[i].value.toString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2021-03-26 12:47:54 -07:00
|
|
|
|
2021-03-28 02:11:00 -07:00
|
|
|
it('No Data', async () => {
|
|
|
|
const mock = fetchMock.mockResponse(JSON.stringify(fakeEmptyTSDBStatusResponse));
|
|
|
|
let page: any;
|
|
|
|
await act(async () => {
|
|
|
|
page = mount(
|
|
|
|
<PathPrefixContext.Provider value="/path/prefix">
|
|
|
|
<TSDBStatus />
|
|
|
|
</PathPrefixContext.Provider>
|
|
|
|
);
|
|
|
|
});
|
|
|
|
page.update();
|
2021-03-26 12:47:54 -07:00
|
|
|
|
2021-03-28 02:11:00 -07:00
|
|
|
expect(mock).toHaveBeenCalledWith('/path/prefix/api/v1/status/tsdb', {
|
|
|
|
cache: 'no-store',
|
|
|
|
credentials: 'same-origin',
|
|
|
|
});
|
2021-03-26 12:47:54 -07:00
|
|
|
|
2021-03-28 02:11:00 -07:00
|
|
|
expect(page.find('h2').text()).toEqual('TSDB Status');
|
2021-03-26 12:47:54 -07:00
|
|
|
|
2021-09-03 08:41:20 -07:00
|
|
|
const headStats = page.find(Table).at(0).find('tbody').find('td');
|
2021-03-28 02:11:00 -07:00
|
|
|
['0', '0', '0', 'No datapoints yet', 'No datapoints yet'].forEach((value, i) => {
|
2021-03-26 12:47:54 -07:00
|
|
|
expect(headStats.at(i).text()).toEqual(value);
|
2021-03-28 02:11:00 -07:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('Invalid min/max Timestamp', async () => {
|
|
|
|
const mock = fetchMock.mockResponse(JSON.stringify(fakeInvalidTimestampTSDBStatusResponse));
|
|
|
|
let page: any;
|
|
|
|
await act(async () => {
|
|
|
|
page = mount(
|
|
|
|
<PathPrefixContext.Provider value="/path/prefix">
|
|
|
|
<TSDBStatus />
|
|
|
|
</PathPrefixContext.Provider>
|
|
|
|
);
|
|
|
|
});
|
|
|
|
page.update();
|
|
|
|
|
|
|
|
expect(mock).toHaveBeenCalledWith('/path/prefix/api/v1/status/tsdb', {
|
|
|
|
cache: 'no-store',
|
|
|
|
credentials: 'same-origin',
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(page.find('h2').text()).toEqual('TSDB Status');
|
|
|
|
|
2021-09-03 08:41:20 -07:00
|
|
|
const headStats = page.find(Table).at(0).find('tbody').find('td');
|
2021-03-28 02:11:00 -07:00
|
|
|
['1', '0', '0', 'Error parsing time (9223372036854776000)', 'Error parsing time (-9223372036854776000)'].forEach(
|
|
|
|
(value, i) => {
|
|
|
|
expect(headStats.at(i).text()).toEqual(value);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
2021-03-26 12:47:54 -07:00
|
|
|
});
|
2019-11-12 02:15:20 -08:00
|
|
|
});
|