Influxdb: Fix toMetricFindValue function (#90514)

Improved toMetricFindValue to be quicker
This commit is contained in:
Andrew Hackmann 2024-07-17 15:16:07 -07:00 committed by GitHub
parent 88ed77e7e8
commit 41ae376aa4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -30,7 +30,6 @@ import {
BackendDataSourceResponse,
DataSourceWithBackend,
FetchResponse,
frameToMetricFindValue,
getBackendSrv,
getTemplateSrv,
TemplateSrv,
@ -414,13 +413,23 @@ export default class InfluxDatasource extends DataSourceWithBackend<InfluxQuery,
}
toMetricFindValue(rsp: DataQueryResponse): MetricFindValue[] {
const data = rsp.data ?? [];
const valueMap = new Map<string, MetricFindValue>();
// Create MetricFindValue object for all frames
const values = data.map((d) => frameToMetricFindValue(d)).flat();
// Filter out duplicate elements
return values.filter((elm, idx, self) => idx === self.findIndex((t) => t.text === elm.text));
rsp?.data?.forEach((frame: DataFrame) => {
if (frame && frame.length > 0) {
let field = frame.fields.find((f) => f.type === FieldType.string);
if (!field) {
field = frame.fields.find((f) => f.type !== FieldType.time);
}
if (field) {
field.values.forEach((v) => {
valueMap.set(v.toString(), { text: v.toString() });
});
}
}
});
return Array.from(valueMap.values());
}
// By implementing getTagKeys and getTagValues we add ad-hoc filters functionality
// Used in public/app/features/variables/adhoc/picker/AdHocFilterKey.tsx::fetchFilterKeys
getTagKeys(options?: DataSourceGetTagKeysOptions<InfluxQuery>) {