|
|
|
@ -1,4 +1,4 @@ |
|
|
|
|
import { nanoid } from '@reduxjs/toolkit'; |
|
|
|
|
import { customAlphabet } from 'nanoid'; |
|
|
|
|
import { Unsubscribable } from 'rxjs'; |
|
|
|
|
import { v4 as uuidv4 } from 'uuid'; |
|
|
|
|
|
|
|
|
@ -34,6 +34,9 @@ export const DEFAULT_UI_STATE = { |
|
|
|
|
dedupStrategy: LogsDedupStrategy.none, |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
export const ID_ALPHABET = '0123456789abcdefghijklmnopqrstuvwxyz'; |
|
|
|
|
const nanoid = customAlphabet(ID_ALPHABET, 3); |
|
|
|
|
|
|
|
|
|
const MAX_HISTORY_ITEMS = 100; |
|
|
|
|
|
|
|
|
|
const LAST_USED_DATASOURCE_KEY = 'grafana.explore.datasource'; |
|
|
|
@ -52,7 +55,13 @@ export interface GetExploreUrlArguments { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export function generateExploreId() { |
|
|
|
|
return nanoid(3); |
|
|
|
|
while (true) { |
|
|
|
|
const id = nanoid(3); |
|
|
|
|
|
|
|
|
|
if (!/^\d+$/.test(id)) { |
|
|
|
|
return id; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -101,19 +110,9 @@ export function buildQueryTransaction( |
|
|
|
|
timeZone?: TimeZone, |
|
|
|
|
scopedVars?: ScopedVars |
|
|
|
|
): QueryTransaction { |
|
|
|
|
const key = queries.reduce((combinedKey, query) => { |
|
|
|
|
combinedKey += query.key; |
|
|
|
|
return combinedKey; |
|
|
|
|
}, ''); |
|
|
|
|
|
|
|
|
|
const panelId = Number.parseInt(exploreId, 36); |
|
|
|
|
const { interval, intervalMs } = getIntervals(range, queryOptions.minInterval, queryOptions.maxDataPoints); |
|
|
|
|
|
|
|
|
|
// Most datasource is using `panelId + query.refId` for cancellation logic.
|
|
|
|
|
// Using `format` here because it relates to the view panel that the request is for.
|
|
|
|
|
// However, some datasources don't use `panelId + query.refId`, but only `panelId`.
|
|
|
|
|
// Therefore panel id has to be unique.
|
|
|
|
|
const panelId = `${key}`; |
|
|
|
|
|
|
|
|
|
const request: DataQueryRequest = { |
|
|
|
|
app: CoreApp.Explore, |
|
|
|
|
// TODO probably should be taken from preferences but does not seem to be used anyway.
|
|
|
|
@ -121,9 +120,7 @@ export function buildQueryTransaction( |
|
|
|
|
startTime: Date.now(), |
|
|
|
|
interval, |
|
|
|
|
intervalMs, |
|
|
|
|
// TODO: the query request expects number and we are using string here. Seems like it works so far but can create
|
|
|
|
|
// issues down the road.
|
|
|
|
|
panelId: panelId as any, |
|
|
|
|
panelId, |
|
|
|
|
targets: queries, // Datasources rely on DataQueries being passed under the targets key.
|
|
|
|
|
range, |
|
|
|
|
requestId: 'explore_' + exploreId, |
|
|
|
|