mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Explore: show meta data when available (#25798)
* Return valid metadata even if data is empty * Make sure fields is not accessed when there is no data * Meta Info should depend only on meta data * Refactor condition for better reading * Change data to empty array for better condition handling * Remove unecessary checks * Add test for showing metaData even when data is empty
This commit is contained in:
@@ -269,7 +269,7 @@ function separateLogsAndMetrics(dataFrames: DataFrame[]) {
|
||||
const logSeries: DataFrame[] = [];
|
||||
|
||||
for (const dataFrame of dataFrames) {
|
||||
if (isLogsData(dataFrame)) {
|
||||
if (isLogsData(dataFrame) || !dataFrame.fields.length) {
|
||||
logSeries.push(dataFrame);
|
||||
continue;
|
||||
}
|
||||
@@ -303,23 +303,29 @@ export function logSeriesToLogsModel(logSeries: DataFrame[]): LogsModel | undefi
|
||||
const allLabels: Labels[] = [];
|
||||
|
||||
// Find the fields we care about and collect all labels
|
||||
const allSeries: LogFields[] = logSeries.map(series => {
|
||||
const fieldCache = new FieldCache(series);
|
||||
const stringField = fieldCache.getFirstFieldOfType(FieldType.string);
|
||||
if (stringField?.labels) {
|
||||
allLabels.push(stringField.labels);
|
||||
}
|
||||
return {
|
||||
series,
|
||||
timeField: fieldCache.getFirstFieldOfType(FieldType.time),
|
||||
timeNanosecondField: fieldCache.hasFieldWithNameAndType('tsNs', FieldType.time)
|
||||
? fieldCache.getFieldByName('tsNs')
|
||||
: undefined,
|
||||
stringField,
|
||||
logLevelField: fieldCache.getFieldByName('level'),
|
||||
idField: getIdField(fieldCache),
|
||||
} as LogFields;
|
||||
});
|
||||
let allSeries: LogFields[] = [];
|
||||
|
||||
if (hasFields(logSeries)) {
|
||||
allSeries = logSeries.map(series => {
|
||||
const fieldCache = new FieldCache(series);
|
||||
const stringField = fieldCache.getFirstFieldOfType(FieldType.string);
|
||||
|
||||
if (stringField?.labels) {
|
||||
allLabels.push(stringField.labels);
|
||||
}
|
||||
|
||||
return {
|
||||
series,
|
||||
timeField: fieldCache.getFirstFieldOfType(FieldType.time),
|
||||
timeNanosecondField: fieldCache.hasFieldWithNameAndType('tsNs', FieldType.time)
|
||||
? fieldCache.getFieldByName('tsNs')
|
||||
: undefined,
|
||||
stringField,
|
||||
logLevelField: fieldCache.getFieldByName('level'),
|
||||
idField: getIdField(fieldCache),
|
||||
} as LogFields;
|
||||
});
|
||||
}
|
||||
|
||||
const commonLabels = allLabels.length > 0 ? findCommonLabels(allLabels) : {};
|
||||
|
||||
@@ -445,6 +451,10 @@ 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