Submit
Path:
~
/
/
usr
/
share
/
grafana
/
public
/
app
/
plugins
/
datasource
/
loki
/
__mocks__
/
File Content:
metadataRequest.ts
export function createMetadataRequest( labelsAndValues: Record<string, string[]>, series?: Record<string, Array<Record<string, string>>> ) { // added % to allow urlencoded labelKeys. Note, that this is not confirm with Loki, as loki does not allow specialcharacters in labelKeys, but needed for tests. const lokiLabelsAndValuesEndpointRegex = /^label\/([%\w]*)\/values/; const lokiSeriesEndpointRegex = /^series/; const lokiLabelsEndpoint = 'labels'; const labels = Object.keys(labelsAndValues); return async function metadataRequestMock(url: string, params?: Record<string, string | number>) { if (url === lokiLabelsEndpoint) { return labels; } else { const labelsMatch = url.match(lokiLabelsAndValuesEndpointRegex); const seriesMatch = url.match(lokiSeriesEndpointRegex); if (labelsMatch) { return labelsAndValues[labelsMatch[1]] || []; } else if (seriesMatch && series && params) { return series[params['match[]']] || []; } else { throw new Error(`Unexpected url error, ${url}`); } } }; }
Submit
FILE
FOLDER
INFO
Name
Size
Permission
Action
datasource.ts
1401 bytes
0644
frames.ts
4219 bytes
0644
metadataRequest.ts
1089 bytes
0644
N4ST4R_ID | Naxtarrr