You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by wu...@apache.org on 2019/05/31 13:40:26 UTC

[skywalking] branch config-API updated: Add new gRPC service for configuration.

This is an automated email from the ASF dual-hosted git repository.

wusheng pushed a commit to branch config-API
in repository https://gitbox.apache.org/repos/asf/skywalking.git


The following commit(s) were added to refs/heads/config-API by this push:
     new 828839b  Add new gRPC service for configuration.
828839b is described below

commit 828839be65735bcae1a1d4b9b173077b892db7bc
Author: Wu Sheng <wu...@foxmail.com>
AuthorDate: Fri May 31 21:40:14 2019 +0800

    Add new gRPC service for configuration.
---
 docs/en/guides/How-to-build.md                     |  1 +
 .../configuration/api/ConfigWatcherRegister.java   |  4 +-
 .../grpc-configuration-sync}/pom.xml               | 53 +++++-----------------
 .../grpc/GRPCConfigWatcherRegister.java            | 41 +++++++++++++++++
 .../grpc/GRPCConfigurationProvider.java            | 49 ++++++++++++++++++++
 .../configuration/grpc/RemoteEndpointSettings.java | 34 ++++++++++++++
 .../src/main/proto/configuration-service.proto     | 50 ++++++++++++++++++++
 ...alking.oap.server.library.module.ModuleProvider | 19 ++++++++
 oap-server/server-configuration/pom.xml            |  2 +-
 oap-server/server-core/pom.xml                     |  2 +-
 oap-server/server-starter/pom.xml                  |  7 +++
 pom.xml                                            |  3 +-
 12 files changed, 220 insertions(+), 45 deletions(-)

diff --git a/docs/en/guides/How-to-build.md b/docs/en/guides/How-to-build.md
index f403b05..893e7ad 100644
--- a/docs/en/guides/How-to-build.md
+++ b/docs/en/guides/How-to-build.md
@@ -72,6 +72,7 @@ a oap image with name `bar/oap:foo`, run the following command
     * `grpc-java` and `java` folders in **oap-server/server-core/target/generated-sources/protobuf**
     * `grpc-java` and `java` folders in **oap-server/server-receiver-plugin/receiver-proto/target/generated-sources/protobuf**
     * `grpc-java` and `java` folders in **oap-server/exporter/target/generated-sources/protobuf**
+    * `grpc-java` and `java` folders in **oap-server/server-configuration/grpc-configuration-sync/target/generated-sources/protobuf**
     * `antlr4` folder in **oap-server/generate-tool-grammar/target/generated-sources**
     * `oal` folder in **oap-server/generated-analysis/target/generated-sources**
     
diff --git a/oap-server/server-configuration/configuration-api/src/main/java/org/apache/skywalking/oap/server/configuration/api/ConfigWatcherRegister.java b/oap-server/server-configuration/configuration-api/src/main/java/org/apache/skywalking/oap/server/configuration/api/ConfigWatcherRegister.java
index 3ff2250..3e3428c 100644
--- a/oap-server/server-configuration/configuration-api/src/main/java/org/apache/skywalking/oap/server/configuration/api/ConfigWatcherRegister.java
+++ b/oap-server/server-configuration/configuration-api/src/main/java/org/apache/skywalking/oap/server/configuration/api/ConfigWatcherRegister.java
@@ -61,7 +61,7 @@ public abstract class ConfigWatcherRegister implements DynamicConfigurationServi
         isStarted = true;
 
         configSync();
-        logger.info("Current the config value after the bootstrap sync." + LINE_SEPARATOR + register.toString());
+        logger.info("Current configurations after the bootstrap sync." + LINE_SEPARATOR + register.toString());
 
         Executors.newSingleThreadScheduledExecutor().scheduleAtFixedRate(
             new RunnableWithExceptionProtection(() -> configSync(),
@@ -95,6 +95,8 @@ public abstract class ConfigWatcherRegister implements DynamicConfigurationServi
                 logger.warn("Config {} from configuration center, doesn't match any watcher, ignore.", itemName);
             }
         });
