All files / modules/75-ce/components/CloudCostInsightChart ChartConfigs.tsx

100% Statements 22/22
100% Branches 6/6
100% Functions 3/3
100% Lines 22/22

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 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149              7x 7x 7x 7x   7x 7x 7x     7x 7x 7x 7x     7x   7x 7x 7x 7x 7x 7x 7x     7x                       7x                                                                                                                                           7x                                                                
/*
 * Copyright 2021 Harness Inc. All rights reserved.
 * Use of this source code is governed by the PolyForm Shield 1.0.0 license
 * that can be found in the licenses directory at the root of this repository, also available at
 * https://polyformproject.org/wp-content/uploads/2020/06/PolyForm-Shield-1.0.0.txt.
 */
 
export const BLUE_500 = '#22A5F7'
export const ORANGE = '#F35E13'
export const PURPLE = '#A82CCA'
export const LIGHT_GREEN = '#36D0AF'
 
export enum ResourceType {
  CPU = 'CPU',
  MEMORY = 'MEMORY'
}
 
enum ResourceChartLabels {
  USED = 'Used',
  LIMIT = 'Limit',
  REQUESTED = 'Requested'
}
 
export const POD_COUNT_CHART_NAME = 'Pods'
 
enum ResourceChartTypeEnums {
  CPU_USED = 'CPU_USED',
  CPU_LIMIT = 'CPU_LIMIT',
  CPU_REQUESTED = 'CPU_REQUESTED',
  MEMORY_USED = 'MEMORY_USED',
  MEMORY_LIMIT = 'MEMORY_LIMIT',
  MEMORY_REQUESTED = 'MEMORY_REQUESTED'
}
 
export const podCountConfig = {
  name: POD_COUNT_CHART_NAME,
  color: BLUE_500,
  showInLegend: true
}
 
type ChartConfigType = {
  name: string
  color: string
  showInLegend: boolean
}
 
export const chartOptionsMapping: Record<string, Record<string, ChartConfigType>> = {
  [ResourceChartTypeEnums.CPU_USED]: {
    MAX: {
      name: ResourceChartLabels.USED,
      color: LIGHT_GREEN,
      showInLegend: true
    },
    AVG: {
      name: ResourceChartLabels.USED,
      color: LIGHT_GREEN,
      showInLegend: true
    }
  },
 
  [ResourceChartTypeEnums.CPU_LIMIT]: {
    LIMIT: {
      name: ResourceChartLabels.LIMIT,
      color: PURPLE,
      showInLegend: true
    }
  },
 
  [ResourceChartTypeEnums.CPU_REQUESTED]: {
    REQUEST: {
      name: ResourceChartLabels.REQUESTED,
      color: ORANGE,
      showInLegend: true
    },
    DEFAULT: {
      name: ResourceChartLabels.REQUESTED,
      color: ORANGE,
      showInLegend: true
    }
  },
 
  [ResourceChartTypeEnums.MEMORY_USED]: {
    MAX: {
      name: ResourceChartLabels.USED,
      color: LIGHT_GREEN,
      showInLegend: true
    },
    AVG: {
      name: ResourceChartLabels.USED,
      color: LIGHT_GREEN,
      showInLegend: true
    }
  },
 
  [ResourceChartTypeEnums.MEMORY_LIMIT]: {
    LIMIT: {
      name: ResourceChartLabels.LIMIT,
      color: PURPLE,
      showInLegend: true
    }
  },
 
  [ResourceChartTypeEnums.MEMORY_REQUESTED]: {
    REQUEST: {
      name: ResourceChartLabels.REQUESTED,
      color: ORANGE,
      showInLegend: true
    },
    DEFAULT: {
      name: ResourceChartLabels.REQUESTED,
      color: ORANGE,
      showInLegend: true
    }
  }
}
 
export const chartConfigMapping: Record<
  string,
  {
    chartType: string
    resource: string
  }
> = {
  cpuUtilValues: {
    chartType: ResourceChartTypeEnums.CPU_USED,
    resource: ResourceType.CPU
  },
  cpuLimit: {
    chartType: ResourceChartTypeEnums.CPU_LIMIT,
    resource: ResourceType.CPU
  },
  cpuRequest: {
    chartType: ResourceChartTypeEnums.CPU_REQUESTED,
    resource: ResourceType.CPU
  },
  memoryUtilValues: {
    chartType: ResourceChartTypeEnums.MEMORY_USED,
    resource: ResourceType.MEMORY
  },
  memoryLimit: {
    chartType: ResourceChartTypeEnums.MEMORY_LIMIT,
    resource: ResourceType.MEMORY
  },
  memoryRequest: {
    chartType: ResourceChartTypeEnums.MEMORY_REQUESTED,
    resource: ResourceType.MEMORY
  }
}