mirror of
https://github.com/grafana/grafana.git
synced 2025-02-10 23:55:47 -06:00
logs: use explicit frame-type-check (#48940)
This commit is contained in:
parent
f256f625d8
commit
683c1c0f40
@ -114,7 +114,11 @@ func adjustLogsFrame(frame *data.Frame, query *lokiQuery) error {
|
||||
}
|
||||
|
||||
frame.Meta.Stats = parseStats(frame.Meta.Custom)
|
||||
frame.Meta.Custom = nil
|
||||
// TODO: when we get a real frame-type in grafana-plugin-sdk-go,
|
||||
// move this to frame.Meta.FrameType
|
||||
frame.Meta.Custom = map[string]string{
|
||||
"frameType": "LabeledTimeValues",
|
||||
}
|
||||
|
||||
frame.Meta.ExecutedQueryString = "Expr: " + query.Expr
|
||||
|
||||
|
File diff suppressed because one or more lines are too long
@ -387,6 +387,9 @@ describe('dataFrameToLogsModel', () => {
|
||||
],
|
||||
meta: {
|
||||
limit: 1000,
|
||||
custom: {
|
||||
frameType: 'LabeledTimeValues',
|
||||
},
|
||||
},
|
||||
}),
|
||||
];
|
||||
@ -464,15 +467,24 @@ describe('dataFrameToLogsModel', () => {
|
||||
values: ['line1'],
|
||||
};
|
||||
|
||||
const meta = {
|
||||
custom: {
|
||||
frameType: 'LabeledTimeValues',
|
||||
},
|
||||
};
|
||||
|
||||
const frame1 = new MutableDataFrame({
|
||||
meta,
|
||||
fields: [labels, time, line],
|
||||
});
|
||||
|
||||
const frame2 = new MutableDataFrame({
|
||||
meta,
|
||||
fields: [time, labels, line],
|
||||
});
|
||||
|
||||
const frame3 = new MutableDataFrame({
|
||||
meta,
|
||||
fields: [time, line, labels],
|
||||
});
|
||||
|
||||
|
@ -316,11 +316,11 @@ function getAllLabels(fields: LogFields): Labels[] {
|
||||
|
||||
const { stringField, labelsField } = fields;
|
||||
|
||||
const fieldLabels = stringField.labels !== undefined ? [stringField.labels] : [];
|
||||
|
||||
const labelsFieldLabels: Labels[] = labelsField !== undefined ? labelsField.values.toArray() : [];
|
||||
|
||||
return [...fieldLabels, ...labelsFieldLabels];
|
||||
if (labelsField !== undefined) {
|
||||
return labelsField.values.toArray();
|
||||
} else {
|
||||
return [stringField.labels ?? {}];
|
||||
}
|
||||
}
|
||||
|
||||
function getLabelsForFrameRow(fields: LogFields, index: number): Labels {
|
||||
@ -329,10 +329,11 @@ function getLabelsForFrameRow(fields: LogFields, index: number): Labels {
|
||||
|
||||
const { stringField, labelsField } = fields;
|
||||
|
||||
return {
|
||||
...stringField.labels,
|
||||
...labelsField?.values.get(index),
|
||||
};
|
||||
if (labelsField !== undefined) {
|
||||
return labelsField.values.get(index);
|
||||
} else {
|
||||
return stringField.labels ?? {};
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -357,7 +358,11 @@ export function logSeriesToLogsModel(logSeries: DataFrame[]): LogsModel | undefi
|
||||
const fieldCache = new FieldCache(series);
|
||||
const stringField = fieldCache.getFirstFieldOfType(FieldType.string);
|
||||
const timeField = fieldCache.getFirstFieldOfType(FieldType.time);
|
||||
const labelsField = fieldCache.getFieldByName('labels');
|
||||
// NOTE: this is experimental, please do not use in your code.
|
||||
// we will get this custom-frame-type into the "real" frame-type list soon,
|
||||
// but the name might change, so please do not use it until then.
|
||||
const labelsField =
|
||||
series.meta?.custom?.frameType === 'LabeledTimeValues' ? fieldCache.getFieldByName('labels') : undefined;
|
||||
|
||||
if (stringField !== undefined && timeField !== undefined) {
|
||||
const info = {
|
||||
|
@ -22,6 +22,9 @@ const inputFrame: DataFrame = {
|
||||
refId: 'A',
|
||||
meta: {
|
||||
executedQueryString: LOKI_EXPR,
|
||||
custom: {
|
||||
frameType: 'LabeledTimeValues',
|
||||
},
|
||||
},
|
||||
fields: [
|
||||
{
|
||||
@ -71,6 +74,7 @@ describe('loki backendResultTransformer', () => {
|
||||
preferredVisualisationType: 'logs',
|
||||
searchWords: ['thing1'],
|
||||
custom: {
|
||||
...expectedFrame.meta?.custom,
|
||||
lokiQueryStatKey: 'Summary: total bytes processed',
|
||||
},
|
||||
};
|
||||
|
@ -10,7 +10,7 @@ function isMetricFrame(frame: DataFrame): boolean {
|
||||
return frame.fields.every((field) => field.type === FieldType.time || field.type === FieldType.number);
|
||||
}
|
||||
|
||||
// returns a new frame, with meta merged with it's original meta
|
||||
// returns a new frame, with meta shallow merged with it's original meta
|
||||
function setFrameMeta(frame: DataFrame, meta: QueryResultMeta): DataFrame {
|
||||
const { meta: oldMeta, ...rest } = frame;
|
||||
// meta maybe be undefined, we need to handle that
|
||||
@ -27,6 +27,7 @@ function processStreamFrame(
|
||||
derivedFieldConfigs: DerivedFieldConfig[]
|
||||
): DataFrame {
|
||||
const custom: Record<string, string> = {
|
||||
...frame.meta?.custom, // keep the original meta.custom
|
||||
// used by logs_model
|
||||
lokiQueryStatKey: 'Summary: total bytes processed',
|
||||
};
|
||||
|
@ -334,6 +334,9 @@ export function lokiStreamsToDataFrames(
|
||||
// Use custom mechanism to identify which stat we want to promote to label
|
||||
const custom = {
|
||||
lokiQueryStatKey: 'Summary: total bytes processed',
|
||||
// TODO: when we get a real frame-type in @grafana/data
|
||||
// move this to frame.meta.type
|
||||
frameType: 'LabeledTimeValues',
|
||||
};
|
||||
|
||||
const meta: QueryResultMeta = {
|
||||
|
Loading…
Reference in New Issue
Block a user