mirror of
https://github.com/prometheus/prometheus.git
synced 2024-12-25 21:54:10 -08:00
Fix Blank TSDB Status Page (#8654)
* Check response and return alternate page if no statistics Signed-off-by: Levi Harrison <git@leviharrison.dev> * Added tests for alternate page Signed-off-by: Levi Harrison <git@leviharrison.dev> * Change error handling in unixToTime Signed-off-by: Levi Harrison <git@leviharrison.dev>
This commit is contained in:
parent
cceab6defa
commit
1b4e4aa81a
|
@ -51,6 +51,26 @@ const fakeTSDBStatusResponse: {
|
|||
},
|
||||
};
|
||||
|
||||
const fakeEmptyTSDBStatusResponse: {
|
||||
status: string;
|
||||
data: TSDBMap;
|
||||
} = {
|
||||
status: 'success',
|
||||
data: {
|
||||
headStats: {
|
||||
numSeries: 0,
|
||||
numLabelPairs: 0,
|
||||
chunkCount: 0,
|
||||
minTime: 9223372036854776000,
|
||||
maxTime: -9223372036854776000,
|
||||
},
|
||||
labelValueCountByLabelName: [],
|
||||
seriesCountByMetricName: [],
|
||||
memoryInBytesByLabelName: [],
|
||||
seriesCountByLabelValuePair: [],
|
||||
},
|
||||
};
|
||||
|
||||
describe('TSDB Stats', () => {
|
||||
beforeEach(() => {
|
||||
fetchMock.resetMocks();
|
||||
|
@ -111,4 +131,35 @@ describe('TSDB Stats', () => {
|
|||
}
|
||||
});
|
||||
});
|
||||
|
||||
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();
|
||||
|
||||
expect(mock).toHaveBeenCalledWith('/path/prefix/api/v1/status/tsdb', {
|
||||
cache: 'no-store',
|
||||
credentials: 'same-origin',
|
||||
});
|
||||
|
||||
expect(page.find('h2').text()).toEqual('TSDB Status');
|
||||
|
||||
const headStats = page
|
||||
.find(Table)
|
||||
.at(0)
|
||||
.find('tbody')
|
||||
.find('td');
|
||||
['0', '0', '0', 'Error parsing time (9223372036854776000)', 'Error parsing time (-9223372036854776000)'].forEach(
|
||||
(value, i) => {
|
||||
expect(headStats.at(i).text()).toEqual(value);
|
||||
}
|
||||
);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -35,7 +35,13 @@ export const TSDBStatusContent: FC<TSDBMap> = ({
|
|||
memoryInBytesByLabelName,
|
||||
seriesCountByLabelValuePair,
|
||||
}) => {
|
||||
const unixToTime = (unix: number): string => new Date(unix).toISOString();
|
||||
const unixToTime = (unix: number): string => {
|
||||
try {
|
||||
return new Date(unix).toISOString();
|
||||
} catch {
|
||||
return 'Error parsing time';
|
||||
}
|
||||
};
|
||||
const { chunkCount, numSeries, numLabelPairs, minTime, maxTime } = headStats;
|
||||
const stats = [
|
||||
{ header: 'Number of Series', value: numSeries },
|
||||
|
|
Loading…
Reference in a new issue