You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by ke...@apache.org on 2021/01/05 06:25:38 UTC

[skywalking] branch bugfix/mx-mesh-customized-svc-name created (now 65b85c9)

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

kezhenxu94 pushed a change to branch bugfix/mx-mesh-customized-svc-name
in repository https://gitbox.apache.org/repos/asf/skywalking.git.


      at 65b85c9  Unify the service name rule in `metadata-service-mapping.yml` of `mx-mesh` analyzer and Envoy metrics service

This branch includes the following new commits:

     new 65b85c9  Unify the service name rule in `metadata-service-mapping.yml` of `mx-mesh` analyzer and Envoy metrics service

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: Unify the service name rule in `metadata-service-mapping.yml` of `mx-mesh` analyzer and Envoy metrics service

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

kezhenxu94 pushed a commit to branch bugfix/mx-mesh-customized-svc-name
in repository https://gitbox.apache.org/repos/asf/skywalking.git

commit 65b85c9044a4c22ada7ac74b06f6ce83aace2436
Author: kezhenxu94 <ke...@apache.org>
AuthorDate: Tue Jan 5 14:25:11 2021 +0800

    Unify the service name rule in `metadata-service-mapping.yml` of `mx-mesh` analyzer and Envoy metrics service
---
 CHANGES.md                                         |  3 +-
 .../envoy/als/mx/ServiceMetaInfoAdapter.java       | 51 ++++++++++++++++++++--
 2 files changed, 50 insertions(+), 4 deletions(-)

diff --git a/CHANGES.md b/CHANGES.md
index 1766fd6..9720b15 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -44,7 +44,8 @@ Release Notes.
 * Support Envoy {AccessLog,Metrics}Service API V3.
 * Adopt the [MAL](docs/en/concepts-and-designs/mal.md) in Envoy metrics service analyzer.
 * Fix the priority setting doesn't work of the ALS analyzers.
-* Fix bug that `endpoint-name-grouping.yml` is not customizable in Dockerized case.
+* Fix bug that `metadata-service-mapping.yml` is not customizable in Dockerized case.
+* Unify the service name rule in `metadata-service-mapping.yml` of `mx-mesh` analyzer and Envoy metrics service.
 
 #### UI
 * Fix un-removed tags in trace query.
diff --git a/oap-server/server-receiver-plugin/envoy-metrics-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/envoy/als/mx/ServiceMetaInfoAdapter.java b/oap-server/server-receiver-plugin/envoy-metrics-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/envoy/als/mx/ServiceMetaInfoAdapter.java
index c8ca1ac..099231d 100644
--- a/oap-server/server-receiver-plugin/envoy-metrics-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/envoy/als/mx/ServiceMetaInfoAdapter.java
+++ b/oap-server/server-receiver-plugin/envoy-metrics-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/envoy/als/mx/ServiceMetaInfoAdapter.java
@@ -18,18 +18,22 @@
 
 package org.apache.skywalking.oap.server.receiver.envoy.als.mx;
 
+import com.google.common.base.Joiner;
 import com.google.protobuf.Any;
 import com.google.protobuf.ByteString;
 import com.google.protobuf.BytesValue;
 import com.google.protobuf.Struct;
+import com.google.protobuf.Value;
 import java.nio.ByteBuffer;
-import java.util.Optional;
+import java.util.ArrayList;
+import java.util.List;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.skywalking.oap.server.receiver.envoy.als.ServiceMetaInfo;
 import Wasm.Common.FlatNode;
 import Wasm.Common.KeyVal;
 
+import static com.google.common.base.Strings.nullToEmpty;
 import static java.util.Objects.nonNull;
 import static java.util.Objects.requireNonNull;
 
@@ -58,8 +62,8 @@ public class ServiceMetaInfoAdapter extends ServiceMetaInfo {
             }
         }
 
-        setServiceName(Optional.ofNullable(flatNode.labelsByKey("app")).map(KeyVal::value).orElse("-"));
-        setServiceInstanceName(flatNode.name());
+        final Struct metadata = requireNonNull(extractStructFromNodeFlatBuffer(flatNode));
+        FieldsHelper.SINGLETON.inflate(metadata, this);
     }
 
     /**
@@ -73,6 +77,47 @@ public class ServiceMetaInfoAdapter extends ServiceMetaInfo {
     }
 
     /**
+     * This method does the reverse conversion of https://github.com/istio/proxy/blob/938a9485a4286f0ce824b76df221a9bb6c8a6989/extensions/common/proto_util.cc#L112. It extracts the metadata from the
+     * {@link FlatNode flat buffer node} so that we can reuse the logic of {@link FieldsHelper}.
+     *
+     * @param node the flat buffer node where to extract the metadata
+     * @return the metadata {@link Struct}
+     */
+    protected Struct extractStructFromNodeFlatBuffer(final FlatNode node) {
+        final Struct.Builder builder = Struct.newBuilder();
+
+        builder.putFields("NAME", Value.newBuilder().setStringValue(nullToEmpty(node.name())).build());
+        builder.putFields("NAMESPACE", Value.newBuilder().setStringValue(nullToEmpty(node.namespace())).build());
+        builder.putFields("OWNER", Value.newBuilder().setStringValue(nullToEmpty(node.owner())).build());
+        builder.putFields("WORKLOAD_NAME", Value.newBuilder().setStringValue(nullToEmpty(node.workloadName())).build());
+        builder.putFields("ISTIO_VERSION", Value.newBuilder().setStringValue(nullToEmpty(node.istioVersion())).build());
+        builder.putFields("MESH_ID", Value.newBuilder().setStringValue(nullToEmpty(node.meshId())).build());
+        builder.putFields("CLUSTER_ID", Value.newBuilder().setStringValue(nullToEmpty(node.clusterId())).build());
+
+        final Struct.Builder labels = Struct.newBuilder();
+        for (int i = 0; i < node.labelsLength(); i++) {
+            final KeyVal label = node.labels(i);
+            labels.putFields(nullToEmpty(label.key()), Value.newBuilder().setStringValue(nullToEmpty(label.value())).build());
+        }
+        builder.putFields("LABELS", Value.newBuilder().setStructValue(labels).build());
+
+        final Struct.Builder platformMetadata = Struct.newBuilder();
+        for (int i = 0; i < node.platformMetadataLength(); i++) {
+            final KeyVal platformMd = node.platformMetadata(i);
+            platformMetadata.putFields(nullToEmpty(platformMd.key()), Value.newBuilder().setStringValue(nullToEmpty(platformMd.value())).build());
+        }
+        builder.putFields("PLATFORM_METADATA", Value.newBuilder().setStructValue(platformMetadata).build());
+
+        final List<String> appContainers = new ArrayList<>();
+        for (int i = 0; i < node.appContainersLength(); i++) {
+            appContainers.add(node.appContainers(i));
+        }
+        builder.putFields("APP_CONTAINERS", Value.newBuilder().setStringValue(Joiner.on(",").join(appContainers)).build());
+
+        return builder.build();
+    }
+
+    /**
      * The same functionality with {@link ServiceMetaInfoAdapter#ServiceMetaInfoAdapter(com.google.protobuf.ByteString)}.
      *
      * @param metadata the {@link Struct struct} to adapt from.