You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by ha...@apache.org on 2021/03/30 04:18:24 UTC

[skywalking] branch envoy-service-name created (now 48a9149)

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

hanahmily pushed a change to branch envoy-service-name
in repository https://gitbox.apache.org/repos/asf/skywalking.git.


      at 48a9149  Resolve envoy service name from a different position

This branch includes the following new commits:

     new 48a9149  Resolve envoy service name from a different position

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


[skywalking] 01/01: Resolve envoy service name from a different position

Posted by ha...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

hanahmily pushed a commit to branch envoy-service-name
in repository https://gitbox.apache.org/repos/asf/skywalking.git

commit 48a9149b4543299c614e6dd0b5cca89b750caf08
Author: Gao Hongtao <ha...@gmail.com>
AuthorDate: Tue Mar 30 12:15:25 2021 +0800

    Resolve envoy service name from a different position
    
     * Using "service.istio.io/canonical-name" to replace "app" label to resolve service name
     * Improving FieldsHelper to support dot in labels
    
    Signed-off-by: Gao Hongtao <ha...@gmail.com>
---
 .../main/resources/metadata-service-mapping.yaml   |  2 +-
 .../oap/server/library/util/ResourceUtils.java     |  3 ++-
 .../server/receiver/envoy/als/mx/FieldsHelper.java | 22 +++++++++++++++++++++-
 .../receiver/envoy/als/mx/FieldsHelperTest.java    |  8 ++++----
 4 files changed, 28 insertions(+), 7 deletions(-)

diff --git a/oap-server/server-bootstrap/src/main/resources/metadata-service-mapping.yaml b/oap-server/server-bootstrap/src/main/resources/metadata-service-mapping.yaml
index 3526f66..941ece6 100644
--- a/oap-server/server-bootstrap/src/main/resources/metadata-service-mapping.yaml
+++ b/oap-server/server-bootstrap/src/main/resources/metadata-service-mapping.yaml
@@ -13,5 +13,5 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-serviceName: ${LABELS.app}
+serviceName: ${LABELS."service.istio.io/canonical-name"}
 serviceInstanceName: ${NAME}
