populateSettingValuesFromConfigMap

in build/common/installer/scripts/tomlparser-mdm-metrics-config.rb [44:132]


def populateSettingValuesFromConfigMap(parsedConfig)
  if !parsedConfig.nil? && !parsedConfig[:alertable_metrics_configuration_settings].nil?
    
    begin
      resourceUtilization = parsedConfig[:alertable_metrics_configuration_settings][:container_resource_utilization_thresholds]
      if !resourceUtilization.nil?
        
        cpuThreshold = resourceUtilization[:container_cpu_threshold_percentage]
        cpuThresholdFloat = cpuThreshold.to_f
        if cpuThresholdFloat.kind_of? Float
          @percentageCpuUsageThreshold = cpuThresholdFloat
        else
          puts "config::Non floating point value or value not convertible to float specified for Cpu threshold, using default "
          @percentageCpuUsageThreshold = Constants::DEFAULT_MDM_CPU_UTILIZATION_THRESHOLD
        end
        
        memoryRssThreshold = resourceUtilization[:container_memory_rss_threshold_percentage]
        memoryRssThresholdFloat = memoryRssThreshold.to_f
        if memoryRssThresholdFloat.kind_of? Float
          @percentageMemoryRssThreshold = memoryRssThresholdFloat
        else
          puts "config::Non floating point value or value not convertible to float specified for Memory Rss threshold, using default "
          @percentageMemoryRssThreshold = Constants::DEFAULT_MDM_MEMORY_RSS_THRESHOLD
        end
        
        memoryWorkingSetThreshold = resourceUtilization[:container_memory_working_set_threshold_percentage]
        memoryWorkingSetThresholdFloat = memoryWorkingSetThreshold.to_f
        if memoryWorkingSetThresholdFloat.kind_of? Float
          @percentageMemoryWorkingSetThreshold = memoryWorkingSetThresholdFloat
        else
          puts "config::Non floating point value or value not convertible to float specified for Memory Working Set threshold, using default "
          @percentageMemoryWorkingSetThreshold = Constants::DEFAULT_MDM_MEMORY_WORKING_SET_THRESHOLD
        end
        puts "config::Using config map settings for MDM metric configuration settings for container resource utilization"
      end
    rescue => errorStr
      ConfigParseErrorLogger.logError("Exception while reading config map settings for MDM metric configuration settings for resource utilization - #{errorStr}, using defaults, please check config map for errors")
      @percentageCpuUsageThreshold = Constants::DEFAULT_MDM_CPU_UTILIZATION_THRESHOLD
      @percentageMemoryRssThreshold = Constants::DEFAULT_MDM_MEMORY_RSS_THRESHOLD
      @percentageMemoryWorkingSetThreshold = Constants::DEFAULT_MDM_MEMORY_WORKING_SET_THRESHOLD
    end

    
    begin
      isUsingPVThresholdConfig = false
      pvUtilizationThresholds = parsedConfig[:alertable_metrics_configuration_settings][:pv_utilization_thresholds]
      if !pvUtilizationThresholds.nil?
        pvUsageThreshold = pvUtilizationThresholds[:pv_usage_threshold_percentage]
        if !pvUsageThreshold.nil?
          pvUsageThresholdFloat = pvUsageThreshold.to_f
          if pvUsageThresholdFloat.kind_of? Float
            @percentagePVUsageThreshold = pvUsageThresholdFloat
            isUsingPVThresholdConfig = true
          end
        end
      end

      if isUsingPVThresholdConfig
        puts "config::Using config map settings for MDM metric configuration settings for PV utilization"
      else
        puts "config::Non floating point value or value not convertible to float specified for PV threshold, using default "
        @percentagePVUsageThreshold = Constants::DEFAULT_MDM_PV_UTILIZATION_THRESHOLD
      end
    rescue => errorStr
      ConfigParseErrorLogger.logError("Exception while reading config map settings for MDM metric configuration settings for PV utilization - #{errorStr}, using defaults, please check config map for errors")
      @percentagePVUsageThreshold = Constants::DEFAULT_MDM_PV_UTILIZATION_THRESHOLD
    end

    
    begin
      jobCompletion = parsedConfig[:alertable_metrics_configuration_settings][:job_completion_threshold]
      if !jobCompletion.nil?
        jobCompletionThreshold = jobCompletion[:job_completion_threshold_time_minutes]
        jobCompletionThresholdInt = jobCompletionThreshold.to_i
        if jobCompletionThresholdInt.kind_of? Integer
          @jobCompletionThresholdMinutes = jobCompletionThresholdInt
        else
          puts "config::Non interger value or value not convertible to integer specified for job completion threshold, using default "
          @jobCompletionThresholdMinutes = Constants::DEFAULT_MDM_JOB_COMPLETED_TIME_THRESHOLD_MINUTES
        end
        puts "config::Using config map settings for MDM metric configuration settings for job completion"
      end
    rescue => errorStr
      ConfigParseErrorLogger.logError("Exception while reading config map settings for MDM metric configuration settings for job completion - #{errorStr}, using defaults, please check config map for errors")
      @jobCompletionThresholdMinutes = Constants::DEFAULT_MDM_JOB_COMPLETED_TIME_THRESHOLD_MINUTES
    end
  end
end