MCPcopy
hub / github.com/deepops-ai/deepops / queryVariableValues

Function queryVariableValues

ui/src/views/variables/SelectVariable.tsx:339–383  ·  view source on GitHub ↗
(v: Variable, datasources: Datasource[])

Source from the content-addressed store, hash-verified

337}
338
339export const queryVariableValues = async (v: Variable, datasources: Datasource[]) => {
340 let result = {
341 error: null,
342 data: null
343 }
344
345 if (v.type == VariableQueryType.Custom) {
346 if (v.value.trim() != "") {
347 result.data = v.value.split(",")
348 }
349 } else if (v.type == VariableQueryType.Datasource) {
350 result.data = datasources.map(ds => ds.name)
351 } else if (v.type == VariableQueryType.Query) {
352 const ds = getDatasource(v.datasource, datasources)
353 //@needs-update-when-add-new-variable-datasource
354 switch (ds?.type) {
355 case DatasourceType.Prometheus:
356 result = await queryPromethuesVariableValues(v)
357 break;
358 case DatasourceType.ExternalHttp:
359 result = await queryHttpVariableValues(v) as any
360 break;
361 case DatasourceType.Jaeger:
362 result = await queryJaegerVariableValues(v)
363 break
364 case DatasourceType.Loki:
365 result = await queryLokiVariableValues(v)
366 break
367 default:
368 break;
369 }
370 }
371
372 if (result.error) {
373 return result
374 }
375
376
377 if (!isEmpty(v.regex)) {
378 const regex = v.regex.toLowerCase()
379 result.data = result?.data?.filter((r: string) => r.toLowerCase().match(regex))
380 }
381
382 return result
383}
384
385const autoSetSelected = (v: Variable, result: string[]) => {
386 // if (!isEmpty(v.default)) {

Callers 2

queryValuesFunction · 0.90
loadValuesFunction · 0.85

Calls 6

getDatasourceFunction · 0.90
queryHttpVariableValuesFunction · 0.90
queryLokiVariableValuesFunction · 0.90
isEmptyFunction · 0.90

Tested by

no test coverage detected