Commit 8eb78ea9 by Marcus Efraimsson Committed by GitHub

Explore: Fix empty result from datasource should render logs container (#16999)

Make sure to return an empty logs model instead of undefined so that 
the logs container renders an empty graph and log result in Explore.

Fixes #16997
parent d5a35f36
......@@ -356,7 +356,12 @@ export function seriesDataToLogsModel(seriesData: SeriesData[], intervalMs: numb
return logsModel;
}
return undefined;
return {
hasUniqueLabels: false,
rows: [],
meta: [],
series: [],
};
}
export function logSeriesToLogsModel(logSeries: SeriesData[]): LogsModel {
......
......@@ -333,22 +333,29 @@ describe('LogsParsers', () => {
});
});
const emptyLogsModel = {
hasUniqueLabels: false,
rows: [],
meta: [],
series: [],
};
describe('seriesDataToLogsModel', () => {
it('given empty series should return undefined', () => {
expect(seriesDataToLogsModel([] as SeriesData[], 0)).toBeUndefined();
it('given empty series should return empty logs model', () => {
expect(seriesDataToLogsModel([] as SeriesData[], 0)).toMatchObject(emptyLogsModel);
});
it('given series without correct series name should not be processed', () => {
it('given series without correct series name should return empty logs model', () => {
const series: SeriesData[] = [
{
fields: [],
rows: [],
},
];
expect(seriesDataToLogsModel(series, 0)).toBeUndefined();
expect(seriesDataToLogsModel(series, 0)).toMatchObject(emptyLogsModel);
});
it('given series without a time field should not be processed', () => {
it('given series without a time field should return empty logs model', () => {
const series: SeriesData[] = [
{
fields: [
......@@ -360,10 +367,10 @@ describe('seriesDataToLogsModel', () => {
rows: [],
},
];
expect(seriesDataToLogsModel(series, 0)).toBeUndefined();
expect(seriesDataToLogsModel(series, 0)).toMatchObject(emptyLogsModel);
});
it('given series without a string field should not be processed', () => {
it('given series without a string field should return empty logs model', () => {
const series: SeriesData[] = [
{
fields: [
......@@ -375,7 +382,7 @@ describe('seriesDataToLogsModel', () => {
rows: [],
},
];
expect(seriesDataToLogsModel(series, 0)).toBeUndefined();
expect(seriesDataToLogsModel(series, 0)).toMatchObject(emptyLogsModel);
});
it('given one series should return expected logs model', () => {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment