Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[improve] Add whitespace checkstyle #1824

Merged
merged 3 commits into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -329,8 +329,7 @@ private boolean execAlertExpression(Map<String, Object> fieldValueMap, String ex
}
});
match = (Boolean) expression.execute(fieldValueMap);
} catch (CompileExpressionErrorException |
ExpressionSyntaxErrorException compileException) {
} catch (CompileExpressionErrorException | ExpressionSyntaxErrorException compileException) {
log.error("Alert Define Rule: {} Compile Error: {}.", expr, compileException.getMessage());
throw compileException;
} catch (ExpressionRuntimeException expressionRuntimeException) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public ResponseEntity<Message<Page<AlertSilence>>> getAlertSilences(
Specification<AlertSilence> specification = (root, query, criteriaBuilder) -> {
List<Predicate> andList = new ArrayList<>();
if (ids != null && !ids.isEmpty()) {
CriteriaBuilder.In<Long> inPredicate= criteriaBuilder.in(root.get("id"));
CriteriaBuilder.In<Long> inPredicate = criteriaBuilder.in(root.get("id"));
for (long id : ids) {
inPredicate.value(id);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ public interface AlertDefineDao extends JpaRepository<AlertDefine, Long>, JpaSpe
* @param metrics metrics
* @return Alarm Definition List
*/
@Query("select define from AlertDefine define join AlertDefineMonitorBind bind on bind.alertDefineId = define.id " +
"where bind.monitorId = :monitorId and define.app = :app and define.metric = :metrics and define.enable = true and define.preset = false")
@Query("select define from AlertDefine define join AlertDefineMonitorBind bind on bind.alertDefineId = define.id "
+ "where bind.monitorId = :monitorId and define.app = :app and define.metric = :metrics and define.enable = true and define.preset = false")
List<AlertDefine> queryAlertDefinesByMonitor(@Param(value = "monitorId") Long monitorId,
@Param(value = "app") String app,
@Param(value = "metrics") String metrics);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,8 @@ public boolean filterSilence(Alert alert) {
LocalDateTime nowDate = LocalDateTime.now();
if (alertSilence.getType() == 0) {
// once time
boolean startMatch = alertSilence.getPeriodStart() == null ||
nowDate.isAfter(alertSilence.getPeriodStart().toLocalDateTime());
boolean endMatch = alertSilence.getPeriodEnd() == null ||
nowDate.isBefore(alertSilence.getPeriodEnd().toLocalDateTime());
boolean startMatch = alertSilence.getPeriodStart() == null || nowDate.isAfter(alertSilence.getPeriodStart().toLocalDateTime());
boolean endMatch = alertSilence.getPeriodEnd() == null || nowDate.isBefore(alertSilence.getPeriodEnd().toLocalDateTime());
if (startMatch && endMatch) {
int times = Optional.ofNullable(alertSilence.getTimes()).orElse(0);
alertSilence.setTimes(times + 1);
Expand All @@ -104,10 +102,8 @@ public boolean filterSilence(Alert alert) {
boolean dayMatch = alertSilence.getDays().stream().anyMatch(item -> item == currentDayOfWeek);
if (dayMatch) {
LocalTime nowTime = nowDate.toLocalTime();
boolean startMatch = alertSilence.getPeriodStart() == null ||
nowTime.isAfter(alertSilence.getPeriodStart().toLocalTime());
boolean endMatch = alertSilence.getPeriodEnd() == null ||
nowTime.isBefore(alertSilence.getPeriodEnd().toLocalTime());
boolean startMatch = alertSilence.getPeriodStart() == null || nowTime.isAfter(alertSilence.getPeriodStart().toLocalTime());
boolean endMatch = alertSilence.getPeriodEnd() == null || nowTime.isBefore(alertSilence.getPeriodEnd().toLocalTime());
if (startMatch && endMatch) {
int times = Optional.ofNullable(alertSilence.getTimes()).orElse(0);
alertSilence.setTimes(times + 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ private Alert buildAlertData(AlertReport alertReport){
annotations.forEach((k, v) -> {
finalSb.append(k).append(":").append(v).append("\n");
});
}else {
} else {
sb = new StringBuilder(alertReport.getContent());
}
LocalDateTime dateTime = LocalDateTime.ofInstant(Instant.ofEpochMilli(alertReport.getAlertTime()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ public class CacheIdentifier {

@Override
public String toString() {
return "CacheIdentifier {" +
"ip='" + ip + '\'' +
", port='" + port + '\'' +
", username+password=>hash='" + Objects.hash(username, password) + '\'' +
", customArg='" + customArg + '\'' +
'}';
return "CacheIdentifier {"
+ "ip='" + ip + '\''
+ ", port='" + port + '\''
+ ", username+password=>hash='" + Objects.hash(username, password) + '\''
+ ", customArg='" + customArg + '\''
+ '}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public void collect(CollectRep.MetricsData.Builder builder, long monitorId, Stri
// add header columns
Map<String, String> headerInfo = dnsResolveResult.getHeaderInfo();
metrics.getAliasFields().forEach(field -> valueRowBuilder.addColumns(headerInfo.getOrDefault(field, CommonConstants.NULL_VALUE)));
}else {
} else {
// add question/answer/authority/additional columns
List<String> currentMetricsResolveResultList = dnsResolveResult.getList(metrics.getName());
for (int index = 0; index < metrics.getAliasFields().size(); index++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,8 +290,8 @@ private void parseResponseBySiteMap(String resp, List<String> aliasFields,
if (CollectorConstants.URL.equalsIgnoreCase(alias)) {
valueRowBuilder.addColumns(siteUrl);
} else if (CollectorConstants.STATUS_CODE.equalsIgnoreCase(alias)) {
valueRowBuilder.addColumns(statusCode == null ?
CommonConstants.NULL_VALUE : String.valueOf(statusCode));
valueRowBuilder.addColumns(statusCode == null
? CommonConstants.NULL_VALUE : String.valueOf(statusCode));
} else if (CollectorConstants.RESPONSE_TIME.equalsIgnoreCase(alias)) {
valueRowBuilder.addColumns(String.valueOf(responseTime));
} else if (CollectorConstants.ERROR_MSG.equalsIgnoreCase(alias)) {
Expand Down Expand Up @@ -452,8 +452,8 @@ public HttpContext createHttpContext(HttpProtocol httpProtocol) {
if (StringUtils.hasText(auth.getDigestAuthUsername())
&& StringUtils.hasText(auth.getDigestAuthPassword())) {
CredentialsProvider provider = new BasicCredentialsProvider();
UsernamePasswordCredentials credentials
= new UsernamePasswordCredentials(auth.getDigestAuthUsername(), auth.getDigestAuthPassword());
UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(auth.getDigestAuthUsername(),
auth.getDigestAuthPassword());
provider.setCredentials(AuthScope.ANY, credentials);
AuthCache authCache = new BasicAuthCache();
authCache.put(new HttpHost(httpProtocol.getHost(), Integer.parseInt(httpProtocol.getPort())), new DigestScheme());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,9 @@ private void parseMetric(StrBuffer buffer) {
// todo 这里可能存在问题, 目前逻辑是HISTOGRAM和SUMMARY只创建一个metric
// 相比源码有所改动: 源码通过属性存储解析结果; 这边通过参数传递
MetricFamily.Metric metric;
if (!metricList.isEmpty() &&
(this.currentMetricFamily.getMetricType().equals(MetricType.HISTOGRAM) ||
this.currentMetricFamily.getMetricType().equals(MetricType.SUMMARY))) {
if (!metricList.isEmpty()
&& (this.currentMetricFamily.getMetricType().equals(MetricType.HISTOGRAM)
|| this.currentMetricFamily.getMetricType().equals(MetricType.SUMMARY))) {
metric = metricList.get(0);
} else {
metric = new MetricFamily.Metric();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
*/
@Slf4j
public class HttpsdImpl extends AbstractCollect {
private final static String SERVER = "server";
private static final String SERVER = "server";
private final DiscoveryClientManagement discoveryClientManagement = new DiscoveryClientManagement();

@Override
Expand Down Expand Up @@ -78,13 +78,13 @@ private void collectMetrics(CollectRep.MetricsData.Builder builder, Metrics metr
metrics.getAliasFields().forEach(fieldName -> {
if (StringUtils.equalsAnyIgnoreCase(CollectorConstants.RESPONSE_TIME, fieldName)) {
valueRowBuilder.addColumns(String.valueOf(System.currentTimeMillis() - beginTime));
}else {
} else {
addColumnIfMatched(fieldName, serverInfo, valueRowBuilder);
}
});

builder.addValues(valueRowBuilder.build());
}else {
} else {
// Service instances monitor
discoveryClient.getServices().forEach(serviceInstance -> {
CollectRep.ValueRow.Builder valueRowBuilder = CollectRep.ValueRow.newBuilder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public void initClient(ConnectConfig connectConfig) {
try {
localConnectConfig = connectConfig;
namingService = NamingFactory.createNamingService(connectConfig.getHost() + ":" + connectConfig.getPort());
}catch (NacosException exception) {
} catch (NacosException exception) {
throw new RuntimeException("Failed to init namingService");
}
}
Expand Down Expand Up @@ -106,7 +106,7 @@ public void close() {

try {
namingService.shutDown();
}catch (NacosException ignore) {
} catch (NacosException ignore) {
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public void collect(CollectRep.MetricsData.Builder builder, long monitorId, Stri
}
ClientSession clientSession = null;
MongoClient mongoClient;
CacheIdentifier identifier= null;
CacheIdentifier identifier = null;
try {
identifier = getIdentifier(metrics.getMongodb());
mongoClient = getClient(metrics, identifier);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,19 @@
*/
@Slf4j
public class NebulaGraphCollectImpl extends AbstractCollect {
private final static int SUCCESS_CODE = 200;
private static final int SUCCESS_CODE = 200;

private final static String[] TIME_RANGE = new String[]{"5", "60", "600", "3600"};
private static final String[] TIME_RANGE = new String[]{"5", "60", "600", "3600"};

private final static String REGEX = "\\.%s\\=";
private static final String REGEX = "\\.%s\\=";

private final static String STR_SPLIT = "\n";
private static final String STR_SPLIT = "\n";

private final static String STORAGE_SPLIT_KEY_VALUE = "=";
private static final String STORAGE_SPLIT_KEY_VALUE = "=";

private final static String GRAPH_API = "/stats";
private static final String GRAPH_API = "/stats";

private final static String STORAGE_API = "/rocksdb_stats";
private static final String STORAGE_API = "/rocksdb_stats";


@Override
Expand All @@ -79,7 +79,7 @@ public void collect(CollectRep.MetricsData.Builder builder, long monitorId, Stri
NebulaGraphProtocol nebulaGraph = metrics.getNebulaGraph();
String timePeriod = nebulaGraph.getTimePeriod();

if (!Objects.isNull(nebulaGraph.getTimePeriod())&&!Arrays.asList(TIME_RANGE).contains(timePeriod)) {
if (!Objects.isNull(nebulaGraph.getTimePeriod()) && !Arrays.asList(TIME_RANGE).contains(timePeriod)) {
builder.setCode(CollectRep.Code.FAIL);
builder.setMsg("The time range for metric statistics, currently supporting 5 seconds, 60 seconds, 600 seconds, and 3600 seconds.");
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,19 +60,19 @@
@Slf4j
public class NginxCollectImpl extends AbstractCollect {

private final static int SUCCESS_CODE = 200;
private final static String NGINX_STATUS_NAME = "nginx_status";
private final static String REQ_STATUS_NAME = "req_status";
private final static String AVAILABLE = "available";
private final static String CONNECTIONS = "connections";
private final static String ACTIVE = "active";
private final static String GET = "get";
private final static String FIELD_SPLIT = "_";
private final static String REGEX_KEYS = "server\\s+(\\w+)\\s+(\\w+)\\s+(\\w+)";
private final static String REGEX_VALUES = "(\\d+) (\\d+) (\\d+)";
private final static String REGEX_SERVER = "(\\w+): (\\d+)";
private final static String REGEX_SPLIT = "\\r?\\n";
private final static String REGEX_LINE_SPLIT = "\\s+";
private static final int SUCCESS_CODE = 200;
private static final String NGINX_STATUS_NAME = "nginx_status";
private static final String REQ_STATUS_NAME = "req_status";
private static final String AVAILABLE = "available";
private static final String CONNECTIONS = "connections";
private static final String ACTIVE = "active";
private static final String GET = "get";
private static final String FIELD_SPLIT = "_";
private static final String REGEX_KEYS = "server\\s+(\\w+)\\s+(\\w+)\\s+(\\w+)";
private static final String REGEX_VALUES = "(\\d+) (\\d+) (\\d+)";
private static final String REGEX_SERVER = "(\\w+): (\\d+)";
private static final String REGEX_SPLIT = "\\r?\\n";
private static final String REGEX_LINE_SPLIT = "\\s+";


public NginxCollectImpl() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@
@Slf4j
public class Pop3CollectImpl extends AbstractCollect {

private final static String EMAIL_COUNT = "email_count";
private final static String MAILBOX_SIZE = "mailbox_size";
private static final String EMAIL_COUNT = "email_count";
private static final String MAILBOX_SIZE = "mailbox_size";

public Pop3CollectImpl() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,8 @@ public HttpContext createHttpContext(PrometheusProtocol protocol) {
if (StringUtils.hasText(auth.getDigestAuthUsername())
&& StringUtils.hasText(auth.getDigestAuthPassword())) {
CredentialsProvider provider = new BasicCredentialsProvider();
UsernamePasswordCredentials credentials
= new UsernamePasswordCredentials(auth.getDigestAuthUsername(), auth.getDigestAuthPassword());
UsernamePasswordCredentials credentials =
new UsernamePasswordCredentials(auth.getDigestAuthUsername(), auth.getDigestAuthPassword());
provider.setCredentials(AuthScope.ANY, credentials);
AuthCache authCache = new BasicAuthCache();
authCache.put(new HttpHost(protocol.getHost(), Integer.parseInt(protocol.getPort())), new DigestScheme());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ public class SnmpCollectImpl extends AbstractCollect {
private static final String OPERATION_WALK = "walk";
private static final String HEX_SPLIT = ":";
private static final String FORMAT_PATTERN =
"{0,choice,0#|1#1 day, |1<{0,number,integer} days, }" +
"{1,choice,0#|1#1 hour, |1<{1,number,integer} hours, }" +
"{2,choice,0#|1#1 minute, |1<{2,number,integer} minutes, }" +
"{3,choice,0#|1#1 second, |1<{3,number,integer} seconds }";
"{0,choice,0#|1#1 day, |1<{0,number,integer} days, }"
+ "{1,choice,0#|1#1 hour, |1<{1,number,integer} hours, }"
+ "{2,choice,0#|1#1 minute, |1<{2,number,integer} minutes, }"
+ "{3,choice,0#|1#1 second, |1<{3,number,integer} seconds }";

private final Map<Integer, Snmp> versionSnmpService = new ConcurrentHashMap<>(3);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -399,8 +399,8 @@ private void validateResponse(CollectRep.MetricsData metricsData) {
}

private void setNewThreadName(long monitorId, String app, long startTime, Metrics metrics) {
String builder = monitorId + "-" + app + "-" + metrics.getName() +
"-" + String.valueOf(startTime).substring(9);
String builder = monitorId + "-" + app + "-" + metrics.getName()
+ "-" + String.valueOf(startTime).substring(9);
Thread.currentThread().setName(builder);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,8 @@ public HashedWheelTimer(

this.maxPendingTimeouts = maxPendingTimeouts;

if (INSTANCE_COUNTER.incrementAndGet() > INSTANCE_COUNT_LIMIT &&
WARNED_TOO_MANY_INSTANCES.compareAndSet(false, true)) {
if (INSTANCE_COUNTER.incrementAndGet() > INSTANCE_COUNT_LIMIT
&& WARNED_TOO_MANY_INSTANCES.compareAndSet(false, true)) {
reportTooManyInstances();
}
}
Expand Down Expand Up @@ -331,9 +331,9 @@ public void start() {
public Set<Timeout> stop() {
if (Thread.currentThread() == workerThread) {
throw new IllegalStateException(
HashedWheelTimer.class.getSimpleName() +
".stop() cannot be called from " +
TimerTask.class.getSimpleName());
HashedWheelTimer.class.getSimpleName()
+ ".stop() cannot be called from "
+ TimerTask.class.getSimpleName());
}

if (!WORKER_STATE_UPDATER.compareAndSet(this, WORKER_STATE_STARTED, WORKER_STATE_SHUTDOWN)) {
Expand Down Expand Up @@ -411,9 +411,9 @@ public long pendingTimeouts() {
}

private static void reportTooManyInstances() {
logger.error("You are creating too many HashedWheelTimer instances. " +
"HashedWheelTimer is a shared resource that must be reused across the JVM," +
"so that only a few instances are created.");
logger.error("You are creating too many HashedWheelTimer instances. "
+ "HashedWheelTimer is a shared resource that must be reused across the JVM,"
+ "so that only a few instances are created.");
}

private final class Worker implements Runnable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,16 +90,16 @@ public class Alert {
@Column(length = 4096)
private String content;

@Schema(title = "Alarm status: " +
"0-normal alarm (to be processed) " +
"1-threshold triggered but not reached the number of alarms " +
"2-recovered alarm " +
"3-processed",
description = "Alarm status: " +
"0-normal alarm (to be processed) " +
"1-threshold triggered but not reached the number of alarms " +
"2-recovered alarm " +
"3-processed",
@Schema(title = "Alarm status: "
+ "0-normal alarm (to be processed) "
+ "1-threshold triggered but not reached the number of alarms "
+ "2-recovered alarm "
+ "3-processed",
description = "Alarm status: "
+ "0-normal alarm (to be processed) "
+ "1-threshold triggered but not reached the number of alarms "
+ "2-recovered alarm "
+ "3-processed",
example = "1", accessMode = READ_WRITE)
@Min(0)
@Max(3)
Expand Down
Loading
Loading