Skip to content

Commit

Permalink
Use grafana- 9.5 compatible ArrayVector for field.values
Browse files Browse the repository at this point in the history
  • Loading branch information
ddelemeny committed Feb 22, 2024
1 parent bd0169b commit c5d7665
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/datasource/processResponse.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DataFrame, DataLink, DataQueryRequest, DataQueryResponse, Field, FieldType } from "@grafana/data";
import { DataFrame, DataLink, DataQueryRequest, DataQueryResponse, Field, FieldType, ArrayVector } from "@grafana/data";
import { getDataSourceSrv } from "@grafana/runtime";
import { QuickwitDataSource } from 'datasource';
import { DataLinkConfig, ElasticsearchQuery } from "../types";
Expand Down Expand Up @@ -35,15 +35,19 @@ export function processLogsDataFrame(datasource: QuickwitDataSource, dataFrame:
field_idx_list.push(field_idx);
}
}

// XXX : Compatibility - prior to grafana-10.0.0, Field.values only supports Vector interface
const getFieldValue = (field: typeof dataFrame.fields[0], idx: number) => ( field.values.get(idx) )

const displayedMessages = Array(dataFrame.length);
for (let idx = 0; idx < dataFrame.length; idx++) {
let displayedMessage = "";
// If we have only one field, we assume the field name is obvious for the user and we don't need to show it.
if (field_idx_list.length === 1) {
displayedMessage = `${dataFrame.fields[field_idx_list[0]].values[idx]}`;
displayedMessage = `${getFieldValue(dataFrame.fields[field_idx_list[0]], idx)}`;
} else {
for (const field_idx of field_idx_list) {
displayedMessage += ` ${dataFrame.fields[field_idx].name}=${dataFrame.fields[field_idx].values[idx]}`;
displayedMessage += ` ${dataFrame.fields[field_idx].name}=${getFieldValue(dataFrame.fields[field_idx], idx)}`;
}
}
displayedMessages[idx] = displayedMessage.trim();
Expand All @@ -53,7 +57,8 @@ export function processLogsDataFrame(datasource: QuickwitDataSource, dataFrame:
name: getCustomFieldName('message'),
type: FieldType.string,
config: {},
values: displayedMessages,
// XXX : Compatibility - prior to grafana-10.0.0, Field.values only supports Vector interface
values: new ArrayVector(displayedMessages),
};
const [timestamp, ...rest] = dataFrame.fields;
dataFrame.fields = [timestamp, newField, ...rest];
Expand Down

0 comments on commit c5d7665

Please sign in to comment.