doleyzi commented on code in PR #10398:
URL: https://github.com/apache/inlong/pull/10398#discussion_r1637838790


##########
inlong-audit/audit-sdk/src/main/java/org/apache/inlong/audit/send/ProxyManager.java:
##########
@@ -42,13 +60,77 @@ public static ProxyManager getInstance() {
     /**
      * update config
      */
-    public void setAuditProxy(HashSet<String> ipPortList) {
+    public synchronized void setAuditProxy(HashSet<String> ipPortList) {
         if (!ipPortList.equals(new HashSet<>(currentIpPorts))) {
             currentIpPorts.clear();
             currentIpPorts.addAll(ipPortList);
         }
     }
 
+    public synchronized void setManagerConfig(AuditComponent component, String 
managerHost, AuthConfig authConfig) {
+        if (!managerHost.endsWith("/")) {
+            managerHost = managerHost + "/";
+        }
+        if (!(managerHost.startsWith("http://";) || 
managerHost.startsWith("https://";))) {
+            managerHost = "http://"; + managerHost;
+        }
+        auditProxyApiUrl = String.format("%s%s", managerHost, 
GET_AUDIT_PROXY_API_PATH);
+        LOGGER.info("Audit Proxy API URL: {}", auditProxyApiUrl);
+
+        this.authConfig = authConfig;
+        this.component = component;
+
+        updateAuditProxy();
+
+        if (autoUpdateAuditProxy) {
+            startTimer();
+            LOGGER.info("Auto Update from manager");
+        }
+    }
+
+    private void updateAuditProxy() {
+        String response = HttpUtils.httpGet(component.getComponent(), 
auditProxyApiUrl, authConfig, timeoutMs);
+        if (response == null) {
+            LOGGER.error("Response is null: {} {} {} ", 
component.getComponent(), auditProxyApiUrl, authConfig);
+            return;
+        }
+        CommonResponse<AuditProxy> commonResponse =
+                CommonResponse.fromJson(response, AuditProxy.class);
+        if (commonResponse == null) {
+            LOGGER.error("No data in the response: {} {} {} ", 
component.getComponent(), auditProxyApiUrl, authConfig);
+            return;
+        }
+        HashSet<String> proxyList = new HashSet<>();
+        for (AuditProxy auditProxy : commonResponse.getData()) {
+            proxyList.add(auditProxy.toString());
+        }
+        setAuditProxy(proxyList);
+        LOGGER.info("Get audit proxy from manager: {}", proxyList);
+    }
+
+    private synchronized void startTimer() {
+        if (timerStarted) {
+            return;
+        }
+        timer.scheduleWithFixedDelay(this::updateAuditProxy,
+                0,
+                updateInterval,
+                TimeUnit.MILLISECONDS);
+        timerStarted = true;
+    }
+
+    public void setManagerTimeout(int timeoutMs) {
+        this.timeoutMs = timeoutMs;
+    }
+
+    public void setAutoUpdateAuditProxy(boolean autoUpdateAuditProxy) {
+        this.autoUpdateAuditProxy = autoUpdateAuditProxy;
+    }
+
+    public void setUpdateInterval(int updateInterval) {
+        this.updateInterval = updateInterval;
+    }
+

Review Comment:
   Fixed



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to