pocozh commented on code in PR #5301:
URL: https://github.com/apache/inlong/pull/5301#discussion_r934344859


##########
inlong-agent/agent-plugins/src/test/java/org/apache/inlong/agent/plugin/sources/TestTextFileReader.java:
##########
@@ -56,7 +53,7 @@
 import static org.apache.inlong.agent.constant.JobConstants.JOB_FILE_MAX_WAIT;
 import static org.apache.inlong.agent.constant.JobConstants.JOB_INSTANCE_ID;
 
-@RunWith(PowerMockRunner.class)
+// @RunWith(PowerMockRunner.class)

Review Comment:
   please remove unused code



##########
inlong-agent/agent-common/src/main/java/org/apache/inlong/agent/metrics/AgentMetricSingleton.java:
##########
@@ -0,0 +1,76 @@
+/*
+ * 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.metrics;
+
+import org.apache.commons.lang3.ClassUtils;
+import org.apache.inlong.agent.conf.AgentConfiguration;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import static 
org.apache.inlong.agent.constant.AgentConstants.AGENT_METRIC_LISTENER_CLASS;
+import static 
org.apache.inlong.agent.constant.AgentConstants.AGENT_METRIC_LISTENER_CLASS_DEFAULT;
+
+/**
+ * metric singleton
+ */
+public class AgentMetricSingleton {
+
+    private static final Logger LOGGER = 
LoggerFactory.getLogger(AgentMetricSingleton.class);
+    private static AgentMetricBaseHandler agentMetricBaseHandler;
+
+    private AgentMetricSingleton() {
+    }
+
+    public static AgentMetricBaseHandler getAgentMetricHandler() {
+        if (agentMetricBaseHandler == null) {
+            synchronized (AgentJmxMetricHandler.class) {
+                if (agentMetricBaseHandler == null) {
+                    agentMetricBaseHandler = getAgentMetricByConf();
+                    agentMetricBaseHandler.init();
+                }
+            }
+        }
+        return agentMetricBaseHandler;
+    }
+
+    private static AgentMetricBaseHandler getAgentMetricByConf() {
+        AgentConfiguration conf = AgentConfiguration.getAgentConf();
+        try {
+            Class<?> handlerClass = ClassUtils
+                    .getClass(conf.get(AGENT_METRIC_LISTENER_CLASS, 
AGENT_METRIC_LISTENER_CLASS_DEFAULT));
+            Object handlerObject = 
handlerClass.getDeclaredConstructor().newInstance();
+            //
+            // final MetricListener listener = (MetricListener) listenerObject;
+            // Constructor<?> constructor =
+            //         Class.forName(conf.get(AGENT_METRIC_LISTENER_CLASS, 
AGENT_METRIC_LISTENER_CLASS_DEFAULT))
+            //                 
.getDeclaredConstructor(AgentMetricBaseHandler.class);
+            // constructor.setAccessible(true);

Review Comment:
   please remove unused code



##########
inlong-agent/conf/agent.properties:
##########
@@ -112,14 +112,13 @@ agent.manager.auth.secretKey=
 
 
 ############################
-# prometheus config
+# metric config
 ############################
-# whether to enable prometheus
-agent.prometheus.enable=true
+metricDomains=Agent
+metricDomains.Agent.domainListeners=org.apache.inlong.agent.metrics.AgentPrometheusMetricHandler

Review Comment:
   Would it be more intuitive using `xxxxListener` , such as 
`AgentPrometheusMetricListener`?



##########
inlong-agent/agent-common/src/main/java/org/apache/inlong/agent/metrics/AgentPrometheusMetricHandler.java:
##########
@@ -0,0 +1,78 @@
+/*
+ * 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.metrics;
+
+import io.prometheus.client.exporter.HTTPServer;
+import io.prometheus.client.hotspot.DefaultExports;
+import org.apache.inlong.agent.conf.AgentConfiguration;
+import org.apache.inlong.agent.metrics.global.PrometheusGlobalMetrics;
+import org.apache.inlong.agent.metrics.job.JobPrometheusMetrics;
+import org.apache.inlong.agent.metrics.task.TaskPrometheusMetrics;
+import org.apache.inlong.common.metric.MetricItemValue;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.util.List;
+
+import static 
org.apache.inlong.agent.constant.AgentConstants.DEFAULT_PROMETHEUS_EXPORTER_PORT;
+import static 
org.apache.inlong.agent.constant.AgentConstants.PROMETHEUS_EXPORTER_PORT;
+
+/**
+ * prometheus metric handler
+ */
+public class AgentPrometheusMetricHandler extends AgentMetricBaseHandler {
+
+    private static final Logger LOGGER = 
LoggerFactory.getLogger(AgentPrometheusMetricHandler.class);
+    private static HTTPServer metricsServer;
+
+    static {
+        DefaultExports.initialize();
+    }
+
+    public AgentPrometheusMetricHandler() {
+        jobMetrics = new JobPrometheusMetrics();
+        taskMetrics = new TaskPrometheusMetrics();
+        globalMetrics = new PrometheusGlobalMetrics();
+    }
+
+    @Override
+    public void snapshot(String domain, List<MetricItemValue> itemValues) {
+        // nothing
+    }
+
+    @Override
+    public void init() {
+        // starting metrics server
+        int metricsServerPort = AgentConfiguration.getAgentConf()
+                .getInt(PROMETHEUS_EXPORTER_PORT, 
DEFAULT_PROMETHEUS_EXPORTER_PORT);

Review Comment:
   This can't handle the scenario where there are multi kinds of listeners in 
config file. Could you extend it?



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