From 1a96ec490cdcc9ab6159b892ce14c3e4fe03c548 Mon Sep 17 00:00:00 2001 From: doleyzi <43397300+doleyzi@users.noreply.github.com> Date: Fri, 11 Oct 2024 14:09:13 +0800 Subject: [PATCH] [INLONG-11330][Audit] Audit SDK supports custom setting of local IP (#11331) --- .../java/org/apache/inlong/audit/AuditReporterImpl.java | 8 ++++++++ .../main/java/org/apache/inlong/audit/util/Config.java | 9 +++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/inlong-audit/audit-sdk/src/main/java/org/apache/inlong/audit/AuditReporterImpl.java b/inlong-audit/audit-sdk/src/main/java/org/apache/inlong/audit/AuditReporterImpl.java index e8a38da28f9..7d3f1c5755d 100644 --- a/inlong-audit/audit-sdk/src/main/java/org/apache/inlong/audit/AuditReporterImpl.java +++ b/inlong-audit/audit-sdk/src/main/java/org/apache/inlong/audit/AuditReporterImpl.java @@ -194,6 +194,14 @@ public void setAuditProxy(HashSet ipPortList) { ProxyManager.getInstance().setAuditProxy(ipPortList); } + /** + * Set local IP + * @param localIP + */ + public void setLocalIP(String localIP) { + config.setLocalIP(localIP); + } + /** * Set AuditProxy from the manager host */ diff --git a/inlong-audit/audit-sdk/src/main/java/org/apache/inlong/audit/util/Config.java b/inlong-audit/audit-sdk/src/main/java/org/apache/inlong/audit/util/Config.java index a18ba1a8607..a519a7a85fd 100644 --- a/inlong-audit/audit-sdk/src/main/java/org/apache/inlong/audit/util/Config.java +++ b/inlong-audit/audit-sdk/src/main/java/org/apache/inlong/audit/util/Config.java @@ -31,7 +31,7 @@ public class Config { private static final Logger logger = LoggerFactory.getLogger(Config.class); - private String localIP = ""; + private String localIP; private String dockerId = ""; private static final int CGROUP_FILE_LENGTH = 50; private static final int DOCKERID_LENGTH = 10; @@ -40,7 +40,9 @@ public void init() { initIP(); initDockerId(); } - + public void setLocalIP(String localIP) { + this.localIP = localIP; + } public String getLocalIP() { return localIP; } @@ -50,6 +52,9 @@ public String getDockerId() { } private void initIP() { + if (localIP != null) { + return; + } try { for (Enumeration en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();) { NetworkInterface intf = en.nextElement();