Search in sources :

Example 6 with StatInfo

use of com.tencent.polaris.api.plugin.stat.StatInfo in project polaris-java by polarismesh.

the class PrometheusPushHandlerTest method testServiceCallSuccessStrategy.

@Test
public void testServiceCallSuccessStrategy() throws InterruptedException {
    int count = 10;
    int expected = 3;
    CountDownLatch latch = new CountDownLatch(2);
    new Thread(() -> {
        try {
            batchDone(() -> {
                StatInfo statInfo = new StatInfo();
                ServiceCallResult callResult = mockFixedLabelServiceCallResult(200, 1000);
                callResult.setRetStatus(RetStatus.RetSuccess);
                statInfo.setRouterGauge(callResult);
                handler.handle(statInfo);
            }, expected);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        latch.countDown();
    }).start();
    new Thread(() -> {
        try {
            batchDone(() -> {
                StatInfo statInfo = new StatInfo();
                ServiceCallResult callResult = mockFixedLabelServiceCallResult(200, 1000);
                callResult.setRetStatus(RetStatus.RetFail);
                statInfo.setRouterGauge(callResult);
                handler.handle(statInfo);
            }, count - expected);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        latch.countDown();
    }).start();
    latch.await();
    // mock pushing
    Thread.sleep(pushInterval + 1000);
    handler.stopHandle();
    ServiceCallResult example = mockFixedLabelServiceCallResult(200, 1000);
    Double result = getServiceCallSuccessResult(example);
    Assert.assertEquals(new Double(expected), result);
}
Also used : ServiceCallResult(com.tencent.polaris.api.rpc.ServiceCallResult) CountDownLatch(java.util.concurrent.CountDownLatch) StatInfo(com.tencent.polaris.api.plugin.stat.StatInfo) Test(org.junit.Test)

Example 7 with StatInfo

use of com.tencent.polaris.api.plugin.stat.StatInfo in project polaris-java by polarismesh.

the class InMemoryRegistry method reportCircuitStat.

private void reportCircuitStat(Entry<StatusDimension, CircuitBreakerStatus> dimensionEntry, Instance instance) {
    if (null != statPlugins) {
        try {
            for (Plugin statPlugin : statPlugins) {
                if (statPlugin instanceof StatReporter) {
                    StatInfo info = new StatInfo();
                    info.setCircuitBreakGauge(convertToCircuitBreakGauge(dimensionEntry, instance));
                    ((StatReporter) statPlugin).reportStat(info);
                }
            }
        } catch (Exception ex) {
            LOG.info("circuit breaker report encountered exception, e: {}", ex.getMessage());
        }
    }
}
Also used : StatReporter(com.tencent.polaris.api.plugin.stat.StatReporter) StatInfo(com.tencent.polaris.api.plugin.stat.StatInfo) IOException(java.io.IOException) PolarisException(com.tencent.polaris.api.exception.PolarisException) Plugin(com.tencent.polaris.api.plugin.Plugin)

Example 8 with StatInfo

use of com.tencent.polaris.api.plugin.stat.StatInfo in project polaris-java by polarismesh.

the class ServiceCallStatCollector method convert.

private static StatInfo convert(InstanceGauge result) {
    StatInfo statInfo = new StatInfo();
    statInfo.setRouterGauge(result);
    return statInfo;
}
Also used : StatInfo(com.tencent.polaris.api.plugin.stat.StatInfo)

Example 9 with StatInfo

use of com.tencent.polaris.api.plugin.stat.StatInfo in project polaris-java by polarismesh.

the class DefaultLimitAPI method reportRateLimit.

private void reportRateLimit(QuotaRequest req, QuotaResponse rsp) {
    if (null != statPlugins) {
        try {
            DefaultRateLimitResult rateLimitGauge = new DefaultRateLimitResult();
            rateLimitGauge.setLabels(formatLabelsToStr(req.getLabels()));
            rateLimitGauge.setMethod(req.getMethod());
            rateLimitGauge.setNamespace(req.getNamespace());
            rateLimitGauge.setService(req.getService());
            rateLimitGauge.setResult(rsp.getCode() == QuotaResultOk ? RateLimitGauge.Result.PASSED : RateLimitGauge.Result.LIMITED);
            StatInfo statInfo = new StatInfo();
            statInfo.setRateLimitGauge(rateLimitGauge);
            for (Plugin statPlugin : statPlugins) {
                if (statPlugin instanceof StatReporter) {
                    ((StatReporter) statPlugin).reportStat(statInfo);
                }
            }
        } catch (Exception ex) {
            LOG.info("rate limit report encountered exception, e: {}", ex.getMessage());
        }
    }
}
Also used : DefaultRateLimitResult(com.tencent.polaris.api.plugin.stat.DefaultRateLimitResult) StatReporter(com.tencent.polaris.api.plugin.stat.StatReporter) StatInfo(com.tencent.polaris.api.plugin.stat.StatInfo) PolarisException(com.tencent.polaris.api.exception.PolarisException) Plugin(com.tencent.polaris.api.plugin.Plugin)

Example 10 with StatInfo

use of com.tencent.polaris.api.plugin.stat.StatInfo in project polaris-java by polarismesh.

the class PrometheusPushHandlerTest method testServiceCallSumAndMaxStrategy.

@Test
public void testServiceCallSumAndMaxStrategy() throws InterruptedException {
    List<Integer> delayList = Collections.synchronizedList(new ArrayList<>());
    int count = 20;
    batchDone(() -> {
        int delay = random.nextInt(1000) + 100;
        delayList.add(delay);
        StatInfo statInfo = new StatInfo();
        ServiceCallResult callResult = mockFixedLabelServiceCallResult(200, delay);
        statInfo.setRouterGauge(callResult);
        handler.handle(statInfo);
    }, count);
    // mock pushing
    Thread.sleep(pushInterval + 1000);
    handler.stopHandle();
    int maxExpected = 0;
    int sumExpected = 0;
    for (Integer i : delayList) {
        if (i > maxExpected) {
            maxExpected = i;
        }
        sumExpected += i;
    }
    ServiceCallResult example = mockFixedLabelServiceCallResult(200, 1000);
    Double maxResult = getServiceCallMaxResult(example);
    Double sumResult = getServiceCallSumResult(example);
    Assert.assertEquals(new Double(maxExpected), maxResult);
    Assert.assertEquals(new Double(sumExpected), sumResult);
}
Also used : ServiceCallResult(com.tencent.polaris.api.rpc.ServiceCallResult) StatInfo(com.tencent.polaris.api.plugin.stat.StatInfo) Test(org.junit.Test)

Aggregations

StatInfo (com.tencent.polaris.api.plugin.stat.StatInfo)11 Test (org.junit.Test)7 ServiceCallResult (com.tencent.polaris.api.rpc.ServiceCallResult)4 PolarisException (com.tencent.polaris.api.exception.PolarisException)2 Plugin (com.tencent.polaris.api.plugin.Plugin)2 DefaultRateLimitResult (com.tencent.polaris.api.plugin.stat.DefaultRateLimitResult)2 StatReporter (com.tencent.polaris.api.plugin.stat.StatReporter)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 IOException (java.io.IOException)1