Add tenantId tag to Rule Engine consumer stats
This commit is contained in:
parent
01335e87ee
commit
2e20ad6dc6
@ -18,7 +18,6 @@ package org.thingsboard.server.service.queue;
|
||||
import io.micrometer.core.instrument.Timer;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.thingsboard.server.common.data.id.TenantId;
|
||||
import org.thingsboard.server.common.data.queue.Queue;
|
||||
import org.thingsboard.server.common.msg.queue.RuleEngineException;
|
||||
import org.thingsboard.server.common.stats.StatsCounter;
|
||||
import org.thingsboard.server.common.stats.StatsFactory;
|
||||
@ -45,6 +44,7 @@ public class TbRuleEngineConsumerStats {
|
||||
public static final String FAILED_MSGS = "failedMsgs";
|
||||
public static final String SUCCESSFUL_ITERATIONS = "successfulIterations";
|
||||
public static final String FAILED_ITERATIONS = "failedIterations";
|
||||
public static final String TENANT_ID_TAG = "tenantId";
|
||||
|
||||
private final StatsFactory statsFactory;
|
||||
|
||||
@ -73,14 +73,15 @@ public class TbRuleEngineConsumerStats {
|
||||
this.statsFactory = statsFactory;
|
||||
|
||||
String statsKey = StatsType.RULE_ENGINE.getName() + "." + queueName;
|
||||
this.totalMsgCounter = statsFactory.createStatsCounter(statsKey, TOTAL_MSGS);
|
||||
this.successMsgCounter = statsFactory.createStatsCounter(statsKey, SUCCESSFUL_MSGS);
|
||||
this.timeoutMsgCounter = statsFactory.createStatsCounter(statsKey, TIMEOUT_MSGS);
|
||||
this.failedMsgCounter = statsFactory.createStatsCounter(statsKey, FAILED_MSGS);
|
||||
this.tmpTimeoutMsgCounter = statsFactory.createStatsCounter(statsKey, TMP_TIMEOUT);
|
||||
this.tmpFailedMsgCounter = statsFactory.createStatsCounter(statsKey, TMP_FAILED);
|
||||
this.successIterationsCounter = statsFactory.createStatsCounter(statsKey, SUCCESSFUL_ITERATIONS);
|
||||
this.failedIterationsCounter = statsFactory.createStatsCounter(statsKey, FAILED_ITERATIONS);
|
||||
String tenant = tenantId == null || tenantId.isSysTenantId() ? "system" : tenantId.toString();
|
||||
this.totalMsgCounter = statsFactory.createStatsCounter(statsKey, TOTAL_MSGS, TENANT_ID_TAG, tenant);
|
||||
this.successMsgCounter = statsFactory.createStatsCounter(statsKey, SUCCESSFUL_MSGS, TENANT_ID_TAG, tenant);
|
||||
this.timeoutMsgCounter = statsFactory.createStatsCounter(statsKey, TIMEOUT_MSGS, TENANT_ID_TAG, tenant);
|
||||
this.failedMsgCounter = statsFactory.createStatsCounter(statsKey, FAILED_MSGS, TENANT_ID_TAG, tenant);
|
||||
this.tmpTimeoutMsgCounter = statsFactory.createStatsCounter(statsKey, TMP_TIMEOUT, TENANT_ID_TAG, tenant);
|
||||
this.tmpFailedMsgCounter = statsFactory.createStatsCounter(statsKey, TMP_FAILED, TENANT_ID_TAG, tenant);
|
||||
this.successIterationsCounter = statsFactory.createStatsCounter(statsKey, SUCCESSFUL_ITERATIONS, TENANT_ID_TAG, tenant);
|
||||
this.failedIterationsCounter = statsFactory.createStatsCounter(statsKey, FAILED_ITERATIONS, TENANT_ID_TAG, tenant);
|
||||
|
||||
counters.add(totalMsgCounter);
|
||||
counters.add(successMsgCounter);
|
||||
@ -93,7 +94,7 @@ public class TbRuleEngineConsumerStats {
|
||||
counters.add(failedIterationsCounter);
|
||||
}
|
||||
|
||||
public Timer getTimer(TenantId tenantId, String status){
|
||||
public Timer getTimer(TenantId tenantId, String status) {
|
||||
return tenantMsgProcessTimers.computeIfAbsent(tenantId,
|
||||
id -> statsFactory.createTimer(StatsType.RULE_ENGINE.getName() + "." + queueName,
|
||||
"tenantId", tenantId.getId().toString(),
|
||||
|
||||
@ -19,6 +19,7 @@ import io.micrometer.core.instrument.Counter;
|
||||
import io.micrometer.core.instrument.MeterRegistry;
|
||||
import io.micrometer.core.instrument.Tags;
|
||||
import io.micrometer.core.instrument.Timer;
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
@ -61,12 +62,17 @@ public class DefaultStatsFactory implements StatsFactory {
|
||||
|
||||
|
||||
@Override
|
||||
public StatsCounter createStatsCounter(String key, String statsName) {
|
||||
public StatsCounter createStatsCounter(String key, String statsName, String... otherTags) {
|
||||
String[] tags = new String[]{STATS_NAME_TAG, statsName};
|
||||
if (otherTags.length > 0) {
|
||||
if (otherTags.length % 2 != 0) {
|
||||
throw new IllegalArgumentException("Invalid tags array size");
|
||||
}
|
||||
tags = ArrayUtils.addAll(tags, otherTags);
|
||||
}
|
||||
return new StatsCounter(
|
||||
new AtomicInteger(0),
|
||||
metricsEnabled ?
|
||||
meterRegistry.counter(key, STATS_NAME_TAG, statsName)
|
||||
: STUB_COUNTER,
|
||||
metricsEnabled ? meterRegistry.counter(key, tags) : STUB_COUNTER,
|
||||
statsName
|
||||
);
|
||||
}
|
||||
|
||||
@ -18,7 +18,8 @@ package org.thingsboard.server.common.stats;
|
||||
import io.micrometer.core.instrument.Timer;
|
||||
|
||||
public interface StatsFactory {
|
||||
StatsCounter createStatsCounter(String key, String statsName);
|
||||
|
||||
StatsCounter createStatsCounter(String key, String statsName, String... otherTags);
|
||||
|
||||
DefaultCounter createDefaultCounter(String key, String... tags);
|
||||
|
||||
@ -27,4 +28,5 @@ public interface StatsFactory {
|
||||
MessagesStats createMessagesStats(String key);
|
||||
|
||||
Timer createTimer(String key, String... tags);
|
||||
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user