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 2020/11/04 13:45:28 UTC
[skywalking] 01/01: Refactor Kubernetes analyzer and add metadata
exchang impl
This is an automated email from the ASF dual-hosted git repository.
kezhenxu94 pushed a commit to branch feature/als-mx
in repository https://gitbox.apache.org/repos/asf/skywalking.git
commit 7ff371018f00b42241767076f7ba736f96050cc0
Author: kezhenxu94 <ke...@163.com>
AuthorDate: Mon Nov 2 18:53:39 2020 +0800
Refactor Kubernetes analyzer and add metadata exchang impl
---
.github/workflows/docker-ci.yaml | 1 +
.github/workflows/e2e.istio.yaml | 10 +-
oap-server/pom.xml | 8 +
.../server-bootstrap/src/main/resources/log4j2.xml | 5 +-
.../main/resources/metadata-service-mapping.yaml} | 10 +-
.../envoy-metrics-receiver-plugin/pom.xml | 5 +
.../envoy/AccessLogServiceGRPCHandler.java | 19 +-
.../server/receiver/envoy/als/ALSHTTPAnalysis.java | 8 +-
.../receiver/envoy/als/AbstractALSAnalyzer.java | 64 ++++
.../envoy/als/LogEntry2MetricsAdapter.java | 169 +++++++++++
.../server/receiver/envoy/als/ServiceMetaInfo.java | 30 +-
.../als/k8s/K8SALSServiceMeshHTTPAnalyzer.java | 167 +++++++++++
.../als/k8s/K8sALSServiceMeshHTTPAnalysis.java | 334 ---------------------
.../server/receiver/envoy/als/mx/FieldsHelper.java | 101 +++++++
.../envoy/als/mx/MetaExchangeALSHTTPAnalyzer.java | 125 ++++++++
.../envoy/als/mx/ServiceMetaInfoAdapter.java | 82 +++++
.../{ALSHTTPAnalysis.java => mx/package-info.java} | 20 +-
.../src/main/java/wasm/common/FlatNode.java | 132 ++++++++
.../src/main/java/wasm/common/KeyVal.java | 93 ++++++
...g.oap.server.receiver.envoy.als.ALSHTTPAnalysis | 3 +-
...java => K8SALSServiceMeshHTTPAnalyzerTest.java} | 48 ++-
.../server-receiver-plugin/receiver-proto/pom.xml | 83 ++++-
.../src/main/fbs/istio/node-info.fbs | 48 +++
pom.xml | 8 +-
.../org/apache/skywalking/e2e/mesh/IDManager.java | 58 ----
25 files changed, 1144 insertions(+), 487 deletions(-)
diff --git a/.github/workflows/docker-ci.yaml b/.github/workflows/docker-ci.yaml
index f6fe273..0b556bc 100644
--- a/.github/workflows/docker-ci.yaml
+++ b/.github/workflows/docker-ci.yaml
@@ -30,6 +30,7 @@ jobs:
runs-on: ubuntu-16.04
timeout-minutes: 90
strategy:
+ fail-fast: true
matrix:
es: [es6, es7]
steps:
diff --git a/.github/workflows/e2e.istio.yaml b/.github/workflows/e2e.istio.yaml
index 34d590e..adc4838 100644
--- a/.github/workflows/e2e.istio.yaml
+++ b/.github/workflows/e2e.istio.yaml
@@ -19,10 +19,12 @@ name: Istio
on:
pull_request:
paths:
+ - '**'
- '!**.md'
push:
branches:
- master
+ - feature/als-mx
env:
SKIP_TEST: true
@@ -36,7 +38,11 @@ jobs:
als:
runs-on: ubuntu-16.04
timeout-minutes: 60
- name: Istio+Envoy Access Log Service
+ strategy:
+ fail-fast: true
+ matrix:
+ analyzer: [k8s-mesh, mx-mesh]
+ name: Istio+ALS(${{ matrix.analyzer }})
steps:
- uses: actions/checkout@v2
with:
@@ -72,7 +78,7 @@ jobs:
--set elasticsearch.replicas=1 \
--set elasticsearch.minimumMasterNodes=1 \
--set elasticsearch.imageTag=7.5.1 \
- --set oap.env.SW_ENVOY_METRIC_ALS_HTTP_ANALYSIS=k8s-mesh \
+ --set oap.env.SW_ENVOY_METRIC_ALS_HTTP_ANALYSIS=${{ matrix.analyzer }} \
--set oap.envoy.als.enabled=true \
--set oap.replicas=1 \
--set ui.image.repository=skywalking/ui \
diff --git a/oap-server/pom.xml b/oap-server/pom.xml
index 90185e9..402ac20 100755
--- a/oap-server/pom.xml
+++ b/oap-server/pom.xml
@@ -100,6 +100,7 @@
<kafka-clients.version>2.4.1</kafka-clients.version>
<spring-kafka-test.version>2.4.6.RELEASE</spring-kafka-test.version>
<commons-beanutils.version>1.9.4</commons-beanutils.version>
+ <flatbuffers-java.version>1.12.0</flatbuffers-java.version>
</properties>
<dependencies>
@@ -554,6 +555,13 @@
</exclusion>
</exclusions>
</dependency>
+
+
+ <dependency>
+ <groupId>com.google.flatbuffers</groupId>
+ <artifactId>flatbuffers-java</artifactId>
+ <version>${flatbuffers-java.version}</version>
+ </dependency>
</dependencies>
</dependencyManagement>
</project>
diff --git a/oap-server/server-bootstrap/src/main/resources/log4j2.xml b/oap-server/server-bootstrap/src/main/resources/log4j2.xml
index dde0c31..8a97a75 100644
--- a/oap-server/server-bootstrap/src/main/resources/log4j2.xml
+++ b/oap-server/server-bootstrap/src/main/resources/log4j2.xml
@@ -32,11 +32,10 @@
<logger name="io.netty" level="INFO"/>
<logger name="org.apache.http" level="INFO"/>
<logger name="org.apache.skywalking.oap.server.core.alarm.AlarmStandardPersistence" level="DEBUG"/>
- <logger name="org.apache.skywalking.oap.server.core" level="DEBUG"/>
<logger name="org.apache.skywalking.oap.server.core.analysis.worker" level="DEBUG" />
- <logger name="org.apache.skywalking.oap.server.core.remote.client" level="DEBUG"/>
+ <logger name="org.apache.skywalking.oap.server.receiver.envoy" level="DEBUG" />
<logger name="org.apache.skywalking.oap.server.library.buffer" level="INFO"/>
- <Root level="DEBUG">
+ <Root level="INFO">
<AppenderRef ref="Console"/>
</Root>
</Loggers>
diff --git a/oap-server/server-receiver-plugin/envoy-metrics-receiver-plugin/src/main/resources/META-INF/services/org.apache.skywalking.oap.server.receiver.envoy.als.ALSHTTPAnalysis b/oap-server/server-bootstrap/src/main/resources/metadata-service-mapping.yaml
similarity index 86%
copy from oap-server/server-receiver-plugin/envoy-metrics-receiver-plugin/src/main/resources/META-INF/services/org.apache.skywalking.oap.server.receiver.envoy.als.ALSHTTPAnalysis
copy to oap-server/server-bootstrap/src/main/resources/metadata-service-mapping.yaml
index 215d7a0..6c6397c 100644
--- a/oap-server/server-receiver-plugin/envoy-metrics-receiver-plugin/src/main/resources/META-INF/services/org.apache.skywalking.oap.server.receiver.envoy.als.ALSHTTPAnalysis
+++ b/oap-server/server-bootstrap/src/main/resources/metadata-service-mapping.yaml
@@ -1,4 +1,3 @@
-#
# 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.
@@ -13,8 +12,9 @@
# 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.receiver.envoy.als.k8s.K8sALSServiceMeshHTTPAnalysis
+serviceName: LABELS.app
+serviceInstanceName: NAME
+#subset: LABELS.version
+#namespace: NAMESPACE
+#cluster: CLUSTER_ID
diff --git a/oap-server/server-receiver-plugin/envoy-metrics-receiver-plugin/pom.xml b/oap-server/server-receiver-plugin/envoy-metrics-receiver-plugin/pom.xml
index 5e2428f..5d46fd3 100644
--- a/oap-server/server-receiver-plugin/envoy-metrics-receiver-plugin/pom.xml
+++ b/oap-server/server-receiver-plugin/envoy-metrics-receiver-plugin/pom.xml
@@ -61,5 +61,10 @@
<version>${org.apache.tomcat.annotations-api.version}</version>
<scope>provided</scope>
</dependency>
+
+ <dependency>
+ <groupId>com.google.flatbuffers</groupId>
+ <artifactId>flatbuffers-java</artifactId>
+ </dependency>
</dependencies>
</project>
diff --git a/oap-server/server-receiver-plugin/envoy-metrics-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/envoy/AccessLogServiceGRPCHandler.java b/oap-server/server-receiver-plugin/envoy-metrics-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/envoy/AccessLogServiceGRPCHandler.java
index b715ee3..4b8b79d 100644
--- a/oap-server/server-receiver-plugin/envoy-metrics-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/envoy/AccessLogServiceGRPCHandler.java
+++ b/oap-server/server-receiver-plugin/envoy-metrics-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/envoy/AccessLogServiceGRPCHandler.java
@@ -25,10 +25,10 @@ import io.grpc.stub.StreamObserver;
import java.util.ArrayList;
import java.util.List;
import java.util.ServiceLoader;
-import org.apache.skywalking.oap.server.core.CoreModule;
-import org.apache.skywalking.oap.server.core.source.Source;
-import org.apache.skywalking.oap.server.core.source.SourceReceiver;
+import org.apache.skywalking.aop.server.receiver.mesh.TelemetryDataDispatcher;
+import org.apache.skywalking.apm.network.servicemesh.v3.ServiceMeshMetric;
import org.apache.skywalking.oap.server.library.module.ModuleManager;
+import org.apache.skywalking.oap.server.library.module.ModuleStartException;
import org.apache.skywalking.oap.server.receiver.envoy.als.ALSHTTPAnalysis;
import org.apache.skywalking.oap.server.receiver.envoy.als.Role;
import org.apache.skywalking.oap.server.telemetry.TelemetryModule;
@@ -42,18 +42,18 @@ import org.slf4j.LoggerFactory;
public class AccessLogServiceGRPCHandler extends AccessLogServiceGrpc.AccessLogServiceImplBase {
private static final Logger LOGGER = LoggerFactory.getLogger(AccessLogServiceGRPCHandler.class);
private final List<ALSHTTPAnalysis> envoyHTTPAnalysisList;
- private final SourceReceiver sourceReceiver;
+
private final CounterMetrics counter;
private final HistogramMetrics histogram;
private final CounterMetrics sourceDispatcherCounter;
- public AccessLogServiceGRPCHandler(ModuleManager manager, EnvoyMetricReceiverConfig config) {
+ public AccessLogServiceGRPCHandler(ModuleManager manager, EnvoyMetricReceiverConfig config) throws ModuleStartException {
ServiceLoader<ALSHTTPAnalysis> alshttpAnalyses = ServiceLoader.load(ALSHTTPAnalysis.class);
envoyHTTPAnalysisList = new ArrayList<>();
for (String httpAnalysisName : config.getAlsHTTPAnalysis()) {
for (ALSHTTPAnalysis httpAnalysis : alshttpAnalyses) {
if (httpAnalysisName.equals(httpAnalysis.name())) {
- httpAnalysis.init(config);
+ httpAnalysis.init(manager, config);
envoyHTTPAnalysisList.add(httpAnalysis);
}
}
@@ -61,8 +61,6 @@ public class AccessLogServiceGRPCHandler extends AccessLogServiceGrpc.AccessLogS
LOGGER.debug("envoy HTTP analysis: " + envoyHTTPAnalysisList);
- sourceReceiver = manager.find(CoreModule.NAME).provider().getService(SourceReceiver.class);
-
MetricsCreator metricCreator = manager.find(TelemetryModule.NAME).provider().getService(MetricsCreator.class);
counter = metricCreator.createCounter("envoy_als_in_count", "The count of envoy ALS metric received", MetricsTag.EMPTY_KEY, MetricsTag.EMPTY_VALUE);
histogram = metricCreator.createHistogramMetric("envoy_als_in_latency", "The process latency of service ALS metric receiver", MetricsTag.EMPTY_KEY, MetricsTag.EMPTY_VALUE);
@@ -103,7 +101,7 @@ public class AccessLogServiceGRPCHandler extends AccessLogServiceGrpc.AccessLogS
case HTTP_LOGS:
StreamAccessLogsMessage.HTTPAccessLogEntries logs = message.getHttpLogs();
- List<Source> sourceResult = new ArrayList<>();
+ List<ServiceMeshMetric.Builder> sourceResult = new ArrayList<>();
for (ALSHTTPAnalysis analysis : envoyHTTPAnalysisList) {
logs.getLogEntryList().forEach(log -> {
sourceResult.addAll(analysis.analysis(identifier, log, role));
@@ -111,7 +109,8 @@ public class AccessLogServiceGRPCHandler extends AccessLogServiceGrpc.AccessLogS
}
sourceDispatcherCounter.inc(sourceResult.size());
- sourceResult.forEach(sourceReceiver::receive);
+ sourceResult.forEach(TelemetryDataDispatcher::process);
+ break;
}
} finally {
timer.finish();
diff --git a/oap-server/server-receiver-plugin/envoy-metrics-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/envoy/als/ALSHTTPAnalysis.java b/oap-server/server-receiver-plugin/envoy-metrics-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/envoy/als/ALSHTTPAnalysis.java
index 4297f3d..ae75c32 100644
--- a/oap-server/server-receiver-plugin/envoy-metrics-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/envoy/als/ALSHTTPAnalysis.java
+++ b/oap-server/server-receiver-plugin/envoy-metrics-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/envoy/als/ALSHTTPAnalysis.java
@@ -21,7 +21,9 @@ package org.apache.skywalking.oap.server.receiver.envoy.als;
import io.envoyproxy.envoy.data.accesslog.v2.HTTPAccessLogEntry;
import io.envoyproxy.envoy.service.accesslog.v2.StreamAccessLogsMessage;
import java.util.List;
-import org.apache.skywalking.oap.server.core.source.Source;
+import org.apache.skywalking.apm.network.servicemesh.v3.ServiceMeshMetric;
+import org.apache.skywalking.oap.server.library.module.ModuleManager;
+import org.apache.skywalking.oap.server.library.module.ModuleStartException;
import org.apache.skywalking.oap.server.receiver.envoy.EnvoyMetricReceiverConfig;
/**
@@ -30,9 +32,9 @@ import org.apache.skywalking.oap.server.receiver.envoy.EnvoyMetricReceiverConfig
public interface ALSHTTPAnalysis {
String name();
- void init(EnvoyMetricReceiverConfig config);
+ void init(ModuleManager manager, EnvoyMetricReceiverConfig config) throws ModuleStartException;
- List<Source> analysis(StreamAccessLogsMessage.Identifier identifier, HTTPAccessLogEntry entry, Role role);
+ List<ServiceMeshMetric.Builder> analysis(StreamAccessLogsMessage.Identifier identifier, HTTPAccessLogEntry entry, Role role);
Role identify(StreamAccessLogsMessage.Identifier alsIdentifier, Role prev);
}
diff --git a/oap-server/server-receiver-plugin/envoy-metrics-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/envoy/als/AbstractALSAnalyzer.java b/oap-server/server-receiver-plugin/envoy-metrics-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/envoy/als/AbstractALSAnalyzer.java
new file mode 100644
index 0000000..fae8cd1
--- /dev/null
+++ b/oap-server/server-receiver-plugin/envoy-metrics-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/envoy/als/AbstractALSAnalyzer.java
@@ -0,0 +1,64 @@
+/*
+ * 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.receiver.envoy.als;
+
+import io.envoyproxy.envoy.api.v2.core.Node;
+import io.envoyproxy.envoy.data.accesslog.v2.HTTPAccessLogEntry;
+import io.envoyproxy.envoy.service.accesslog.v2.StreamAccessLogsMessage;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.skywalking.apm.network.servicemesh.v3.ServiceMeshMetric;
+
+@Slf4j
+public abstract class AbstractALSAnalyzer implements ALSHTTPAnalysis {
+
+ @Override
+ public Role identify(final StreamAccessLogsMessage.Identifier alsIdentifier, final Role defaultRole) {
+ if (alsIdentifier == null) {
+ return defaultRole;
+ }
+ final Node node = alsIdentifier.getNode();
+ if (node == null) {
+ return defaultRole;
+ }
+ final String id = node.getId();
+ if (id.startsWith("router~")) {
+ return Role.PROXY;
+ } else if (id.startsWith("sidecar~")) {
+ return Role.SIDECAR;
+ }
+ return defaultRole;
+ }
+
+ /**
+ * Create an adapter to adapt the {@link HTTPAccessLogEntry log entry} into a {@link ServiceMeshMetric.Builder}.
+ *
+ * @param entry the access log entry that is to be adapted from.
+ * @param sourceService the source service.
+ * @param targetService the target/destination service.
+ * @return an adapter that adapts {@link HTTPAccessLogEntry log entry} into a {@link ServiceMeshMetric.Builder}.
+ */
+ protected LogEntry2MetricsAdapter newAdapter(
+ final HTTPAccessLogEntry entry,
+ final ServiceMetaInfo sourceService,
+ final ServiceMetaInfo targetService
+ ) {
+ return new LogEntry2MetricsAdapter(entry, sourceService, targetService);
+ }
+
+}
diff --git a/oap-server/server-receiver-plugin/envoy-metrics-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/envoy/als/LogEntry2MetricsAdapter.java b/oap-server/server-receiver-plugin/envoy-metrics-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/envoy/als/LogEntry2MetricsAdapter.java
new file mode 100644
index 0000000..3785266
--- /dev/null
+++ b/oap-server/server-receiver-plugin/envoy-metrics-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/envoy/als/LogEntry2MetricsAdapter.java
@@ -0,0 +1,169 @@
+/*
+ * 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.receiver.envoy.als;
+
+import com.google.protobuf.Duration;
+import com.google.protobuf.Timestamp;
+import com.google.protobuf.UInt32Value;
+import io.envoyproxy.envoy.data.accesslog.v2.AccessLogCommon;
+import io.envoyproxy.envoy.data.accesslog.v2.HTTPAccessLogEntry;
+import io.envoyproxy.envoy.data.accesslog.v2.HTTPRequestProperties;
+import io.envoyproxy.envoy.data.accesslog.v2.HTTPResponseProperties;
+import io.envoyproxy.envoy.data.accesslog.v2.TLSProperties;
+import java.time.Instant;
+import java.util.Optional;
+import lombok.RequiredArgsConstructor;
+import org.apache.skywalking.apm.network.common.v3.DetectPoint;
+import org.apache.skywalking.apm.network.servicemesh.v3.Protocol;
+import org.apache.skywalking.apm.network.servicemesh.v3.ServiceMeshMetric;
+
+import static com.google.common.base.Strings.isNullOrEmpty;
+import static java.util.Optional.ofNullable;
+
+/**
+ * Adapt {@link HTTPAccessLogEntry} objects to {@link ServiceMeshMetric} builders.
+ */
+@RequiredArgsConstructor
+public class LogEntry2MetricsAdapter {
+
+ public static final String NON_TLS = "NONE";
+
+ public static final String M_TLS = "mTLS";
+
+ public static final String TLS = "TLS";
+
+ /**
+ * The access log entry that is to be adapted into metrics builders.
+ */
+ private final HTTPAccessLogEntry entry;
+
+ private final ServiceMetaInfo sourceService;
+
+ private final ServiceMetaInfo targetService;
+
+ /**
+ * Adapt the {@code entry} partially, into a downstream metrics {@link ServiceMeshMetric.Builder}.
+ *
+ * @return the {@link ServiceMeshMetric.Builder} adapted from the given entry.
+ */
+ public ServiceMeshMetric.Builder adaptToDownstreamMetrics() {
+ final AccessLogCommon properties = entry.getCommonProperties();
+ final long startTime = formatAsLong(properties.getStartTime());
+ final long duration = formatAsLong(properties.getTimeToLastDownstreamTxByte());
+
+ final ServiceMeshMetric.Builder builder = adaptCommonPart()
+ .setStartTime(startTime)
+ .setEndTime(startTime + duration)
+ .setLatency((int) Math.max(1L, duration));
+
+ Optional.ofNullable(sourceService)
+ .map(ServiceMetaInfo::getServiceName)
+ .ifPresent(builder::setSourceServiceName);
+
+ Optional.ofNullable(sourceService)
+ .map(ServiceMetaInfo::getServiceInstanceName)
+ .ifPresent(builder::setSourceServiceInstance);
+
+ Optional.ofNullable(targetService)
+ .map(ServiceMetaInfo::getServiceName)
+ .ifPresent(builder::setDestServiceName);
+
+ Optional.ofNullable(targetService)
+ .map(ServiceMetaInfo::getServiceInstanceName)
+ .ifPresent(builder::setDestServiceInstance);
+
+ builder.setDetectPoint(DetectPoint.server);
+
+ return builder;
+ }
+
+ /**
+ * Adapt the {@code entry} partially, into a upstream metrics {@link ServiceMeshMetric.Builder}.
+ *
+ * @return the {@link ServiceMeshMetric.Builder} adapted from the given entry.
+ */
+ public ServiceMeshMetric.Builder adaptToUpstreamMetrics() {
+ final AccessLogCommon properties = entry.getCommonProperties();
+ final long startTime = formatAsLong(properties.getStartTime());
+ final long outboundStartTime = startTime + formatAsLong(properties.getTimeToFirstUpstreamTxByte());
+ final long outboundEndTime = startTime + formatAsLong(properties.getTimeToLastUpstreamRxByte());
+ return adaptCommonPart()
+ .setStartTime(outboundStartTime)
+ .setEndTime(outboundEndTime)
+ .setLatency((int) Math.max(1L, outboundEndTime - outboundStartTime))
+ .setSourceServiceName(sourceService.getServiceName())
+ .setSourceServiceInstance(sourceService.getServiceInstanceName())
+ .setDestServiceName(targetService.getServiceName())
+ .setDestServiceInstance(targetService.getServiceInstanceName())
+ .setDetectPoint(DetectPoint.client);
+ }
+
+ protected ServiceMeshMetric.Builder adaptCommonPart() {
+ final AccessLogCommon properties = entry.getCommonProperties();
+ final String endpoint = ofNullable(entry.getRequest()).map(HTTPRequestProperties::getPath).orElse("/");
+ final int responseCode = ofNullable(entry.getResponse()).map(HTTPResponseProperties::getResponseCode).map(UInt32Value::getValue).orElse(200);
+ final boolean status = responseCode >= 200 && responseCode < 400;
+ final Protocol protocol = requestProtocol(entry.getRequest());
+ final String tlsMode = parseTLS(properties.getTlsProperties());
+
+ return ServiceMeshMetric.newBuilder()
+ .setEndpoint(endpoint)
+ .setResponseCode(Math.toIntExact(responseCode))
+ .setStatus(status)
+ .setProtocol(protocol)
+ .setTlsMode(tlsMode);
+ }
+
+ protected static long formatAsLong(final Timestamp timestamp) {
+ return Instant.ofEpochSecond(timestamp.getSeconds(), timestamp.getNanos()).toEpochMilli();
+ }
+
+ protected static long formatAsLong(final Duration duration) {
+ return Instant.ofEpochSecond(duration.getSeconds(), duration.getNanos()).toEpochMilli();
+ }
+
+ protected static Protocol requestProtocol(final HTTPRequestProperties request) {
+ if (request == null) {
+ return Protocol.HTTP;
+ }
+ final String scheme = request.getScheme();
+ if (scheme.startsWith("http")) {
+ return Protocol.HTTP;
+ }
+ return Protocol.gRPC;
+ }
+
+ protected static String parseTLS(final TLSProperties properties) {
+ if (properties == null) {
+ return NON_TLS;
+ }
+ if (isNullOrEmpty(Optional.ofNullable(properties.getLocalCertificateProperties())
+ .orElse(TLSProperties.CertificateProperties.newBuilder().build())
+ .getSubject())) {
+ return NON_TLS;
+ }
+ if (isNullOrEmpty(Optional.ofNullable(properties.getPeerCertificateProperties())
+ .orElse(TLSProperties.CertificateProperties.newBuilder().build())
+ .getSubject())) {
+ return TLS;
+ }
+ return M_TLS;
+ }
+
+}
diff --git a/oap-server/server-receiver-plugin/envoy-metrics-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/envoy/als/ServiceMetaInfo.java b/oap-server/server-receiver-plugin/envoy-metrics-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/envoy/als/ServiceMetaInfo.java
index 41ba0e5..75a9c3c 100644
--- a/oap-server/server-receiver-plugin/envoy-metrics-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/envoy/als/ServiceMetaInfo.java
+++ b/oap-server/server-receiver-plugin/envoy-metrics-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/envoy/als/ServiceMetaInfo.java
@@ -19,8 +19,9 @@
package org.apache.skywalking.oap.server.receiver.envoy.als;
import java.util.List;
-import java.util.Objects;
+import lombok.EqualsAndHashCode;
import lombok.Getter;
+import lombok.NoArgsConstructor;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import lombok.ToString;
@@ -28,13 +29,16 @@ import lombok.ToString;
@Getter
@Setter
@ToString
+@NoArgsConstructor
+@EqualsAndHashCode(onlyExplicitlyIncluded = true)
public class ServiceMetaInfo {
+ @EqualsAndHashCode.Include
private String serviceName;
+
+ @EqualsAndHashCode.Include
private String serviceInstanceName;
- private List<KeyValue> tags;
- public ServiceMetaInfo() {
- }
+ private List<KeyValue> tags;
public ServiceMetaInfo(String serviceName, String serviceInstanceName) {
this.serviceName = serviceName;
@@ -43,26 +47,12 @@ public class ServiceMetaInfo {
@Setter
@Getter
- @RequiredArgsConstructor
@ToString
+ @RequiredArgsConstructor
public static class KeyValue {
private final String key;
- private final String value;
- }
- @Override
- public boolean equals(Object o) {
- if (this == o)
- return true;
- if (o == null || getClass() != o.getClass())
- return false;
- ServiceMetaInfo info = (ServiceMetaInfo) o;
- return Objects.equals(serviceName, info.serviceName) && Objects.equals(serviceInstanceName, info.serviceInstanceName);
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(serviceName, serviceInstanceName);
+ private final String value;
}
public static final ServiceMetaInfo UNKNOWN = new ServiceMetaInfo("UNKNOWN", "UNKNOWN");
diff --git a/oap-server/server-receiver-plugin/envoy-metrics-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/envoy/als/k8s/K8SALSServiceMeshHTTPAnalyzer.java b/oap-server/server-receiver-plugin/envoy-metrics-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/envoy/als/k8s/K8SALSServiceMeshHTTPAnalyzer.java
new file mode 100644
index 0000000..7814ace
--- /dev/null
+++ b/oap-server/server-receiver-plugin/envoy-metrics-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/envoy/als/k8s/K8SALSServiceMeshHTTPAnalyzer.java
@@ -0,0 +1,167 @@
+/*
+ * 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.receiver.envoy.als.k8s;
+
+import io.envoyproxy.envoy.api.v2.core.Address;
+import io.envoyproxy.envoy.api.v2.core.SocketAddress;
+import io.envoyproxy.envoy.data.accesslog.v2.AccessLogCommon;
+import io.envoyproxy.envoy.data.accesslog.v2.HTTPAccessLogEntry;
+import io.envoyproxy.envoy.service.accesslog.v2.StreamAccessLogsMessage;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import lombok.SneakyThrows;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.skywalking.apm.network.servicemesh.v3.ServiceMeshMetric;
+import org.apache.skywalking.oap.server.library.module.ModuleManager;
+import org.apache.skywalking.oap.server.receiver.envoy.EnvoyMetricReceiverConfig;
+import org.apache.skywalking.oap.server.receiver.envoy.als.AbstractALSAnalyzer;
+import org.apache.skywalking.oap.server.receiver.envoy.als.Role;
+import org.apache.skywalking.oap.server.receiver.envoy.als.ServiceMetaInfo;
+
+import static org.apache.skywalking.oap.server.receiver.envoy.als.LogEntry2MetricsAdapter.NON_TLS;
+
+/**
+ * Analysis log based on ingress and mesh scenarios.
+ */
+@Slf4j
+public class K8SALSServiceMeshHTTPAnalyzer extends AbstractALSAnalyzer {
+ protected K8SServiceRegistry serviceRegistry;
+
+ @Override
+ public String name() {
+ return "k8s-mesh";
+ }
+
+ @Override
+ @SneakyThrows
+ public void init(ModuleManager manager, EnvoyMetricReceiverConfig config) {
+ serviceRegistry = new K8SServiceRegistry(config);
+ serviceRegistry.start();
+ }
+
+ @Override
+ public List<ServiceMeshMetric.Builder> analysis(StreamAccessLogsMessage.Identifier identifier, HTTPAccessLogEntry entry, Role role) {
+ if (serviceRegistry.isEmpty()) {
+ return Collections.emptyList();
+ }
+ switch (role) {
+ case PROXY:
+ return analyzeProxy(entry);
+ case SIDECAR:
+ return analyzeSideCar(entry);
+ }
+
+ return Collections.emptyList();
+ }
+
+ protected List<ServiceMeshMetric.Builder> analyzeSideCar(final HTTPAccessLogEntry entry) {
+ final AccessLogCommon properties = entry.getCommonProperties();
+ if (properties == null) {
+ return Collections.emptyList();
+ }
+ final String cluster = properties.getUpstreamCluster();
+ if (cluster == null) {
+ return Collections.emptyList();
+ }
+
+ final List<ServiceMeshMetric.Builder> sources = new ArrayList<>();
+
+ final Address downstreamRemoteAddress = properties.getDownstreamRemoteAddress();
+ final ServiceMetaInfo downstreamService = find(downstreamRemoteAddress.getSocketAddress().getAddress());
+ final Address downstreamLocalAddress = properties.getDownstreamLocalAddress();
+ final ServiceMetaInfo localService = find(downstreamLocalAddress.getSocketAddress().getAddress());
+
+ if (cluster.startsWith("inbound|")) {
+ // Server side
+ final ServiceMeshMetric.Builder metrics;
+ if (downstreamService.equals(ServiceMetaInfo.UNKNOWN)) {
+ // Ingress -> sidecar(server side)
+ // Mesh telemetry without source, the relation would be generated.
+ metrics = newAdapter(entry, null, localService).adaptToDownstreamMetrics();
+
+ log.debug("Transformed ingress->sidecar inbound mesh metrics {}", metrics);
+ } else {
+ // sidecar -> sidecar(server side)
+ metrics = newAdapter(entry, downstreamService, localService).adaptToDownstreamMetrics();
+
+ log.debug("Transformed sidecar->sidecar(server side) inbound mesh metrics {}", metrics);
+ }
+ sources.add(metrics);
+ } else if (cluster.startsWith("outbound|")) {
+ // sidecar(client side) -> sidecar
+ final Address upstreamRemoteAddress = properties.getUpstreamRemoteAddress();
+ final ServiceMetaInfo destService = find(upstreamRemoteAddress.getSocketAddress().getAddress());
+
+ final ServiceMeshMetric.Builder metric = newAdapter(entry, downstreamService, destService).adaptToDownstreamMetrics();
+
+ log.debug("Transformed sidecar->sidecar(server side) inbound mesh metric {}", metric);
+ sources.add(metric);
+ }
+
+ return sources;
+ }
+
+ protected List<ServiceMeshMetric.Builder> analyzeProxy(final HTTPAccessLogEntry entry) {
+ final AccessLogCommon properties = entry.getCommonProperties();
+ if (properties == null) {
+ return Collections.emptyList();
+ }
+ final Address downstreamLocalAddress = properties.getDownstreamLocalAddress();
+ final Address downstreamRemoteAddress = properties.getDownstreamRemoteAddress();
+ final Address upstreamRemoteAddress = properties.getUpstreamRemoteAddress();
+ if (downstreamLocalAddress == null || downstreamRemoteAddress == null || upstreamRemoteAddress == null) {
+ return Collections.emptyList();
+ }
+
+ final List<ServiceMeshMetric.Builder> result = new ArrayList<>(2);
+ final SocketAddress downstreamRemoteAddressSocketAddress = downstreamRemoteAddress.getSocketAddress();
+ final ServiceMetaInfo outside = find(downstreamRemoteAddressSocketAddress.getAddress());
+
+ final SocketAddress downstreamLocalAddressSocketAddress = downstreamLocalAddress.getSocketAddress();
+ final ServiceMetaInfo ingress = find(downstreamLocalAddressSocketAddress.getAddress());
+
+ final ServiceMeshMetric.Builder metric = newAdapter(entry, outside, ingress).adaptToDownstreamMetrics();
+
+ log.debug("Transformed ingress inbound mesh metric {}", metric);
+ result.add(metric);
+
+ final SocketAddress upstreamRemoteAddressSocketAddress = upstreamRemoteAddress.getSocketAddress();
+ final ServiceMetaInfo targetService = find(upstreamRemoteAddressSocketAddress.getAddress());
+
+ final ServiceMeshMetric.Builder outboundMetric =
+ newAdapter(entry, ingress, targetService)
+ .adaptToUpstreamMetrics()
+ // Can't parse it from tls properties, leave it to Server side.
+ .setTlsMode(NON_TLS);
+
+ log.debug("Transformed ingress outbound mesh metric {}", outboundMetric);
+ result.add(outboundMetric);
+
+ return result;
+ }
+
+ /**
+ * @return found service info, or {@link ServiceMetaInfo#UNKNOWN} to represent not found.
+ */
+ protected ServiceMetaInfo find(String ip) {
+ return serviceRegistry.findService(ip);
+ }
+
+}
diff --git a/oap-server/server-receiver-plugin/envoy-metrics-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/envoy/als/k8s/K8sALSServiceMeshHTTPAnalysis.java b/oap-server/server-receiver-plugin/envoy-metrics-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/envoy/als/k8s/K8sALSServiceMeshHTTPAnalysis.java
deleted file mode 100644
index f06d941..0000000
--- a/oap-server/server-receiver-plugin/envoy-metrics-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/envoy/als/k8s/K8sALSServiceMeshHTTPAnalysis.java
+++ /dev/null
@@ -1,334 +0,0 @@
-/*
- * 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.receiver.envoy.als.k8s;
-
-import com.google.common.base.Strings;
-import com.google.protobuf.Duration;
-import com.google.protobuf.Timestamp;
-import io.envoyproxy.envoy.api.v2.core.Address;
-import io.envoyproxy.envoy.api.v2.core.Node;
-import io.envoyproxy.envoy.api.v2.core.SocketAddress;
-import io.envoyproxy.envoy.data.accesslog.v2.AccessLogCommon;
-import io.envoyproxy.envoy.data.accesslog.v2.HTTPAccessLogEntry;
-import io.envoyproxy.envoy.data.accesslog.v2.HTTPRequestProperties;
-import io.envoyproxy.envoy.data.accesslog.v2.HTTPResponseProperties;
-import io.envoyproxy.envoy.data.accesslog.v2.TLSProperties;
-import io.envoyproxy.envoy.service.accesslog.v2.StreamAccessLogsMessage;
-import java.time.Instant;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import java.util.Optional;
-import lombok.SneakyThrows;
-import lombok.extern.slf4j.Slf4j;
-import org.apache.skywalking.aop.server.receiver.mesh.TelemetryDataDispatcher;
-import org.apache.skywalking.apm.network.common.v3.DetectPoint;
-import org.apache.skywalking.apm.network.servicemesh.v3.Protocol;
-import org.apache.skywalking.apm.network.servicemesh.v3.ServiceMeshMetric;
-import org.apache.skywalking.oap.server.core.source.Source;
-import org.apache.skywalking.oap.server.receiver.envoy.EnvoyMetricReceiverConfig;
-import org.apache.skywalking.oap.server.receiver.envoy.als.ALSHTTPAnalysis;
-import org.apache.skywalking.oap.server.receiver.envoy.als.Role;
-import org.apache.skywalking.oap.server.receiver.envoy.als.ServiceMetaInfo;
-
-/**
- * Analysis log based on ingress and mesh scenarios.
- */
-@Slf4j
-public class K8sALSServiceMeshHTTPAnalysis implements ALSHTTPAnalysis {
- private static final String NON_TLS = "NONE";
-
- private static final String M_TLS = "mTLS";
-
- private static final String TLS = "TLS";
-
- protected K8SServiceRegistry serviceRegistry;
-
- @Override
- public String name() {
- return "k8s-mesh";
- }
-
- @Override
- @SneakyThrows
- public void init(EnvoyMetricReceiverConfig config) {
- serviceRegistry = new K8SServiceRegistry(config);
- serviceRegistry.start();
- }
-
- @Override
- public List<Source> analysis(StreamAccessLogsMessage.Identifier identifier, HTTPAccessLogEntry entry, Role role) {
- if (serviceRegistry.isEmpty()) {
- return Collections.emptyList();
- }
- switch (role) {
- case PROXY:
- analysisProxy(identifier, entry);
- break;
- case SIDECAR:
- return analysisSideCar(identifier, entry);
- }
-
- return Collections.emptyList();
- }
-
- protected List<Source> analysisSideCar(StreamAccessLogsMessage.Identifier identifier, HTTPAccessLogEntry entry) {
- List<Source> sources = new ArrayList<>();
- AccessLogCommon properties = entry.getCommonProperties();
- if (properties != null) {
- String cluster = properties.getUpstreamCluster();
- if (cluster != null) {
- long startTime = formatAsLong(properties.getStartTime());
- long duration = formatAsLong(properties.getTimeToLastDownstreamTxByte());
-
- HTTPRequestProperties request = entry.getRequest();
- String endpoint = "/";
- Protocol protocol = Protocol.HTTP;
- if (request != null) {
- endpoint = request.getPath();
- String schema = request.getScheme();
- if ("http".equals(schema) || "https".equals(schema)) {
- protocol = Protocol.HTTP;
- } else {
- protocol = Protocol.gRPC;
- }
- }
- HTTPResponseProperties response = entry.getResponse();
- int responseCode = 200;
- if (response != null) {
- responseCode = response.getResponseCode().getValue();
- }
- boolean status = responseCode >= 200 && responseCode < 400;
-
- Address downstreamRemoteAddress = properties.getDownstreamRemoteAddress();
- ServiceMetaInfo downstreamService = find(downstreamRemoteAddress.getSocketAddress().getAddress());
- Address downstreamLocalAddress = properties.getDownstreamLocalAddress();
- ServiceMetaInfo localService = find(downstreamLocalAddress.getSocketAddress().getAddress());
- String tlsMode = parseTLS(properties.getTlsProperties());
-
- ServiceMeshMetric.Builder metric = null;
- if (cluster.startsWith("inbound|")) {
- // Server side
- if (downstreamService.equals(ServiceMetaInfo.UNKNOWN)) {
- // Ingress -> sidecar(server side)
- // Mesh telemetry without source, the relation would be generated.
- metric = ServiceMeshMetric.newBuilder()
- .setStartTime(startTime)
- .setEndTime(startTime + duration)
- .setDestServiceName(localService.getServiceName())
- .setDestServiceInstance(localService.getServiceInstanceName())
- .setEndpoint(endpoint)
- .setLatency((int) duration)
- .setResponseCode(Math.toIntExact(responseCode))
- .setStatus(status)
- .setProtocol(protocol)
- .setTlsMode(tlsMode)
- .setDetectPoint(DetectPoint.server);
-
- log.debug("Transformed ingress->sidecar inbound mesh metric {}", metric);
- } else {
- // sidecar -> sidecar(server side)
- metric = ServiceMeshMetric.newBuilder()
- .setStartTime(startTime)
- .setEndTime(startTime + duration)
- .setSourceServiceName(downstreamService.getServiceName())
- .setSourceServiceInstance(downstreamService.getServiceInstanceName())
- .setDestServiceName(localService.getServiceName())
- .setDestServiceInstance(localService.getServiceInstanceName())
- .setEndpoint(endpoint)
- .setLatency((int) duration)
- .setResponseCode(Math.toIntExact(responseCode))
- .setStatus(status)
- .setProtocol(protocol)
- .setTlsMode(tlsMode)
- .setDetectPoint(DetectPoint.server);
-
- log.debug("Transformed sidecar->sidecar(server side) inbound mesh metric {}", metric);
- }
- } else if (cluster.startsWith("outbound|")) {
- // sidecar(client side) -> sidecar
- Address upstreamRemoteAddress = properties.getUpstreamRemoteAddress();
- ServiceMetaInfo destService = find(upstreamRemoteAddress.getSocketAddress().getAddress());
-
- metric = ServiceMeshMetric.newBuilder()
- .setStartTime(startTime)
- .setEndTime(startTime + duration)
- .setSourceServiceName(downstreamService.getServiceName())
- .setSourceServiceInstance(downstreamService.getServiceInstanceName())
- .setDestServiceName(destService.getServiceName())
- .setDestServiceInstance(destService.getServiceInstanceName())
- .setEndpoint(endpoint)
- .setLatency((int) duration)
- .setResponseCode(Math.toIntExact(responseCode))
- .setStatus(status)
- .setProtocol(protocol)
- .setTlsMode(tlsMode)
- .setDetectPoint(DetectPoint.client);
-
- log.debug("Transformed sidecar->sidecar(server side) inbound mesh metric {}", metric);
- }
-
- Optional.ofNullable(metric).ifPresent(this::forward);
- }
- }
- return sources;
- }
-
- private String parseTLS(TLSProperties properties) {
- if (properties == null) {
- return NON_TLS;
- }
- if (Strings.isNullOrEmpty(Optional.ofNullable(properties.getLocalCertificateProperties())
- .orElse(TLSProperties.CertificateProperties.newBuilder().build()).getSubject())) {
- return NON_TLS;
- }
- if (Strings.isNullOrEmpty(Optional.ofNullable(properties.getPeerCertificateProperties())
- .orElse(TLSProperties.CertificateProperties.newBuilder().build()).getSubject())) {
- return TLS;
- }
- return M_TLS;
- }
-
- protected void analysisProxy(StreamAccessLogsMessage.Identifier identifier, HTTPAccessLogEntry entry) {
- AccessLogCommon properties = entry.getCommonProperties();
- if (properties != null) {
- Address downstreamLocalAddress = properties.getDownstreamLocalAddress();
- Address downstreamRemoteAddress = properties.getDownstreamRemoteAddress();
- Address upstreamRemoteAddress = properties.getUpstreamRemoteAddress();
- if (downstreamLocalAddress != null && downstreamRemoteAddress != null && upstreamRemoteAddress != null) {
- SocketAddress downstreamRemoteAddressSocketAddress = downstreamRemoteAddress.getSocketAddress();
- ServiceMetaInfo outside = find(downstreamRemoteAddressSocketAddress.getAddress());
-
- SocketAddress downstreamLocalAddressSocketAddress = downstreamLocalAddress.getSocketAddress();
- ServiceMetaInfo ingress = find(downstreamLocalAddressSocketAddress.getAddress());
-
- long startTime = formatAsLong(properties.getStartTime());
- long duration = formatAsLong(properties.getTimeToLastDownstreamTxByte());
-
- HTTPRequestProperties request = entry.getRequest();
- String endpoint = "/";
- Protocol protocol = Protocol.HTTP;
- if (request != null) {
- endpoint = request.getPath();
- String schema = request.getScheme();
- if ("http".equals(schema) || "https".equals(schema)) {
- protocol = Protocol.HTTP;
- } else {
- protocol = Protocol.gRPC;
- }
- }
- HTTPResponseProperties response = entry.getResponse();
- int responseCode = 200;
- if (response != null) {
- responseCode = response.getResponseCode().getValue();
- }
- boolean status = responseCode >= 200 && responseCode < 400;
- String tlsMode = parseTLS(properties.getTlsProperties());
-
- ServiceMeshMetric.Builder metric = ServiceMeshMetric.newBuilder()
- .setStartTime(startTime)
- .setEndTime(startTime + duration)
- .setSourceServiceName(outside.getServiceName())
- .setSourceServiceInstance(
- outside.getServiceInstanceName())
- .setDestServiceName(ingress.getServiceName())
- .setDestServiceInstance(
- ingress.getServiceInstanceName())
- .setEndpoint(endpoint)
- .setLatency((int) duration)
- .setResponseCode(Math.toIntExact(responseCode))
- .setStatus(status)
- .setProtocol(protocol)
- .setTlsMode(tlsMode)
- .setDetectPoint(DetectPoint.server);
-
- log.debug("Transformed ingress inbound mesh metric {}", metric);
- forward(metric);
-
- SocketAddress upstreamRemoteAddressSocketAddress = upstreamRemoteAddress.getSocketAddress();
- ServiceMetaInfo targetService = find(upstreamRemoteAddressSocketAddress.getAddress());
-
- long outboundStartTime = startTime + formatAsLong(properties.getTimeToFirstUpstreamTxByte());
- long outboundEndTime = startTime + formatAsLong(properties.getTimeToLastUpstreamRxByte());
-
- ServiceMeshMetric.Builder outboundMetric = ServiceMeshMetric.newBuilder()
- .setStartTime(outboundStartTime)
- .setEndTime(outboundEndTime)
- .setSourceServiceName(
- ingress.getServiceName())
- .setSourceServiceInstance(
- ingress.getServiceInstanceName())
- .setDestServiceName(
- targetService.getServiceName())
- .setDestServiceInstance(
- targetService.getServiceInstanceName())
- .setEndpoint(endpoint)
- .setLatency(
- (int) (outboundEndTime - outboundStartTime))
- .setResponseCode(
- Math.toIntExact(responseCode))
- .setStatus(status)
- .setProtocol(protocol)
- // Can't parse it from tls properties, leave
- // it to Server side.
- .setTlsMode(NON_TLS)
- .setDetectPoint(DetectPoint.client);
-
- log.debug("Transformed ingress outbound mesh metric {}", outboundMetric);
- forward(outboundMetric);
- }
- }
- }
-
- @Override
- public Role identify(StreamAccessLogsMessage.Identifier alsIdentifier, Role prev) {
- if (alsIdentifier != null) {
- Node node = alsIdentifier.getNode();
- if (node != null) {
- String id = node.getId();
- if (id.startsWith("router~")) {
- return Role.PROXY;
- } else if (id.startsWith("sidecar~")) {
- return Role.SIDECAR;
- }
- }
- }
-
- return prev;
- }
-
- /**
- * @return found service info, or {@link ServiceMetaInfo#UNKNOWN} to represent not found.
- */
- protected ServiceMetaInfo find(String ip) {
- return serviceRegistry.findService(ip);
- }
-
- protected void forward(ServiceMeshMetric.Builder metric) {
- TelemetryDataDispatcher.process(metric);
- }
-
- private long formatAsLong(Timestamp timestamp) {
- return Instant.ofEpochSecond(timestamp.getSeconds(), timestamp.getNanos()).toEpochMilli();
- }
-
- private long formatAsLong(Duration duration) {
- return Instant.ofEpochSecond(duration.getSeconds(), duration.getNanos()).toEpochMilli();
- }
-}
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
new file mode 100644
index 0000000..0cb21e9
--- /dev/null
+++ b/oap-server/server-receiver-plugin/envoy-metrics-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/envoy/als/mx/FieldsHelper.java
@@ -0,0 +1,101 @@
+/*
+ * 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.receiver.envoy.als.mx;
+
+import com.google.common.base.Splitter;
+import com.google.common.reflect.Invokable;
+import com.google.common.reflect.TypeToken;
+import com.google.protobuf.Struct;
+import com.google.protobuf.Value;
+import java.io.InputStream;
+import java.lang.reflect.Method;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.skywalking.oap.server.library.module.ModuleStartException;
+import org.apache.skywalking.oap.server.library.util.ResourceUtils;
+import org.apache.skywalking.oap.server.receiver.envoy.als.ServiceMetaInfo;
+import org.yaml.snakeyaml.Yaml;
+
+@Slf4j
+@SuppressWarnings("UnstableApiUsage")
+enum FieldsHelper {
+ SINGLETON;
+
+ private boolean initialized = false;
+
+ /**
+ * The mappings from the field name of {@link ServiceMetaInfo} to the field name of {@code flatbuffers}.
+ */
+ private Map<String, List<String>> fieldNameMapping;
+
+ /**
+ * The mappings from the field name of {@link ServiceMetaInfo} to its {@code setter}.
+ */
+ private Map<String, Invokable<ServiceMetaInfo, ?>> fieldSetterMapping;
+
+ @SuppressWarnings("unchecked")
+ public void init(final String file) throws Exception {
+ if (initialized) {
+ return;
+ }
+ final Yaml yaml = new Yaml();
+ final InputStream inputStream = ResourceUtils.readToStream(file);
+ final Map<String, String> config = (Map<String, String>) yaml.load(inputStream);
+
+ fieldNameMapping = new HashMap<>(config.size());
+ fieldSetterMapping = new HashMap<>(config.size());
+
+ for (final Map.Entry<String, String> entry : config.entrySet()) {
+ final String serviceMetaInfoFieldName = entry.getKey();
+ final String flatBuffersFieldName = entry.getValue();
+ final List<String> flatBuffersFieldNames = Splitter.on('.').omitEmptyStrings().splitToList(flatBuffersFieldName);
+ fieldNameMapping.put(serviceMetaInfoFieldName, flatBuffersFieldNames);
+
+ try {
+ final Method setterMethod = ServiceMetaInfo.class.getMethod("set" + StringUtils.capitalize(serviceMetaInfoFieldName), String.class);
+ final Invokable<ServiceMetaInfo, ?> setter = new TypeToken<ServiceMetaInfo>() {
+ }.method(setterMethod);
+ setter.setAccessible(true);
+ fieldSetterMapping.put(serviceMetaInfoFieldName, setter);
+ } catch (final NoSuchMethodException e) {
+ throw new ModuleStartException("Initialize method error", e);
+ }
+ }
+ initialized = true;
+ }
+
+ public void inflate(final Struct metadata, final ServiceMetaInfo result) throws Exception {
+ final Value root = Value.newBuilder().setStructValue(metadata).build();
+ for (Map.Entry<String, List<String>> entry : fieldNameMapping.entrySet()) {
+ Value value = root;
+ for (final String property : entry.getValue()) {
+ value = value.getStructValue().getFieldsOrThrow(property);
+ }
+ setValue(entry.getKey(), value, result);
+ }
+ }
+
+ public void setValue(final String key, final Value value, final ServiceMetaInfo result) throws Exception {
+ fieldSetterMapping.get(key).invoke(result, value.getStringValue());
+ }
+
+}
diff --git a/oap-server/server-receiver-plugin/envoy-metrics-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/envoy/als/mx/MetaExchangeALSHTTPAnalyzer.java b/oap-server/server-receiver-plugin/envoy-metrics-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/envoy/als/mx/MetaExchangeALSHTTPAnalyzer.java
new file mode 100644
index 0000000..796c23e
--- /dev/null
+++ b/oap-server/server-receiver-plugin/envoy-metrics-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/envoy/als/mx/MetaExchangeALSHTTPAnalyzer.java
@@ -0,0 +1,125 @@
+/*
+ * 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.receiver.envoy.als.mx;
+
+import com.google.protobuf.Any;
+import com.google.protobuf.TextFormat;
+import io.envoyproxy.envoy.data.accesslog.v2.AccessLogCommon;
+import io.envoyproxy.envoy.data.accesslog.v2.HTTPAccessLogEntry;
+import io.envoyproxy.envoy.service.accesslog.v2.StreamAccessLogsMessage;
+import java.util.ArrayList;
+import java.util.Base64;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.atomic.AtomicBoolean;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.skywalking.apm.network.servicemesh.v3.ServiceMeshMetric;
+import org.apache.skywalking.oap.server.library.module.ModuleManager;
+import org.apache.skywalking.oap.server.library.module.ModuleStartException;
+import org.apache.skywalking.oap.server.receiver.envoy.EnvoyMetricReceiverConfig;
+import org.apache.skywalking.oap.server.receiver.envoy.als.AbstractALSAnalyzer;
+import org.apache.skywalking.oap.server.receiver.envoy.als.Role;
+import org.apache.skywalking.oap.server.receiver.envoy.als.ServiceMetaInfo;
+
+import static org.apache.skywalking.oap.server.receiver.envoy.als.LogEntry2MetricsAdapter.NON_TLS;
+import static org.apache.skywalking.oap.server.receiver.envoy.als.ServiceMetaInfo.UNKNOWN;
+
+@Slf4j
+public class MetaExchangeALSHTTPAnalyzer extends AbstractALSAnalyzer {
+
+ private static final String UPSTREAM_KEY = "wasm.upstream_peer";
+
+ private static final String DOWNSTREAM_KEY = "wasm.downstream_peer";
+
+ @Override
+ public String name() {
+ return "mx-mesh";
+ }
+
+ @Override
+ public void init(ModuleManager manager, EnvoyMetricReceiverConfig config) throws ModuleStartException {
+ try {
+ FieldsHelper.SINGLETON.init("metadata-service-mapping.yaml");
+ } catch (final Exception e) {
+ throw new ModuleStartException("Failed to load metadata-service-mapping.yaml", e);
+ }
+ }
+
+ @Override
+ public List<ServiceMeshMetric.Builder> analysis(StreamAccessLogsMessage.Identifier identifier, HTTPAccessLogEntry entry, Role role) {
+ final AccessLogCommon properties = entry.getCommonProperties();
+ if (properties == null) {
+ return Collections.emptyList();
+ }
+ final Map<String, Any> stateMap = properties.getFilterStateObjectsMap();
+ if (stateMap == null) {
+ return Collections.emptyList();
+ }
+ final ServiceMetaInfo currSvc;
+ try {
+ currSvc = new ServiceMetaInfoAdapter(identifier.getNode().getMetadata());
+ } catch (Exception e) {
+ log.error("Failed to inflate the ServiceMetaInfo from identifier.node.metadata. ", e);
+ return Collections.emptyList();
+ }
+
+ final List<ServiceMeshMetric.Builder> result = new ArrayList<>();
+ final AtomicBoolean downstreamExists = new AtomicBoolean();
+ stateMap.forEach((key, value) -> {
+ if (!key.equals(UPSTREAM_KEY) && !key.equals(DOWNSTREAM_KEY)) {
+ return;
+ }
+ final ServiceMetaInfo svc;
+ try {
+ svc = new ServiceMetaInfoAdapter(value);
+ } catch (Exception e) {
+ log.error("Fail to parse metadata {} to FlatNode", Base64.getEncoder().encode(value.toByteArray()));
+ return;
+ }
+ final ServiceMeshMetric.Builder metrics;
+ switch (key) {
+ case UPSTREAM_KEY:
+ metrics = newAdapter(entry, currSvc, svc).adaptToUpstreamMetrics().setTlsMode(NON_TLS);
+ if (log.isDebugEnabled()) {
+ log.debug("Transformed a {} outbound mesh metrics {}", role, TextFormat.shortDebugString(metrics));
+ }
+ result.add(metrics);
+ break;
+ case DOWNSTREAM_KEY:
+ metrics = newAdapter(entry, svc, currSvc).adaptToDownstreamMetrics();
+ if (log.isDebugEnabled()) {
+ log.debug("Transformed a {} inbound mesh metrics {}", role, TextFormat.shortDebugString(metrics));
+ }
+ result.add(metrics);
+ downstreamExists.set(true);
+ break;
+ }
+ });
+ if (role.equals(Role.PROXY) && !downstreamExists.get()) {
+ final ServiceMeshMetric.Builder metric = newAdapter(entry, UNKNOWN, currSvc).adaptToDownstreamMetrics();
+ if (log.isDebugEnabled()) {
+ log.debug("Transformed a {} inbound mesh metric {}", role, TextFormat.shortDebugString(metric));
+ }
+ result.add(metric);
+ }
+ return result;
+ }
+
+}
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
new file mode 100644
index 0000000..8e94c37
--- /dev/null
+++ b/oap-server/server-receiver-plugin/envoy-metrics-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/envoy/als/mx/ServiceMetaInfoAdapter.java
@@ -0,0 +1,82 @@
+/*
+ * 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.receiver.envoy.als.mx;
+
+import com.google.protobuf.Any;
+import com.google.protobuf.ByteString;
+import com.google.protobuf.BytesValue;
+import com.google.protobuf.Struct;
+import java.nio.ByteBuffer;
+import java.util.Optional;
+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 java.util.Objects.requireNonNull;
+
+/**
+ * Adapter to {@link ServiceMetaInfo} from various of other datastructures.
+ */
+@Slf4j
+@RequiredArgsConstructor
+public class ServiceMetaInfoAdapter extends ServiceMetaInfo {
+
+ /**
+ * Try to adapt a {@link ByteString} to {@link ServiceMetaInfo} instance.
+ *
+ * @param bv the {@link ByteString byte string} to adapt from.
+ * @throws Exception if the {@link ByteString byte string} can not be adapted to a {@link ServiceMetaInfo}.
+ */
+ public ServiceMetaInfoAdapter(final ByteString bv) throws Exception {
+ final ByteBuffer buffer = ByteBuffer.wrap(BytesValue.parseFrom(bv).getValue().toByteArray());
+ final FlatNode flatNode = FlatNode.getRootAsFlatNode(buffer);
+ if (log.isDebugEnabled()) {
+ for (int i = 0; i < flatNode.labelsLength(); i++) {
+ KeyVal kv = flatNode.labels(i);
+ log.debug("wasm label: {} : {}", kv.key(), kv.value());
+ }
+ }
+
+ setServiceName(Optional.ofNullable(flatNode.labelsByKey("app")).map(KeyVal::value).orElse("-"));
+ setServiceInstanceName(flatNode.name());
+ }
+
+ /**
+ * The same functionality with {@link ServiceMetaInfoAdapter#ServiceMetaInfoAdapter(com.google.protobuf.ByteString)}.
+ *
+ * @param any {@link Any any object} to adapt from.
+ * @throws Exception if the {@link Any any object} can not be adapted to a {@link ServiceMetaInfo}.
+ */
+ public ServiceMetaInfoAdapter(final Any any) throws Exception {
+ this(any.getValue());
+ }
+
+ /**
+ * The same functionality with {@link ServiceMetaInfoAdapter#ServiceMetaInfoAdapter(com.google.protobuf.ByteString)}.
+ *
+ * @param metadata the {@link Struct struct} to adapt from.
+ * @throws Exception if the {@link Struct struct} can not be adapted to a {@link ServiceMetaInfo}.
+ */
+ public ServiceMetaInfoAdapter(final Struct metadata) throws Exception {
+ FieldsHelper.SINGLETON.inflate(requireNonNull(metadata), this);
+ }
+
+}
diff --git a/oap-server/server-receiver-plugin/envoy-metrics-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/envoy/als/ALSHTTPAnalysis.java b/oap-server/server-receiver-plugin/envoy-metrics-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/envoy/als/mx/package-info.java
similarity index 53%
copy from oap-server/server-receiver-plugin/envoy-metrics-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/envoy/als/ALSHTTPAnalysis.java
copy to oap-server/server-receiver-plugin/envoy-metrics-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/envoy/als/mx/package-info.java
index 4297f3d..9564f0e 100644
--- a/oap-server/server-receiver-plugin/envoy-metrics-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/envoy/als/ALSHTTPAnalysis.java
+++ b/oap-server/server-receiver-plugin/envoy-metrics-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/envoy/als/mx/package-info.java
@@ -16,23 +16,9 @@
*
*/
-package org.apache.skywalking.oap.server.receiver.envoy.als;
-
-import io.envoyproxy.envoy.data.accesslog.v2.HTTPAccessLogEntry;
-import io.envoyproxy.envoy.service.accesslog.v2.StreamAccessLogsMessage;
-import java.util.List;
-import org.apache.skywalking.oap.server.core.source.Source;
-import org.apache.skywalking.oap.server.receiver.envoy.EnvoyMetricReceiverConfig;
-
/**
- * Analysis source metrics from ALS
+ * {@link org.apache.skywalking.oap.server.receiver.envoy.als.ALSHTTPAnalysis} implementation
+ * based on the Envoy metadata exchange.
*/
-public interface ALSHTTPAnalysis {
- String name();
-
- void init(EnvoyMetricReceiverConfig config);
-
- List<Source> analysis(StreamAccessLogsMessage.Identifier identifier, HTTPAccessLogEntry entry, Role role);
- Role identify(StreamAccessLogsMessage.Identifier alsIdentifier, Role prev);
-}
+package org.apache.skywalking.oap.server.receiver.envoy.als.mx;
diff --git a/oap-server/server-receiver-plugin/envoy-metrics-receiver-plugin/src/main/java/wasm/common/FlatNode.java b/oap-server/server-receiver-plugin/envoy-metrics-receiver-plugin/src/main/java/wasm/common/FlatNode.java
new file mode 100644
index 0000000..e979257
--- /dev/null
+++ b/oap-server/server-receiver-plugin/envoy-metrics-receiver-plugin/src/main/java/wasm/common/FlatNode.java
@@ -0,0 +1,132 @@
+/*
+ * 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.
+ *
+ */
+
+// automatically generated by the FlatBuffers compiler, do not modify
+
+package wasm.common;
+
+import com.google.flatbuffers.*;
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+
+// TODO: generate on the fly instead of copying
+@SuppressWarnings("unused")
+public final class FlatNode extends Table {
+ public static void ValidateVersion() { Constants.FLATBUFFERS_1_12_0(); }
+ public static FlatNode getRootAsFlatNode(ByteBuffer _bb) { return getRootAsFlatNode(_bb, new FlatNode()); }
+ public static FlatNode getRootAsFlatNode(ByteBuffer _bb, FlatNode obj) { _bb.order(ByteOrder.LITTLE_ENDIAN); return (obj.__assign(_bb.getInt(_bb.position()) + _bb.position(), _bb)); }
+ public void __init(int _i, ByteBuffer _bb) { __reset(_i, _bb); }
+ public FlatNode __assign(int _i, ByteBuffer _bb) { __init(_i, _bb); return this; }
+
+ public String name() { int o = __offset(4); return o != 0 ? __string(o + bb_pos) : null; }
+ public ByteBuffer nameAsByteBuffer() { return __vector_as_bytebuffer(4, 1); }
+ public ByteBuffer nameInByteBuffer(ByteBuffer _bb) { return __vector_in_bytebuffer(_bb, 4, 1); }
+ public String namespace() { int o = __offset(6); return o != 0 ? __string(o + bb_pos) : null; }
+ public ByteBuffer namespaceAsByteBuffer() { return __vector_as_bytebuffer(6, 1); }
+ public ByteBuffer namespaceInByteBuffer(ByteBuffer _bb) { return __vector_in_bytebuffer(_bb, 6, 1); }
+ public wasm.common.KeyVal labels(int j) { return labels(new wasm.common.KeyVal(), j); }
+ public wasm.common.KeyVal labels(wasm.common.KeyVal obj, int j) { int o = __offset(8); return o != 0 ? obj.__assign(__indirect(__vector(o) + j * 4), bb) : null; }
+ public int labelsLength() { int o = __offset(8); return o != 0 ? __vector_len(o) : 0; }
+ public wasm.common.KeyVal labelsByKey(String key) { int o = __offset(8); return o != 0 ? wasm.common.KeyVal.__lookup_by_key(null, __vector(o), key, bb) : null; }
+ public wasm.common.KeyVal labelsByKey(wasm.common.KeyVal obj, String key) { int o = __offset(8); return o != 0 ? wasm.common.KeyVal.__lookup_by_key(obj, __vector(o), key, bb) : null; }
+ public wasm.common.KeyVal.Vector labelsVector() { return labelsVector(new wasm.common.KeyVal.Vector()); }
+ public wasm.common.KeyVal.Vector labelsVector(wasm.common.KeyVal.Vector obj) { int o = __offset(8); return o != 0 ? obj.__assign(__vector(o), 4, bb) : null; }
+ public String owner() { int o = __offset(10); return o != 0 ? __string(o + bb_pos) : null; }
+ public ByteBuffer ownerAsByteBuffer() { return __vector_as_bytebuffer(10, 1); }
+ public ByteBuffer ownerInByteBuffer(ByteBuffer _bb) { return __vector_in_bytebuffer(_bb, 10, 1); }
+ public String workloadName() { int o = __offset(12); return o != 0 ? __string(o + bb_pos) : null; }
+ public ByteBuffer workloadNameAsByteBuffer() { return __vector_as_bytebuffer(12, 1); }
+ public ByteBuffer workloadNameInByteBuffer(ByteBuffer _bb) { return __vector_in_bytebuffer(_bb, 12, 1); }
+ public wasm.common.KeyVal platformMetadata(int j) { return platformMetadata(new wasm.common.KeyVal(), j); }
+ public wasm.common.KeyVal platformMetadata(wasm.common.KeyVal obj, int j) { int o = __offset(14); return o != 0 ? obj.__assign(__indirect(__vector(o) + j * 4), bb) : null; }
+ public int platformMetadataLength() { int o = __offset(14); return o != 0 ? __vector_len(o) : 0; }
+ public wasm.common.KeyVal platformMetadataByKey(String key) { int o = __offset(14); return o != 0 ? wasm.common.KeyVal.__lookup_by_key(null, __vector(o), key, bb) : null; }
+ public wasm.common.KeyVal platformMetadataByKey(wasm.common.KeyVal obj, String key) { int o = __offset(14); return o != 0 ? wasm.common.KeyVal.__lookup_by_key(obj, __vector(o), key, bb) : null; }
+ public wasm.common.KeyVal.Vector platformMetadataVector() { return platformMetadataVector(new wasm.common.KeyVal.Vector()); }
+ public wasm.common.KeyVal.Vector platformMetadataVector(wasm.common.KeyVal.Vector obj) { int o = __offset(14); return o != 0 ? obj.__assign(__vector(o), 4, bb) : null; }
+ public String istioVersion() { int o = __offset(16); return o != 0 ? __string(o + bb_pos) : null; }
+ public ByteBuffer istioVersionAsByteBuffer() { return __vector_as_bytebuffer(16, 1); }
+ public ByteBuffer istioVersionInByteBuffer(ByteBuffer _bb) { return __vector_in_bytebuffer(_bb, 16, 1); }
+ public String meshId() { int o = __offset(18); return o != 0 ? __string(o + bb_pos) : null; }
+ public ByteBuffer meshIdAsByteBuffer() { return __vector_as_bytebuffer(18, 1); }
+ public ByteBuffer meshIdInByteBuffer(ByteBuffer _bb) { return __vector_in_bytebuffer(_bb, 18, 1); }
+ public String appContainers(int j) { int o = __offset(20); return o != 0 ? __string(__vector(o) + j * 4) : null; }
+ public int appContainersLength() { int o = __offset(20); return o != 0 ? __vector_len(o) : 0; }
+ public StringVector appContainersVector() { return appContainersVector(new StringVector()); }
+ public StringVector appContainersVector(StringVector obj) { int o = __offset(20); return o != 0 ? obj.__assign(__vector(o), 4, bb) : null; }
+ public String clusterId() { int o = __offset(22); return o != 0 ? __string(o + bb_pos) : null; }
+ public ByteBuffer clusterIdAsByteBuffer() { return __vector_as_bytebuffer(22, 1); }
+ public ByteBuffer clusterIdInByteBuffer(ByteBuffer _bb) { return __vector_in_bytebuffer(_bb, 22, 1); }
+
+ public static int createFlatNode(FlatBufferBuilder builder,
+ int nameOffset,
+ int namespaceOffset,
+ int labelsOffset,
+ int ownerOffset,
+ int workload_nameOffset,
+ int platform_metadataOffset,
+ int istio_versionOffset,
+ int mesh_idOffset,
+ int app_containersOffset,
+ int cluster_idOffset) {
+ builder.startTable(10);
+ FlatNode.addClusterId(builder, cluster_idOffset);
+ FlatNode.addAppContainers(builder, app_containersOffset);
+ FlatNode.addMeshId(builder, mesh_idOffset);
+ FlatNode.addIstioVersion(builder, istio_versionOffset);
+ FlatNode.addPlatformMetadata(builder, platform_metadataOffset);
+ FlatNode.addWorkloadName(builder, workload_nameOffset);
+ FlatNode.addOwner(builder, ownerOffset);
+ FlatNode.addLabels(builder, labelsOffset);
+ FlatNode.addNamespace(builder, namespaceOffset);
+ FlatNode.addName(builder, nameOffset);
+ return FlatNode.endFlatNode(builder);
+ }
+
+ public static void startFlatNode(FlatBufferBuilder builder) { builder.startTable(10); }
+ public static void addName(FlatBufferBuilder builder, int nameOffset) { builder.addOffset(0, nameOffset, 0); }
+ public static void addNamespace(FlatBufferBuilder builder, int namespaceOffset) { builder.addOffset(1, namespaceOffset, 0); }
+ public static void addLabels(FlatBufferBuilder builder, int labelsOffset) { builder.addOffset(2, labelsOffset, 0); }
+ public static int createLabelsVector(FlatBufferBuilder builder, int[] data) { builder.startVector(4, data.length, 4); for (int i = data.length - 1; i >= 0; i--) builder.addOffset(data[i]); return builder.endVector(); }
+ public static void startLabelsVector(FlatBufferBuilder builder, int numElems) { builder.startVector(4, numElems, 4); }
+ public static void addOwner(FlatBufferBuilder builder, int ownerOffset) { builder.addOffset(3, ownerOffset, 0); }
+ public static void addWorkloadName(FlatBufferBuilder builder, int workloadNameOffset) { builder.addOffset(4, workloadNameOffset, 0); }
+ public static void addPlatformMetadata(FlatBufferBuilder builder, int platformMetadataOffset) { builder.addOffset(5, platformMetadataOffset, 0); }
+ public static int createPlatformMetadataVector(FlatBufferBuilder builder, int[] data) { builder.startVector(4, data.length, 4); for (int i = data.length - 1; i >= 0; i--) builder.addOffset(data[i]); return builder.endVector(); }
+ public static void startPlatformMetadataVector(FlatBufferBuilder builder, int numElems) { builder.startVector(4, numElems, 4); }
+ public static void addIstioVersion(FlatBufferBuilder builder, int istioVersionOffset) { builder.addOffset(6, istioVersionOffset, 0); }
+ public static void addMeshId(FlatBufferBuilder builder, int meshIdOffset) { builder.addOffset(7, meshIdOffset, 0); }
+ public static void addAppContainers(FlatBufferBuilder builder, int appContainersOffset) { builder.addOffset(8, appContainersOffset, 0); }
+ public static int createAppContainersVector(FlatBufferBuilder builder, int[] data) { builder.startVector(4, data.length, 4); for (int i = data.length - 1; i >= 0; i--) builder.addOffset(data[i]); return builder.endVector(); }
+ public static void startAppContainersVector(FlatBufferBuilder builder, int numElems) { builder.startVector(4, numElems, 4); }
+ public static void addClusterId(FlatBufferBuilder builder, int clusterIdOffset) { builder.addOffset(9, clusterIdOffset, 0); }
+ public static int endFlatNode(FlatBufferBuilder builder) {
+ int o = builder.endTable();
+ return o;
+ }
+ public static void finishFlatNodeBuffer(FlatBufferBuilder builder, int offset) { builder.finish(offset); }
+ public static void finishSizePrefixedFlatNodeBuffer(FlatBufferBuilder builder, int offset) { builder.finishSizePrefixed(offset); }
+
+ public static final class Vector extends BaseVector {
+ public Vector __assign(int _vector, int _element_size, ByteBuffer _bb) { __reset(_vector, _element_size, _bb); return this; }
+
+ public FlatNode get(int j) { return get(new FlatNode(), j); }
+ public FlatNode get(FlatNode obj, int j) { return obj.__assign(__indirect(__element(j), bb), bb); }
+ }
+}
+
diff --git a/oap-server/server-receiver-plugin/envoy-metrics-receiver-plugin/src/main/java/wasm/common/KeyVal.java b/oap-server/server-receiver-plugin/envoy-metrics-receiver-plugin/src/main/java/wasm/common/KeyVal.java
new file mode 100644
index 0000000..0019a87
--- /dev/null
+++ b/oap-server/server-receiver-plugin/envoy-metrics-receiver-plugin/src/main/java/wasm/common/KeyVal.java
@@ -0,0 +1,93 @@
+/*
+ * 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.
+ *
+ */
+
+// automatically generated by the FlatBuffers compiler, do not modify
+
+package wasm.common;
+
+import com.google.flatbuffers.*;
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+
+@SuppressWarnings("unused")
+public final class KeyVal extends Table {
+ public static void ValidateVersion() { Constants.FLATBUFFERS_1_12_0(); }
+ public static KeyVal getRootAsKeyVal(ByteBuffer _bb) { return getRootAsKeyVal(_bb, new KeyVal()); }
+ public static KeyVal getRootAsKeyVal(ByteBuffer _bb, KeyVal obj) { _bb.order(ByteOrder.LITTLE_ENDIAN); return (obj.__assign(_bb.getInt(_bb.position()) + _bb.position(), _bb)); }
+ public void __init(int _i, ByteBuffer _bb) { __reset(_i, _bb); }
+ public KeyVal __assign(int _i, ByteBuffer _bb) { __init(_i, _bb); return this; }
+
+ public String key() { int o = __offset(4); return o != 0 ? __string(o + bb_pos) : null; }
+ public ByteBuffer keyAsByteBuffer() { return __vector_as_bytebuffer(4, 1); }
+ public ByteBuffer keyInByteBuffer(ByteBuffer _bb) { return __vector_in_bytebuffer(_bb, 4, 1); }
+ public String value() { int o = __offset(6); return o != 0 ? __string(o + bb_pos) : null; }
+ public ByteBuffer valueAsByteBuffer() { return __vector_as_bytebuffer(6, 1); }
+ public ByteBuffer valueInByteBuffer(ByteBuffer _bb) { return __vector_in_bytebuffer(_bb, 6, 1); }
+
+ public static int createKeyVal(FlatBufferBuilder builder,
+ int keyOffset,
+ int valueOffset) {
+ builder.startTable(2);
+ KeyVal.addValue(builder, valueOffset);
+ KeyVal.addKey(builder, keyOffset);
+ return KeyVal.endKeyVal(builder);
+ }
+
+ public static void startKeyVal(FlatBufferBuilder builder) { builder.startTable(2); }
+ public static void addKey(FlatBufferBuilder builder, int keyOffset) { builder.addOffset(0, keyOffset, 0); }
+ public static void addValue(FlatBufferBuilder builder, int valueOffset) { builder.addOffset(1, valueOffset, 0); }
+ public static int endKeyVal(FlatBufferBuilder builder) {
+ int o = builder.endTable();
+ builder.required(o, 4); // key
+ return o;
+ }
+
+ @Override
+ protected int keysCompare(Integer o1, Integer o2, ByteBuffer _bb) { return compareStrings(__offset(4, o1, _bb), __offset(4, o2, _bb), _bb); }
+
+ public static KeyVal __lookup_by_key(KeyVal obj, int vectorLocation, String key, ByteBuffer bb) {
+ byte[] byteKey = key.getBytes(java.nio.charset.StandardCharsets.UTF_8);
+ int span = bb.getInt(vectorLocation - 4);
+ int start = 0;
+ while (span != 0) {
+ int middle = span / 2;
+ int tableOffset = __indirect(vectorLocation + 4 * (start + middle), bb);
+ int comp = compareStrings(__offset(4, bb.capacity() - tableOffset, bb), byteKey, bb);
+ if (comp > 0) {
+ span = middle;
+ } else if (comp < 0) {
+ middle++;
+ start += middle;
+ span -= middle;
+ } else {
+ return (obj == null ? new KeyVal() : obj).__assign(tableOffset, bb);
+ }
+ }
+ return null;
+ }
+
+ public static final class Vector extends BaseVector {
+ public Vector __assign(int _vector, int _element_size, ByteBuffer _bb) { __reset(_vector, _element_size, _bb); return this; }
+
+ public KeyVal get(int j) { return get(new KeyVal(), j); }
+ public KeyVal get(KeyVal obj, int j) { return obj.__assign(__indirect(__element(j), bb), bb); }
+ public KeyVal getByKey(String key) { return __lookup_by_key(null, __vector(), key, bb); }
+ public KeyVal getByKey(KeyVal obj, String key) { return __lookup_by_key(obj, __vector(), key, bb); }
+ }
+}
+
diff --git a/oap-server/server-receiver-plugin/envoy-metrics-receiver-plugin/src/main/resources/META-INF/services/org.apache.skywalking.oap.server.receiver.envoy.als.ALSHTTPAnalysis b/oap-server/server-receiver-plugin/envoy-metrics-receiver-plugin/src/main/resources/META-INF/services/org.apache.skywalking.oap.server.receiver.envoy.als.ALSHTTPAnalysis
index 215d7a0..39c1b2e 100644
--- a/oap-server/server-receiver-plugin/envoy-metrics-receiver-plugin/src/main/resources/META-INF/services/org.apache.skywalking.oap.server.receiver.envoy.als.ALSHTTPAnalysis
+++ b/oap-server/server-receiver-plugin/envoy-metrics-receiver-plugin/src/main/resources/META-INF/services/org.apache.skywalking.oap.server.receiver.envoy.als.ALSHTTPAnalysis
@@ -17,4 +17,5 @@
#
-org.apache.skywalking.oap.server.receiver.envoy.als.k8s.K8sALSServiceMeshHTTPAnalysis
+org.apache.skywalking.oap.server.receiver.envoy.als.k8s.K8SALSServiceMeshHTTPAnalyzer
+org.apache.skywalking.oap.server.receiver.envoy.als.mx.MetaExchangeALSHTTPAnalyzer
diff --git a/oap-server/server-receiver-plugin/envoy-metrics-receiver-plugin/src/test/java/org/apache/skywalking/oap/server/receiver/envoy/als/k8s/K8sHTTPAnalysisTest.java b/oap-server/server-receiver-plugin/envoy-metrics-receiver-plugin/src/test/java/org/apache/skywalking/oap/server/receiver/envoy/als/k8s/K8SALSServiceMeshHTTPAnalyzerTest.java
similarity index 77%
rename from oap-server/server-receiver-plugin/envoy-metrics-receiver-plugin/src/test/java/org/apache/skywalking/oap/server/receiver/envoy/als/k8s/K8sHTTPAnalysisTest.java
rename to oap-server/server-receiver-plugin/envoy-metrics-receiver-plugin/src/test/java/org/apache/skywalking/oap/server/receiver/envoy/als/k8s/K8SALSServiceMeshHTTPAnalyzerTest.java
index 7ad64a5..d51c813 100644
--- a/oap-server/server-receiver-plugin/envoy-metrics-receiver-plugin/src/test/java/org/apache/skywalking/oap/server/receiver/envoy/als/k8s/K8sHTTPAnalysisTest.java
+++ b/oap-server/server-receiver-plugin/envoy-metrics-receiver-plugin/src/test/java/org/apache/skywalking/oap/server/receiver/envoy/als/k8s/K8SALSServiceMeshHTTPAnalyzerTest.java
@@ -23,10 +23,10 @@ import io.envoyproxy.envoy.service.accesslog.v2.StreamAccessLogsMessage;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
-import java.util.ArrayList;
import java.util.List;
import org.apache.skywalking.apm.network.common.v3.DetectPoint;
import org.apache.skywalking.apm.network.servicemesh.v3.ServiceMeshMetric;
+import org.apache.skywalking.oap.server.library.module.ModuleManager;
import org.apache.skywalking.oap.server.receiver.envoy.EnvoyMetricReceiverConfig;
import org.apache.skywalking.oap.server.receiver.envoy.MetricServiceGRPCHandlerTestMain;
import org.apache.skywalking.oap.server.receiver.envoy.als.Role;
@@ -39,14 +39,14 @@ import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
-public class K8sHTTPAnalysisTest {
+public class K8SALSServiceMeshHTTPAnalyzerTest {
- private MockK8sAnalysis analysis;
+ private MockK8SAnalyzer analysis;
@Before
public void setUp() {
- analysis = new MockK8sAnalysis();
- analysis.init(null);
+ analysis = new MockK8SAnalyzer();
+ analysis.init(null, null);
}
@Test
@@ -77,16 +77,16 @@ public class K8sHTTPAnalysisTest {
StreamAccessLogsMessage.Builder requestBuilder = StreamAccessLogsMessage.newBuilder();
JsonFormat.parser().merge(isr, requestBuilder);
- analysis.analysis(requestBuilder.getIdentifier(), requestBuilder.getHttpLogs().getLogEntry(0), Role.PROXY);
+ List<ServiceMeshMetric.Builder> result = this.analysis.analysis(requestBuilder.getIdentifier(), requestBuilder.getHttpLogs().getLogEntry(0), Role.PROXY);
- Assert.assertEquals(2, analysis.metrics.size());
+ Assert.assertEquals(2, result.size());
- ServiceMeshMetric.Builder incoming = analysis.metrics.get(0);
+ ServiceMeshMetric.Builder incoming = result.get(0);
Assert.assertEquals("UNKNOWN", incoming.getSourceServiceName());
Assert.assertEquals("ingress", incoming.getDestServiceName());
Assert.assertEquals(DetectPoint.server, incoming.getDetectPoint());
- ServiceMeshMetric.Builder outgoing = analysis.metrics.get(1);
+ ServiceMeshMetric.Builder outgoing = result.get(1);
Assert.assertEquals("ingress", outgoing.getSourceServiceName());
Assert.assertEquals("productpage", outgoing.getDestServiceName());
Assert.assertEquals(DetectPoint.client, outgoing.getDetectPoint());
@@ -99,12 +99,11 @@ public class K8sHTTPAnalysisTest {
StreamAccessLogsMessage.Builder requestBuilder = StreamAccessLogsMessage.newBuilder();
JsonFormat.parser().merge(isr, requestBuilder);
- analysis.analysis(requestBuilder.getIdentifier(), requestBuilder.getHttpLogs()
- .getLogEntry(0), Role.SIDECAR);
+ List<ServiceMeshMetric.Builder> result = this.analysis.analysis(requestBuilder.getIdentifier(), requestBuilder.getHttpLogs().getLogEntry(0), Role.SIDECAR);
- Assert.assertEquals(1, analysis.metrics.size());
+ Assert.assertEquals(1, result.size());
- ServiceMeshMetric.Builder incoming = analysis.metrics.get(0);
+ ServiceMeshMetric.Builder incoming = result.get(0);
Assert.assertEquals("", incoming.getSourceServiceName());
Assert.assertEquals("productpage", incoming.getDestServiceName());
Assert.assertEquals(DetectPoint.server, incoming.getDetectPoint());
@@ -117,12 +116,11 @@ public class K8sHTTPAnalysisTest {
StreamAccessLogsMessage.Builder requestBuilder = StreamAccessLogsMessage.newBuilder();
JsonFormat.parser().merge(isr, requestBuilder);
- analysis.analysis(requestBuilder.getIdentifier(), requestBuilder.getHttpLogs()
- .getLogEntry(0), Role.SIDECAR);
+ List<ServiceMeshMetric.Builder> result = this.analysis.analysis(requestBuilder.getIdentifier(), requestBuilder.getHttpLogs().getLogEntry(0), Role.SIDECAR);
- Assert.assertEquals(1, analysis.metrics.size());
+ Assert.assertEquals(1, result.size());
- ServiceMeshMetric.Builder incoming = analysis.metrics.get(0);
+ ServiceMeshMetric.Builder incoming = result.get(0);
Assert.assertEquals("productpage", incoming.getSourceServiceName());
Assert.assertEquals("review", incoming.getDestServiceName());
Assert.assertEquals(DetectPoint.server, incoming.getDetectPoint());
@@ -135,23 +133,21 @@ public class K8sHTTPAnalysisTest {
StreamAccessLogsMessage.Builder requestBuilder = StreamAccessLogsMessage.newBuilder();
JsonFormat.parser().merge(isr, requestBuilder);
- analysis.analysis(requestBuilder.getIdentifier(), requestBuilder.getHttpLogs()
- .getLogEntry(0), Role.SIDECAR);
+ List<ServiceMeshMetric.Builder> result = this.analysis.analysis(requestBuilder.getIdentifier(), requestBuilder.getHttpLogs().getLogEntry(0), Role.SIDECAR);
- Assert.assertEquals(1, analysis.metrics.size());
+ Assert.assertEquals(1, result.size());
- ServiceMeshMetric.Builder incoming = analysis.metrics.get(0);
+ ServiceMeshMetric.Builder incoming = result.get(0);
Assert.assertEquals("productpage", incoming.getSourceServiceName());
Assert.assertEquals("detail", incoming.getDestServiceName());
Assert.assertEquals(DetectPoint.client, incoming.getDetectPoint());
}
}
- public static class MockK8sAnalysis extends K8sALSServiceMeshHTTPAnalysis {
- private List<ServiceMeshMetric.Builder> metrics = new ArrayList<>();
+ public static class MockK8SAnalyzer extends K8SALSServiceMeshHTTPAnalyzer {
@Override
- public void init(EnvoyMetricReceiverConfig config) {
+ public void init(ModuleManager manager, EnvoyMetricReceiverConfig config) {
serviceRegistry = mock(K8SServiceRegistry.class);
when(serviceRegistry.findService(anyString())).thenReturn(ServiceMetaInfo.UNKNOWN);
when(serviceRegistry.findService("10.44.2.56")).thenReturn(new ServiceMetaInfo("ingress", "ingress-Inst"));
@@ -160,10 +156,6 @@ public class K8sHTTPAnalysisTest {
when(serviceRegistry.findService("10.44.2.55")).thenReturn(new ServiceMetaInfo("review", "detail-Inst"));
}
- @Override
- protected void forward(ServiceMeshMetric.Builder metric) {
- metrics.add(metric);
- }
}
private static InputStream getResourceAsStream(final String resource) {
diff --git a/oap-server/server-receiver-plugin/receiver-proto/pom.xml b/oap-server/server-receiver-plugin/receiver-proto/pom.xml
index e7ca3bf..1f39c3f 100644
--- a/oap-server/server-receiver-plugin/receiver-proto/pom.xml
+++ b/oap-server/server-receiver-plugin/receiver-proto/pom.xml
@@ -17,7 +17,8 @@
~
-->
-<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>server-receiver-plugin</artifactId>
<groupId>org.apache.skywalking</groupId>
@@ -28,9 +29,14 @@
<artifactId>receiver-proto</artifactId>
<packaging>jar</packaging>
+ <properties>
+ <fbs.sources>${basedir}/src/main/fbs</fbs.sources>
+ <fbs.generated.sources>${project.build.directory}/generated-sources/java</fbs.generated.sources>
+ </properties>
+
<build>
<plugins>
- <plugin>
+ <plugin>
<groupId>kr.motd.maven</groupId>
<artifactId>os-maven-plugin</artifactId>
<version>${os-maven-plugin.version}</version>
@@ -53,10 +59,12 @@
protobuf-java directly, you will be transitively depending on the
protobuf-java version that grpc depends on.
-->
- <protocArtifact>com.google.protobuf:protoc:${com.google.protobuf.protoc.version}:exe:${os.detected.classifier}
+ <protocArtifact>
+ com.google.protobuf:protoc:${com.google.protobuf.protoc.version}:exe:${os.detected.classifier}
</protocArtifact>
<pluginId>grpc-java</pluginId>
- <pluginArtifact>io.grpc:protoc-gen-grpc-java:${protoc-gen-grpc-java.plugin.version}:exe:${os.detected.classifier}
+ <pluginArtifact>
+ io.grpc:protoc-gen-grpc-java:${protoc-gen-grpc-java.plugin.version}:exe:${os.detected.classifier}
</pluginArtifact>
</configuration>
<executions>
@@ -68,6 +76,71 @@
</execution>
</executions>
</plugin>
+
+<!-- <plugin>-->
+<!-- <groupId>org.apache.maven.plugins</groupId>-->
+<!-- <artifactId>maven-dependency-plugin</artifactId>-->
+<!-- <version>${maven-dependency-plugin.version}</version>-->
+<!-- <executions>-->
+<!-- <execution>-->
+<!-- <id>unpack</id>-->
+<!-- <phase>generate-sources</phase>-->
+<!-- <goals>-->
+<!-- <goal>unpack</goal>-->
+<!-- </goals>-->
+<!-- <configuration>-->
+<!-- <artifactItems>-->
+<!-- <artifactItem>-->
+<!-- <groupId>com.github.davidmoten</groupId>-->
+<!-- <artifactId>flatbuffers-compiler</artifactId>-->
+<!-- <version>1.12.0.1</version>-->
+<!-- <type>tar.gz</type>-->
+<!-- <classifier>distribution-${os.detected.name}</classifier>-->
+<!-- <overWrite>true</overWrite>-->
+<!-- <outputDirectory>${project.build.directory}</outputDirectory>-->
+<!-- </artifactItem>-->
+<!-- </artifactItems>-->
+<!-- </configuration>-->
+<!-- </execution>-->
+<!-- </executions>-->
+<!-- </plugin>-->
+<!-- <plugin>-->
+<!-- <groupId>org.codehaus.mojo</groupId>-->
+<!-- <artifactId>exec-maven-plugin</artifactId>-->
+<!-- <version>${exec-maven-plugin.version}</version>-->
+<!-- <executions>-->
+<!-- <execution>-->
+<!-- <goals>-->
+<!-- <goal>exec</goal>-->
+<!-- </goals>-->
+<!-- <phase>generate-sources</phase>-->
+<!-- </execution>-->
+<!-- </executions>-->
+<!-- <configuration>-->
+<!-- <executable>${project.build.directory}/bin/flatc</executable>-->
+<!-- <workingDirectory>${fbs.sources}</workingDirectory>-->
+<!-- <arguments>-->
+<!-- <argument>--java</argument>-->
+<!-- <argument>--gen-mutable</argument>-->
+<!-- <arguments>istio/node-info.fbs</arguments>-->
+<!-- <argument>-o</argument>-->
+<!-- <argument>${fbs.generated.sources}</argument></arguments>-->
+<!-- </configuration>-->
+<!-- </plugin>-->
+<!-- <plugin>-->
+<!-- <groupId>org.codehaus.mojo</groupId>-->
+<!-- <artifactId>build-helper-maven-plugin</artifactId>-->
+<!-- <version>${build-helper-maven-plugin.version}</version>-->
+<!-- <executions>-->
+<!-- <execution>-->
+<!-- <id>add-source</id>-->
+<!-- <phase>generate-sources</phase>-->
+<!-- <goals>-->
+<!-- <goal>add-source</goal>-->
+<!-- </goals>-->
+<!-- </execution>-->
+<!-- </executions>-->
+<!-- </plugin>-->
</plugins>
</build>
-</project>
\ No newline at end of file
+</project>
diff --git a/oap-server/server-receiver-plugin/receiver-proto/src/main/fbs/istio/node-info.fbs b/oap-server/server-receiver-plugin/receiver-proto/src/main/fbs/istio/node-info.fbs
new file mode 100644
index 0000000..f8dd462
--- /dev/null
+++ b/oap-server/server-receiver-plugin/receiver-proto/src/main/fbs/istio/node-info.fbs
@@ -0,0 +1,48 @@
+/* Copyright 2020 Istio Authors. All Rights Reserved.
+ *
+ * Licensed 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.
+ */
+
+namespace Wasm.Common;
+
+table KeyVal {
+ key:string (key);
+ value:string;
+}
+
+// NodeInfo represents the information extracted from proxy node metadata.
+table FlatNode {
+ // Name of the node. e.g. in k8s, name is the pod name.
+ name:string;
+ // Namespace that the node runs in.
+ namespace:string;
+ // K8s or vm workload attributes.
+ labels:[KeyVal];
+ owner:string;
+ workload_name:string;
+ // Platform metadata uses prefixed keys
+ // GCP uses gcp_* keys
+ platform_metadata:[KeyVal];
+ // Version identifier for the proxy.
+ istio_version:string;
+ // Unique identifier for the mesh. Taken from global mesh id parameter (or
+ // the configured trust domain when not specified).
+ mesh_id:string;
+ // List of short names for application containers that are using this proxy.
+ // This is only used for kubernetes, and is populated by the sidecar injector.
+ app_containers:[string];
+ // Identifier for the cluster to which this workload belongs (for k8s workloads).
+ cluster_id:string;
+}
+
+root_type FlatNode;
diff --git a/pom.xml b/pom.xml
index ad73b56..d09be80 100755
--- a/pom.xml
+++ b/pom.xml
@@ -207,9 +207,11 @@
<takari-maven-plugin.version>0.6.1</takari-maven-plugin.version>
<exec-maven-plugin.version>1.6.0</exec-maven-plugin.version>
<maven-antrun-plugin.version>1.8</maven-antrun-plugin.version>
+ <maven-dependency-plugin.version>2.10</maven-dependency-plugin.version>
<maven-deploy-plugin.version>2.8.2</maven-deploy-plugin.version>
<maven-assembly-plugin.version>3.1.0</maven-assembly-plugin.version>
<maven-failsafe-plugin.version>2.22.0</maven-failsafe-plugin.version>
+ <build-helper-maven-plugin.version>3.2.0</build-helper-maven-plugin.version>
<maven-surefire-plugin.version>2.22.0</maven-surefire-plugin.version>
<maven-jar-plugin.version>3.1.0</maven-jar-plugin.version>
<maven-shade-plugin.version>3.1.1</maven-shade-plugin.version>
@@ -225,6 +227,7 @@
<gmaven-plugin.version>1.5</gmaven-plugin.version>
<cobertura-maven-plugin.version>2.7</cobertura-maven-plugin.version>
<checkstyle.fails.on.error>true</checkstyle.fails.on.error>
+
</properties>
<dependencies>
@@ -498,6 +501,7 @@
<exclude>skywalking-ui/package-lock.json</exclude>
<!-- Proto files of Istio, envoy, prometheus and gogoproto projects -->
+ <exclude>**/src/main/fbs/istio/**</exclude>
<exclude>**/src/main/proto/envoy/**</exclude>
<exclude>**/src/main/proto/gogoproto/gogo.proto</exclude>
<exclude>**/src/main/proto/google/**</exclude>
@@ -624,7 +628,9 @@
org/apache/skywalking/oap/server/exporter/grpc/*.java,
org/apache/skywalking/oap/server/configuration/service/*.java,
**/generated/*_jmhType*.java,
- **/generated/*_jmhTest.java
+ **/generated/*_jmhTest.java,
+ wasm/common/FlatNode.java,
+ wasm/common/KeyVal.java
</excludes>
<propertyExpansion>
import.control=${maven.multiModuleProjectDirectory}/apm-checkstyle/importControl.xml
diff --git a/test/e2e/e2e-test/src/test/java/org/apache/skywalking/e2e/mesh/IDManager.java b/test/e2e/e2e-test/src/test/java/org/apache/skywalking/e2e/mesh/IDManager.java
deleted file mode 100644
index ce2fb0c..0000000
--- a/test/e2e/e2e-test/src/test/java/org/apache/skywalking/e2e/mesh/IDManager.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * 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.e2e.mesh;
-
-import java.nio.charset.StandardCharsets;
-import java.util.Base64;
-import lombok.EqualsAndHashCode;
-import lombok.Getter;
-import lombok.RequiredArgsConstructor;
-
-public class IDManager {
- public static class ServiceID {
-
- public static ServiceIDDefinition analysisId(String id) {
- final String[] strings = id.split("\\.");
- if (strings.length != 2) {
- throw new RuntimeException("Can't split service id into 2 parts, " + id);
- }
- return new ServiceIDDefinition(
- decode(strings[0]),
- Integer.parseInt(strings[1]) == 1
- );
- }
-
- @RequiredArgsConstructor
- @Getter
- @EqualsAndHashCode
- public static class ServiceIDDefinition {
- private final String name;
-
- private final boolean isReal;
- }
- }
-
- /**
- * @param base64text Base64 encoded UTF-8 string
- * @return normal literal string
- */
- private static String decode(String base64text) {
- return new String(Base64.getDecoder().decode(base64text), StandardCharsets.UTF_8);
- }
-}