Search in sources :

Example 1 with MeasureResultDetail

use of com.alipay.sofa.rpc.client.aft.MeasureResultDetail in project sofa-rpc by sofastack.

the class ServiceHorizontalMeasureStrategy method measure.

@Override
public MeasureResult measure(MeasureModel measureModel) {
    MeasureResult measureResult = new MeasureResult();
    measureResult.setMeasureModel(measureModel);
    String appName = measureModel.getAppName();
    List<InvocationStat> stats = measureModel.getInvocationStats();
    if (!CommonUtils.isNotEmpty(stats)) {
        return measureResult;
    }
    // 如果有被新剔除的InvocationStat,则不会存在于该次获取结果中。
    List<InvocationStat> invocationStats = getInvocationStatSnapshots(stats);
    long timeWindow = FaultToleranceConfigManager.getTimeWindow(appName);
    /* leastWindowCount在同一次度量中保持不变*/
    long leastWindowCount = FaultToleranceConfigManager.getLeastWindowCount(appName);
    leastWindowCount = leastWindowCount < LEGAL_LEAST_WINDOW_COUNT ? LEGAL_LEAST_WINDOW_COUNT : leastWindowCount;
    /* 计算平均异常率和度量单个ip的时候都需要使用到appWeight*/
    double averageExceptionRate = calculateAverageExceptionRate(invocationStats, leastWindowCount);
    double leastWindowExceptionRateMultiple = FaultToleranceConfigManager.getLeastWindowExceptionRateMultiple(appName);
    for (InvocationStat invocationStat : invocationStats) {
        MeasureResultDetail measureResultDetail = null;
        InvocationStatDimension statDimension = invocationStat.getDimension();
        long windowCount = invocationStat.getInvokeCount();
        long invocationLeastWindowCount = getInvocationLeastWindowCount(invocationStat, ProviderInfoWeightManager.getWeight(statDimension.getProviderInfo()), leastWindowCount);
        if (averageExceptionRate == -1) {
            measureResultDetail = new MeasureResultDetail(statDimension, MeasureState.IGNORE);
        } else {
            if (invocationLeastWindowCount != -1 && windowCount >= invocationLeastWindowCount) {
                double windowExceptionRate = invocationStat.getExceptionRate();
                if (averageExceptionRate == 0) {
                    measureResultDetail = new MeasureResultDetail(statDimension, MeasureState.HEALTH);
                } else {
                    double windowExceptionRateMultiple = CalculateUtils.divide(windowExceptionRate, averageExceptionRate);
                    measureResultDetail = windowExceptionRateMultiple >= leastWindowExceptionRateMultiple ? new MeasureResultDetail(statDimension, MeasureState.ABNORMAL) : new MeasureResultDetail(statDimension, MeasureState.HEALTH);
                }
                measureResultDetail.setAbnormalRate(windowExceptionRate);
                measureResultDetail.setAverageAbnormalRate(averageExceptionRate);
                measureResultDetail.setLeastAbnormalRateMultiple(leastWindowExceptionRateMultiple);
            } else {
                measureResultDetail = new MeasureResultDetail(statDimension, MeasureState.IGNORE);
            }
        }
        measureResultDetail.setWindowCount(windowCount);
        measureResultDetail.setTimeWindow(timeWindow);
        measureResultDetail.setLeastWindowCount(invocationLeastWindowCount);
        measureResult.addMeasureDetail(measureResultDetail);
    }
    logMeasureResult(measureResult, timeWindow, leastWindowCount, averageExceptionRate, leastWindowExceptionRateMultiple);
    InvocationStatFactory.updateInvocationStats(invocationStats);
    return measureResult;
}
Also used : MeasureResult(com.alipay.sofa.rpc.client.aft.MeasureResult) InvocationStat(com.alipay.sofa.rpc.client.aft.InvocationStat) InvocationStatDimension(com.alipay.sofa.rpc.client.aft.InvocationStatDimension) MeasureResultDetail(com.alipay.sofa.rpc.client.aft.MeasureResultDetail)

Example 2 with MeasureResultDetail

use of com.alipay.sofa.rpc.client.aft.MeasureResultDetail in project sofa-rpc by sofastack.

the class ServiceHorizontalMeasureStrategy method logMeasureResult.

/**
 * Print the measurement result details for each time window.
 * @param measureResult
 * @param timeWindow
 * @param leastWindowCount
 * @param averageExceptionRate
 * @param leastWindowExceptionRateMultiple
 */
private void logMeasureResult(MeasureResult measureResult, long timeWindow, long leastWindowCount, double averageExceptionRate, double leastWindowExceptionRateMultiple) {
    if (measureResult == null) {
        return;
    }
    MeasureModel measureModel = measureResult.getMeasureModel();
    String appName = measureModel.getAppName();
    if (!LOGGER.isDebugEnabled(appName)) {
        return;
    }
    String service = measureModel.getService();
    List<InvocationStat> stats = measureModel.getInvocationStats();
    List<MeasureResultDetail> details = measureResult.getAllMeasureResultDetails();
    StringBuilder info = new StringBuilder();
    info.append("measure info: service[" + service + "];stats{");
    for (InvocationStat stat : stats) {
        info.append(stat.getDimension().getIp());
        info.append(",");
    }
    if (stats.size() > 0) {
        info.deleteCharAt(info.length() - 1);
    }
    info.append("};details{");
    info.append("timeWindow[" + timeWindow + "];leastWindowCount[" + leastWindowCount + "];averageExceptionRate[" + averageExceptionRate + "];leastWindowExceptionRateMultiple[" + leastWindowExceptionRateMultiple + "];");
    info.append("detail[");
    for (MeasureResultDetail detail : details) {
        String ip = detail.getInvocationStatDimension().getIp();
        double abnormalRate = detail.getAbnormalRate();
        long invocationLeastWindowCount = detail.getLeastWindowCount();
        String measureState = detail.getMeasureState().name();
        info.append("(ip:" + ip + ",abnormalRate:" + abnormalRate + ",invocationLeastWindowCount:" + invocationLeastWindowCount + ",measureState:" + measureState + ")");
    }
    info.append("]");
    LOGGER.debugWithApp(appName, info.toString());
}
Also used : InvocationStat(com.alipay.sofa.rpc.client.aft.InvocationStat) MeasureResultDetail(com.alipay.sofa.rpc.client.aft.MeasureResultDetail) MeasureModel(com.alipay.sofa.rpc.client.aft.MeasureModel)

Aggregations

InvocationStat (com.alipay.sofa.rpc.client.aft.InvocationStat)2 MeasureResultDetail (com.alipay.sofa.rpc.client.aft.MeasureResultDetail)2 InvocationStatDimension (com.alipay.sofa.rpc.client.aft.InvocationStatDimension)1 MeasureModel (com.alipay.sofa.rpc.client.aft.MeasureModel)1 MeasureResult (com.alipay.sofa.rpc.client.aft.MeasureResult)1