mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Loki: Fix error when some queries return zero results (#28645)
* Fix logSeriesToLogsModel when some data frames have empty fields * Update test * Update public/app/core/logs_model.ts Co-authored-by: Zoltán Bedi <zoltan.bedi@gmail.com> Co-authored-by: Zoltán Bedi <zoltan.bedi@gmail.com>
This commit is contained in:
@@ -270,6 +270,7 @@ function separateLogsAndMetrics(dataFrames: DataFrame[]) {
|
||||
const logSeries: DataFrame[] = [];
|
||||
|
||||
for (const dataFrame of dataFrames) {
|
||||
// We want to show meta stats even if no result was returned. That's why we are pushing also data frames with no fields.
|
||||
if (isLogsData(dataFrame) || !dataFrame.fields.length) {
|
||||
logSeries.push(dataFrame);
|
||||
continue;
|
||||
@@ -306,8 +307,12 @@ export function logSeriesToLogsModel(logSeries: DataFrame[]): LogsModel | undefi
|
||||
// Find the fields we care about and collect all labels
|
||||
let allSeries: LogFields[] = [];
|
||||
|
||||
if (hasFields(logSeries)) {
|
||||
allSeries = logSeries.map(series => {
|
||||
// We are sometimes passing data frames with no fields because we want to calculate correct meta stats.
|
||||
// Therefore we need to filter out series with no fields. These series are used only for meta stats calculation.
|
||||
const seriesWithFields = logSeries.filter(series => series.fields.length);
|
||||
|
||||
if (seriesWithFields.length) {
|
||||
allSeries = seriesWithFields.map(series => {
|
||||
const fieldCache = new FieldCache(series);
|
||||
const stringField = fieldCache.getFirstFieldOfType(FieldType.string);
|
||||
|
||||
@@ -463,10 +468,6 @@ export function logSeriesToLogsModel(logSeries: DataFrame[]): LogsModel | undefi
|
||||
};
|
||||
}
|
||||
|
||||
function hasFields(logSeries: DataFrame[]): boolean {
|
||||
return logSeries.some(series => series.fields.length);
|
||||
}
|
||||
|
||||
function getIdField(fieldCache: FieldCache): FieldWithIndex | undefined {
|
||||
const idFieldNames = ['id'];
|
||||
for (const fieldName of idFieldNames) {
|
||||
|
||||
Reference in New Issue
Block a user