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 05:33:39 UTC

[skywalking] branch envoy-service-name updated (4badd1f -> ad9c31c)

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.


 discard 4badd1f  Resolve envoy service name from a different position
     new ad9c31c  Resolve envoy service name from a different position

This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (4badd1f)
            \
             N -- N -- N   refs/heads/envoy-service-name (ad9c31c)

You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

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.


Summary of changes:
 .../server-bootstrap/src/main/resources/application.yml |  2 +-
 .../receiver/envoy/als/k8s/ServiceNameFormatter.java    |  2 +-
 .../envoy/als/k8s/ServiceNameFormatterTest.java         | 17 +++++++++--------
 .../src/test/resources/metadata-service-mapping.yaml    |  2 +-
 4 files changed, 12 insertions(+), 11 deletions(-)

[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 ad9c31c9bb7d0c8c5c9eafce14936c34c92e779a
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>
---
 CHANGES.md                                         |  1 +
 .../src/main/resources/application.yml             |  2 +-
 .../main/resources/metadata-service-mapping.yaml   |  2 +-
 .../oap/server/library/util/ResourceUtils.java     |  3 ++-
 .../envoy/als/k8s/ServiceNameFormatter.java        |  2 +-
 .../server/receiver/envoy/als/mx/FieldsHelper.java | 22 +++++++++++++++++++++-
 .../envoy/als/k8s/ServiceNameFormatterTest.java    | 17 +++++++++--------
 .../receiver/envoy/als/mx/FieldsHelperTest.java    |  8 ++++----
 .../test/resources/metadata-service-mapping.yaml   |  2 +-
 9 files changed, 41 insertions(+), 18 deletions(-)

diff --git a/CHANGES.md b/CHANGES.md
index d5c1d81..1e4986e 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -62,6 +62,7 @@ Release Notes.
 * Optimize the self monitoring grafana dashboard.
 * Enhance the export service.
 * Add function `retagByK8sMeta` and opt type `K8sRetagType.Pod2Service` in MAL for k8s to relate pods and services.
+* Using "service.istio.io/canonical-name" to replace "app" label to resolve Envoy ALS service name
 
 #### UI
 * Update selector scroller to show in all pages.
diff --git a/oap-server/server-bootstrap/src/main/resources/application.yml b/oap-server/server-bootstrap/src/main/resources/application.yml
index 91ea490..a5d6f27 100755
--- a/oap-server/server-bootstrap/src/main/resources/application.yml
+++ b/oap-server/server-bootstrap/src/main/resources/application.yml
@@ -327,7 +327,7 @@ envoy-metric:
     # the available variables are `pod`, `service`, f.e., you can use `${service.metadata.name}-${pod.metadata.labels.version}`
     # to append the version number to the service name.
     # Be careful, when using environment variables to pass this configuration, use single quotes(`''`) to avoid it being evaluated by the shell.
-    k8sServiceNameRule: ${K8S_SERVICE_NAME_RULE:"${service.metadata.name}"}
+    k8sServiceNameRule: ${K8S_SERVICE_NAME_RULE:"${pod.metadata.labels.(service.istio.io/canonical-name)}"}
 
 prometheus-fetcher:
   selector: ${SW_PROMETHEUS_FETCHER:-}
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/k8s/ServiceNameFormatter.java b/oap-server/server-receiver-plugin/envoy-metrics-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/envoy/als/k8s/ServiceNameFormatter.java
index 12534de..64d34ae 100644
--- a/oap-server/server-receiver-plugin/envoy-metrics-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/envoy/als/k8s/ServiceNameFormatter.java
+++ b/oap-server/server-receiver-plugin/envoy-metrics-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/envoy/als/k8s/ServiceNameFormatter.java
@@ -34,7 +34,7 @@ public class ServiceNameFormatter {
     private final StringBuffer serviceNamePattern;
 
     public ServiceNameFormatter(String rule) {
-        rule = StringUtils.defaultIfBlank(rule, "${service.metadata.name}");
+        rule = StringUtils.defaultIfBlank(rule, "${pod.metadata.labels.(service.istio.io/canonical-name)}");
 
         this.properties = new ArrayList<>();
         this.serviceNamePattern = new StringBuffer();
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/k8s/ServiceNameFormatterTest.java b/oap-server/server-receiver-plugin/envoy-metrics-receiver-plugin/src/test/java/org/apache/skywalking/oap/server/receiver/envoy/als/k8s/ServiceNameFormatterTest.java
index 581f5c1..f7de096 100644
--- a/oap-server/server-receiver-plugin/envoy-metrics-receiver-plugin/src/test/java/org/apache/skywalking/oap/server/receiver/envoy/als/k8s/ServiceNameFormatterTest.java
+++ b/oap-server/server-receiver-plugin/envoy-metrics-receiver-plugin/src/test/java/org/apache/skywalking/oap/server/receiver/envoy/als/k8s/ServiceNameFormatterTest.java
@@ -28,6 +28,7 @@ import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.junit.runners.Parameterized;
 
+import static com.google.common.collect.ImmutableSortedMap.of;
 import static junit.framework.TestCase.assertEquals;
 
 @RequiredArgsConstructor
@@ -40,22 +41,22 @@ public class ServiceNameFormatterTest {
         return new Case[] {
             new Case(
                 null,
-                ImmutableMap.of("service", service("Clash")),
+                ImmutableMap.of("pod", pod(of("service.istio.io/canonical-name","Clash"))),
                 "Clash"
             ),
             new Case(
                 null,
-                ImmutableMap.of("service", service("ClashX"), "pod", pod("version", "v1")),
+                ImmutableMap.of("pod", pod(of("service.istio.io/canonical-name","ClashX", "service.istio.io/canonical-revision", "v1"))),
                 "ClashX"
             ),
             new Case(
-                "${service.metadata.name}-${pod.metadata.labels.version}",
-                ImmutableMap.of("service", service("Clash"), "pod", pod("version", "v1beta")),
+                "${pod.metadata.labels.(service.istio.io/canonical-name)}-${pod.metadata.labels.(service.istio.io/canonical-revision)}",
+                ImmutableMap.of("pod", pod(of("service.istio.io/canonical-name","Clash", "service.istio.io/canonical-revision", "v1beta"))),
                 "Clash-v1beta"
             ),
             new Case(
-                "${pod.metadata.labels.app}",
-                ImmutableMap.of("service", service("Clash"), "pod", pod("app", "ClashX-alpha")),
+                "${pod.metadata.labels.(service.istio.io/canonical-name)}",
+                ImmutableMap.of("service", service("Clash"), "pod", pod(of("service.istio.io/canonical-name", "ClashX-alpha"))),
                 "ClashX-alpha"
             )
         };
@@ -80,14 +81,14 @@ public class ServiceNameFormatterTest {
         };
     }
 
-    static V1Pod pod(final String label, final String value) {
+    static V1Pod pod(ImmutableMap<String, String> lb) {
         return new V1Pod() {
             @Override
             public V1ObjectMeta getMetadata() {
                 return new V1ObjectMeta() {
                     @Override
                     public Map<String, String> getLabels() {
-                        return ImmutableMap.of(label, value);
+                        return lb;
                     }
                 };
             }
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"
             }
diff --git a/test/e2e/e2e-test/src/test/resources/metadata-service-mapping.yaml b/test/e2e/e2e-test/src/test/resources/metadata-service-mapping.yaml
index 0177de8..9e58722 100644
--- a/test/e2e/e2e-test/src/test/resources/metadata-service-mapping.yaml
+++ b/test/e2e/e2e-test/src/test/resources/metadata-service-mapping.yaml
@@ -13,5 +13,5 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-serviceName: e2e::${LABELS.app}
+serviceName: e2e::${LABELS."service.istio.io/canonical-name"}
 serviceInstanceName: ${NAME}