Skip to content

Commit

Permalink
fixbug: fix pmd
Browse files Browse the repository at this point in the history
  • Loading branch information
luckyQing committed Apr 23, 2024
1 parent 46180e8 commit fe5409e
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.ToString;

import java.util.concurrent.atomic.LongAdder;

Expand All @@ -27,6 +28,7 @@
* @date 2024-01-6
*/
@Getter
@ToString
@AllArgsConstructor
public class ApiHealthCacheDTO {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
*/
@Getter
@Setter
@ToString
public class UnHealthApiDTO {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import java.io.Serializable;

Expand All @@ -30,6 +31,7 @@
*/
@Getter
@Setter
@ToString
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonPropertyOrder({"classMethod", "cost", "params", "headers", "result"})
public class FeignLogAspectDO implements Serializable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ protected Mono<Void> doNotify(InstanceEvent event, Instance instance) {
}

StatusInfo statusInfo = instance.getStatusInfo();
if (statusInfo.isUp() && (startUpTs == null || System.currentTimeMillis() - startUpTs <= monitorProperties.getFilterEventTs())) {
if (filter(statusInfo)) {
//服务启动时,60秒内的服务上线通知过滤掉
return;
}
Expand All @@ -103,7 +103,7 @@ protected Mono<Void> doNotify(InstanceEvent event, Instance instance) {
appChangeEvent = new UnknownEvent(this);
}

if (appChangeEvent instanceof DownEvent || appChangeEvent instanceof OfflineEvent || appChangeEvent instanceof MarkedOfflineEvent) {
if (isOffline(appChangeEvent)) {
log.warn("{}==>{}", registration.getName(), JacksonUtil.toJson(instance));
} else {
log.info("{}==>{}", registration.getName(), statusInfo.getStatus());
Expand All @@ -123,4 +123,24 @@ protected Mono<Void> doNotify(InstanceEvent event, Instance instance) {
});
}

/**
* 是否需要过滤事件
*
* @param statusInfo
* @return
*/
private boolean filter(StatusInfo statusInfo) {
return statusInfo.isUp() && (startUpTs == null || System.currentTimeMillis() - startUpTs <= monitorProperties.getFilterEventTs());
}

/**
* 是否是离线
*
* @param appChangeEvent
* @return
*/
private boolean isOffline(AbstractAppChangeEvent appChangeEvent) {
return appChangeEvent instanceof DownEvent || appChangeEvent instanceof OfflineEvent || appChangeEvent instanceof MarkedOfflineEvent;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
public class RateLimitInstanceFactory implements InitializingBean {

private final RateLimitProperties rateLimitProperties;
private static final Map<String, Semaphore> RATE_LIMIT_INSTANCES = new ConcurrentHashMap<>();
private static final Map<String, Semaphore> RATE_LIMIT_INSTANCES = new ConcurrentHashMap<>(4);

@Override
public void afterPropertiesSet() throws Exception {
Expand All @@ -60,7 +60,7 @@ public Semaphore get(String name) {
* 初始化限流bean实例
*/
private void initRateLimitBeans() {
Map<String, Integer> rateLimitConfig = new HashMap<>();
Map<String, Integer> rateLimitConfig = new HashMap<>(4);

// 注解限流
Set<Method> methods = ReflectionUtil.getMethodsAnnotatedWith(RateLimiter.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
* @date 2019-04-09
*/
@Getter
@ToString
@SuperBuilder
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonPropertyOrder({"url", "method", "cost", "head", "queryParams", "args", "result"})
Expand Down

0 comments on commit fe5409e

Please sign in to comment.