Monitoring: minor refactoring
This commit is contained in:
		
							parent
							
								
									a8a0083bb2
								
							
						
					
					
						commit
						d6a4d454fd
					
				@ -52,8 +52,6 @@ public abstract class BaseHealthChecker<C extends MonitoringConfig, T extends Mo
 | 
			
		||||
    private TbStopWatch stopWatch;
 | 
			
		||||
    @Value("${monitoring.check_timeout_ms}")
 | 
			
		||||
    private int resultCheckTimeoutMs;
 | 
			
		||||
    @Value("${monitoring.calculated_fields.enabled:true}")
 | 
			
		||||
    protected boolean checkCalculatedFields;
 | 
			
		||||
 | 
			
		||||
    @Getter
 | 
			
		||||
    private final Map<String, BaseHealthChecker<C, T>> associates = new HashMap<>();
 | 
			
		||||
@ -71,7 +69,7 @@ public abstract class BaseHealthChecker<C extends MonitoringConfig, T extends Mo
 | 
			
		||||
    public final void check(WsClient wsClient) {
 | 
			
		||||
        log.debug("[{}] Checking", info);
 | 
			
		||||
        try {
 | 
			
		||||
            int expectedUpdatesCount = checkCalculatedFields ? 2 : 1;
 | 
			
		||||
            int expectedUpdatesCount = isCfMonitoringEnabled() ? 2 : 1;
 | 
			
		||||
            wsClient.registerWaitForUpdates(expectedUpdatesCount);
 | 
			
		||||
 | 
			
		||||
            String testValue = UUID.randomUUID().toString();
 | 
			
		||||
@ -114,7 +112,7 @@ public abstract class BaseHealthChecker<C extends MonitoringConfig, T extends Mo
 | 
			
		||||
        if (!testValue.equals(actualValue)) {
 | 
			
		||||
            throw new ServiceFailureException(info, "Was expecting value " + testValue + " but got " + actualValue);
 | 
			
		||||
        }
 | 
			
		||||
        if (checkCalculatedFields) {
 | 
			
		||||
        if (isCfMonitoringEnabled()) {
 | 
			
		||||
            String cfTestValue = testValue + "-cf";
 | 
			
		||||
            String actualCfValue = latest.get(TEST_CF_TELEMETRY_KEY);
 | 
			
		||||
            if (actualCfValue == null) {
 | 
			
		||||
@ -141,4 +139,6 @@ public abstract class BaseHealthChecker<C extends MonitoringConfig, T extends Mo
 | 
			
		||||
 | 
			
		||||
    protected abstract String getKey();
 | 
			
		||||
 | 
			
		||||
    protected abstract boolean isCfMonitoringEnabled();
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -18,6 +18,7 @@ package org.thingsboard.monitoring.service.transport;
 | 
			
		||||
import com.fasterxml.jackson.databind.node.TextNode;
 | 
			
		||||
import lombok.extern.slf4j.Slf4j;
 | 
			
		||||
import org.apache.commons.lang3.RandomStringUtils;
 | 
			
		||||
import org.springframework.beans.factory.annotation.Value;
 | 
			
		||||
import org.thingsboard.common.util.JacksonUtil;
 | 
			
		||||
import org.thingsboard.monitoring.client.TbClient;
 | 
			
		||||
import org.thingsboard.monitoring.config.transport.DeviceConfig;
 | 
			
		||||
@ -60,6 +61,9 @@ import java.util.Map;
 | 
			
		||||
@Slf4j
 | 
			
		||||
public abstract class TransportHealthChecker<C extends TransportMonitoringConfig> extends BaseHealthChecker<C, TransportMonitoringTarget> {
 | 
			
		||||
 | 
			
		||||
    @Value("${monitoring.calculated_fields.enabled:true}")
 | 
			
		||||
    private boolean calculatedFieldsMonitoringEnabled;
 | 
			
		||||
 | 
			
		||||
    public TransportHealthChecker(C config, TransportMonitoringTarget target) {
 | 
			
		||||
        super(config, target);
 | 
			
		||||
    }
 | 
			
		||||
@ -100,7 +104,7 @@ public abstract class TransportHealthChecker<C extends TransportMonitoringConfig
 | 
			
		||||
        String deviceName = String.format("%s %s (%s) - %s", target.getNamePrefix(), transportType.getName(), target.getQueue(), target.getBaseUrl()).trim();
 | 
			
		||||
        Device device = tbClient.getTenantDevice(deviceName).orElse(null);
 | 
			
		||||
        if (device != null) {
 | 
			
		||||
            if (checkCalculatedFields) {
 | 
			
		||||
            if (isCfMonitoringEnabled()) {
 | 
			
		||||
                CalculatedField calculatedField = tbClient.getCalculatedFieldsByEntityId(device.getId(), new PageLink(1, 0, TEST_CF_TELEMETRY_KEY))
 | 
			
		||||
                        .getData().stream().findFirst().orElse(null);
 | 
			
		||||
                if (calculatedField == null) {
 | 
			
		||||
@ -198,4 +202,9 @@ public abstract class TransportHealthChecker<C extends TransportMonitoringConfig
 | 
			
		||||
        tbClient.saveCalculatedField(calculatedField);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    protected boolean isCfMonitoringEnabled() {
 | 
			
		||||
        return calculatedFieldsMonitoringEnabled;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user