Пример #1
0
 def test_convertPromesResponseToMetricInfos_baseline(self):
     isProphet = False
     period = METRIC_PERIOD.BASELINE.value
     djson = getBaselinejson()
     metricInfolist = convertPromesResponseToMetricInfos(
         djson, period, isProphet)
     self.assertEqual(len(metricInfolist) > 0, True)
Пример #2
0
def queryData(metricUrl, period, isProphet=False, datasource='prometheus'):
    djson = {}
    for i in range(RETRY_COUNT):
        try:
            if datasource == 'prometheus':
                respStr = dorequest(metricUrl)
                djson = json.loads(respStr)
            elif datasource == 'wavefront':
                datalist = metricUrl.split("&&")
                if len(datalist) < 4:
                    logger.error("missing wavefront query parameters : " +
                                 metricUrl)
                    return []
                qresult = executeQuery(datalist[0], datalist[1], datalist[2],
                                       datalist[3])
                return convertResponseToMetricInfos(qresult, period, isProphet)
            break
        except Exception as e:
            logger.error(e.__cause__)
            if i == 2:
                logger.warning("Failed to query  metricUrl: " + metricUrl)
                return []
    ###### TODO remove
    '''
        if period ==  METRIC_PERIOD.HISTORICAL.value :
           djson= getHistoricaljson()
        elif period ==  METRIC_PERIOD.CURRENT.value :
           djson= getCurrentjson()  
        else:
           djson= getBaselinejson()
        '''
    if datasource == 'prometheus':
        return convertPromesResponseToMetricInfos(djson, period, isProphet)
    return None
Пример #3
0
 def test_convertPromesResponseToMetricInfos_current(self):
     isProphet = False
     period = METRIC_PERIOD.CURRENT.value
     djson = getCurrentjson()
     metricInfolist = convertPromesResponseToMetricInfos(
         djson, period, isProphet)
     self.assertEqual(len(metricInfolist) > 0, True)
Пример #4
0
 def test_convertPromesResponseToMetricInfos_historical(self):
     isProphet = False
     period = METRIC_PERIOD.HISTORICAL.value
     djson = getHistoricaljson()
     metricInfolist = convertPromesResponseToMetricInfos(
         djson, period, isProphet)
     self.assertEqual(len(metricInfolist) > 0, True)
Пример #5
0
 def testTwoDFMinus(self):
     json1 = getPrometheusResult(False)
     json2 = getPrometheusResult(True)
     metricPeroid1 = METRIC_PERIOD.HISTORICAL.value
     result = convertPromesResponseToMetricInfos(json1, metricPeroid1,
                                                 False, json2)
     self.assertIsNotNone(result)
Пример #6
0
def queryData(metricUrl, period, isProphet = False, datasource='PROMETHEUS'):
        djson = {}
        
        for i in range(RETRY_COUNT):
            try:
                respStr  = dorequest(metricUrl)
                djson = json.loads(respStr)
                break
            except Exception as e:
                logger.error(e.__cause__)
                if i==2:
                    logger.warning("Failed to query  metricUrl: " +metricUrl)
                    return []
        ###### TODO remove 
        '''
        if period ==  METRIC_PERIOD.HISTORICAL.value :
           djson= getHistoricaljson()
        elif period ==  METRIC_PERIOD.CURRENT.value :
           djson= getCurrentjson()  
        else:
           djson= getBaselinejson()
        '''   
        return convertPromesResponseToMetricInfos(djson, period, isProphet ) 
def queryData(metricUrl, period, isProphet=False, datasource='prometheus'):
    djson = {}
    ajson = None
    modeDropAnomaly = config.getValueByKey('MODE_DROP_ANOMALY')
    for i in range(RETRY_COUNT):
        try:
            if datasource == 'prometheus':
                if (period != METRIC_PERIOD.HISTORICAL.value):
                    metricUrl = urlEndNow(metricUrl)
                respStr = dorequest(metricUrl)
                djson = json.loads(respStr)
                if period == METRIC_PERIOD.HISTORICAL.value and (
                        modeDropAnomaly is not None
                        and modeDropAnomaly == 'y'):
                    try:
                        modelUrl = getModelUrl(metricUrl, datasource)
                        respStr = dorequest(modelUrl)
                        ajson = json.loads(respStr)
                    except Exception as e1:
                        logger.error(e1.__cause__)

            elif datasource == 'wavefront':
                writeMetricToWaveFront = config.getValueByKey(
                    'METRIC_DESTINATION') == 'wavefront'
                datalist = metricUrl.split("&&")
                if len(datalist) < 4:
                    logger.error("missing wavefront query parameters : " +
                                 metricUrl)
                    return []
                qresult = executeQuery(datalist[0], datalist[1], datalist[2],
                                       datalist[3])
                if period == METRIC_PERIOD.HISTORICAL.value and (
                        modeDropAnomaly is not None
                        and modeDropAnomaly == 'y'):
                    #amonaly result
                    try:
                        aresult = executeQuery(
                            getModelUrl(dequote(datalist[0]), datasource),
                            datalist[1], datalist[2], datalist[3])
                        return convertResponseToMetricInfos(
                            qresult,
                            period,
                            isProphet,
                            aresult,
                            isDestWaveFront=writeMetricToWaveFront)
                    except Exception as e1:
                        logger.error(e1.__cause__)
                return convertResponseToMetricInfos(
                    qresult,
                    period,
                    isProphet,
                    isDestWaveFront=writeMetricToWaveFront)
            break
        except Exception as e:
            logger.error(e.__cause__)
            if i == 2:
                logger.warning("Failed to query  metricUrl: " + metricUrl)
                return []
    ###### TODO remove
    '''
        if period ==  METRIC_PERIOD.HISTORICAL.value :
           djson= getHistoricaljson()
        elif period ==  METRIC_PERIOD.CURRENT.value :
           djson= getCurrentjson()
        else:
           djson= getBaselinejson()
        '''
    if datasource == 'prometheus':
        return convertPromesResponseToMetricInfos(djson, period, isProphet,
                                                  ajson)
    return []