diff --git a/docs/en/changes/changes.md b/docs/en/changes/changes.md index 0b7480d5745e..206b640b0b01 100644 --- a/docs/en/changes/changes.md +++ b/docs/en/changes/changes.md @@ -54,6 +54,7 @@ * Get endpoint list order by timestamp desc. * Support sort queries on metrics generated by eBPF receiver. * Fix the compatibility with Grafana 11 when using label_values query variables. +* Nacos as config server and cluster coordinator supports configuration contextPath. #### UI diff --git a/docs/en/setup/backend/configuration-vocabulary.md b/docs/en/setup/backend/configuration-vocabulary.md index 461cf105a778..00fd030b4cb3 100644 --- a/docs/en/setup/backend/configuration-vocabulary.md +++ b/docs/en/setup/backend/configuration-vocabulary.md @@ -81,6 +81,7 @@ The Configuration Vocabulary lists all available configurations provided by `app | - | - | namespace | Namespace used by SkyWalking node coordination. | SW_CLUSTER_NACOS_NAMESPACE | public | | - | - | internalComHost | The hostname registered in Nacos for internal communications of the OAP cluster. | SW_CLUSTER_INTERNAL_COM_HOST | - | | - | - | internalComPort | The port registered in Nacos for internal communications of the OAP cluster. | SW_CLUSTER_INTERNAL_COM_PORT | -1 | +| - | - | contextPath | Nacos set contextPath. | SW_CLUSTER_NACOS_CONTEXT_PATH | - | | - | - | username | Nacos Auth username. | SW_CLUSTER_NACOS_USERNAME | - | | - | - | password | Nacos Auth password. | SW_CLUSTER_NACOS_PASSWORD | - | | - | - | accessKey | Nacos Auth accessKey. | SW_CLUSTER_NACOS_ACCESSKEY | - | diff --git a/oap-server/server-cluster-plugin/cluster-nacos-plugin/src/main/java/org/apache/skywalking/oap/server/cluster/plugin/nacos/ClusterModuleNacosConfig.java b/oap-server/server-cluster-plugin/cluster-nacos-plugin/src/main/java/org/apache/skywalking/oap/server/cluster/plugin/nacos/ClusterModuleNacosConfig.java index a6c683af660f..c207cc47730b 100644 --- a/oap-server/server-cluster-plugin/cluster-nacos-plugin/src/main/java/org/apache/skywalking/oap/server/cluster/plugin/nacos/ClusterModuleNacosConfig.java +++ b/oap-server/server-cluster-plugin/cluster-nacos-plugin/src/main/java/org/apache/skywalking/oap/server/cluster/plugin/nacos/ClusterModuleNacosConfig.java @@ -32,6 +32,7 @@ public class ClusterModuleNacosConfig extends ModuleConfig { private String namespace = "public"; private String internalComHost; private int internalComPort = -1; + private String contextPath; private String username; private String password; private String accessKey; diff --git a/oap-server/server-cluster-plugin/cluster-nacos-plugin/src/main/java/org/apache/skywalking/oap/server/cluster/plugin/nacos/ClusterModuleNacosProvider.java b/oap-server/server-cluster-plugin/cluster-nacos-plugin/src/main/java/org/apache/skywalking/oap/server/cluster/plugin/nacos/ClusterModuleNacosProvider.java index 47019f4f9256..afb3c5095d27 100644 --- a/oap-server/server-cluster-plugin/cluster-nacos-plugin/src/main/java/org/apache/skywalking/oap/server/cluster/plugin/nacos/ClusterModuleNacosProvider.java +++ b/oap-server/server-cluster-plugin/cluster-nacos-plugin/src/main/java/org/apache/skywalking/oap/server/cluster/plugin/nacos/ClusterModuleNacosProvider.java @@ -76,6 +76,9 @@ public void prepare() throws ServiceNotProvidedException, ModuleStartException { if (StringUtil.isNotEmpty(config.getUsername()) && StringUtil.isNotEmpty(config.getAccessKey())) { throw new ModuleStartException("Nacos Auth method should choose either username or accessKey, not both"); } + if (StringUtil.isNotEmpty(config.getContextPath())) { + properties.put(PropertyKeyConst.CONTEXT_PATH, config.getContextPath()); + } if (StringUtil.isNotEmpty(config.getUsername())) { properties.put(PropertyKeyConst.USERNAME, config.getUsername()); properties.put(PropertyKeyConst.PASSWORD, config.getPassword()); diff --git a/oap-server/server-configuration/configuration-nacos/src/main/java/org/apache/skywalking/oap/server/configuration/nacos/NacosConfigWatcherRegister.java b/oap-server/server-configuration/configuration-nacos/src/main/java/org/apache/skywalking/oap/server/configuration/nacos/NacosConfigWatcherRegister.java index 663af8763f76..a654490bd28d 100644 --- a/oap-server/server-configuration/configuration-nacos/src/main/java/org/apache/skywalking/oap/server/configuration/nacos/NacosConfigWatcherRegister.java +++ b/oap-server/server-configuration/configuration-nacos/src/main/java/org/apache/skywalking/oap/server/configuration/nacos/NacosConfigWatcherRegister.java @@ -57,6 +57,9 @@ public NacosConfigWatcherRegister(NacosServerSettings settings) throws NacosExce final Properties properties = new Properties(); properties.put(PropertyKeyConst.SERVER_ADDR, serverAddr + ":" + port); properties.put(PropertyKeyConst.NAMESPACE, settings.getNamespace()); + if (StringUtil.isNotEmpty(settings.getContextPath())) { + properties.put(PropertyKeyConst.CONTEXT_PATH, settings.getContextPath()); + } if (StringUtil.isNotEmpty(settings.getUsername())) { properties.put(PropertyKeyConst.USERNAME, settings.getUsername()); properties.put(PropertyKeyConst.PASSWORD, settings.getPassword()); diff --git a/oap-server/server-configuration/configuration-nacos/src/main/java/org/apache/skywalking/oap/server/configuration/nacos/NacosServerSettings.java b/oap-server/server-configuration/configuration-nacos/src/main/java/org/apache/skywalking/oap/server/configuration/nacos/NacosServerSettings.java index cd76635f6d51..5d9f478c9730 100644 --- a/oap-server/server-configuration/configuration-nacos/src/main/java/org/apache/skywalking/oap/server/configuration/nacos/NacosServerSettings.java +++ b/oap-server/server-configuration/configuration-nacos/src/main/java/org/apache/skywalking/oap/server/configuration/nacos/NacosServerSettings.java @@ -34,6 +34,7 @@ public class NacosServerSettings extends ModuleConfig { private int period = 60; private String username; private String password; + private String contextPath; private String accessKey; private String secretKey; } diff --git a/oap-server/server-configuration/configuration-nacos/src/test/resources/application.yml b/oap-server/server-configuration/configuration-nacos/src/test/resources/application.yml index 375be7a63853..5e7c46d60b08 100755 --- a/oap-server/server-configuration/configuration-nacos/src/test/resources/application.yml +++ b/oap-server/server-configuration/configuration-nacos/src/test/resources/application.yml @@ -33,6 +33,7 @@ configuration: period: 1 # the name of current cluster, set the name if you want to upstream system known. clusterName: "default" + contextPath: '/nacos' # Nacos auth username username: 'nacos' password: 'nacos' diff --git a/oap-server/server-starter/src/main/resources/application.yml b/oap-server/server-starter/src/main/resources/application.yml index 75a0b2fd4521..44c825a3bd42 100644 --- a/oap-server/server-starter/src/main/resources/application.yml +++ b/oap-server/server-starter/src/main/resources/application.yml @@ -56,6 +56,7 @@ cluster: hostPort: ${SW_CLUSTER_NACOS_HOST_PORT:localhost:8848} # Nacos Naming namespace namespace: ${SW_CLUSTER_NACOS_NAMESPACE:"public"} + contextPath: ${SW_CLUSTER_NACOS_CONTEXT_PATH:""} # Nacos auth username username: ${SW_CLUSTER_NACOS_USERNAME:""} password: ${SW_CLUSTER_NACOS_PASSWORD:""}