+
+        logger.trace("Current configurations after the sync." + LINE_SEPARATOR + register.toString());
     }
 
     public abstract ConfigTable readConfig();
diff --git a/oap-server/server-core/pom.xml b/oap-server/server-configuration/grpc-configuration-sync/pom.xml
similarity index 65%
copy from oap-server/server-core/pom.xml
copy to oap-server/server-configuration/grpc-configuration-sync/pom.xml
index 047de59..10d7840 100644
--- a/oap-server/server-core/pom.xml
+++ b/oap-server/server-configuration/grpc-configuration-sync/pom.xml
@@ -17,41 +17,22 @@
   ~
   -->
 
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
     <parent>
-        <artifactId>oap-server</artifactId>
+        <artifactId>server-configuration</artifactId>
         <groupId>org.apache.skywalking</groupId>
         <version>6.2.0-SNAPSHOT</version>
     </parent>
     <modelVersion>4.0.0</modelVersion>
 
-    <artifactId>server-core</artifactId>
-    <packaging>jar</packaging>
+    <artifactId>grpc-configuration-sync</artifactId>
 
     <dependencies>
         <dependency>
-            <groupId>org.yaml</groupId>
-            <artifactId>snakeyaml</artifactId>
-        </dependency>
-
-        <dependency>
-            <groupId>org.apache.skywalking</groupId>
-            <artifactId>library-module</artifactId>
-            <version>${project.version}</version>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.skywalking</groupId>
-            <artifactId>telemetry-api</artifactId>
-            <version>${project.version}</version>
-        </dependency>
-        <dependency>
             <groupId>org.apache.skywalking</groupId>
             <artifactId>configuration-api</artifactId>
-            <version>6.2.0-SNAPSHOT</version>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.skywalking</groupId>
-            <artifactId>library-util</artifactId>
             <version>${project.version}</version>
         </dependency>
         <dependency>
@@ -60,30 +41,20 @@
             <version>${project.version}</version>
         </dependency>
         <dependency>
-            <groupId>org.apache.skywalking</groupId>
-            <artifactId>library-server</artifactId>
-            <version>${project.version}</version>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.skywalking</groupId>
-            <artifactId>apm-datacarrier</artifactId>
-            <version>${project.version}</version>
+            <groupId>io.grpc</groupId>
+            <artifactId>grpc-core</artifactId>
         </dependency>
         <dependency>
-            <groupId>org.apache.skywalking</groupId>
-            <artifactId>apm-network</artifactId>
-            <version>${project.version}</version>
+            <groupId>io.grpc</groupId>
+            <artifactId>grpc-netty</artifactId>
         </dependency>
         <dependency>
-            <groupId>org.apache.skywalking</groupId>
-            <artifactId>server-testing</artifactId>
-            <version>${project.version}</version>
-            <scope>test</scope>
+            <groupId>io.grpc</groupId>
+            <artifactId>grpc-protobuf</artifactId>
         </dependency>
         <dependency>
             <groupId>io.grpc</groupId>
-            <artifactId>grpc-testing</artifactId>
-            <scope>test</scope>
+            <artifactId>grpc-stub</artifactId>
         </dependency>
     </dependencies>
 
