All files / src/utils/playbook/options datadogService.ts

0% Statements 0/22
0% Branches 0/5
0% Functions 0/8
0% Lines 0/21

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61                                                                                                                         
import { Task } from "../../../types/index.ts";
import { getCurrentAsset } from "../getCurrentAsset.ts";
import { Key, KeyType } from "../key.ts";
import { getTaskData } from "../task/getTaskData.ts";
 
export const datadogService = (key: KeyType, task: Task): any[] => {
  const assets = task.ui_requirement.assets;
  const options = assets?.map((asset: any) => {
    const metricFamilies = asset.metrics?.map(
      (metric: any) => metric.metric_family,
    );
    const uniqueFamilies = [...new Set(metricFamilies)];
    return {
      name: asset.service_name,
      id: asset.service_name,
      label: asset.service_name,
      metric_families: uniqueFamilies,
    };
  });
  switch (key) {
    case Key.SERVICE_NAME:
      return options;
    case Key.METRIC_FAMILY:
      return options
        ?.find((e: any) => e.name === getTaskData(task)?.[Key.SERVICE_NAME])
        ?.metric_families?.map((x: any) => ({ id: x, label: x }));
    case Key.ENVIRONMENT_NAME:
      return getCurrentAsset(
        task,
        Key.SERVICE_NAME,
        "service_name",
        undefined,
        "environments",
      ).map((e: any) => {
        return {
          id: e,
          label: e,
        };
      });
    case Key.METRIC:
      return getCurrentAsset(
        task,
        Key.SERVICE_NAME,
        "service_name",
        undefined,
        "metrics",
      )
        .filter(
          (e) => e.metric_family === getTaskData(task)?.[Key.METRIC_FAMILY],
        )
        ?.map((e) => {
          return {
            id: e.metric,
            label: e.metric,
          };
        });
    default:
      return [];
  }
};