fuweng11 commented on code in PR #11708: URL: https://github.com/apache/inlong/pull/11708#discussion_r1925194375
########## inlong-sdk/dataproxy-sdk/src/main/java/org/apache/inlong/sdk/dataproxy/metric/MetricDataHolder.java: ########## @@ -0,0 +1,347 @@ +/* + * 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.sdk.dataproxy.metric; + +import org.apache.inlong.sdk.dataproxy.common.ProcessResult; +import org.apache.inlong.sdk.dataproxy.sender.BaseSender; +import org.apache.inlong.sdk.dataproxy.sender.http.HttpMsgSenderConfig; +import org.apache.inlong.sdk.dataproxy.sender.tcp.TcpMsgSender; +import org.apache.inlong.sdk.dataproxy.sender.tcp.TcpMsgSenderConfig; +import org.apache.inlong.sdk.dataproxy.utils.LogCounter; +import org.apache.inlong.sdk.dataproxy.utils.ProxyUtils; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicLong; +import java.util.concurrent.atomic.LongAdder; + +public class MetricDataHolder implements Runnable { + + private static final String DEFAULT_KEY_SPLITTER = "#"; + private static final Logger logger = LoggerFactory.getLogger(MetricDataHolder.class); + private static final LogCounter exceptCnt = new LogCounter(10, 100000, 60 * 1000L); + + private final MetricConfig metricConfig; + private final BaseSender sender; + private volatile boolean started = true; + // Current writable index + private volatile int itemIndex; + // metric data items + private final MetricInfoUnit[] metricUnits = new MetricInfoUnit[2]; + // Last snapshot time + private volatile long lstReportTime; + private final ScheduledExecutorService outputExecutor = + Executors.newScheduledThreadPool(1); + + public MetricDataHolder(BaseSender sender) { + this.sender = sender; + this.metricConfig = sender.getConfigure().getMetricConfig(); + this.itemIndex = 0; + this.metricUnits[0] = new MetricInfoUnit(); + this.metricUnits[1] = new MetricInfoUnit(); + } + + public boolean start(ProcessResult procResult) { + this.outputExecutor.scheduleWithFixedDelay(this, + this.metricConfig.getMetricOutIntvlMs(), + this.metricConfig.getMetricOutIntvlMs(), TimeUnit.MILLISECONDS); + logger.info("Metric DataHolder({}) started!", this.sender.getSenderId()); + return procResult.setSuccess(); + } + + @Override + public void run() { + long startTime = System.currentTimeMillis(); + outputMetricData(startTime, getAndIncIndex()); + long dltTime = System.currentTimeMillis() - startTime; + if (dltTime > this.metricConfig.getMetricOutWarnIntMs()) { + logger.warn("Metric DataHolder({}) snapshot finished, wast={}ms!", + this.sender.getSenderId(), dltTime); + } + this.lstReportTime = startTime; + } + + public void close() { + logger.info("Metric DataHolder({}) closing ......", this.sender.getSenderId()); + // process rest data + this.outputExecutor.shutdown(); + long startTime = System.currentTimeMillis(); + outputMetricData(startTime, getOldIndex()); + outputMetricData(startTime, getCurIndex()); + this.started = false; + logger.info("Metric DataHolder({}) closed, wast{}ms!", + this.sender.getSenderId(), System.currentTimeMillis() - startTime); Review Comment: ```suggestion logger.info("Metric DataHolder({}) closed, wast {} ms!", this.sender.getSenderId(), System.currentTimeMillis() - startTime); ``` -- 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-unsubscr...@inlong.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org