diff --git a/oap-server/server-configuration/grpc-configuration-sync/src/main/java/org/apache/skywalking/oap/server/configuration/grpc/GRPCConfigWatcherRegister.java b/oap-server/server-configuration/grpc-configuration-sync/src/main/java/org/apache/skywalking/oap/server/configuration/grpc/GRPCConfigWatcherRegister.java
new file mode 100644
index 0000000..8ed938b
--- /dev/null
+++ b/oap-server/server-configuration/grpc-configuration-sync/src/main/java/org/apache/skywalking/oap/server/configuration/grpc/GRPCConfigWatcherRegister.java
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.skywalking.oap.server.configuration.grpc;
+
+import io.grpc.netty.NettyChannelBuilder;
+import org.apache.skywalking.oap.server.configuration.api.*;
+import org.apache.skywalking.oap.server.configuration.service.ConfigurationServiceGrpc;
+
+/**
+ * @author wusheng
+ */
+public class GRPCConfigWatcherRegister extends ConfigWatcherRegister {
+    private RemoteEndpointSettings settings;
+    private ConfigurationServiceGrpc.ConfigurationServiceBlockingStub stub;
+
+    public GRPCConfigWatcherRegister(RemoteEndpointSettings settings) {
+        super(settings.getPeriod());
+        this.settings = settings;
+        stub = ConfigurationServiceGrpc.newBlockingStub(NettyChannelBuilder.forAddress(settings.getHost(), settings.getPort()).build());
+    }
+
+    @Override public ConfigTable readConfig() {
+        return null;
+    }
+}
diff --git a/oap-server/server-configuration/grpc-configuration-sync/src/main/java/org/apache/skywalking/oap/server/configuration/grpc/GRPCConfigurationProvider.java b/oap-server/server-configuration/grpc-configuration-sync/src/main/java/org/apache/skywalking/oap/server/configuration/grpc/GRPCConfigurationProvider.java
new file mode 100644
index 0000000..55a4ebd
--- /dev/null
+++ b/oap-server/server-configuration/grpc-configuration-sync/src/main/java/org/apache/skywalking/oap/server/configuration/grpc/GRPCConfigurationProvider.java
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.skywalking.oap.server.configuration.grpc;
+
+import org.apache.skywalking.oap.server.configuration.api.*;
+import org.apache.skywalking.oap.server.library.module.ModuleConfig;
+
+/**
+ * Get configuration from remote through gRPC protocol.
+ *
+ * Read configuration-service.proto for more details.
+ *
+ * @author wusheng
+ */
+public class GRPCConfigurationProvider extends AbstractConfigurationProvider {
+    private RemoteEndpointSettings settings;
+
+    public GRPCConfigurationProvider() {
+        settings = new RemoteEndpointSettings();
+    }
+
+    @Override public String name() {
+        return "grpc";
+    }
+
+    @Override public ModuleConfig createConfigBeanIfAbsent() {
+        return settings;
+    }
+
+    @Override protected ConfigWatcherRegister initConfigReader() {
+        return new GRPCConfigWatcherRegister(settings);
+    }
+}
diff --git a/oap-server/server-configuration/grpc-configuration-sync/src/main/java/org/apache/skywalking/oap/server/configuration/grpc/RemoteEndpointSettings.java b/oap-server/server-configuration/grpc-configuration-sync/src/main/java/org/apache/skywalking/oap/server/configuration/grpc/RemoteEndpointSettings.java
new file mode 100644
index 0000000..cb8ac9c
--- /dev/null
+++ b/oap-server/server-configuration/grpc-configuration-sync/src/main/java/org/apache/skywalking/oap/server/configuration/grpc/RemoteEndpointSettings.java
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.skywalking.oap.server.configuration.grpc;
+
+import lombok.*;
+import org.apache.skywalking.oap.server.library.module.ModuleConfig;
+
+/**
+ * @author wusheng
+ */
+@Setter
+@Getter
+public class RemoteEndpointSettings extends ModuleConfig {
+    private String host;
+    private int port;
+    // Sync configuration per 60 seconds.
+    private int period = 60;
+}
diff --git a/oap-server/server-configuration/grpc-configuration-sync/src/main/proto/configuration-service.proto b/oap-server/server-configuration/grpc-configuration-sync/src/main/proto/configuration-service.proto
new file mode 100644
index 0000000..858de28
--- /dev/null
+++ b/oap-server/server-configuration/grpc-configuration-sync/src/main/proto/configuration-service.proto
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ *
+ */
+
+syntax = "proto3";
+
+option java_multiple_files = true;
+option java_package = "org.apache.skywalking.oap.server.configuration.service";
+
+service ConfigurationService {
+    rpc call (ConfigurationRequest) returns (ConfigurationResponse) {
+    }
+}
+
+message ConfigurationRequest {
+    // Logic name of this cluster,
+    // in case the remote configuration center implementation support
+    // configuration management for multiple clusters.
+    string clusterName = 1;
+}
+
+message ConfigurationResponse {
+    // Include all config items.
+    // All config name should be not empty,
+    // the name is composed by "module name"."provider name"."item name".
+    // Each watcher implementor will provide this, and it will be notified when the name matched.
+    //
+    // If the config center wants to set the value to NULL or empty,
+    // must set the name with empty and NULL explicitly.
+    repeated Config configTable = 1;
+}
+
+message Config {
+    string name = 1;
+    string value = 2;
+}
\ No newline at end of file
diff --git a/oap-server/server-configuration/grpc-configuration-sync/src/main/resources/META-INF/services/org.apache.skywalking.oap.server.library.module.ModuleProvider b/oap-server/server-configuration/grpc-configuration-sync/src/main/resources/META-INF/services/org.apache.skywalking.oap.server.library.module.ModuleProvider
new file mode 100644
index 0000000..1a9644e
--- /dev/null
+++ b/oap-server/server-configuration/grpc-configuration-sync/src/main/resources/META-INF/services/org.apache.skywalking.oap.server.library.module.ModuleProvider
@@ -0,0 +1,19 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You 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.
+#
+#
+
+org.apache.skywalking.oap.server.configuration.grpc.GRPCConfigurationProvider
\ No newline at end of file
diff --git a/oap-server/server-configuration/pom.xml b/oap-server/server-configuration/pom.xml
index a759bf7..b161e51 100644
--- a/oap-server/server-configuration/pom.xml
+++ b/oap-server/server-configuration/pom.xml
@@ -31,7 +31,7 @@
     <packaging>pom</packaging>
     <modules>
         <module>configuration-api</module>
