You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@inlong.apache.org by GitBox <gi...@apache.org> on 2022/03/02 02:36:03 UTC

[GitHub] [incubator-inlong] luchunliang commented on a change in pull request #2806: [INLONG-2805][DataProxy] Add stream config log report

luchunliang commented on a change in pull request #2806:
URL: https://github.com/apache/incubator-inlong/pull/2806#discussion_r817297029



##########
File path: inlong-dataproxy/dataproxy-source/src/main/java/org/apache/inlong/dataproxy/sink/PulsarSink.java
##########
@@ -221,14 +224,32 @@ public void configure(Context context) {
         topicProperties = configManager.getTopicProperties();
         pulsarCluster = configManager.getThirdPartyClusterUrl2Token();
         pulsarConfig = configManager.getThirdPartyClusterConfig(); //pulsar common config
+        commonProperties = configManager.getCommonProperties();
         pulsarClientService = new PulsarClientService(pulsarConfig);
+        boolean enableReportConfigLog =
+                Boolean.parseBoolean(commonProperties
+                        .getOrDefault(ConfigConstants.CONFIG_LOG_REPORT_ENABLE,"true"));
+        localIp = NetworkUtils.getLocalIp();
+        if (enableReportConfigLog) {
+            String reportConfigServerUrl = commonProperties
+                    .getOrDefault(ConfigConstants.CONFIG_LOG_REPORT_SERVER_URL, "");
+            String reportConfigLogInterval = commonProperties
+                    .getOrDefault(ConfigConstants.CONFIG_LOG_REPORT_INTERVAL, "60000");
+            String clientVersion = commonProperties
+                    .getOrDefault(ConfigConstants.CONFIG_LOG_REPORT_CLIENT_VERSION, "");
+            streamConfigLogMetric = new StreamConfigLogMetric(ConfigConstants.COMPONENT_NAME,
+                    reportConfigServerUrl, Long.parseLong(reportConfigLogInterval),
+                    localIp, clientVersion);

Review comment:
       This metric can be reported in MetricLisenter, exception id can be a sink-data-id.
   For example:
   metricDomains.DataProxy.domainListeners=com.tencent.pcg.atta.dataproxy.metrics.m007.M007MetricListener com.tencent.pcg.atta.dataproxy.metrics.attaaudit.AttaAuditMetricListener

##########
File path: inlong-common/src/main/java/org/apache/inlong/common/reporpter/StreamConfigLogMetric.java
##########
@@ -0,0 +1,113 @@
+/*
+ * 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.inlong.common.reporpter;
+
+import com.google.common.util.concurrent.ThreadFactoryBuilder;
+import java.time.Instant;
+import java.util.Map.Entry;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+import org.apache.inlong.common.reporpter.dto.StreamConfigLogInfo;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class StreamConfigLogMetric implements Runnable {
+
+    public static final Logger LOGGER = LoggerFactory.getLogger(StreamConfigLogMetric.class);
+
+    private StreamConfigLogReporter streamConfigLogReporter;
+
+    private String moduleName;
+
+    private String clientVersion;
+
+    private String localIp;
+
+    private long reportInterval;
+
+    public ConcurrentHashMap<String, StreamConfigLogInfo> dataCacheMap = new ConcurrentHashMap<>();
+
+    private static ScheduledExecutorService statExecutor =
+            Executors.newScheduledThreadPool(2, new ThreadFactoryBuilder()
+                    .setNameFormat("StreamConfigLogMetric-Report")
+                    .setUncaughtExceptionHandler((t, e) ->
+                            LOGGER.error(t.getName() + " has an uncaught exception: ", e))
+                    .build());
+
+    public StreamConfigLogMetric(String moduleName, String serverUrl, long reportInterval,
+            String localIp, String clientVersion) {
+        this.streamConfigLogReporter = new StreamConfigLogReporter(serverUrl);
+        this.reportInterval = reportInterval;
+        this.moduleName = moduleName;
+        this.localIp = localIp;
+        this.clientVersion = clientVersion;
+        statExecutor.scheduleWithFixedDelay(this,
+                reportInterval, reportInterval, TimeUnit.MILLISECONDS);
+    }
+
+    public void updateConfigLog(String inlongGroupId, String inlongStreamId, String configName,
+            ConfigLogTypeEnum configLogTypeEnum, String log) {
+        String key = moduleName + inlongGroupId + inlongStreamId + configName;

Review comment:
       Two different keys perhaps are same without separator.

##########
File path: inlong-manager/manager-web/src/main/java/org/apache/inlong/manager/web/controller/openapi/StreamConfigLogController.java
##########
@@ -23,20 +23,22 @@
 import org.apache.inlong.manager.common.pojo.stream.InlongStreamConfigLogRequest;
 import org.apache.inlong.manager.service.core.StreamConfigLogService;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.MediaType;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
 @RestController
-@RequestMapping("/openapi")
+@RequestMapping("/openapi/stream")
 @Api(tags = "Stream Config")
 public class StreamConfigLogController {
 
     @Autowired
     private StreamConfigLogService streamConfigLogService;
 
-    @PostMapping("/stream/log/reportConfigLogStatus")
+    @PostMapping(value = "/log/reportConfigLogStatus",
+            produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
     @ApiOperation(value = "stream config log status")
     public Response<String> reportStreamConfigLogStatus(@RequestBody
             InlongStreamConfigLogRequest info) {

Review comment:
       It is not suggested to save the log to DB, if the inlong datastream is more than 1000 and proxy node is more than 100.

##########
File path: inlong-common/src/main/java/org/apache/inlong/common/reporpter/StreamConfigLogMetric.java
##########
@@ -0,0 +1,113 @@
+/*
+ * 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.inlong.common.reporpter;
+
+import com.google.common.util.concurrent.ThreadFactoryBuilder;
+import java.time.Instant;
+import java.util.Map.Entry;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+import org.apache.inlong.common.reporpter.dto.StreamConfigLogInfo;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class StreamConfigLogMetric implements Runnable {
+
+    public static final Logger LOGGER = LoggerFactory.getLogger(StreamConfigLogMetric.class);
+
+    private StreamConfigLogReporter streamConfigLogReporter;
+
+    private String moduleName;
+
+    private String clientVersion;
+
+    private String localIp;
+
+    private long reportInterval;
+
+    public ConcurrentHashMap<String, StreamConfigLogInfo> dataCacheMap = new ConcurrentHashMap<>();
+
+    private static ScheduledExecutorService statExecutor =
+            Executors.newScheduledThreadPool(2, new ThreadFactoryBuilder()
+                    .setNameFormat("StreamConfigLogMetric-Report")
+                    .setUncaughtExceptionHandler((t, e) ->
+                            LOGGER.error(t.getName() + " has an uncaught exception: ", e))
+                    .build());
+
+    public StreamConfigLogMetric(String moduleName, String serverUrl, long reportInterval,
+            String localIp, String clientVersion) {
+        this.streamConfigLogReporter = new StreamConfigLogReporter(serverUrl);
+        this.reportInterval = reportInterval;
+        this.moduleName = moduleName;
+        this.localIp = localIp;
+        this.clientVersion = clientVersion;
+        statExecutor.scheduleWithFixedDelay(this,
+                reportInterval, reportInterval, TimeUnit.MILLISECONDS);
+    }
+
+    public void updateConfigLog(String inlongGroupId, String inlongStreamId, String configName,
+            ConfigLogTypeEnum configLogTypeEnum, String log) {
+        String key = moduleName + inlongGroupId + inlongStreamId + configName;
+        LOGGER.debug("updateConfigLog key = {}", key);
+        dataCacheMap.compute(key, (k, v) -> {
+            if (v == null) {
+                v = new StreamConfigLogInfo();
+            }
+            updateDataValue(v, inlongGroupId,
+                    inlongStreamId, configName, configLogTypeEnum, log);
+            return v;
+        });
+    }
+
+    private void updateDataValue(StreamConfigLogInfo streamConfigLogInfo,
+            String inlongGroupId, String inlongStreamId, String configName,
+            ConfigLogTypeEnum configLogTypeEnum, String log) {
+        streamConfigLogInfo.setComponentName(moduleName);
+        streamConfigLogInfo.setConfigName(configName);
+        streamConfigLogInfo.setInlongGroupId(inlongGroupId);
+        streamConfigLogInfo.setInlongStreamId(inlongStreamId);
+        streamConfigLogInfo.setIp(localIp);
+        streamConfigLogInfo.setVersion(clientVersion);
+        streamConfigLogInfo.setLogInfo(log);
+        streamConfigLogInfo.setReportTime(Instant.now().toEpochMilli());
+        streamConfigLogInfo.setLogType(configLogTypeEnum.getType());

Review comment:
       Miss count field.




-- 
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: commits-unsubscribe@inlong.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org