Skip to content

fix:fix tsf consul event not working bug. #603

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

Merged
merged 2 commits into from
May 15, 2025
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 @@ -24,25 +24,13 @@
import com.tencent.polaris.api.pojo.RetStatus;
import com.tencent.polaris.api.pojo.ServiceEventKey;
import com.tencent.polaris.api.pojo.ServiceKey;
import com.tencent.polaris.api.rpc.BaseEntity;
import com.tencent.polaris.api.rpc.GetAllInstancesRequest;
import com.tencent.polaris.api.rpc.GetHealthyInstancesRequest;
import com.tencent.polaris.api.rpc.GetInstancesRequest;
import com.tencent.polaris.api.rpc.GetOneInstanceRequest;
import com.tencent.polaris.api.rpc.GetResourcesRequest;
import com.tencent.polaris.api.rpc.GetServiceContractRequest;
import com.tencent.polaris.api.rpc.GetServiceRuleRequest;
import com.tencent.polaris.api.rpc.InstanceDeregisterRequest;
import com.tencent.polaris.api.rpc.InstanceHeartbeatRequest;
import com.tencent.polaris.api.rpc.InstanceRegisterRequest;
import com.tencent.polaris.api.rpc.ServiceCallResult;
import com.tencent.polaris.api.rpc.UnWatchServiceRequest;
import com.tencent.polaris.api.rpc.WatchServiceRequest;
import com.tencent.polaris.api.rpc.*;
import com.tencent.polaris.api.utils.CollectionUtils;
import com.tencent.polaris.api.utils.StringUtils;
import com.tencent.polaris.client.util.CommonValidator;
import com.tencent.polaris.logging.LoggerFactory;
import org.slf4j.Logger;

import java.util.Objects;
import java.util.Set;

/**
Expand All @@ -53,6 +41,8 @@
*/
public class Validator {

private static final Logger LOG = LoggerFactory.getLogger(Validator.class);

private static final int MAX_PORT = 65536;

/**
Expand Down Expand Up @@ -164,7 +154,7 @@ public static void validateServiceCallResult(ServiceCallResult serviceCallResult
throw new PolarisException(ErrorCode.API_INVALID_ARGUMENT, "delay can not be less than 0");
}
if (!RetStatus.RetReject.equals(serviceCallResult.getRetStatus())) {
validateHostPort(serviceCallResult.getHost(), serviceCallResult.getPort());
validateServiceCallResultHostPort(serviceCallResult.getHost(), serviceCallResult.getPort());
}
}

Expand All @@ -187,6 +177,29 @@ private static void validateHostPort(String host, Integer port) throws PolarisEx
}
}

/**
* 校验服务请求端口信息。某些场景下端口号为0,例如Dubbo的本地调用。
*
* @param host
* @param port
* @throws PolarisException
*/
private static void validateServiceCallResultHostPort(String host, Integer port) throws PolarisException {
if (StringUtils.isBlank(host)) {
throw new PolarisException(ErrorCode.API_INVALID_ARGUMENT, "host can not be blank");
}
if (port == null) {
throw new PolarisException(ErrorCode.API_INVALID_ARGUMENT, "port can not be null");
}
if (port == 0) {
LOG.warn("port is 0 with host {}. Please check if it meets expectations.", host);
}
if (port < 0 || port >= MAX_PORT) {
throw new PolarisException(
ErrorCode.API_INVALID_ARGUMENT, "port value should be in range [0, 65536).");
}
}

/**
* 校验实例注册请求
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Tencent is pleased to support the open source community by making polaris-java available.
*
* Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved.
*
* Licensed under the BSD 3-Clause License (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://opensource.org/licenses/BSD-3-Clause
*
* 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.tencent.polaris.discovery.client.util;

/**
* @author Haotian Zhang
*/
public class ValidatorTest {
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
import com.tencent.polaris.api.plugin.common.PluginTypes;
import com.tencent.polaris.api.plugin.compose.Extensions;
import com.tencent.polaris.api.plugin.event.BaseEvent;
import com.tencent.polaris.api.plugin.event.EventConstants;
import com.tencent.polaris.api.plugin.event.EventReporter;
import com.tencent.polaris.api.plugin.event.FlowEvent;
import com.tencent.polaris.api.pojo.ServiceEventKey;
import com.tencent.polaris.api.utils.CollectionUtils;
import com.tencent.polaris.api.utils.StringUtils;
import com.tencent.polaris.api.utils.ThreadPoolUtils;
Expand Down Expand Up @@ -102,10 +102,9 @@ public boolean isEnabled() {
@Override
public boolean reportEvent(BaseEvent baseEvent) {
if (baseEvent instanceof FlowEvent) {
if (baseEvent.getEventType().equals(ServiceEventKey.EventType.CIRCUIT_BREAKING)) {
if (baseEvent.getEventType().equals(EventConstants.EventType.CIRCUIT_BREAKING)) {
return reportV1Event((FlowEvent) baseEvent);
}
else if (baseEvent.getEventType().equals(ServiceEventKey.EventType.RATE_LIMITING)) {
} else if (baseEvent.getEventType().equals(EventConstants.EventType.RATE_LIMITING)) {
return reportReportEvent((FlowEvent) baseEvent);
}
}
Expand Down