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/07/06 08:31:42 UTC

[GitHub] [inlong] luchunliang commented on a diff in pull request #4855: [INLONG-4854][Agent] Report metrics at inongGroupId and inlongStreamId

luchunliang commented on code in PR #4855:
URL: https://github.com/apache/inlong/pull/4855#discussion_r914566906


##########
inlong-agent/agent-plugins/src/main/java/org/apache/inlong/agent/plugin/metrics/GlobalMetrics.java:
##########
@@ -0,0 +1,175 @@
+/*
+ * 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.agent.plugin.metrics;
+
+import org.apache.inlong.agent.utils.ConfigUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Map.Entry;
+import java.util.concurrent.ConcurrentHashMap;
+
+public class GlobalMetrics {
+
+    private static final Logger LOGGER = LoggerFactory.getLogger(GlobalMetrics.class);
+
+    // key: groupId_streamId
+    private static final ConcurrentHashMap<String, PluginMetric> pluginMetrics = new ConcurrentHashMap<>();
+    // key: sourceType_groupId_streamId
+    private static final ConcurrentHashMap<String, SourceMetric> sourceMetrics = new ConcurrentHashMap<>();
+    // key: sinkType_groupId_streamId
+    private static final ConcurrentHashMap<String, SinkMetric> sinkMetrics = new ConcurrentHashMap<>();
+
+    private static PluginMetric getPluginMetric(String tagName) {
+        PluginMetric metric;
+        if (pluginMetrics.containsKey(tagName)) {
+            metric = pluginMetrics.get(tagName);
+        } else {
+            if (ConfigUtil.isPrometheusEnabled()) {
+                metric = new PluginPrometheusMetric(tagName);
+            } else {
+                metric = new PluginJmxMetric(tagName);
+            }
+            pluginMetrics.put(tagName, metric);
+        }
+        return metric;

Review Comment:
   synchronized problem, thread1 and thread2 can create two metrics and return it.
   Please use computeIfAbsent method.



-- 
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