The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
grafana/public/app/features/explore/utils/queries.ts

32 lines
715 B

import { DataQuery } from '@grafana/schema';
import { getNextRefIdChar } from 'app/core/utils/query';
/**
* Makes sure all the queries have unique (and valid) refIds
*/
export function withUniqueRefIds(queries: DataQuery[]): DataQuery[] {
const refIds = new Set<string>(queries.map((query) => query.refId).filter(Boolean));
if (refIds.size === queries.length) {
return queries;
}
refIds.clear();
return queries.map((query) => {
if (query.refId && !refIds.has(query.refId)) {
refIds.add(query.refId);
return query;
}
const refId = getNextRefIdChar(queries);
refIds.add(refId);
const newQuery = {
...query,
refId,
};
return newQuery;
});
}