yzeng1618 commented on code in PR #9576:
URL: https://github.com/apache/seatunnel/pull/9576#discussion_r2387396626


##########
seatunnel-translation/seatunnel-translation-flink/seatunnel-translation-flink-20/src/main/java/org/apache/seatunnel/translation/flink/metric/FlinkMetricContext.java:
##########
@@ -0,0 +1,150 @@
+/*
+ *  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.translation.flink.metric;
+
+import org.apache.seatunnel.api.common.metrics.Counter;
+import org.apache.seatunnel.api.common.metrics.Meter;
+import org.apache.seatunnel.api.common.metrics.MetricNames;
+import org.apache.seatunnel.api.common.metrics.MetricsContext;
+
+import org.apache.flink.api.common.functions.RuntimeContext;
+import org.apache.flink.metrics.MetricGroup;
+import org.apache.flink.streaming.api.operators.StreamingRuntimeContext;
+
+import lombok.extern.slf4j.Slf4j;
+
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+@Slf4j
+public class FlinkMetricContext implements MetricsContext {
+
+    private final MetricGroup metricGroup;
+    private final StreamingRuntimeContext runtimeContext;
+    private final RuntimeContext generalRuntimeContext;
+    private final Map<String, Counter> counters = new ConcurrentHashMap<>();
+    private final Map<String, Meter> meters = new ConcurrentHashMap<>();
+
+    public FlinkMetricContext(StreamingRuntimeContext runtimeContext) {
+        this.runtimeContext = runtimeContext;
+        this.generalRuntimeContext = runtimeContext;
+        this.metricGroup = runtimeContext != null ? 
runtimeContext.getMetricGroup() : null;
+    }
+
+    public FlinkMetricContext(RuntimeContext runtimeContext, MetricGroup 
metricGroup) {
+        this.runtimeContext =
+                runtimeContext instanceof StreamingRuntimeContext
+                        ? (StreamingRuntimeContext) runtimeContext
+                        : null;
+        this.generalRuntimeContext = runtimeContext;
+        this.metricGroup = metricGroup;
+    }
+
+    public FlinkMetricContext(MetricGroup metricGroup) {
+        this.metricGroup = metricGroup;
+        this.generalRuntimeContext = null;
+        this.runtimeContext = null;
+    }
+
+    @Override
+    public Counter counter(String name) {
+        Counter existingCounter = counters.get(name);
+        if (existingCounter != null) {
+            return existingCounter;
+        }
+
+        if (metricGroup == null) {
+            Counter noOpCounter = new NoOpCounter();

Review Comment:
   > It's werid. Why other flink version does not need this?
   
   To maintain consistency, redundant content can be streamlined and removed.



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