Merge pull request #10433 from thingsboard/fix/rule-engine-stats
Add tenantId tag to Rule Engine stats
This commit is contained in:
commit
a740ce15f1
@ -18,7 +18,6 @@ package org.thingsboard.server.service.queue;
|
|||||||
import io.micrometer.core.instrument.Timer;
|
import io.micrometer.core.instrument.Timer;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.thingsboard.server.common.data.id.TenantId;
|
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.msg.queue.RuleEngineException;
|
||||||
import org.thingsboard.server.common.stats.StatsCounter;
|
import org.thingsboard.server.common.stats.StatsCounter;
|
||||||
import org.thingsboard.server.common.stats.StatsFactory;
|
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 FAILED_MSGS = "failedMsgs";
|
||||||
public static final String SUCCESSFUL_ITERATIONS = "successfulIterations";
|
public static final String SUCCESSFUL_ITERATIONS = "successfulIterations";
|
||||||
public static final String FAILED_ITERATIONS = "failedIterations";
|
public static final String FAILED_ITERATIONS = "failedIterations";
|
||||||
|
public static final String TENANT_ID_TAG = "tenantId";
|
||||||
|
|
||||||
private final StatsFactory statsFactory;
|
private final StatsFactory statsFactory;
|
||||||
|
|
||||||
@ -73,14 +73,15 @@ public class TbRuleEngineConsumerStats {
|
|||||||
this.statsFactory = statsFactory;
|
this.statsFactory = statsFactory;
|
||||||
|
|
||||||
String statsKey = StatsType.RULE_ENGINE.getName() + "." + queueName;
|
String statsKey = StatsType.RULE_ENGINE.getName() + "." + queueName;
|
||||||
this.totalMsgCounter = statsFactory.createStatsCounter(statsKey, TOTAL_MSGS);
|
String tenant = tenantId == null || tenantId.isSysTenantId() ? "system" : tenantId.toString();
|
||||||
this.successMsgCounter = statsFactory.createStatsCounter(statsKey, SUCCESSFUL_MSGS);
|
this.totalMsgCounter = statsFactory.createStatsCounter(statsKey, TOTAL_MSGS, TENANT_ID_TAG, tenant);
|
||||||
this.timeoutMsgCounter = statsFactory.createStatsCounter(statsKey, TIMEOUT_MSGS);
|
this.successMsgCounter = statsFactory.createStatsCounter(statsKey, SUCCESSFUL_MSGS, TENANT_ID_TAG, tenant);
|
||||||
this.failedMsgCounter = statsFactory.createStatsCounter(statsKey, FAILED_MSGS);
|
this.timeoutMsgCounter = statsFactory.createStatsCounter(statsKey, TIMEOUT_MSGS, TENANT_ID_TAG, tenant);
|
||||||
this.tmpTimeoutMsgCounter = statsFactory.createStatsCounter(statsKey, TMP_TIMEOUT);
|
this.failedMsgCounter = statsFactory.createStatsCounter(statsKey, FAILED_MSGS, TENANT_ID_TAG, tenant);
|
||||||
this.tmpFailedMsgCounter = statsFactory.createStatsCounter(statsKey, TMP_FAILED);
|
this.tmpTimeoutMsgCounter = statsFactory.createStatsCounter(statsKey, TMP_TIMEOUT, TENANT_ID_TAG, tenant);
|
||||||
this.successIterationsCounter = statsFactory.createStatsCounter(statsKey, SUCCESSFUL_ITERATIONS);
|
this.tmpFailedMsgCounter = statsFactory.createStatsCounter(statsKey, TMP_FAILED, TENANT_ID_TAG, tenant);
|
||||||
this.failedIterationsCounter = statsFactory.createStatsCounter(statsKey, FAILED_ITERATIONS);
|
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(totalMsgCounter);
|
||||||
counters.add(successMsgCounter);
|
counters.add(successMsgCounter);
|
||||||
|
|||||||
@ -19,6 +19,7 @@ import io.micrometer.core.instrument.Counter;
|
|||||||
import io.micrometer.core.instrument.MeterRegistry;
|
import io.micrometer.core.instrument.MeterRegistry;
|
||||||
import io.micrometer.core.instrument.Tags;
|
import io.micrometer.core.instrument.Tags;
|
||||||
import io.micrometer.core.instrument.Timer;
|
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.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
@ -61,12 +62,17 @@ public class DefaultStatsFactory implements StatsFactory {
|
|||||||
|
|
||||||
|
|
||||||
@Override
|
@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(
|
return new StatsCounter(
|
||||||
new AtomicInteger(0),
|
new AtomicInteger(0),
|
||||||
metricsEnabled ?
|
metricsEnabled ? meterRegistry.counter(key, tags) : STUB_COUNTER,
|
||||||
meterRegistry.counter(key, STATS_NAME_TAG, statsName)
|
|
||||||
: STUB_COUNTER,
|
|
||||||
statsName
|
statsName
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -18,7 +18,8 @@ package org.thingsboard.server.common.stats;
|
|||||||
import io.micrometer.core.instrument.Timer;
|
import io.micrometer.core.instrument.Timer;
|
||||||
|
|
||||||
public interface StatsFactory {
|
public interface StatsFactory {
|
||||||
StatsCounter createStatsCounter(String key, String statsName);
|
|
||||||
|
StatsCounter createStatsCounter(String key, String statsName, String... otherTags);
|
||||||
|
|
||||||
DefaultCounter createDefaultCounter(String key, String... tags);
|
DefaultCounter createDefaultCounter(String key, String... tags);
|
||||||
|
|
||||||
@ -27,4 +28,5 @@ public interface StatsFactory {
|
|||||||
MessagesStats createMessagesStats(String key);
|
MessagesStats createMessagesStats(String key);
|
||||||
|
|
||||||
Timer createTimer(String key, String... tags);
|
Timer createTimer(String key, String... tags);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user