Hisoka-X commented on code in PR #7338: URL: https://github.com/apache/seatunnel/pull/7338#discussion_r1716502798
########## seatunnel-engine/seatunnel-engine-server/src/main/java/org/apache/seatunnel/engine/server/metrics/TaskMetricsCalcContext.java: ########## @@ -0,0 +1,213 @@ +/* + * 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.seatunnel.engine.server.metrics; + +import org.apache.seatunnel.api.common.metrics.Counter; +import org.apache.seatunnel.api.common.metrics.Meter; +import org.apache.seatunnel.api.common.metrics.MetricsContext; +import org.apache.seatunnel.api.table.catalog.TablePath; +import org.apache.seatunnel.api.table.type.SeaTunnelRow; +import org.apache.seatunnel.common.constants.PluginType; + +import org.apache.commons.lang3.StringUtils; + +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.concurrent.ConcurrentHashMap; + +import static org.apache.seatunnel.api.common.metrics.MetricNames.SINK_WRITE_BYTES; +import static org.apache.seatunnel.api.common.metrics.MetricNames.SINK_WRITE_BYTES_PER_SECONDS; +import static org.apache.seatunnel.api.common.metrics.MetricNames.SINK_WRITE_COUNT; +import static org.apache.seatunnel.api.common.metrics.MetricNames.SINK_WRITE_QPS; +import static org.apache.seatunnel.api.common.metrics.MetricNames.SOURCE_RECEIVED_BYTES; +import static org.apache.seatunnel.api.common.metrics.MetricNames.SOURCE_RECEIVED_BYTES_PER_SECONDS; +import static org.apache.seatunnel.api.common.metrics.MetricNames.SOURCE_RECEIVED_COUNT; +import static org.apache.seatunnel.api.common.metrics.MetricNames.SOURCE_RECEIVED_QPS; + +public class TaskMetricsCalcContext { + + private final MetricsContext metricsContext; + + private final PluginType type; + + private Counter count; + + private Map<String, Counter> countPerTable = new ConcurrentHashMap<>(); + + private Meter QPS; + + private Map<String, Meter> QPSPerTable = new ConcurrentHashMap<>(); + + private Counter bytes; + + private Map<String, Counter> bytesPerTable = new ConcurrentHashMap<>(); + + private Meter bytesPerSeconds; + + private Map<String, Meter> bytesPerSecondsPerTable = new ConcurrentHashMap<>(); + + public TaskMetricsCalcContext( + MetricsContext metricsContext, + PluginType type, + boolean isMulti, + List<TablePath> tables) { + this.metricsContext = metricsContext; + this.type = type; + initializeMetrics(isMulti, tables); + } + + private void initializeMetrics(boolean isMulti, List<TablePath> tables) { + if (type.equals(PluginType.SINK)) { + this.initializeMetrics( + isMulti, + tables, + SINK_WRITE_COUNT, + SINK_WRITE_QPS, + SINK_WRITE_BYTES, + SINK_WRITE_BYTES_PER_SECONDS); + } else if (type.equals(PluginType.SOURCE)) { + this.initializeMetrics( + isMulti, + tables, + SOURCE_RECEIVED_COUNT, + SOURCE_RECEIVED_QPS, + SOURCE_RECEIVED_BYTES, + SOURCE_RECEIVED_BYTES_PER_SECONDS); + } + } + + private void initializeMetrics( + boolean isMulti, + List<TablePath> tables, + String writeCountName, + String writeQpsName, + String writeBytesName, + String writeBytesPerSecondsName) { Review Comment: ```suggestion private void initializeMetrics( boolean isMulti, List<TablePath> tables, String countName, String qpsName, String bytesName, String bytesPerSecondsName) { ``` Sorry, I made a mistake. -- 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]
