Search in sources :

Example 1 with StatReporter

use of com.tencent.polaris.api.plugin.stat.StatReporter 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 2 with StatReporter

use of com.tencent.polaris.api.plugin.stat.StatReporter 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)

Aggregations

PolarisException (com.tencent.polaris.api.exception.PolarisException)2 Plugin (com.tencent.polaris.api.plugin.Plugin)2 StatInfo (com.tencent.polaris.api.plugin.stat.StatInfo)2 StatReporter (com.tencent.polaris.api.plugin.stat.StatReporter)2 DefaultRateLimitResult (com.tencent.polaris.api.plugin.stat.DefaultRateLimitResult)1 IOException (java.io.IOException)1