Skip to content

Commit

Permalink
Support to analysis the ztunnel mapped IP address in eBPF Access Log …
Browse files Browse the repository at this point in the history
…Receiver (#12620)
  • Loading branch information
mrproliu authored Sep 14, 2024
1 parent 216c4a2 commit f8716b4
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
2 changes: 1 addition & 1 deletion apm-protocol/apm-network/src/main/proto
Submodule proto updated 2 files
+4 −1 common/BUILD
+21 −0 ebpf/accesslog.proto
1 change: 1 addition & 0 deletions docs/en/changes/changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down

0 comments on commit f8716b4

Please sign in to comment.