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);
}
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());
}
}
}
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;
}
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());
}
}
}
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);
}
Aggregations