+        <module>grpc-configuration-sync</module>
     </modules>
 
-
 </project>
\ No newline at end of file
diff --git a/oap-server/server-core/pom.xml b/oap-server/server-core/pom.xml
index 047de59..0eb0a88 100644
--- a/oap-server/server-core/pom.xml
+++ b/oap-server/server-core/pom.xml
@@ -47,7 +47,7 @@
         <dependency>
             <groupId>org.apache.skywalking</groupId>
             <artifactId>configuration-api</artifactId>
-            <version>6.2.0-SNAPSHOT</version>
+            <version>${project.version}</version>
         </dependency>
         <dependency>
             <groupId>org.apache.skywalking</groupId>
diff --git a/oap-server/server-starter/pom.xml b/oap-server/server-starter/pom.xml
index 44653f9..c80be5b 100644
--- a/oap-server/server-starter/pom.xml
+++ b/oap-server/server-starter/pom.xml
@@ -171,6 +171,13 @@
             <artifactId>exporter</artifactId>
             <version>${project.version}</version>
         </dependency>
+
+        <!-- configuration -->
+        <dependency>
+            <groupId>org.apache.skywalking</groupId>
+            <artifactId>grpc-configuration-sync</artifactId>
+            <version>${project.version}</version>
+        </dependency>
     </dependencies>
     <build>
         <finalName>skywalking-oap</finalName>
diff --git a/pom.xml b/pom.xml
index 4b1ce2b..a4dce43 100644
--- a/pom.xml
+++ b/pom.xml
@@ -485,7 +485,8 @@
                                 org/apache/skywalking/apm/network/language/**/*.java,
                                 org/apache/skywalking/oap/server/core/remote/grpc/proto/*.java,
                                 org/apache/skywalking/oal/tool/grammar/*.java,
-                                org/apache/skywalking/oap/server/exporter/grpc/*.java
+                                org/apache/skywalking/oap/server/exporter/grpc/*.java,
+                                org/apache/skywalking/oap/server/configuration/service/*.java
                             </excludes>
                         </configuration>
                         <goals>