export function getDashboardFilterFromLabelKey()

in scripts/dashboard-importer/src/dashboards/converter/template_variables/label_values.ts [69:106]


export function getDashboardFilterFromLabelKey(
  queryString: string,
  templateVariable: TemplateVariable,
): Result<DashboardFilter> {
  const labelKeyResult = getLabelKey(queryString);
  let labelKey = labelKeyResult.result;
  if (labelKey === 'kubernetes_io_hostname') {
    labelKey = 'node';
  }
  if (labelKey === null) {
    return warning(labelKeyResult.warnings);
  }

  const stringValue = typeof templateVariable.current?.value === 'string' ?
      templateVariable.current?.value :
      '';

  const dashboardFilter: DashboardFilter = {
    labelKey,
    templateVariable: templateVariable.name,
    stringValue,
    filterType: RESOURCE_LABELS.includes(labelKey)
      ? 'RESOURCE_LABEL'
      : 'METRIC_LABEL',
  };

  // Some Grafana TVs have select all value option
  // We instead have a * value that is implicitly added.
  if (dashboardFilter.stringValue === '$__all') {
    dashboardFilter.stringValue = '';
  }

  return success(
    dashboardFilter,
    [...labelKeyResult.warnings],
    [...labelKeyResult.errors],
  );
}