From c25cd0b165da6027702db5a07685b1ab8692737e Mon Sep 17 00:00:00 2001 From: scienceZ Date: Tue, 26 Jul 2022 20:30:59 +0800 Subject: [PATCH] [ISSUE#8481]Unified TRACE capacity building 1. Event type add to traceEvent. 2. The event about instance add instancePort. 3. Add health check type to healthChangeEvent. 4. Other fixup. --- ...ChangeReason.java => HealthCheckType.java} | 29 +- .../common/trace/event/NamingTraceEvent.java | 258 ------------------ .../nacos/common/trace/event/TraceEvent.java | 9 +- .../naming/DeregisterInstanceTraceEvent.java | 72 +++++ .../naming/DeregisterServiceTraceEvent.java | 31 +++ .../naming/HealthStateChangeTraceEvent.java | 79 ++++++ .../trace/event/naming/NamingTraceEvent.java | 34 +++ .../event/naming/PushServiceTraceEvent.java | 67 +++++ .../naming/RegisterInstanceTraceEvent.java | 63 +++++ .../naming/RegisterServiceTraceEvent.java | 31 +++ .../naming/SubscribeServiceTraceEvent.java | 38 +++ .../naming/UnsubscribeServiceTraceEvent.java | 38 +++ .../trace/publisher/TraceEventPublisher.java | 3 +- .../publisher/TraceEventPublisherFactory.java | 21 +- .../TraceEventPublisherFactoryTest.java | 2 +- .../publisher/TraceEventPublisherTest.java | 11 - .../controllers/InstanceController.java | 13 +- .../controllers/InstanceControllerV2.java | 11 +- .../naming/controllers/ServiceController.java | 7 +- .../controllers/ServiceControllerV2.java | 7 +- .../v2/index/ClientServiceIndexesManager.java | 10 +- .../healthcheck/ClientBeatProcessor.java | 7 +- .../naming/healthcheck/HealthCheckCommon.java | 17 +- .../heartbeat/ClientBeatProcessorV2.java | 7 +- .../heartbeat/ExpiredInstanceChecker.java | 7 +- .../heartbeat/UnhealthyInstanceChecker.java | 9 +- .../v2/processor/HealthCheckCommonV2.java | 15 +- .../naming/push/v2/task/PushExecuteTask.java | 6 +- .../rpc/handler/InstanceRequestHandler.java | 12 +- .../SubscribeServiceRequestHandler.java | 7 +- 30 files changed, 571 insertions(+), 350 deletions(-) rename common/src/main/java/com/alibaba/nacos/common/trace/{HealthStateChangeReason.java => HealthCheckType.java} (63%) delete mode 100644 common/src/main/java/com/alibaba/nacos/common/trace/event/NamingTraceEvent.java create mode 100644 common/src/main/java/com/alibaba/nacos/common/trace/event/naming/DeregisterInstanceTraceEvent.java create mode 100644 common/src/main/java/com/alibaba/nacos/common/trace/event/naming/DeregisterServiceTraceEvent.java create mode 100644 common/src/main/java/com/alibaba/nacos/common/trace/event/naming/HealthStateChangeTraceEvent.java create mode 100644 common/src/main/java/com/alibaba/nacos/common/trace/event/naming/NamingTraceEvent.java create mode 100644 common/src/main/java/com/alibaba/nacos/common/trace/event/naming/PushServiceTraceEvent.java create mode 100644 common/src/main/java/com/alibaba/nacos/common/trace/event/naming/RegisterInstanceTraceEvent.java create mode 100644 common/src/main/java/com/alibaba/nacos/common/trace/event/naming/RegisterServiceTraceEvent.java create mode 100644 common/src/main/java/com/alibaba/nacos/common/trace/event/naming/SubscribeServiceTraceEvent.java create mode 100644 common/src/main/java/com/alibaba/nacos/common/trace/event/naming/UnsubscribeServiceTraceEvent.java diff --git a/common/src/main/java/com/alibaba/nacos/common/trace/HealthStateChangeReason.java b/common/src/main/java/com/alibaba/nacos/common/trace/HealthCheckType.java similarity index 63% rename from common/src/main/java/com/alibaba/nacos/common/trace/HealthStateChangeReason.java rename to common/src/main/java/com/alibaba/nacos/common/trace/HealthCheckType.java index df6d2668818..1681abb4aa6 100644 --- a/common/src/main/java/com/alibaba/nacos/common/trace/HealthStateChangeReason.java +++ b/common/src/main/java/com/alibaba/nacos/common/trace/HealthCheckType.java @@ -17,26 +17,35 @@ package com.alibaba.nacos.common.trace; /** - * The reasons of health state change. + * The types of health check. * * @author yanda */ - -public enum HealthStateChangeReason { +public enum HealthCheckType { /** * Instance heart beat timeout. */ - HEARTBEAT_TIMEOUT, + CLIENT_BEAT("client_beat"), /** - * Instance heart beat refresh. + * Http health check. */ - HEARTBEAT_REFRESH, + HTTP_HEALTH_CHECK("http"), /** - * Instance health check fail. + * Mysql health check. */ - HEALTH_CHECK_FAIL, + MYSQL_HEALTH_CHECK("mysql"), /** - * Instance health check success. + * Tcp super sense health check . */ - HEALTH_CHECK_SUCCESS; + TCP_SUPER_SENSE("tcp"); + + private String prefix; + + private HealthCheckType(String prefix) { + this.prefix = prefix; + } + + public String getPrefix() { + return prefix; + } } diff --git a/common/src/main/java/com/alibaba/nacos/common/trace/event/NamingTraceEvent.java b/common/src/main/java/com/alibaba/nacos/common/trace/event/NamingTraceEvent.java deleted file mode 100644 index 91b7b5d4539..00000000000 --- a/common/src/main/java/com/alibaba/nacos/common/trace/event/NamingTraceEvent.java +++ /dev/null @@ -1,258 +0,0 @@ -/* - * Copyright 1999-2018 Alibaba Group Holding Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.alibaba.nacos.common.trace.event; - -import com.alibaba.nacos.common.trace.DeregisterInstanceReason; -import com.alibaba.nacos.common.trace.HealthStateChangeReason; - -/** - * Naming trace event. - * - * @author yanda - */ -public class NamingTraceEvent extends TraceEvent { - - private static final long serialVersionUID = 2923077640400851816L; - - public NamingTraceEvent(long eventTime, String serviceNamespace, String serviceGroup, String name) { - super(eventTime, serviceNamespace, serviceGroup, name); - } - - /** - * Naming register instance trace event. - */ - public static class RegisterInstanceTraceEvent extends NamingTraceEvent { - - private static final long serialVersionUID = -8283438151444483864L; - - private final String clientIp; - - private final boolean rpc; - - private final String instanceIp; - - public String getClientIp() { - return clientIp; - } - - public boolean isRpc() { - return rpc; - } - - public String getInstanceIp() { - return instanceIp; - } - - public RegisterInstanceTraceEvent(long eventTime, String clientIp, boolean rpc, String serviceNamespace, - String serviceGroup, String serviceName, String instanceIp) { - super(eventTime, serviceNamespace, serviceGroup, serviceName); - this.clientIp = clientIp; - this.rpc = rpc; - this.instanceIp = instanceIp; - } - } - - /** - * Naming deregister instance trace event. - */ - public static class DeregisterInstanceTraceEvent extends NamingTraceEvent { - - private static final long serialVersionUID = 3850573686472190256L; - - private final String clientIp; - - private final boolean rpc; - - private final String instanceIp; - - public final DeregisterInstanceReason reason; - - public String getClientIp() { - return clientIp; - } - - public boolean isRpc() { - return rpc; - } - - public String getInstanceIp() { - return instanceIp; - } - - public DeregisterInstanceReason getReason() { - return reason; - } - - public DeregisterInstanceTraceEvent(long eventTime, String clientIp, boolean rpc, DeregisterInstanceReason reason, - String serviceNamespace, String serviceGroup, String serviceName, String instanceIp) { - super(eventTime, serviceNamespace, serviceGroup, serviceName); - this.clientIp = clientIp; - this.reason = reason; - this.rpc = rpc; - this.instanceIp = instanceIp; - } - } - - /** - * Naming deregister service trace event. - */ - public static class RegisterServiceTraceEvent extends NamingTraceEvent { - - private static final long serialVersionUID = -8568231862586636388L; - - public RegisterServiceTraceEvent(long eventTime, String serviceNamespace, - String serviceGroup, String serviceName) { - super(eventTime, serviceNamespace, serviceGroup, serviceName); - } - } - - /** - * Naming deregister service trace event. - */ - public static class DeregisterServiceTraceEvent extends NamingTraceEvent { - - private static final long serialVersionUID = 7358195336881398548L; - - public DeregisterServiceTraceEvent(long eventTime, String serviceNamespace, - String serviceGroup, String serviceName) { - super(eventTime, serviceNamespace, serviceGroup, serviceName); - } - } - - /** - * Naming subscribe service trace event. - */ - public static class SubscribeServiceTraceEvent extends NamingTraceEvent { - - private static final long serialVersionUID = -8856834879168816801L; - - private final String clientIp; - - public String getClientIp() { - return clientIp; - } - - public SubscribeServiceTraceEvent(long eventTime, String clientIp, String serviceNamespace, - String serviceGroup, String serviceName) { - super(eventTime, serviceNamespace, serviceGroup, serviceName); - this.clientIp = clientIp; - } - } - - /** - * Naming unsubscribe service trace event. - */ - public static class UnsubscribeServiceTraceEvent extends NamingTraceEvent { - - private static final long serialVersionUID = -7461808613817897106L; - - private final String clientIp; - - public String getClientIp() { - return clientIp; - } - - public UnsubscribeServiceTraceEvent(long eventTime, String clientIp, String serviceNamespace, - String serviceGroup, String serviceName) { - super(eventTime, serviceNamespace, serviceGroup, serviceName); - this.clientIp = clientIp; - } - } - - /** - * Naming push service trace event. - */ - public static class PushServiceTraceEvent extends NamingTraceEvent { - - private static final long serialVersionUID = 787915741281241877L; - - private final String clientIp; - - private final int instanceSize; - - private final long pushCostTimeForNetWork; - - private final long pushCostTimeForAll; - - private final long serviceLevelAgreementTime; - - public String getClientIp() { - return clientIp; - } - - public int getInstanceSize() { - return instanceSize; - } - - public long getPushCostTimeForNetWork() { - return pushCostTimeForNetWork; - } - - public long getPushCostTimeForAll() { - return pushCostTimeForAll; - } - - public long getServiceLevelAgreementTime() { - return serviceLevelAgreementTime; - } - - public PushServiceTraceEvent(long eventTime, long pushCostTimeForNetWork, long pushCostTimeForAll, - long serviceLevelAgreementTime, String clientIp, String serviceNamespace, - String serviceGroup, String serviceName, int instanceSize) { - super(eventTime, serviceNamespace, serviceGroup, serviceName); - this.clientIp = clientIp; - this.instanceSize = instanceSize; - this.pushCostTimeForAll = pushCostTimeForAll; - this.pushCostTimeForNetWork = pushCostTimeForNetWork; - this.serviceLevelAgreementTime = serviceLevelAgreementTime; - } - } - - /** - * Naming instance http heartbeat timeout trace event. - */ - public static class HealthStateChangeTraceEvent extends NamingTraceEvent { - - private static final long serialVersionUID = 6966396191118694597L; - - private final String instanceIp; - - private boolean isHealthy; - - private HealthStateChangeReason reason; - - public String getInstanceIp() { - return instanceIp; - } - - public boolean isHealthy() { - return isHealthy; - } - - public HealthStateChangeReason getReason() { - return reason; - } - - public HealthStateChangeTraceEvent(long eventTime, String serviceNamespace, String serviceGroup, - String serviceName, String instanceIp, boolean isHealthy, HealthStateChangeReason reason) { - super(eventTime, serviceNamespace, serviceGroup, serviceName); - this.instanceIp = instanceIp; - this.isHealthy = isHealthy; - this.reason = reason; - } - } -} diff --git a/common/src/main/java/com/alibaba/nacos/common/trace/event/TraceEvent.java b/common/src/main/java/com/alibaba/nacos/common/trace/event/TraceEvent.java index c5a47444afa..9d216ce2432 100644 --- a/common/src/main/java/com/alibaba/nacos/common/trace/event/TraceEvent.java +++ b/common/src/main/java/com/alibaba/nacos/common/trace/event/TraceEvent.java @@ -24,6 +24,8 @@ * @author yanda */ public class TraceEvent extends Event { + private String type; + private final long eventTime; private final String namespace; @@ -32,6 +34,10 @@ public class TraceEvent extends Event { private final String name; + public String getType() { + return type; + } + public long getEventTime() { return eventTime; } @@ -48,7 +54,8 @@ public String getName() { return name; } - public TraceEvent(long eventTime, String namespace, String group, String name) { + public TraceEvent(String eventType, long eventTime, String namespace, String group, String name) { + this.type = eventType; this.eventTime = eventTime; this.namespace = namespace; this.group = group; diff --git a/common/src/main/java/com/alibaba/nacos/common/trace/event/naming/DeregisterInstanceTraceEvent.java b/common/src/main/java/com/alibaba/nacos/common/trace/event/naming/DeregisterInstanceTraceEvent.java new file mode 100644 index 00000000000..8386d4b5e1b --- /dev/null +++ b/common/src/main/java/com/alibaba/nacos/common/trace/event/naming/DeregisterInstanceTraceEvent.java @@ -0,0 +1,72 @@ +/* + * Copyright 1999-2018 Alibaba Group Holding Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.alibaba.nacos.common.trace.event.naming; + +import com.alibaba.nacos.common.trace.DeregisterInstanceReason; + +/** + * Naming deregister instance trace event. + * @author yanda + */ +public class DeregisterInstanceTraceEvent extends NamingTraceEvent { + + private static final long serialVersionUID = 3850573686472190256L; + + private final String clientIp; + + private final boolean rpc; + + private String instanceIp; + + private int instancePort; + + public final DeregisterInstanceReason reason; + + public String getClientIp() { + return clientIp; + } + + public boolean isRpc() { + return rpc; + } + + public String getIp() { + return instanceIp; + } + + public int getPort() { + return instancePort; + } + + public String toInetAddr() { + return instanceIp + ":" + instancePort; + } + + public DeregisterInstanceReason getReason() { + return reason; + } + + public DeregisterInstanceTraceEvent(long eventTime, String clientIp, boolean rpc, DeregisterInstanceReason reason, + String serviceNamespace, String serviceGroup, String serviceName, String instanceIp, int instancePort) { + super("DEREGISTER_INSTANCE_TRACE_EVENT", eventTime, serviceNamespace, serviceGroup, serviceName); + this.clientIp = clientIp; + this.reason = reason; + this.rpc = rpc; + this.instanceIp = instanceIp; + this.instancePort = instancePort; + } +} diff --git a/common/src/main/java/com/alibaba/nacos/common/trace/event/naming/DeregisterServiceTraceEvent.java b/common/src/main/java/com/alibaba/nacos/common/trace/event/naming/DeregisterServiceTraceEvent.java new file mode 100644 index 00000000000..617c97d7a0b --- /dev/null +++ b/common/src/main/java/com/alibaba/nacos/common/trace/event/naming/DeregisterServiceTraceEvent.java @@ -0,0 +1,31 @@ +/* + * Copyright 1999-2018 Alibaba Group Holding Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.alibaba.nacos.common.trace.event.naming; + +/** + * Naming deregister service trace event. + * @author yanda + */ +public class DeregisterServiceTraceEvent extends NamingTraceEvent { + + private static final long serialVersionUID = 7358195336881398548L; + + public DeregisterServiceTraceEvent(long eventTime, String serviceNamespace, + String serviceGroup, String serviceName) { + super("DEREGISTER_SERVICE_TRACE_EVENT", eventTime, serviceNamespace, serviceGroup, serviceName); + } +} diff --git a/common/src/main/java/com/alibaba/nacos/common/trace/event/naming/HealthStateChangeTraceEvent.java b/common/src/main/java/com/alibaba/nacos/common/trace/event/naming/HealthStateChangeTraceEvent.java new file mode 100644 index 00000000000..b77c11a6e6c --- /dev/null +++ b/common/src/main/java/com/alibaba/nacos/common/trace/event/naming/HealthStateChangeTraceEvent.java @@ -0,0 +1,79 @@ +/* + * Copyright 1999-2018 Alibaba Group Holding Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.alibaba.nacos.common.trace.event.naming; + +import com.alibaba.nacos.common.trace.HealthCheckType; + +/** + * Naming instance health state change trace event. + * @author yanda + */ +public class HealthStateChangeTraceEvent extends NamingTraceEvent { + + private static final long serialVersionUID = 6966396191118694597L; + + private String instanceIp; + + private int instancePort; + + private boolean isHealthy; + + private HealthCheckType healthCheckType; + + private String healthStateChangeReason; + + public String getIp() { + return instanceIp; + } + + public int getPort() { + return instancePort; + } + + public String toInetAddr() { + return instanceIp + ":" + instancePort; + } + + public boolean isHealthy() { + return isHealthy; + } + + public HealthCheckType getHealthCheckType() { + return healthCheckType; + } + + public HealthStateChangeTraceEvent(long eventTime, String serviceNamespace, String serviceGroup, + String serviceName, String instanceIp, int instancePort, boolean isHealthy, String healthStateChangeReason) { + super("HEALTH_STATE_CHANGE_TRACE_EVENT", eventTime, serviceNamespace, serviceGroup, serviceName); + this.instanceIp = instanceIp; + this.instancePort = instancePort; + this.isHealthy = isHealthy; + this.healthCheckType = getHealthCheckTypeFromReason(healthStateChangeReason); + this.healthStateChangeReason = healthStateChangeReason; + } + + public HealthCheckType getHealthCheckTypeFromReason(String reason) { + if (reason.startsWith(HealthCheckType.HTTP_HEALTH_CHECK.getPrefix())) { + return HealthCheckType.HTTP_HEALTH_CHECK; + } else if (reason.startsWith(HealthCheckType.TCP_SUPER_SENSE.getPrefix())) { + return HealthCheckType.TCP_SUPER_SENSE; + } else if (reason.startsWith(HealthCheckType.MYSQL_HEALTH_CHECK.getPrefix())) { + return HealthCheckType.MYSQL_HEALTH_CHECK; + } + return HealthCheckType.CLIENT_BEAT; + } +} diff --git a/common/src/main/java/com/alibaba/nacos/common/trace/event/naming/NamingTraceEvent.java b/common/src/main/java/com/alibaba/nacos/common/trace/event/naming/NamingTraceEvent.java new file mode 100644 index 00000000000..ca195d811c4 --- /dev/null +++ b/common/src/main/java/com/alibaba/nacos/common/trace/event/naming/NamingTraceEvent.java @@ -0,0 +1,34 @@ +/* + * Copyright 1999-2018 Alibaba Group Holding Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.alibaba.nacos.common.trace.event.naming; + +import com.alibaba.nacos.common.trace.event.TraceEvent; + +/** + * Naming trace event. + * + * @author yanda + */ +public class NamingTraceEvent extends TraceEvent { + + private static final long serialVersionUID = 2923077640400851816L; + + public NamingTraceEvent(String eventType, long eventTime, + String serviceNamespace, String serviceGroup, String name) { + super(eventType, eventTime, serviceNamespace, serviceGroup, name); + } +} diff --git a/common/src/main/java/com/alibaba/nacos/common/trace/event/naming/PushServiceTraceEvent.java b/common/src/main/java/com/alibaba/nacos/common/trace/event/naming/PushServiceTraceEvent.java new file mode 100644 index 00000000000..aca60c172f8 --- /dev/null +++ b/common/src/main/java/com/alibaba/nacos/common/trace/event/naming/PushServiceTraceEvent.java @@ -0,0 +1,67 @@ +/* + * Copyright 1999-2018 Alibaba Group Holding Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.alibaba.nacos.common.trace.event.naming; + +/** + * Naming push service trace event. + * @author yanda + */ +public class PushServiceTraceEvent extends NamingTraceEvent { + + private static final long serialVersionUID = 787915741281241877L; + + private final String clientIp; + + private final int instanceSize; + + private final long pushCostTimeForNetWork; + + private final long pushCostTimeForAll; + + private final long serviceLevelAgreementTime; + + public String getClientIp() { + return clientIp; + } + + public int getInstanceSize() { + return instanceSize; + } + + public long getPushCostTimeForNetWork() { + return pushCostTimeForNetWork; + } + + public long getPushCostTimeForAll() { + return pushCostTimeForAll; + } + + public long getServiceLevelAgreementTime() { + return serviceLevelAgreementTime; + } + + public PushServiceTraceEvent(long eventTime, long pushCostTimeForNetWork, long pushCostTimeForAll, + long serviceLevelAgreementTime, String clientIp, String serviceNamespace, + String serviceGroup, String serviceName, int instanceSize) { + super("PUSH_SERVICE_TRACE_EVENT", eventTime, serviceNamespace, serviceGroup, serviceName); + this.clientIp = clientIp; + this.instanceSize = instanceSize; + this.pushCostTimeForAll = pushCostTimeForAll; + this.pushCostTimeForNetWork = pushCostTimeForNetWork; + this.serviceLevelAgreementTime = serviceLevelAgreementTime; + } +} diff --git a/common/src/main/java/com/alibaba/nacos/common/trace/event/naming/RegisterInstanceTraceEvent.java b/common/src/main/java/com/alibaba/nacos/common/trace/event/naming/RegisterInstanceTraceEvent.java new file mode 100644 index 00000000000..37bf440ae2d --- /dev/null +++ b/common/src/main/java/com/alibaba/nacos/common/trace/event/naming/RegisterInstanceTraceEvent.java @@ -0,0 +1,63 @@ +/* + * Copyright 1999-2018 Alibaba Group Holding Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.alibaba.nacos.common.trace.event.naming; + +/** + * Naming register instance trace event. + * @author yanda + */ +public class RegisterInstanceTraceEvent extends NamingTraceEvent { + + private static final long serialVersionUID = -8283438151444483864L; + + private final String clientIp; + + private final boolean rpc; + + private String instanceIp; + + private int instancePort; + + public String getClientIp() { + return clientIp; + } + + public boolean isRpc() { + return rpc; + } + + public String getInstanceIp() { + return instanceIp; + } + + public int getPort() { + return instancePort; + } + + public String toInetAddr() { + return instanceIp + ":" + instancePort; + } + + public RegisterInstanceTraceEvent(long eventTime, String clientIp, boolean rpc, String serviceNamespace, + String serviceGroup, String serviceName, String instanceIp, int instancePort) { + super("REGISTER_INSTANCE_TRACE_EVENT", eventTime, serviceNamespace, serviceGroup, serviceName); + this.clientIp = clientIp; + this.rpc = rpc; + this.instanceIp = instanceIp; + this.instancePort = instancePort; + } +} \ No newline at end of file diff --git a/common/src/main/java/com/alibaba/nacos/common/trace/event/naming/RegisterServiceTraceEvent.java b/common/src/main/java/com/alibaba/nacos/common/trace/event/naming/RegisterServiceTraceEvent.java new file mode 100644 index 00000000000..c123f65168c --- /dev/null +++ b/common/src/main/java/com/alibaba/nacos/common/trace/event/naming/RegisterServiceTraceEvent.java @@ -0,0 +1,31 @@ +/* + * Copyright 1999-2018 Alibaba Group Holding Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.alibaba.nacos.common.trace.event.naming; + +/** + * Naming deregister service trace event. + * @author yanda + */ +public class RegisterServiceTraceEvent extends NamingTraceEvent { + + private static final long serialVersionUID = -8568231862586636388L; + + public RegisterServiceTraceEvent(long eventTime, String serviceNamespace, + String serviceGroup, String serviceName) { + super("REGISTER_SERVICE_TRACE_EVENT", eventTime, serviceNamespace, serviceGroup, serviceName); + } +} diff --git a/common/src/main/java/com/alibaba/nacos/common/trace/event/naming/SubscribeServiceTraceEvent.java b/common/src/main/java/com/alibaba/nacos/common/trace/event/naming/SubscribeServiceTraceEvent.java new file mode 100644 index 00000000000..a8c987cb866 --- /dev/null +++ b/common/src/main/java/com/alibaba/nacos/common/trace/event/naming/SubscribeServiceTraceEvent.java @@ -0,0 +1,38 @@ +/* + * Copyright 1999-2018 Alibaba Group Holding Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.alibaba.nacos.common.trace.event.naming; + +/** + * Naming subscribe service trace event. + * @author yanda + */ +public class SubscribeServiceTraceEvent extends NamingTraceEvent { + + private static final long serialVersionUID = -8856834879168816801L; + + private final String clientIp; + + public String getClientIp() { + return clientIp; + } + + public SubscribeServiceTraceEvent(long eventTime, String clientIp, String serviceNamespace, + String serviceGroup, String serviceName) { + super("SUBSCRIBE_SERVICE_TRACE_EVENT", eventTime, serviceNamespace, serviceGroup, serviceName); + this.clientIp = clientIp; + } +} diff --git a/common/src/main/java/com/alibaba/nacos/common/trace/event/naming/UnsubscribeServiceTraceEvent.java b/common/src/main/java/com/alibaba/nacos/common/trace/event/naming/UnsubscribeServiceTraceEvent.java new file mode 100644 index 00000000000..0fc195dfd5e --- /dev/null +++ b/common/src/main/java/com/alibaba/nacos/common/trace/event/naming/UnsubscribeServiceTraceEvent.java @@ -0,0 +1,38 @@ +/* + * Copyright 1999-2018 Alibaba Group Holding Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.alibaba.nacos.common.trace.event.naming; + +/** + * Naming unsubscribe service trace event. + * @author yanda + */ +public class UnsubscribeServiceTraceEvent extends NamingTraceEvent { + + private static final long serialVersionUID = -7461808613817897106L; + + private final String clientIp; + + public String getClientIp() { + return clientIp; + } + + public UnsubscribeServiceTraceEvent(long eventTime, String clientIp, String serviceNamespace, + String serviceGroup, String serviceName) { + super("UNSUBSCRIBE_SERVICE_TRACE_EVENT", eventTime, serviceNamespace, serviceGroup, serviceName); + this.clientIp = clientIp; + } +} diff --git a/common/src/main/java/com/alibaba/nacos/common/trace/publisher/TraceEventPublisher.java b/common/src/main/java/com/alibaba/nacos/common/trace/publisher/TraceEventPublisher.java index 4818278de60..cb89af38d85 100644 --- a/common/src/main/java/com/alibaba/nacos/common/trace/publisher/TraceEventPublisher.java +++ b/common/src/main/java/com/alibaba/nacos/common/trace/publisher/TraceEventPublisher.java @@ -102,8 +102,7 @@ public boolean publish(Event event) { checkIsStart(); boolean success = this.queue.offer(event); if (!success) { - LOGGER.warn("Unable to plug in due to interruption, synchronize sending time, event : {}", event); - handleEvent(event); + LOGGER.warn("Trace Event Publish failed, event : {}, publish queue size : {}", event, currentEventSize()); return true; } return true; diff --git a/common/src/main/java/com/alibaba/nacos/common/trace/publisher/TraceEventPublisherFactory.java b/common/src/main/java/com/alibaba/nacos/common/trace/publisher/TraceEventPublisherFactory.java index 9ffcab72cc8..5bf18e74268 100644 --- a/common/src/main/java/com/alibaba/nacos/common/trace/publisher/TraceEventPublisherFactory.java +++ b/common/src/main/java/com/alibaba/nacos/common/trace/publisher/TraceEventPublisherFactory.java @@ -19,8 +19,11 @@ import com.alibaba.nacos.common.notify.Event; import com.alibaba.nacos.common.notify.EventPublisher; import com.alibaba.nacos.common.notify.EventPublisherFactory; +import com.alibaba.nacos.common.trace.event.TraceEvent; +import com.alibaba.nacos.common.utils.ConcurrentHashSet; import java.util.Map; +import java.util.Set; import java.util.concurrent.ConcurrentHashMap; /** @@ -33,9 +36,12 @@ public class TraceEventPublisherFactory implements EventPublisherFactory { private static final TraceEventPublisherFactory INSTANCE = new TraceEventPublisherFactory(); private final Map, TraceEventPublisher> publisher; + + private final Set> publisherEvents; private TraceEventPublisherFactory() { publisher = new ConcurrentHashMap<>(); + publisherEvents = new ConcurrentHashSet<>(); } public static TraceEventPublisherFactory getInstance() { @@ -45,8 +51,15 @@ public static TraceEventPublisherFactory getInstance() { @Override public EventPublisher apply(final Class eventType, final Integer maxQueueSize) { // Like ClientEvent$ClientChangeEvent cache by ClientEvent - Class cachedEventType = - eventType.isMemberClass() ? (Class) eventType.getEnclosingClass() : eventType; + Class cachedEventType = TraceEvent.class; + + for (Class publisherEvent : publisherEvents) { + if (publisherEvent.isAssignableFrom(eventType)) { + cachedEventType = publisherEvent; + break; + } + } + publisher.computeIfAbsent(cachedEventType, eventClass -> { TraceEventPublisher result = new TraceEventPublisher(); result.init(eventClass, maxQueueSize); @@ -62,4 +75,8 @@ public String getAllPublisherStatues() { } return result.toString(); } + + public void addPublisherEvent(Class event) { + this.publisherEvents.add(event); + } } diff --git a/common/src/test/java/com/alibaba/nacos/common/trace/publisher/TraceEventPublisherFactoryTest.java b/common/src/test/java/com/alibaba/nacos/common/trace/publisher/TraceEventPublisherFactoryTest.java index 6041642ab63..d228a496053 100644 --- a/common/src/test/java/com/alibaba/nacos/common/trace/publisher/TraceEventPublisherFactoryTest.java +++ b/common/src/test/java/com/alibaba/nacos/common/trace/publisher/TraceEventPublisherFactoryTest.java @@ -56,7 +56,7 @@ public void testApply() { TraceEventPublisherFactory.getInstance().apply(TraceTestEvent.TraceTestEvent2.class, Byte.SIZE); TraceEventPublisherFactory.getInstance().apply(TraceTestEvent.class, Byte.SIZE); String expectedStatus = "Trace event publisher statues:\n" - + "\tPublisher TraceTestEvent : shutdown=false, queue= 0/8 \n"; + + "\tPublisher TraceEvent : shutdown=false, queue= 0/8 \n"; assertThat(TraceEventPublisherFactory.getInstance().getAllPublisherStatues(), is(expectedStatus)); } } diff --git a/common/src/test/java/com/alibaba/nacos/common/trace/publisher/TraceEventPublisherTest.java b/common/src/test/java/com/alibaba/nacos/common/trace/publisher/TraceEventPublisherTest.java index d933eb745f0..39a515d7192 100644 --- a/common/src/test/java/com/alibaba/nacos/common/trace/publisher/TraceEventPublisherTest.java +++ b/common/src/test/java/com/alibaba/nacos/common/trace/publisher/TraceEventPublisherTest.java @@ -84,17 +84,6 @@ public void testRemoveSubscriber() { verify(smartSubscriber, never()).onEvent(traceTestEvent1); } - @Test - public void testPublishOverFlow() { - TraceTestEvent testEvent = new TraceTestEvent(); - for (int i = 0; i < Byte.SIZE; i++) { - traceEventPublisher.publish(testEvent); - } - traceEventPublisher.addSubscriber(subscriber, TraceTestEvent.class); - traceEventPublisher.publish(testEvent); - verify(subscriber).onEvent(testEvent); - } - @Test public void getStatus() throws NacosException { traceEventPublisher.publish(new TraceTestEvent()); diff --git a/naming/src/main/java/com/alibaba/nacos/naming/controllers/InstanceController.java b/naming/src/main/java/com/alibaba/nacos/naming/controllers/InstanceController.java index 39a1199fe84..a40723ceab8 100644 --- a/naming/src/main/java/com/alibaba/nacos/naming/controllers/InstanceController.java +++ b/naming/src/main/java/com/alibaba/nacos/naming/controllers/InstanceController.java @@ -25,7 +25,8 @@ import com.alibaba.nacos.common.notify.NotifyCenter; import com.alibaba.nacos.common.spi.NacosServiceLoader; import com.alibaba.nacos.common.trace.DeregisterInstanceReason; -import com.alibaba.nacos.common.trace.event.NamingTraceEvent; +import com.alibaba.nacos.common.trace.event.naming.DeregisterInstanceTraceEvent; +import com.alibaba.nacos.common.trace.event.naming.RegisterInstanceTraceEvent; import com.alibaba.nacos.common.utils.ConvertUtils; import com.alibaba.nacos.common.utils.JacksonUtils; import com.alibaba.nacos.common.utils.StringUtils; @@ -118,9 +119,9 @@ public String register(HttpServletRequest request) throws Exception { .setDefaultInstanceEphemeral(switchDomain.isDefaultInstanceEphemeral()).setRequest(request).build(); getInstanceOperator().registerInstance(namespaceId, serviceName, instance); - NotifyCenter.publishEvent(new NamingTraceEvent.RegisterInstanceTraceEvent(System.currentTimeMillis(), "", + NotifyCenter.publishEvent(new RegisterInstanceTraceEvent(System.currentTimeMillis(), "", false, namespaceId, NamingUtils.getGroupName(serviceName), NamingUtils.getServiceName(serviceName), - instance.toInetAddr())); + instance.getIp(), instance.getPort())); return "ok"; } @@ -142,9 +143,9 @@ public String deregister(HttpServletRequest request) throws Exception { NamingUtils.checkServiceNameFormat(serviceName); getInstanceOperator().removeInstance(namespaceId, serviceName, instance); - NotifyCenter.publishEvent(new NamingTraceEvent.DeregisterInstanceTraceEvent(System.currentTimeMillis(), "", - false, DeregisterInstanceReason.REQUEST, namespaceId, NamingUtils.getGroupName(serviceName), NamingUtils.getServiceName(serviceName), - instance.toInetAddr())); + NotifyCenter.publishEvent(new DeregisterInstanceTraceEvent(System.currentTimeMillis(), "", + false, DeregisterInstanceReason.REQUEST, namespaceId, NamingUtils.getGroupName(serviceName), + NamingUtils.getServiceName(serviceName), instance.getIp(), instance.getPort())); return "ok"; } diff --git a/naming/src/main/java/com/alibaba/nacos/naming/controllers/InstanceControllerV2.java b/naming/src/main/java/com/alibaba/nacos/naming/controllers/InstanceControllerV2.java index c76dc91471e..c09f11f5515 100644 --- a/naming/src/main/java/com/alibaba/nacos/naming/controllers/InstanceControllerV2.java +++ b/naming/src/main/java/com/alibaba/nacos/naming/controllers/InstanceControllerV2.java @@ -25,7 +25,8 @@ import com.alibaba.nacos.auth.annotation.Secured; import com.alibaba.nacos.common.notify.NotifyCenter; import com.alibaba.nacos.common.trace.DeregisterInstanceReason; -import com.alibaba.nacos.common.trace.event.NamingTraceEvent; +import com.alibaba.nacos.common.trace.event.naming.DeregisterInstanceTraceEvent; +import com.alibaba.nacos.common.trace.event.naming.RegisterInstanceTraceEvent; import com.alibaba.nacos.common.utils.JacksonUtils; import com.alibaba.nacos.common.utils.StringUtils; import com.alibaba.nacos.core.utils.WebUtils; @@ -113,9 +114,9 @@ public String register(@RequestParam(defaultValue = Constants.DEFAULT_NAMESPACE_ instance.setEphemeral((switchDomain.isDefaultInstanceEphemeral())); } instanceServiceV2.registerInstance(namespaceId, serviceName, instance); - NotifyCenter.publishEvent(new NamingTraceEvent.RegisterInstanceTraceEvent(System.currentTimeMillis(), "", + NotifyCenter.publishEvent(new RegisterInstanceTraceEvent(System.currentTimeMillis(), "", false, namespaceId, NamingUtils.getGroupName(serviceName), NamingUtils.getServiceName(serviceName), - instance.toInetAddr())); + instance.getIp(), instance.getPort())); return "ok"; } @@ -154,9 +155,9 @@ public String deregister(@RequestParam(defaultValue = Constants.DEFAULT_NAMESPAC } instanceServiceV2.removeInstance(namespaceId, serviceName, instance); - NotifyCenter.publishEvent(new NamingTraceEvent.DeregisterInstanceTraceEvent(System.currentTimeMillis(), "", + NotifyCenter.publishEvent(new DeregisterInstanceTraceEvent(System.currentTimeMillis(), "", false, DeregisterInstanceReason.REQUEST, namespaceId, NamingUtils.getGroupName(serviceName), NamingUtils.getServiceName(serviceName), - instance.toInetAddr())); + instance.getIp(), instance.getPort())); return "ok"; } diff --git a/naming/src/main/java/com/alibaba/nacos/naming/controllers/ServiceController.java b/naming/src/main/java/com/alibaba/nacos/naming/controllers/ServiceController.java index b1dc2ebfaa7..6500c3152d4 100644 --- a/naming/src/main/java/com/alibaba/nacos/naming/controllers/ServiceController.java +++ b/naming/src/main/java/com/alibaba/nacos/naming/controllers/ServiceController.java @@ -25,7 +25,8 @@ import com.alibaba.nacos.common.model.RestResult; import com.alibaba.nacos.common.model.RestResultUtils; import com.alibaba.nacos.common.notify.NotifyCenter; -import com.alibaba.nacos.common.trace.event.NamingTraceEvent; +import com.alibaba.nacos.common.trace.event.naming.DeregisterServiceTraceEvent; +import com.alibaba.nacos.common.trace.event.naming.RegisterServiceTraceEvent; import com.alibaba.nacos.common.utils.IoUtils; import com.alibaba.nacos.common.utils.JacksonUtils; import com.alibaba.nacos.common.utils.NumberUtils; @@ -121,7 +122,7 @@ public String create(@RequestParam(defaultValue = Constants.DEFAULT_NAMESPACE_ID serviceMetadata.setExtendData(UtilsAndCommons.parseMetadata(metadata)); serviceMetadata.setEphemeral(false); getServiceOperator().create(namespaceId, serviceName, serviceMetadata); - NotifyCenter.publishEvent(new NamingTraceEvent.RegisterServiceTraceEvent(System.currentTimeMillis(), + NotifyCenter.publishEvent(new RegisterServiceTraceEvent(System.currentTimeMillis(), namespaceId, NamingUtils.getGroupName(serviceName), NamingUtils.getServiceName(serviceName))); return "ok"; } @@ -140,7 +141,7 @@ public String remove(@RequestParam(defaultValue = Constants.DEFAULT_NAMESPACE_ID @RequestParam String serviceName) throws Exception { getServiceOperator().delete(namespaceId, serviceName); - NotifyCenter.publishEvent(new NamingTraceEvent.DeregisterServiceTraceEvent(System.currentTimeMillis(), + NotifyCenter.publishEvent(new DeregisterServiceTraceEvent(System.currentTimeMillis(), namespaceId, "", serviceName)); return "ok"; } diff --git a/naming/src/main/java/com/alibaba/nacos/naming/controllers/ServiceControllerV2.java b/naming/src/main/java/com/alibaba/nacos/naming/controllers/ServiceControllerV2.java index b69c7e7b4d7..11bc1d68f30 100644 --- a/naming/src/main/java/com/alibaba/nacos/naming/controllers/ServiceControllerV2.java +++ b/naming/src/main/java/com/alibaba/nacos/naming/controllers/ServiceControllerV2.java @@ -25,7 +25,8 @@ import com.alibaba.nacos.common.model.RestResult; import com.alibaba.nacos.common.model.RestResultUtils; import com.alibaba.nacos.common.notify.NotifyCenter; -import com.alibaba.nacos.common.trace.event.NamingTraceEvent; +import com.alibaba.nacos.common.trace.event.naming.DeregisterServiceTraceEvent; +import com.alibaba.nacos.common.trace.event.naming.RegisterServiceTraceEvent; import com.alibaba.nacos.common.utils.JacksonUtils; import com.alibaba.nacos.common.utils.NumberUtils; import com.alibaba.nacos.common.utils.StringUtils; @@ -100,7 +101,7 @@ public RestResult create(@RequestParam(defaultValue = Constants.DEFAULT_ serviceMetadata.setExtendData(UtilsAndCommons.parseMetadata(metadata)); serviceMetadata.setEphemeral(ephemeral); serviceOperatorV2.create(Service.newService(namespaceId, groupName, serviceName, ephemeral), serviceMetadata); - NotifyCenter.publishEvent(new NamingTraceEvent.RegisterServiceTraceEvent(System.currentTimeMillis(), + NotifyCenter.publishEvent(new RegisterServiceTraceEvent(System.currentTimeMillis(), namespaceId, groupName, serviceName)); return RestResultUtils.success("ok"); } @@ -119,7 +120,7 @@ public RestResult remove(@RequestParam(defaultValue = Constants.DEFAULT_ @PathVariable String serviceName, @RequestParam(defaultValue = Constants.DEFAULT_GROUP) String groupName) throws Exception { serviceOperatorV2.delete(Service.newService(namespaceId, groupName, serviceName)); - NotifyCenter.publishEvent(new NamingTraceEvent.DeregisterServiceTraceEvent(System.currentTimeMillis(), + NotifyCenter.publishEvent(new DeregisterServiceTraceEvent(System.currentTimeMillis(), namespaceId, groupName, serviceName)); return RestResultUtils.success("ok"); } diff --git a/naming/src/main/java/com/alibaba/nacos/naming/core/v2/index/ClientServiceIndexesManager.java b/naming/src/main/java/com/alibaba/nacos/naming/core/v2/index/ClientServiceIndexesManager.java index b09a9058e0c..65b283ba44c 100644 --- a/naming/src/main/java/com/alibaba/nacos/naming/core/v2/index/ClientServiceIndexesManager.java +++ b/naming/src/main/java/com/alibaba/nacos/naming/core/v2/index/ClientServiceIndexesManager.java @@ -20,13 +20,14 @@ import com.alibaba.nacos.common.notify.NotifyCenter; import com.alibaba.nacos.common.notify.listener.SmartSubscriber; import com.alibaba.nacos.common.trace.DeregisterInstanceReason; -import com.alibaba.nacos.common.trace.event.NamingTraceEvent; +import com.alibaba.nacos.common.trace.event.naming.DeregisterInstanceTraceEvent; import com.alibaba.nacos.common.utils.ConcurrentHashSet; import com.alibaba.nacos.naming.core.v2.client.Client; import com.alibaba.nacos.naming.core.v2.event.client.ClientEvent; import com.alibaba.nacos.naming.core.v2.event.client.ClientOperationEvent; import com.alibaba.nacos.naming.core.v2.event.publisher.NamingEventPublisherFactory; import com.alibaba.nacos.naming.core.v2.event.service.ServiceEvent; +import com.alibaba.nacos.naming.core.v2.pojo.InstancePublishInfo; import com.alibaba.nacos.naming.core.v2.pojo.Service; import org.springframework.stereotype.Component; @@ -106,9 +107,10 @@ private void handleClientDisconnect(ClientEvent.ClientDisconnectEvent event) { long currentTimeMillis = System.currentTimeMillis(); for (Service each : client.getAllPublishedService()) { removePublisherIndexes(each, client.getClientId()); - NotifyCenter.publishEvent(new NamingTraceEvent.DeregisterInstanceTraceEvent(currentTimeMillis, - "", false, reason, each.getNamespace(), each.getGroup(), - each.getName(), client.getInstancePublishInfo(each).getIp())); + InstancePublishInfo instance = client.getInstancePublishInfo(each); + NotifyCenter.publishEvent(new DeregisterInstanceTraceEvent(currentTimeMillis, + "", false, reason, each.getNamespace(), each.getGroup(), each.getName(), + instance.getIp(), instance.getPort())); } } diff --git a/naming/src/main/java/com/alibaba/nacos/naming/healthcheck/ClientBeatProcessor.java b/naming/src/main/java/com/alibaba/nacos/naming/healthcheck/ClientBeatProcessor.java index 8b13885774d..f2b7592ea01 100644 --- a/naming/src/main/java/com/alibaba/nacos/naming/healthcheck/ClientBeatProcessor.java +++ b/naming/src/main/java/com/alibaba/nacos/naming/healthcheck/ClientBeatProcessor.java @@ -17,8 +17,7 @@ package com.alibaba.nacos.naming.healthcheck; import com.alibaba.nacos.common.notify.NotifyCenter; -import com.alibaba.nacos.common.trace.HealthStateChangeReason; -import com.alibaba.nacos.common.trace.event.NamingTraceEvent; +import com.alibaba.nacos.common.trace.event.naming.HealthStateChangeTraceEvent; import com.alibaba.nacos.naming.healthcheck.heartbeat.BeatProcessor; import com.alibaba.nacos.sys.utils.ApplicationUtils; import com.alibaba.nacos.naming.core.Cluster; @@ -89,9 +88,9 @@ public void run() { cluster.getService().getName(), ip, port, cluster.getName(), UtilsAndCommons.LOCALHOST_SITE); getPushService().serviceChanged(service); - NotifyCenter.publishEvent(new NamingTraceEvent.HealthStateChangeTraceEvent(System.currentTimeMillis(), + NotifyCenter.publishEvent(new HealthStateChangeTraceEvent(System.currentTimeMillis(), service.getNamespaceId(), service.getGroupName(), service.getName(), instance.getIp(), - true, HealthStateChangeReason.HEARTBEAT_REFRESH)); + instance.getPort(), true, "client_beat")); } } } diff --git a/naming/src/main/java/com/alibaba/nacos/naming/healthcheck/HealthCheckCommon.java b/naming/src/main/java/com/alibaba/nacos/naming/healthcheck/HealthCheckCommon.java index 90f51f67110..56226d9dbcd 100644 --- a/naming/src/main/java/com/alibaba/nacos/naming/healthcheck/HealthCheckCommon.java +++ b/naming/src/main/java/com/alibaba/nacos/naming/healthcheck/HealthCheckCommon.java @@ -17,8 +17,7 @@ package com.alibaba.nacos.naming.healthcheck; import com.alibaba.nacos.common.notify.NotifyCenter; -import com.alibaba.nacos.common.trace.HealthStateChangeReason; -import com.alibaba.nacos.common.trace.event.NamingTraceEvent; +import com.alibaba.nacos.common.trace.event.naming.HealthStateChangeTraceEvent; import com.alibaba.nacos.naming.core.Cluster; import com.alibaba.nacos.naming.core.DistroMapper; import com.alibaba.nacos.naming.core.Instance; @@ -104,9 +103,9 @@ public void checkOK(Instance ip, HealthCheckTask task, String msg) { Loggers.EVT_LOG.info("serviceName: {} {POS} {IP-ENABLED} valid: {}:{}@{}, region: {}, msg: {}", cluster.getService().getName(), ip.getIp(), ip.getPort(), cluster.getName(), UtilsAndCommons.LOCALHOST_SITE, msg); - NotifyCenter.publishEvent(new NamingTraceEvent.HealthStateChangeTraceEvent(System.currentTimeMillis(), - service.getNamespaceId(), service.getGroupName(), service.getName(), ip.getIp(), - true, HealthStateChangeReason.HEALTH_CHECK_SUCCESS)); + NotifyCenter.publishEvent(new HealthStateChangeTraceEvent(System.currentTimeMillis(), + service.getNamespaceId(), service.getGroupName(), service.getName(), ip.getIp(), ip.getPort(), + true, msg)); } else { if (!ip.isMockValid()) { ip.setMockValid(true); @@ -156,9 +155,9 @@ public void checkFail(Instance ip, HealthCheckTask task, String msg) { .info("serviceName: {} {POS} {IP-DISABLED} invalid: {}:{}@{}, region: {}, msg: {}", cluster.getService().getName(), ip.getIp(), ip.getPort(), cluster.getName(), UtilsAndCommons.LOCALHOST_SITE, msg); - NotifyCenter.publishEvent(new NamingTraceEvent.HealthStateChangeTraceEvent(System.currentTimeMillis(), + NotifyCenter.publishEvent(new HealthStateChangeTraceEvent(System.currentTimeMillis(), service.getNamespaceId(), service.getGroupName(), service.getName(), ip.getIp(), - false, HealthStateChangeReason.HEALTH_CHECK_FAIL)); + ip.getPort(), false, msg)); } else { Loggers.EVT_LOG .info("serviceName: {} {PROBE} {IP-DISABLED} invalid: {}:{}@{}, region: {}, msg: {}", @@ -205,9 +204,9 @@ public void checkFailNow(Instance ip, HealthCheckTask task, String msg) { .info("serviceName: {} {POS} {IP-DISABLED} invalid-now: {}:{}@{}, region: {}, msg: {}", cluster.getService().getName(), ip.getIp(), ip.getPort(), cluster.getName(), UtilsAndCommons.LOCALHOST_SITE, msg); - NotifyCenter.publishEvent(new NamingTraceEvent.HealthStateChangeTraceEvent(System.currentTimeMillis(), + NotifyCenter.publishEvent(new HealthStateChangeTraceEvent(System.currentTimeMillis(), service.getNamespaceId(), service.getGroupName(), service.getName(), ip.getIp(), - false, HealthStateChangeReason.HEALTH_CHECK_FAIL)); + ip.getPort(), false, msg)); } else { if (ip.isMockValid()) { diff --git a/naming/src/main/java/com/alibaba/nacos/naming/healthcheck/heartbeat/ClientBeatProcessorV2.java b/naming/src/main/java/com/alibaba/nacos/naming/healthcheck/heartbeat/ClientBeatProcessorV2.java index 68a5aa8af83..dee58b8c67f 100644 --- a/naming/src/main/java/com/alibaba/nacos/naming/healthcheck/heartbeat/ClientBeatProcessorV2.java +++ b/naming/src/main/java/com/alibaba/nacos/naming/healthcheck/heartbeat/ClientBeatProcessorV2.java @@ -18,8 +18,7 @@ import com.alibaba.nacos.api.naming.utils.NamingUtils; import com.alibaba.nacos.common.notify.NotifyCenter; -import com.alibaba.nacos.common.trace.HealthStateChangeReason; -import com.alibaba.nacos.common.trace.event.NamingTraceEvent; +import com.alibaba.nacos.common.trace.event.naming.HealthStateChangeTraceEvent; import com.alibaba.nacos.naming.core.v2.client.impl.IpPortBasedClient; import com.alibaba.nacos.naming.core.v2.event.client.ClientEvent; import com.alibaba.nacos.naming.core.v2.event.service.ServiceEvent; @@ -70,9 +69,9 @@ public void run() { rsInfo.getServiceName(), ip, port, rsInfo.getCluster(), UtilsAndCommons.LOCALHOST_SITE); NotifyCenter.publishEvent(new ServiceEvent.ServiceChangedEvent(service)); NotifyCenter.publishEvent(new ClientEvent.ClientChangedEvent(client)); - NotifyCenter.publishEvent(new NamingTraceEvent.HealthStateChangeTraceEvent(System.currentTimeMillis(), + NotifyCenter.publishEvent(new HealthStateChangeTraceEvent(System.currentTimeMillis(), service.getNamespace(), service.getGroup(), service.getName(), instance.getIp(), - true, HealthStateChangeReason.HEARTBEAT_REFRESH)); + instance.getPort(), true, "client_beat")); } } } diff --git a/naming/src/main/java/com/alibaba/nacos/naming/healthcheck/heartbeat/ExpiredInstanceChecker.java b/naming/src/main/java/com/alibaba/nacos/naming/healthcheck/heartbeat/ExpiredInstanceChecker.java index 255e27afe18..8c135fc2584 100644 --- a/naming/src/main/java/com/alibaba/nacos/naming/healthcheck/heartbeat/ExpiredInstanceChecker.java +++ b/naming/src/main/java/com/alibaba/nacos/naming/healthcheck/heartbeat/ExpiredInstanceChecker.java @@ -20,7 +20,7 @@ import com.alibaba.nacos.api.naming.PreservedMetadataKeys; import com.alibaba.nacos.common.notify.NotifyCenter; import com.alibaba.nacos.common.trace.DeregisterInstanceReason; -import com.alibaba.nacos.common.trace.event.NamingTraceEvent; +import com.alibaba.nacos.common.trace.event.naming.DeregisterInstanceTraceEvent; import com.alibaba.nacos.common.utils.ConvertUtils; import com.alibaba.nacos.common.utils.JacksonUtils; import com.alibaba.nacos.naming.core.v2.client.Client; @@ -78,7 +78,8 @@ private void deleteIp(Client client, Service service, InstancePublishInfo instan client.removeServiceInstance(service); NotifyCenter.publishEvent(new ClientOperationEvent.ClientDeregisterServiceEvent(service, client.getClientId())); NotifyCenter.publishEvent(new MetadataEvent.InstanceMetadataEvent(service, instance.getMetadataId(), true)); - NotifyCenter.publishEvent(new NamingTraceEvent.DeregisterInstanceTraceEvent(System.currentTimeMillis(), "", - false, DeregisterInstanceReason.HEARTBEAT_EXPIRE, service.getNamespace(), service.getGroup(), service.getName(), instance.getIp())); + NotifyCenter.publishEvent(new DeregisterInstanceTraceEvent(System.currentTimeMillis(), "", + false, DeregisterInstanceReason.HEARTBEAT_EXPIRE, service.getNamespace(), service.getGroup(), + service.getName(), instance.getIp(), instance.getPort())); } } diff --git a/naming/src/main/java/com/alibaba/nacos/naming/healthcheck/heartbeat/UnhealthyInstanceChecker.java b/naming/src/main/java/com/alibaba/nacos/naming/healthcheck/heartbeat/UnhealthyInstanceChecker.java index d1f97f4c6ec..1614a5cf7aa 100644 --- a/naming/src/main/java/com/alibaba/nacos/naming/healthcheck/heartbeat/UnhealthyInstanceChecker.java +++ b/naming/src/main/java/com/alibaba/nacos/naming/healthcheck/heartbeat/UnhealthyInstanceChecker.java @@ -19,8 +19,7 @@ import com.alibaba.nacos.api.common.Constants; import com.alibaba.nacos.api.naming.PreservedMetadataKeys; import com.alibaba.nacos.common.notify.NotifyCenter; -import com.alibaba.nacos.common.trace.HealthStateChangeReason; -import com.alibaba.nacos.common.trace.event.NamingTraceEvent; +import com.alibaba.nacos.common.trace.event.naming.HealthStateChangeTraceEvent; import com.alibaba.nacos.common.utils.ConvertUtils; import com.alibaba.nacos.naming.core.v2.client.Client; import com.alibaba.nacos.naming.core.v2.event.client.ClientEvent; @@ -79,8 +78,8 @@ private void changeHealthyStatus(Client client, Service service, HealthCheckInst instance.getLastHeartBeatTime()); NotifyCenter.publishEvent(new ServiceEvent.ServiceChangedEvent(service)); NotifyCenter.publishEvent(new ClientEvent.ClientChangedEvent(client)); - NotifyCenter.publishEvent(new NamingTraceEvent.HealthStateChangeTraceEvent(System.currentTimeMillis(), - service.getNamespace(), service.getGroup(), service.getName(), instance.getIp(), - false, HealthStateChangeReason.HEARTBEAT_TIMEOUT)); + NotifyCenter.publishEvent(new HealthStateChangeTraceEvent(System.currentTimeMillis(), + service.getNamespace(), service.getGroup(), service.getName(), instance.getIp(), instance.getPort(), + false, "client_beat")); } } diff --git a/naming/src/main/java/com/alibaba/nacos/naming/healthcheck/v2/processor/HealthCheckCommonV2.java b/naming/src/main/java/com/alibaba/nacos/naming/healthcheck/v2/processor/HealthCheckCommonV2.java index b34d73dcd6e..8af25739f3e 100644 --- a/naming/src/main/java/com/alibaba/nacos/naming/healthcheck/v2/processor/HealthCheckCommonV2.java +++ b/naming/src/main/java/com/alibaba/nacos/naming/healthcheck/v2/processor/HealthCheckCommonV2.java @@ -17,8 +17,7 @@ package com.alibaba.nacos.naming.healthcheck.v2.processor; import com.alibaba.nacos.common.notify.NotifyCenter; -import com.alibaba.nacos.common.trace.HealthStateChangeReason; -import com.alibaba.nacos.common.trace.event.NamingTraceEvent; +import com.alibaba.nacos.common.trace.event.naming.HealthStateChangeTraceEvent; import com.alibaba.nacos.naming.core.DistroMapper; import com.alibaba.nacos.naming.core.v2.pojo.HealthCheckInstancePublishInfo; import com.alibaba.nacos.naming.core.v2.pojo.Service; @@ -107,9 +106,9 @@ public void checkOk(HealthCheckTaskV2 task, Service service, String msg) { Loggers.EVT_LOG.info("serviceName: {} {POS} {IP-ENABLED} valid: {}:{}@{}, region: {}, msg: {}", serviceName, instance.getIp(), instance.getPort(), clusterName, UtilsAndCommons.LOCALHOST_SITE, msg); - NotifyCenter.publishEvent(new NamingTraceEvent.HealthStateChangeTraceEvent(System.currentTimeMillis(), + NotifyCenter.publishEvent(new HealthStateChangeTraceEvent(System.currentTimeMillis(), service.getNamespace(), service.getGroup(), service.getName(), instance.getIp(), - true, HealthStateChangeReason.HEALTH_CHECK_SUCCESS)); + instance.getPort(), true, msg)); } } else { Loggers.EVT_LOG.info("serviceName: {} {OTHER} {IP-ENABLED} pre-valid: {}:{}@{} in {}, msg: {}", @@ -151,9 +150,9 @@ public void checkFail(HealthCheckTaskV2 task, Service service, String msg) { .info("serviceName: {} {POS} {IP-DISABLED} invalid: {}:{}@{}, region: {}, msg: {}", serviceName, instance.getIp(), instance.getPort(), clusterName, UtilsAndCommons.LOCALHOST_SITE, msg); - NotifyCenter.publishEvent(new NamingTraceEvent.HealthStateChangeTraceEvent(System.currentTimeMillis(), + NotifyCenter.publishEvent(new HealthStateChangeTraceEvent(System.currentTimeMillis(), service.getNamespace(), service.getGroup(), service.getName(), instance.getIp(), - false, HealthStateChangeReason.HEALTH_CHECK_FAIL)); + instance.getPort(), false, msg)); } } else { Loggers.EVT_LOG.info("serviceName: {} {OTHER} {IP-DISABLED} pre-invalid: {}:{}@{} in {}, msg: {}", @@ -194,9 +193,9 @@ public void checkFailNow(HealthCheckTaskV2 task, Service service, String msg) { Loggers.EVT_LOG.info("serviceName: {} {POS} {IP-DISABLED} invalid: {}:{}@{}, region: {}, msg: {}", serviceName, instance.getIp(), instance.getPort(), clusterName, UtilsAndCommons.LOCALHOST_SITE, msg); - NotifyCenter.publishEvent(new NamingTraceEvent.HealthStateChangeTraceEvent(System.currentTimeMillis(), + NotifyCenter.publishEvent(new HealthStateChangeTraceEvent(System.currentTimeMillis(), service.getNamespace(), service.getGroup(), service.getName(), instance.getIp(), - false, HealthStateChangeReason.HEALTH_CHECK_FAIL)); + instance.getPort(), false, msg)); } } } finally { diff --git a/naming/src/main/java/com/alibaba/nacos/naming/push/v2/task/PushExecuteTask.java b/naming/src/main/java/com/alibaba/nacos/naming/push/v2/task/PushExecuteTask.java index 12138ece70c..5bd80a70035 100644 --- a/naming/src/main/java/com/alibaba/nacos/naming/push/v2/task/PushExecuteTask.java +++ b/naming/src/main/java/com/alibaba/nacos/naming/push/v2/task/PushExecuteTask.java @@ -19,7 +19,7 @@ import com.alibaba.nacos.api.naming.pojo.ServiceInfo; import com.alibaba.nacos.common.notify.NotifyCenter; import com.alibaba.nacos.common.task.AbstractExecuteTask; -import com.alibaba.nacos.common.trace.event.NamingTraceEvent; +import com.alibaba.nacos.common.trace.event.naming.PushServiceTraceEvent; import com.alibaba.nacos.naming.core.v2.client.Client; import com.alibaba.nacos.naming.core.v2.client.manager.ClientManager; import com.alibaba.nacos.naming.core.v2.metadata.ServiceMetadata; @@ -164,8 +164,8 @@ public void setActualServiceInfo(ServiceInfo actualServiceInfo) { this.actualServiceInfo = actualServiceInfo; } - private NamingTraceEvent.PushServiceTraceEvent getPushServiceTraceEvent(long eventTime, PushResult result) { - return new NamingTraceEvent.PushServiceTraceEvent(eventTime, result.getNetworkCost(), result.getAllCost(), + private PushServiceTraceEvent getPushServiceTraceEvent(long eventTime, PushResult result) { + return new PushServiceTraceEvent(eventTime, result.getNetworkCost(), result.getAllCost(), result.getSla(), result.getSubscriber().getIp(), result.getService().getNamespace(), result.getService().getGroup(), result.getService().getName(), result.getData().getHosts().size()); } diff --git a/naming/src/main/java/com/alibaba/nacos/naming/remote/rpc/handler/InstanceRequestHandler.java b/naming/src/main/java/com/alibaba/nacos/naming/remote/rpc/handler/InstanceRequestHandler.java index 27300049bc2..5b4dd977ed8 100644 --- a/naming/src/main/java/com/alibaba/nacos/naming/remote/rpc/handler/InstanceRequestHandler.java +++ b/naming/src/main/java/com/alibaba/nacos/naming/remote/rpc/handler/InstanceRequestHandler.java @@ -24,7 +24,8 @@ import com.alibaba.nacos.auth.annotation.Secured; import com.alibaba.nacos.common.notify.NotifyCenter; import com.alibaba.nacos.common.trace.DeregisterInstanceReason; -import com.alibaba.nacos.common.trace.event.NamingTraceEvent; +import com.alibaba.nacos.common.trace.event.naming.DeregisterInstanceTraceEvent; +import com.alibaba.nacos.common.trace.event.naming.RegisterInstanceTraceEvent; import com.alibaba.nacos.core.remote.RequestHandler; import com.alibaba.nacos.naming.core.v2.pojo.Service; import com.alibaba.nacos.naming.core.v2.service.impl.EphemeralClientOperationServiceImpl; @@ -63,16 +64,17 @@ public InstanceResponse handle(InstanceRequest request, RequestMeta meta) throws private InstanceResponse registerInstance(Service service, InstanceRequest request, RequestMeta meta) { clientOperationService.registerInstance(service, request.getInstance(), meta.getConnectionId()); - NotifyCenter.publishEvent(new NamingTraceEvent.RegisterInstanceTraceEvent(System.currentTimeMillis(), meta.getClientIp(), - true, service.getNamespace(), service.getGroup(), service.getName(), request.getInstance().toInetAddr())); + NotifyCenter.publishEvent(new RegisterInstanceTraceEvent(System.currentTimeMillis(), + meta.getClientIp(), true, service.getNamespace(), service.getGroup(), service.getName(), + request.getInstance().getIp(), request.getInstance().getPort())); return new InstanceResponse(NamingRemoteConstants.REGISTER_INSTANCE); } private InstanceResponse deregisterInstance(Service service, InstanceRequest request, RequestMeta meta) { clientOperationService.deregisterInstance(service, request.getInstance(), meta.getConnectionId()); - NotifyCenter.publishEvent(new NamingTraceEvent.DeregisterInstanceTraceEvent(System.currentTimeMillis(), + NotifyCenter.publishEvent(new DeregisterInstanceTraceEvent(System.currentTimeMillis(), meta.getClientIp(), true, DeregisterInstanceReason.REQUEST, service.getNamespace(), - service.getGroup(), service.getName(), request.getInstance().toInetAddr())); + service.getGroup(), service.getName(), request.getInstance().getIp(), request.getInstance().getPort())); return new InstanceResponse(NamingRemoteConstants.DE_REGISTER_INSTANCE); } diff --git a/naming/src/main/java/com/alibaba/nacos/naming/remote/rpc/handler/SubscribeServiceRequestHandler.java b/naming/src/main/java/com/alibaba/nacos/naming/remote/rpc/handler/SubscribeServiceRequestHandler.java index 4055b0a772a..a734ff73f5b 100644 --- a/naming/src/main/java/com/alibaba/nacos/naming/remote/rpc/handler/SubscribeServiceRequestHandler.java +++ b/naming/src/main/java/com/alibaba/nacos/naming/remote/rpc/handler/SubscribeServiceRequestHandler.java @@ -25,7 +25,8 @@ import com.alibaba.nacos.api.remote.response.ResponseCode; import com.alibaba.nacos.auth.annotation.Secured; import com.alibaba.nacos.common.notify.NotifyCenter; -import com.alibaba.nacos.common.trace.event.NamingTraceEvent; +import com.alibaba.nacos.common.trace.event.naming.SubscribeServiceTraceEvent; +import com.alibaba.nacos.common.trace.event.naming.UnsubscribeServiceTraceEvent; import com.alibaba.nacos.core.remote.RequestHandler; import com.alibaba.nacos.naming.core.v2.index.ServiceStorage; import com.alibaba.nacos.naming.core.v2.metadata.NamingMetadataManager; @@ -74,11 +75,11 @@ public SubscribeServiceResponse handle(SubscribeServiceRequest request, RequestM true, subscriber.getIp()); if (request.isSubscribe()) { clientOperationService.subscribeService(service, subscriber, meta.getConnectionId()); - NotifyCenter.publishEvent(new NamingTraceEvent.SubscribeServiceTraceEvent(System.currentTimeMillis(), + NotifyCenter.publishEvent(new SubscribeServiceTraceEvent(System.currentTimeMillis(), meta.getClientIp(), service.getNamespace(), service.getGroup(), service.getName())); } else { clientOperationService.unsubscribeService(service, subscriber, meta.getConnectionId()); - NotifyCenter.publishEvent(new NamingTraceEvent.UnsubscribeServiceTraceEvent(System.currentTimeMillis(), + NotifyCenter.publishEvent(new UnsubscribeServiceTraceEvent(System.currentTimeMillis(), meta.getClientIp(), service.getNamespace(), service.getGroup(), service.getName())); } return new SubscribeServiceResponse(ResponseCode.SUCCESS.getCode(), "success", serviceInfo);