diff --git a/oap-server/server-library/library-util/src/main/java/org/apache/skywalking/oap/server/library/util/ResourceUtils.java b/oap-server/server-library/library-util/src/main/java/org/apache/skywalking/oap/server/library/util/ResourceUtils.java
index 48e3d49..1381090 100644
--- a/oap-server/server-library/library-util/src/main/java/org/apache/skywalking/oap/server/library/util/ResourceUtils.java
+++ b/oap-server/server-library/library-util/src/main/java/org/apache/skywalking/oap/server/library/util/ResourceUtils.java
@@ -48,7 +48,8 @@ public class ResourceUtils {
         if (url == null) {
             throw new FileNotFoundException("path not found: " + path);
         }
-        return Objects.requireNonNull(new File(url.getPath()).listFiles(), "No files in " + path);
+        return Arrays.stream(Objects.requireNonNull(new File(url.getPath()).listFiles(), "No files in " + path))
+                     .filter(File::isFile).toArray(File[]::new);
     }
 
     public static File[] getPathFiles(String parentPath, String[] fileNames) throws FileNotFoundException {
diff --git a/oap-server/server-receiver-plugin/envoy-metrics-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/envoy/als/mx/FieldsHelper.java b/oap-server/server-receiver-plugin/envoy-metrics-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/envoy/als/mx/FieldsHelper.java
index 43737d7..04ad511 100644
--- a/oap-server/server-receiver-plugin/envoy-metrics-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/envoy/als/mx/FieldsHelper.java
+++ b/oap-server/server-receiver-plugin/envoy-metrics-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/envoy/als/mx/FieldsHelper.java
@@ -39,6 +39,9 @@ import org.apache.skywalking.oap.server.receiver.envoy.als.ServiceMetaInfo;
 import org.yaml.snakeyaml.Yaml;
 
 @Slf4j
+/**
+ * FieldsHelper
+ */
 public enum FieldsHelper {
     SINGLETON;
 
@@ -82,7 +85,24 @@ public enum FieldsHelper {
             final StringBuffer serviceNamePattern = new StringBuffer();
             while (m.find()) {
                 final String property = m.group("property");
-                flatBuffersFieldNames.add(Splitter.on('.').omitEmptyStrings().splitToList(property));
+                List<String> tokens = Splitter.on('.').omitEmptyStrings().splitToList(property);
+
+                StringBuilder tokenBuffer = new StringBuilder();
+                List<String> compactedTokens = new ArrayList<>(tokens.size());
+                for (String token : tokens) {
+                    if (tokenBuffer.length() == 0 && token.startsWith("\"")) {
+                       tokenBuffer.append(token);
+                    } else if (tokenBuffer.length() > 0) {
+                        tokenBuffer.append(".").append(token);
+                        if (token.endsWith("\"")) {
+                            compactedTokens.add(tokenBuffer.toString().replaceAll("\"", ""));
+                            tokenBuffer.setLength(0);
+                        }
+                    } else {
+                        compactedTokens.add(token);
+                    }
+                }
+                flatBuffersFieldNames.add(compactedTokens);
                 m.appendReplacement(serviceNamePattern, "%s");
             }
 
diff --git a/oap-server/server-receiver-plugin/envoy-metrics-receiver-plugin/src/test/java/org/apache/skywalking/oap/server/receiver/envoy/als/mx/FieldsHelperTest.java b/oap-server/server-receiver-plugin/envoy-metrics-receiver-plugin/src/test/java/org/apache/skywalking/oap/server/receiver/envoy/als/mx/FieldsHelperTest.java
index dc4c210..8a38c18 100644
--- a/oap-server/server-receiver-plugin/envoy-metrics-receiver-plugin/src/test/java/org/apache/skywalking/oap/server/receiver/envoy/als/mx/FieldsHelperTest.java
+++ b/oap-server/server-receiver-plugin/envoy-metrics-receiver-plugin/src/test/java/org/apache/skywalking/oap/server/receiver/envoy/als/mx/FieldsHelperTest.java
@@ -51,22 +51,22 @@ public class FieldsHelperTest {
     public static Collection<Object[]> data() {
         return Arrays.asList(new Object[][] {
             {
-                "serviceName: ${LABELS.app}\nserviceInstanceName: ${NAME}",
+                "serviceName: ${LABELS.\"service.istio.io/canonical-name\"}\nserviceInstanceName: ${NAME}",
                 "productpage",
                 "productpage-v1-65576bb7bf-4mzsp"
             },
             {
-                "serviceName: ${LABELS.app}-${LABELS.version}\nserviceInstanceName: ${NAME}.${NAMESPACE}",
+                "serviceName: ${LABELS.\"service.istio.io/canonical-name\"}-${LABELS.version}\nserviceInstanceName: ${NAME}.${NAMESPACE}",
                 "productpage-v1",
                 "productpage-v1-65576bb7bf-4mzsp.default"
             },
             {
-                "serviceName: ${LABELS.app}-${CLUSTER_ID}\nserviceInstanceName: ${NAME}.${NAMESPACE}.${SERVICE_ACCOUNT}",
+                "serviceName: ${LABELS.\"service.istio.io/canonical-name\"}-${CLUSTER_ID}\nserviceInstanceName: ${NAME}.${NAMESPACE}.${SERVICE_ACCOUNT}",
                 "productpage-Kubernetes",
                 "productpage-v1-65576bb7bf-4mzsp.default.bookinfo-productpage"
             },
             {
-                "serviceName: fixed-${LABELS.app}\nserviceInstanceName: yeah_${NAME}",
+                "serviceName: fixed-${LABELS.\"service.istio.io/canonical-name\"}\nserviceInstanceName: yeah_${NAME}",
                 "fixed-productpage",
                 "yeah_productpage-v1-65576bb7bf-4mzsp"
             }