com.tencent.polaris
diff --git a/polaris-discovery/polaris-discovery-api/src/main/java/com/tencent/polaris/api/core/ConsumerAPI.java b/polaris-discovery/polaris-discovery-api/src/main/java/com/tencent/polaris/api/core/ConsumerAPI.java
index 00f3915d5..59ee38a02 100644
--- a/polaris-discovery/polaris-discovery-api/src/main/java/com/tencent/polaris/api/core/ConsumerAPI.java
+++ b/polaris-discovery/polaris-discovery-api/src/main/java/com/tencent/polaris/api/core/ConsumerAPI.java
@@ -77,7 +77,11 @@ public interface ConsumerAPI extends AutoCloseable, Closeable {
* @param req 请求
* @return 单个服务实例
* @throws PolarisException 错误码及错误信息
+ *
+ * @deprecated
+ * * Use {@link com.tencent.polaris.assembly.api.AssemblyAPI#getOneInstance(com.tencent.polaris.assembly.api.pojo.GetOneInstanceRequest)} instead.
*/
+ @Deprecated
InstancesResponse getOneInstance(GetOneInstanceRequest req) throws PolarisException;
/**
@@ -86,7 +90,11 @@ public interface ConsumerAPI extends AutoCloseable, Closeable {
* @param req 请求
* @return 过滤后的服务列表
* @throws PolarisException 错误码及错误信息
+ *
+ * @deprecated
+ * *
Use {@link com.tencent.polaris.assembly.api.AssemblyAPI#getReachableInstances(com.tencent.polaris.assembly.api.pojo.GetReachableInstancesRequest)} instead.
*/
+ @Deprecated
InstancesResponse getInstances(GetInstancesRequest req) throws PolarisException;
/**
@@ -121,7 +129,11 @@ public interface ConsumerAPI extends AutoCloseable, Closeable {
*
* @param req 调用结果(包括成功失败,返回码,以及时延)
* @throws PolarisException 错误码及错误信息
+ *
+ * @deprecated
+ * *
Use {@link com.tencent.polaris.assembly.api.AssemblyAPI#updateServiceCallResult(ServiceCallResult)} instead.
*/
+ @Deprecated
void updateServiceCallResult(ServiceCallResult req) throws PolarisException;
/**
diff --git a/polaris-discovery/polaris-discovery-client/src/main/java/com/tencent/polaris/discovery/client/flow/CommonInstancesRequest.java b/polaris-discovery/polaris-discovery-client/src/main/java/com/tencent/polaris/discovery/client/flow/CommonInstancesRequest.java
index d79f9e62a..51d45be59 100644
--- a/polaris-discovery/polaris-discovery-client/src/main/java/com/tencent/polaris/discovery/client/flow/CommonInstancesRequest.java
+++ b/polaris-discovery/polaris-discovery-client/src/main/java/com/tencent/polaris/discovery/client/flow/CommonInstancesRequest.java
@@ -32,6 +32,7 @@
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.RequestBaseEntity;
import com.tencent.polaris.api.utils.StringUtils;
import com.tencent.polaris.client.flow.BaseFlow;
import com.tencent.polaris.client.flow.FlowControlParam;
@@ -191,6 +192,25 @@ public CommonInstancesRequest(GetInstancesRequest request, Configuration configu
BaseFlow.buildFlowControlParam(request, configuration, this);
}
+ public CommonInstancesRequest(ServiceEventKey dstInstanceEventKey, ServiceEventKey dstRuleEventKey, ServiceEventKey srcRuleEventKey,
+ RouteInfo routeInfo, Criteria criteria, RequestBaseEntity request, Configuration configuration) {
+ this.srcRuleEventKey = srcRuleEventKey;
+ if (null != srcRuleEventKey) {
+ svcEventKeys.add(srcRuleEventKey);
+ }
+ this.dstInstanceEventKey = dstInstanceEventKey;
+ if (null != dstInstanceEventKey) {
+ svcEventKeys.add(dstInstanceEventKey);
+ }
+ this.dstRuleEventKey = dstRuleEventKey;
+ if (null != dstRuleEventKey) {
+ svcEventKeys.add(dstRuleEventKey);
+ }
+ this.routeInfo = routeInfo;
+ this.criteria = criteria;
+ BaseFlow.buildFlowControlParam(request, configuration, this);
+ }
+
public ServiceEventKey getSrcRuleEventKey() {
return srcRuleEventKey;
}
diff --git a/polaris-plugins/polaris-plugin-api/src/main/java/com/tencent/polaris/api/plugin/common/PluginTypes.java b/polaris-plugins/polaris-plugin-api/src/main/java/com/tencent/polaris/api/plugin/common/PluginTypes.java
index 1113b21cd..654587421 100644
--- a/polaris-plugins/polaris-plugin-api/src/main/java/com/tencent/polaris/api/plugin/common/PluginTypes.java
+++ b/polaris-plugins/polaris-plugin-api/src/main/java/com/tencent/polaris/api/plugin/common/PluginTypes.java
@@ -34,6 +34,7 @@
import com.tencent.polaris.api.plugin.route.ServiceRouter;
import com.tencent.polaris.api.plugin.server.ServerConnector;
import com.tencent.polaris.api.plugin.stat.StatReporter;
+import com.tencent.polaris.api.plugin.stat.TraceReporter;
import com.tencent.polaris.api.plugin.weight.WeightAdjuster;
/**
@@ -91,10 +92,15 @@ public enum PluginTypes {
WEIGHT_ADJUSTER(new PluginType(WeightAdjuster.class, 2)),
/**
- * 统计上报扩展点
+ * 统计监控上报扩展点
*/
STAT_REPORTER(new PluginType(StatReporter.class, 2)),
+ /**
+ * 调用链上报扩展点
+ */
+ TRACE_REPORTER(new PluginType(TraceReporter.class, 2)),
+
/**
* 限流器扩展点
*/
diff --git a/polaris-plugins/polaris-plugin-api/src/main/java/com/tencent/polaris/api/plugin/compose/Extensions.java b/polaris-plugins/polaris-plugin-api/src/main/java/com/tencent/polaris/api/plugin/compose/Extensions.java
index c3b54614e..cd65cdf57 100644
--- a/polaris-plugins/polaris-plugin-api/src/main/java/com/tencent/polaris/api/plugin/compose/Extensions.java
+++ b/polaris-plugins/polaris-plugin-api/src/main/java/com/tencent/polaris/api/plugin/compose/Extensions.java
@@ -44,6 +44,7 @@
import com.tencent.polaris.api.plugin.route.ServiceRouter;
import com.tencent.polaris.api.plugin.server.ServerConnector;
import com.tencent.polaris.api.plugin.stat.StatReporter;
+import com.tencent.polaris.api.plugin.stat.TraceReporter;
import com.tencent.polaris.api.utils.CollectionUtils;
import com.tencent.polaris.api.utils.MapUtils;
import com.tencent.polaris.api.utils.StringUtils;
@@ -84,6 +85,9 @@ public class Extensions extends Destroyable {
private CircuitBreaker resourceBreaker;
private final List statReporters = new ArrayList<>();
+
+ private TraceReporter traceReporter;
+
private Supplier plugins;
//系统服务的路由链
@@ -191,6 +195,9 @@ public void init(Configuration config, Supplier plugins, ValueContext valueConte
// 加载监控上报
loadStatReporters(plugins);
+ // 加载调用链上报
+ loadTraceReporter(plugins);
+
// 加载优雅上下线插件
loadLosslessPolicies(config, plugins);
@@ -274,6 +281,15 @@ private void loadStatReporters(Supplier plugins) throws PolarisException {
}
}
+ private void loadTraceReporter(Supplier plugins) throws PolarisException {
+ if (configuration.getGlobal().getTraceReporter().isEnable()) {
+ Collection reporters = plugins.getPlugins(PluginTypes.TRACE_REPORTER.getBaseType());
+ if (CollectionUtils.isNotEmpty(reporters)) {
+ traceReporter = (TraceReporter) reporters.iterator().next();
+ }
+ }
+ }
+
private void loadLosslessPolicies(Configuration config, Supplier plugins) throws PolarisException {
if (!config.getProvider().getLossless().isEnable()) {
return;
@@ -546,6 +562,10 @@ public List getLosslessPolicies() {
return losslessPolicies;
}
+ public TraceReporter getTraceReporter() {
+ return traceReporter;
+ }
+
@Override
protected void doDestroy() {
if (MapUtils.isNotEmpty(httpServers)) {
diff --git a/polaris-plugins/polaris-plugin-api/src/main/java/com/tencent/polaris/api/plugin/stat/StatReporter.java b/polaris-plugins/polaris-plugin-api/src/main/java/com/tencent/polaris/api/plugin/stat/StatReporter.java
index d458c259c..73f37e6fb 100644
--- a/polaris-plugins/polaris-plugin-api/src/main/java/com/tencent/polaris/api/plugin/stat/StatReporter.java
+++ b/polaris-plugins/polaris-plugin-api/src/main/java/com/tencent/polaris/api/plugin/stat/StatReporter.java
@@ -20,7 +20,7 @@
import com.tencent.polaris.api.plugin.Plugin;
/**
- * 【扩展点接口】上报统计结果
+ * 【扩展点接口】上报统计监控
*
* @author andrewshan
* @date 2019/8/21
diff --git a/polaris-assembly/polaris-assembly-api/src/main/java/com/tencent/polaris/assembly/api/pojo/Capability.java b/polaris-plugins/polaris-plugin-api/src/main/java/com/tencent/polaris/api/plugin/stat/TraceReporter.java
similarity index 57%
rename from polaris-assembly/polaris-assembly-api/src/main/java/com/tencent/polaris/assembly/api/pojo/Capability.java
rename to polaris-plugins/polaris-plugin-api/src/main/java/com/tencent/polaris/api/plugin/stat/TraceReporter.java
index 748049571..60a04ea36 100644
--- a/polaris-assembly/polaris-assembly-api/src/main/java/com/tencent/polaris/assembly/api/pojo/Capability.java
+++ b/polaris-plugins/polaris-plugin-api/src/main/java/com/tencent/polaris/api/plugin/stat/TraceReporter.java
@@ -1,22 +1,43 @@
-/*
- * Tencent is pleased to support the open source community by making Polaris available.
- *
- * Copyright (C) 2019 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.assembly.api.pojo;
-
-public enum Capability {
- ALL, TRACING, DISCOVERY, ROUTER, LOAD_BALANCER, CIRCUIT_BREAKER, RATE_LIMITER, AUTH
-}
+/*
+ * Tencent is pleased to support the open source community by making Polaris available.
+ *
+ * Copyright (C) 2019 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.api.plugin.stat;
+
+import java.util.Map;
+
+import com.tencent.polaris.api.plugin.Plugin;
+
+/**
+ * 【扩展点接口】上报调用链
+ *
+ * @author andrewshan
+ * @date 2024/6/2
+ */
+public interface TraceReporter extends Plugin {
+
+ /**
+ * set the attributes in trace span
+ * @param attributes span attributes
+ */
+ void setSpanAttributes(Map attributes);
+
+ /**
+ * set the attributes in baggage span
+ * @param attributes baggage attributes
+ */
+ void setBaggageAttributes(Map attributes);
+}
diff --git a/polaris-plugins/polaris-plugins-observability/pom.xml b/polaris-plugins/polaris-plugins-observability/pom.xml
index 9fd551a07..a60751920 100644
--- a/polaris-plugins/polaris-plugins-observability/pom.xml
+++ b/polaris-plugins/polaris-plugins-observability/pom.xml
@@ -18,6 +18,7 @@
stat-prometheus
stat-common
+ trace-otel
diff --git a/polaris-plugins/polaris-plugins-observability/trace-otel/pom.xml b/polaris-plugins/polaris-plugins-observability/trace-otel/pom.xml
new file mode 100644
index 000000000..943bc79d3
--- /dev/null
+++ b/polaris-plugins/polaris-plugins-observability/trace-otel/pom.xml
@@ -0,0 +1,29 @@
+
+
+
+ polaris-plugins-observability
+ com.tencent.polaris
+ ${revision}
+ ../pom.xml
+
+ 4.0.0
+
+ trace-otel
+ Polaris Plugins Observability Trace OTel
+ Polaris Plugins Observability Trace OTel JAR
+
+
+
+ polaris-plugin-api
+ com.tencent.polaris
+ ${project.version}
+
+
+ io.opentelemetry
+ opentelemetry-api
+ ${otel.version}
+
+
+
\ No newline at end of file
diff --git a/polaris-plugins/polaris-plugins-observability/trace-otel/src/main/java/com/tencent/polaris/plugins/stat/otel/OtelTraceReporter.java b/polaris-plugins/polaris-plugins-observability/trace-otel/src/main/java/com/tencent/polaris/plugins/stat/otel/OtelTraceReporter.java
new file mode 100644
index 000000000..db464d308
--- /dev/null
+++ b/polaris-plugins/polaris-plugins-observability/trace-otel/src/main/java/com/tencent/polaris/plugins/stat/otel/OtelTraceReporter.java
@@ -0,0 +1,72 @@
+/*
+ * Tencent is pleased to support the open source community by making Polaris available.
+ *
+ * Copyright (C) 2019 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.plugins.stat.otel;
+
+import java.util.Map;
+
+import com.tencent.polaris.api.config.global.TraceReporterConfig;
+import com.tencent.polaris.api.exception.PolarisException;
+import com.tencent.polaris.api.plugin.PluginType;
+import com.tencent.polaris.api.plugin.common.InitContext;
+import com.tencent.polaris.api.plugin.common.PluginTypes;
+import com.tencent.polaris.api.plugin.compose.Extensions;
+import com.tencent.polaris.api.plugin.stat.TraceReporter;
+import io.opentelemetry.api.baggage.Baggage;
+import io.opentelemetry.api.baggage.BaggageBuilder;
+import io.opentelemetry.api.trace.Span;
+
+public class OtelTraceReporter implements TraceReporter {
+
+ @Override
+ public String getName() {
+ return TraceReporterConfig.DEFAULT_REPORTER_OTEL;
+ }
+
+ @Override
+ public PluginType getType() {
+ return PluginTypes.TRACE_REPORTER.getBaseType();
+ }
+
+ @Override
+ public void init(InitContext ctx) throws PolarisException {
+
+ }
+
+ @Override
+ public void postContextInit(Extensions ctx) throws PolarisException {
+
+ }
+
+ @Override
+ public void destroy() {
+
+ }
+
+ @Override
+ public void setSpanAttributes(Map attributes) {
+ Span span = Span.current();
+ attributes.forEach(span::setAttribute);
+ }
+
+ @Override
+ public void setBaggageAttributes(Map attributes) {
+ BaggageBuilder builder = Baggage.current().toBuilder();
+ attributes.forEach(builder::put);
+ builder.build().makeCurrent();
+ }
+}
diff --git a/polaris-plugins/polaris-plugins-observability/trace-otel/src/main/resources/META-INF/services/com.tencent.polaris.api.plugin.stat.TraceReporter b/polaris-plugins/polaris-plugins-observability/trace-otel/src/main/resources/META-INF/services/com.tencent.polaris.api.plugin.stat.TraceReporter
new file mode 100644
index 000000000..56a3a64bf
--- /dev/null
+++ b/polaris-plugins/polaris-plugins-observability/trace-otel/src/main/resources/META-INF/services/com.tencent.polaris.api.plugin.stat.TraceReporter
@@ -0,0 +1 @@
+com.tencent.polaris.plugins.stat.otel.OtelTraceReporter
\ No newline at end of file
diff --git a/polaris-plugins/polaris-plugins-observability/trace-otel/src/test/java/com/tencent/polaris/plugins/stat/otel/OtelTraceReporterTest.java b/polaris-plugins/polaris-plugins-observability/trace-otel/src/test/java/com/tencent/polaris/plugins/stat/otel/OtelTraceReporterTest.java
new file mode 100644
index 000000000..87366af32
--- /dev/null
+++ b/polaris-plugins/polaris-plugins-observability/trace-otel/src/test/java/com/tencent/polaris/plugins/stat/otel/OtelTraceReporterTest.java
@@ -0,0 +1,43 @@
+/*
+ * Tencent is pleased to support the open source community by making Polaris available.
+ *
+ * Copyright (C) 2019 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.plugins.stat.otel;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.junit.Test;
+
+public class OtelTraceReporterTest {
+
+ @Test
+ public void testSetSpanAttributes() {
+ OtelTraceReporter reporter = new OtelTraceReporter();
+ Map values = new HashMap<>();
+ values.put("key1", "value1");
+ reporter.setSpanAttributes(values);
+ }
+
+ @Test
+ public void testSetBaggageAttributes() {
+ OtelTraceReporter reporter = new OtelTraceReporter();
+ Map values = new HashMap<>();
+ values.put("key1", "value1");
+ reporter.setBaggageAttributes(values);
+ }
+
+}
diff --git a/pom.xml b/pom.xml
index 41b8967cb..1494bf30b 100644
--- a/pom.xml
+++ b/pom.xml
@@ -65,7 +65,7 @@
- 1.15.7-SNAPSHOT
+ 1.15.8-SNAPSHOT
${maven.build.timestamp}
false
@@ -97,6 +97,7 @@
3.16.1
-Xmx2048m
0.11.0
+ 1.38.0
3.0.0
3.2.0
3.2.0
From e7d44175a287c1fdce8d80110f1dc868edbcd8f6 Mon Sep 17 00:00:00 2001
From: andrew shan <45474304+andrewshan@users.noreply.github.com>
Date: Mon, 17 Jun 2024 18:03:15 +0800
Subject: [PATCH 2/6] feat: restore version to 1.15.7-SNAPSHOT
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index 1494bf30b..cd68618e6 100644
--- a/pom.xml
+++ b/pom.xml
@@ -65,7 +65,7 @@
- 1.15.8-SNAPSHOT
+ 1.15.7-SNAPSHOT
${maven.build.timestamp}
false
From b76ddf4d9edabbfc6b66699609f8dc6336917a65 Mon Sep 17 00:00:00 2001
From: andrew shan <45474304+andrewshan@users.noreply.github.com>
Date: Mon, 17 Jun 2024 21:50:26 +0800
Subject: [PATCH 3/6] feat: add initService to AssemblyAPI
---
.../polaris/assembly/api/AssemblyAPI.java | 7 ++++++
.../polaris/assembly/api/pojo/Validator.java | 11 ++++++++++
.../assembly/client/DefaultAssemblyAPI.java | 8 +++++++
.../client/flow/DefaultAssemblyFlow.java | 22 +++++++++++++++++++
4 files changed, 48 insertions(+)
diff --git a/polaris-assembly/polaris-assembly-api/src/main/java/com/tencent/polaris/assembly/api/AssemblyAPI.java b/polaris-assembly/polaris-assembly-api/src/main/java/com/tencent/polaris/assembly/api/AssemblyAPI.java
index df2aae2c2..ea5dc00eb 100644
--- a/polaris-assembly/polaris-assembly-api/src/main/java/com/tencent/polaris/assembly/api/AssemblyAPI.java
+++ b/polaris-assembly/polaris-assembly-api/src/main/java/com/tencent/polaris/assembly/api/AssemblyAPI.java
@@ -21,6 +21,7 @@
import java.util.List;
import com.tencent.polaris.api.pojo.Instance;
+import com.tencent.polaris.api.pojo.ServiceKey;
import com.tencent.polaris.api.rpc.ServiceCallResult;
import com.tencent.polaris.assembly.api.pojo.GetOneInstanceRequest;
import com.tencent.polaris.assembly.api.pojo.GetReachableInstancesRequest;
@@ -28,6 +29,12 @@
public interface AssemblyAPI extends AutoCloseable, Closeable {
+ /**
+ * 初始化服务实例列表,避免在服务调用的时候进行拉取,可有效减少调用时延。
+ * @param serviceKey 服务名和命名空间
+ */
+ void initService(ServiceKey serviceKey);
+
/**
* 获取路由后的服务实例列表,贯穿服务发现、服务路由的逻辑
* @param request 多个符合路由条件的服务实例
diff --git a/polaris-assembly/polaris-assembly-api/src/main/java/com/tencent/polaris/assembly/api/pojo/Validator.java b/polaris-assembly/polaris-assembly-api/src/main/java/com/tencent/polaris/assembly/api/pojo/Validator.java
index d216149a8..49faa1254 100644
--- a/polaris-assembly/polaris-assembly-api/src/main/java/com/tencent/polaris/assembly/api/pojo/Validator.java
+++ b/polaris-assembly/polaris-assembly-api/src/main/java/com/tencent/polaris/assembly/api/pojo/Validator.java
@@ -20,6 +20,7 @@
import com.tencent.polaris.api.exception.ErrorCode;
import com.tencent.polaris.api.exception.PolarisException;
import com.tencent.polaris.api.pojo.RetStatus;
+import com.tencent.polaris.api.pojo.ServiceKey;
import com.tencent.polaris.api.rpc.ServiceCallResult;
import com.tencent.polaris.api.utils.StringUtils;
import com.tencent.polaris.client.util.CommonValidator;
@@ -36,6 +37,16 @@ public static void validateGetOneInstanceRequest(GetOneInstanceRequest request)
CommonValidator.validateNamespaceService(request.getNamespace(), request.getService());
}
+ /**
+ * 校验服务名和命名空间
+ *
+ * @param serviceKey 请求对象
+ * @throws PolarisException 校验失败会抛出异常
+ */
+ public static void validateServiceKey(ServiceKey serviceKey) throws PolarisException {
+ CommonValidator.validateNamespaceService(serviceKey.getNamespace(), serviceKey.getService());
+ }
+
/**
* 校验获取批量服务实例的请求
*
diff --git a/polaris-assembly/polaris-assembly-client/src/main/java/com/tencent/polaris/assembly/client/DefaultAssemblyAPI.java b/polaris-assembly/polaris-assembly-client/src/main/java/com/tencent/polaris/assembly/client/DefaultAssemblyAPI.java
index ac74e830d..1c3a8ebf1 100644
--- a/polaris-assembly/polaris-assembly-client/src/main/java/com/tencent/polaris/assembly/client/DefaultAssemblyAPI.java
+++ b/polaris-assembly/polaris-assembly-client/src/main/java/com/tencent/polaris/assembly/client/DefaultAssemblyAPI.java
@@ -21,6 +21,7 @@
import com.tencent.polaris.api.exception.PolarisException;
import com.tencent.polaris.api.pojo.Instance;
+import com.tencent.polaris.api.pojo.ServiceKey;
import com.tencent.polaris.api.rpc.ServiceCallResult;
import com.tencent.polaris.api.utils.CollectionUtils;
import com.tencent.polaris.assembly.api.AssemblyAPI;
@@ -45,6 +46,13 @@ protected void subInit() throws PolarisException {
assemblyFlow = sdkContext.getOrInitFlow(AssemblyFlow.class);
}
+ @Override
+ public void initService(ServiceKey serviceKey) {
+ checkAvailable("AssemblyAPI");
+ Validator.validateServiceKey(serviceKey);
+ assemblyFlow.initService(serviceKey);
+ }
+
@Override
public List getReachableInstances(GetReachableInstancesRequest request) {
checkAvailable("AssemblyAPI");
diff --git a/polaris-assembly/polaris-assembly-client/src/main/java/com/tencent/polaris/assembly/client/flow/DefaultAssemblyFlow.java b/polaris-assembly/polaris-assembly-client/src/main/java/com/tencent/polaris/assembly/client/flow/DefaultAssemblyFlow.java
index 395255bbd..6cbb6db47 100644
--- a/polaris-assembly/polaris-assembly-client/src/main/java/com/tencent/polaris/assembly/client/flow/DefaultAssemblyFlow.java
+++ b/polaris-assembly/polaris-assembly-client/src/main/java/com/tencent/polaris/assembly/client/flow/DefaultAssemblyFlow.java
@@ -32,6 +32,7 @@
import com.tencent.polaris.api.pojo.ServiceInstances;
import com.tencent.polaris.api.pojo.ServiceKey;
import com.tencent.polaris.api.pojo.SourceService;
+import com.tencent.polaris.api.rpc.RequestBaseEntity;
import com.tencent.polaris.api.rpc.ServiceCallResult;
import com.tencent.polaris.api.utils.CollectionUtils;
import com.tencent.polaris.api.utils.StringUtils;
@@ -65,6 +66,27 @@ public void setSDKContext(SDKContext sdkContext) {
serviceCallResultListeners = ServiceCallResultListener.getServiceCallResultListeners(sdkContext);
}
+ @Override
+ public void initService(ServiceKey serviceKey) {
+ CommonInstancesRequest commonInstancesRequest = buildCommonInstancesRequest(serviceKey, sdkContext.getConfig());
+ BaseFlow.syncGetResources(extensions, false, commonInstancesRequest, commonInstancesRequest);
+ }
+
+ private static CommonInstancesRequest buildCommonInstancesRequest(ServiceKey serviceKey, Configuration configuration) {
+ ServiceKey dstSvcKey = new ServiceKey(serviceKey.getNamespace(), serviceKey.getService());
+ ServiceEventKey dstInstanceEventKey = new ServiceEventKey(dstSvcKey, ServiceEventKey.EventType.INSTANCE);
+ ServiceEventKey dstRuleEventKey = new ServiceEventKey(dstSvcKey, ServiceEventKey.EventType.ROUTING);
+ ServiceInfo dstServiceInfo = new ServiceInfo();
+ dstServiceInfo.setNamespace(serviceKey.getNamespace());
+ dstServiceInfo.setService(serviceKey.getService());
+ RequestBaseEntity requestBaseEntity = new RequestBaseEntity();
+ requestBaseEntity.setService(serviceKey.getService());
+ requestBaseEntity.setNamespace(serviceKey.getNamespace());
+ RouteInfo routeInfo = new RouteInfo(null, dstServiceInfo, "", configuration.getProvider().getService());
+ return new CommonInstancesRequest(dstInstanceEventKey, dstRuleEventKey, null, routeInfo,
+ null, requestBaseEntity, configuration);
+ }
+
@Override
public List getReachableInstances(GetReachableInstancesRequest request) {
CommonInstancesRequest commonInstancesRequest = buildCommonInstancesRequest(request, sdkContext.getConfig());
From 174620116c11a7003ea1fcefdd379ca72774518c Mon Sep 17 00:00:00 2001
From: andrew shan <45474304+andrewshan@users.noreply.github.com>
Date: Mon, 17 Jun 2024 21:58:02 +0800
Subject: [PATCH 4/6] test: add test for initService
---
.../polaris/assembly/factory/AssemblyTest.java | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/polaris-assembly/polaris-assembly-factory/src/test/java/com/tencent/polaris/assembly/factory/AssemblyTest.java b/polaris-assembly/polaris-assembly-factory/src/test/java/com/tencent/polaris/assembly/factory/AssemblyTest.java
index a47bffa0f..1c3d2d4f1 100644
--- a/polaris-assembly/polaris-assembly-factory/src/test/java/com/tencent/polaris/assembly/factory/AssemblyTest.java
+++ b/polaris-assembly/polaris-assembly-factory/src/test/java/com/tencent/polaris/assembly/factory/AssemblyTest.java
@@ -168,6 +168,20 @@ public void testSyncGetReachableInstancesAbnormal() {
commonTestSyncGetReachableInstances(Operation.HAS_UNHEALTHY);
}
+ @Test
+ public void testInitService() {
+ ValidParam validParam = validParams.get(Operation.ALL_HEALTHY);
+ Configuration configuration = TestUtils.configWithEnvAddress();
+ try (AssemblyAPI assemblyAPI = AssemblyAPIFactory.createAssemblyAPIByConfig(configuration)) {
+ try {
+ Thread.sleep(3000);
+ } catch (InterruptedException e) {
+ LOG.error("test fail: testInitService", e);
+ }
+ assemblyAPI.initService(new ServiceKey(NAMESPACE_TEST, validParam.getServiceName()));
+ }
+ }
+
private void commonTestSyncGetOneInstance(Operation operation) {
ValidParam validParam = validParams.get(operation);
Configuration configuration = TestUtils.configWithEnvAddress();
From bc9f0f61f61317c0539905bdb8a34c6fa8c60e29 Mon Sep 17 00:00:00 2001
From: andrew shan <45474304+andrewshan@users.noreply.github.com>
Date: Tue, 18 Jun 2024 15:29:28 +0800
Subject: [PATCH 5/6] fix: TraceReporterConfig type mistake
---
.../polaris/factory/config/global/GlobalConfigImpl.java | 2 +-
.../factory/config/global/TraceReporterConfigImpl.java | 4 ++--
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/polaris-common/polaris-config/src/main/java/com/tencent/polaris/factory/config/global/GlobalConfigImpl.java b/polaris-common/polaris-config/src/main/java/com/tencent/polaris/factory/config/global/GlobalConfigImpl.java
index d377c651c..8d4244f7e 100644
--- a/polaris-common/polaris-config/src/main/java/com/tencent/polaris/factory/config/global/GlobalConfigImpl.java
+++ b/polaris-common/polaris-config/src/main/java/com/tencent/polaris/factory/config/global/GlobalConfigImpl.java
@@ -117,7 +117,7 @@ public StatReporterConfigImpl getStatReporter() {
}
@Override
- public TraceReporterConfig getTraceReporter() {
+ public TraceReporterConfigImpl getTraceReporter() {
return traceReporter;
}
diff --git a/polaris-common/polaris-config/src/main/java/com/tencent/polaris/factory/config/global/TraceReporterConfigImpl.java b/polaris-common/polaris-config/src/main/java/com/tencent/polaris/factory/config/global/TraceReporterConfigImpl.java
index ba4ad3b85..f2274057e 100644
--- a/polaris-common/polaris-config/src/main/java/com/tencent/polaris/factory/config/global/TraceReporterConfigImpl.java
+++ b/polaris-common/polaris-config/src/main/java/com/tencent/polaris/factory/config/global/TraceReporterConfigImpl.java
@@ -43,11 +43,11 @@ public String getReporter() {
return reporter;
}
- void setEnable(Boolean enable) {
+ public void setEnable(Boolean enable) {
this.enable = enable;
}
- void setReporter(String reporter) {
+ public void setReporter(String reporter) {
this.reporter = reporter;
}
From 87dd61e1c3a22f92063dc2ee81352e4dc4df819f Mon Sep 17 00:00:00 2001
From: andrew shan <45474304+andrewshan@users.noreply.github.com>
Date: Tue, 18 Jun 2024 17:22:40 +0800
Subject: [PATCH 6/6] feat: support modify loglevel over parameter & support
log in tracereporter
---
.../src/main/resources/polaris-log4j.xml | 14 +++++++-------
.../trace-otel/pom.xml | 11 +++++++++++
.../plugins/stat/otel/OtelTraceReporter.java | 7 +++++++
3 files changed, 25 insertions(+), 7 deletions(-)
diff --git a/polaris-common/polaris-logging/src/main/resources/polaris-log4j.xml b/polaris-common/polaris-logging/src/main/resources/polaris-log4j.xml
index f338d38a2..afc5038e5 100644
--- a/polaris-common/polaris-logging/src/main/resources/polaris-log4j.xml
+++ b/polaris-common/polaris-logging/src/main/resources/polaris-log4j.xml
@@ -73,31 +73,31 @@
-
+
-
+
-
+
-
+
-
+
-
+
-
+
\ No newline at end of file
diff --git a/polaris-plugins/polaris-plugins-observability/trace-otel/pom.xml b/polaris-plugins/polaris-plugins-observability/trace-otel/pom.xml
index 943bc79d3..454784fcc 100644
--- a/polaris-plugins/polaris-plugins-observability/trace-otel/pom.xml
+++ b/polaris-plugins/polaris-plugins-observability/trace-otel/pom.xml
@@ -20,6 +20,17 @@
com.tencent.polaris
${project.version}
+