From f8716b49e6325f97685f65769a5f1b03bea43b50 Mon Sep 17 00:00:00 2001 From: mrproliu <741550557@qq.com> Date: Sat, 14 Sep 2024 14:02:06 +0800 Subject: [PATCH] Support to analysis the ztunnel mapped IP address in eBPF Access Log Receiver (#12620) --- apm-protocol/apm-network/src/main/proto | 2 +- docs/en/changes/changes.md | 1 + .../handler/AccessLogServiceHandler.java | 25 +++++++++++++------ 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/apm-protocol/apm-network/src/main/proto b/apm-protocol/apm-network/src/main/proto index b5f6ebe281b9..4f3b17e1b0b3 160000 --- a/apm-protocol/apm-network/src/main/proto +++ b/apm-protocol/apm-network/src/main/proto @@ -1 +1 @@ -Subproject commit b5f6ebe281b96d89968959f55baa3d9aa1bfecee +Subproject commit 4f3b17e1b0b3c3dcc0e1ed3da86efaac785ea157 diff --git a/docs/en/changes/changes.md b/docs/en/changes/changes.md index 3aa3cd7d130c..96e4410e4152 100644 --- a/docs/en/changes/changes.md +++ b/docs/en/changes/changes.md @@ -64,6 +64,7 @@ * Fix query `getGlobalTopology` throw exception when didn't find any services by the given Layer. * Fix the previous analysis result missing in the ALS `k8s-mesh` analyzer. * Fix `findEndpoint` query require `keyword` when using BanyanDB. +* Support to analysis the ztunnel mapped IP address in eBPF Access Log Receiver. #### UI diff --git a/oap-server/server-receiver-plugin/skywalking-ebpf-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/ebpf/provider/handler/AccessLogServiceHandler.java b/oap-server/server-receiver-plugin/skywalking-ebpf-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/ebpf/provider/handler/AccessLogServiceHandler.java index b0467bbf5a8d..602f68a268c5 100644 --- a/oap-server/server-receiver-plugin/skywalking-ebpf-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/ebpf/provider/handler/AccessLogServiceHandler.java +++ b/oap-server/server-receiver-plugin/skywalking-ebpf-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/ebpf/provider/handler/AccessLogServiceHandler.java @@ -45,6 +45,7 @@ import org.apache.skywalking.apm.network.ebpf.accesslog.v3.EBPFTimestamp; import org.apache.skywalking.apm.network.ebpf.accesslog.v3.IPAddress; import org.apache.skywalking.apm.network.ebpf.accesslog.v3.KubernetesProcessAddress; +import org.apache.skywalking.apm.network.ebpf.accesslog.v3.ZTunnelAttachmentEnvironment; import org.apache.skywalking.library.kubernetes.ObjectID; import org.apache.skywalking.oap.meter.analyzer.k8s.K8sInfoRegistry; import org.apache.skywalking.oap.server.core.Const; @@ -485,15 +486,23 @@ protected void printDropReasons() { }); } - protected KubernetesProcessAddress buildKubernetesAddressByIP(NodeInfo nodeInfo, IPAddress ipAddress) { - final ObjectID service = K8sInfoRegistry.getInstance().findServiceByIP(ipAddress.getHost()); + protected KubernetesProcessAddress buildKubernetesAddressByIP(NodeInfo nodeInfo, AccessLogConnection connection, boolean isLocal, IPAddress ipAddress) { + String host = ipAddress.getHost(); + // if the resolving address is not local, and have attached ztunnel info, then using the ztunnel mapped host + if (!isLocal && connection.hasAttachment() && connection.getAttachment().hasZTunnel()) { + final ZTunnelAttachmentEnvironment ztunnel = connection.getAttachment().getZTunnel(); + host = ztunnel.getRealDestinationIp(); + log.debug("detected the ztunnel connection, so update the remote IP address as: {}, detect by: {}", host, + ztunnel.getBy()); + } + final ObjectID service = K8sInfoRegistry.getInstance().findServiceByIP(host); if (service != ObjectID.EMPTY) { return buildRemoteAddress(nodeInfo, service, null); } - final ObjectID pod = K8sInfoRegistry.getInstance().findPodByIP(ipAddress.getHost()); + final ObjectID pod = K8sInfoRegistry.getInstance().findPodByIP(host); if (pod == ObjectID.EMPTY) { // if cannot found the address, then return the unknown address - log.debug("building unknown address by ip: {}:{}", ipAddress.getHost(), ipAddress.getPort()); + log.debug("building unknown address by ip: {}:{}", host, ipAddress.getPort()); return buildUnknownAddress(); } final ObjectID serviceName = K8sInfoRegistry.getInstance().findService(pod.namespace(), pod.name()); @@ -536,8 +545,8 @@ public class ConnectionInfo { public ConnectionInfo(NamingControl namingControl, NodeInfo nodeInfo, AccessLogConnection connection) { this.originalConnection = connection; this.namingControl = namingControl; - this.local = buildAddress(nodeInfo, connection.getLocal()); - this.remote = buildAddress(nodeInfo, connection.getRemote()); + this.local = buildAddress(nodeInfo, connection, true, connection.getLocal()); + this.remote = buildAddress(nodeInfo, connection, false, connection.getRemote()); this.role = connection.getRole(); this.tlsMode = connection.getTlsMode(); this.nodeInfo = nodeInfo; @@ -549,12 +558,12 @@ public ConnectionInfo(NamingControl namingControl, NodeInfo nodeInfo, AccessLogC } } - private KubernetesProcessAddress buildAddress(NodeInfo nodeInfo, ConnectionAddress address) { + private KubernetesProcessAddress buildAddress(NodeInfo nodeInfo, AccessLogConnection connection, boolean local, ConnectionAddress address) { switch (address.getAddressCase()) { case KUBERNETES: return address.getKubernetes(); case IP: - return buildKubernetesAddressByIP(nodeInfo, address.getIp()); + return buildKubernetesAddressByIP(nodeInfo, connection, local, address.getIp()); } return null; }