コード例 #1
0
def computeHistoricalModel(historicalConfigMap,
                           modelHolder,
                           isProphet=False,
                           historicalMetricStores=None,
                           strategy=None):
    dataSet = {}
    msg = ''
    min_data_points = modelHolder.getModelConfigByKey(MIN_DATA_POINTS)

    #TODO Need to pass during by default could be 30 minutes.
    if strategy == 'hpa':
        modeldata = es.get_model_data(modelHolder.id)
        if modeldata is not None:
            modelHolder.storeModels(modeldata)
            modelParameters = es.get_model_parameters(modelHolder.id)
            modelHolder.storeModelParameters(modelParameters)
            return modelHolder, msg

    for metricType, metricUrl in historicalConfigMap.items():
        metricStore = 'prometheus'
        if historicalMetricStores is not None:
            metricStore = historicalMetricStores[metricType]
        metricInfolist = queryData(metricUrl, METRIC_PERIOD.HISTORICAL.value,
                                   isProphet, metricStore)
        if (len(metricInfolist) == 0):
            continue
        filteredMetricInfoList, str = filterEmptyDF(metricInfolist,
                                                    min_data_points)
        if (str != ''):
            msg = str
        if len(filteredMetricInfoList) == 0:
            continue
        #TODO: can be further optimize
        dataSet.setdefault(metricType, metricInfolist)
    #
    metricTypeCount = len(dataSet)
    if metricTypeCount == 0:
        return modelHolder, msg
    metricTypes, metricInfos = retrieveKVList(dataSet)

    if strategy == 'hpa':
        modelHolder = calculateHPAModels(metricInfos, modelHolder, metricTypes)
        return modelHolder, msg
    for i in range(metricTypeCount):
        modelHolder = calculateModel(metricInfos[i][0], modelHolder,
                                     metricTypes[i], strategy)
    '''
    ##TODO rollback
    if metricTypeCount == 1 :
        metricTypes, metricInfos = retrieveKVList(dataSet)
        #modelHolder  for historical metric there wil be only one
        #TODO pzou
        return calculateModel(metricInfos[0][0], modelHolder), msg
    elif metricTypeCount == 2 :
        pass
    else:
        pass
    '''
    return modelHolder, msg
コード例 #2
0
def computeHistoricalModel(historicalConfigMap, modelHolder, isProphet = False, datasource='PROMETHEUS' ):
    dataSet = {}
    msg = ''
    min_data_points = modelHolder.getModelConfigByKey(MIN_DATA_POINTS)
    for metricType, metricUrl in historicalConfigMap.items(): 
        metricInfolist = queryData(metricUrl, METRIC_PERIOD.HISTORICAL.value, isProphet);
        if(len(metricInfolist)==0):
            continue
        filteredMetricInfoList, str =  filterEmptyDF(metricInfolist, min_data_points)
        if (str!=''):
            msg = str
        if len(filteredMetricInfoList) == 0:
            continue
        #TODO: can be further optimize
        dataSet.setdefault(metricType, metricInfolist)
    #       
    metricTypeCount = len(dataSet)
    if metricTypeCount == 0 :
        return modelHolder, msg

    metricTypes, metricInfos = retrieveKVList(dataSet)
    
    for i in range (metricTypeCount):
      modelHolder = calculateModel(metricInfos[i][0], modelHolder, metricTypes[i])


    '''
    ##TODO rollback
    if metricTypeCount == 1 :
        metricTypes, metricInfos = retrieveKVList(dataSet)
        #modelHolder  for historical metric there wil be only one
        #TODO pzou
        return calculateModel(metricInfos[0][0], modelHolder), msg    
    elif metricTypeCount == 2 :
        pass
    else:
        pass
    '''
    return modelHolder,msg