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


##########
seatunnel-translation/seatunnel-translation-flink/seatunnel-translation-flink-20/src/main/java/org/apache/seatunnel/translation/flink/metric/FlinkJobMetricsSummary.java:
##########
@@ -0,0 +1,185 @@
+/*
+ *  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.MetricNames;
+import org.apache.seatunnel.common.utils.DateTimeUtils;
+import org.apache.seatunnel.common.utils.StringFormatUtils;
+
+import org.apache.flink.api.common.JobExecutionResult;
+
+import lombok.extern.slf4j.Slf4j;
+
+import java.time.Duration;
+import java.time.LocalDateTime;
+import java.util.HashMap;
+import java.util.Map;
+
+@Slf4j
+public class FlinkJobMetricsSummary {
+
+    private final JobExecutionResult jobExecutionResult;
+    private final LocalDateTime jobStartTime;
+    private final LocalDateTime jobEndTime;
+
+    public FlinkJobMetricsSummary(
+            JobExecutionResult jobExecutionResult,
+            LocalDateTime jobStartTime,
+            LocalDateTime jobEndTime) {
+        this.jobExecutionResult = jobExecutionResult;
+        this.jobStartTime = jobStartTime;
+        this.jobEndTime = jobEndTime;
+        log.info(
+                "FlinkJobMetricsSummary created for job: {}",
+                jobExecutionResult != null ? jobExecutionResult.getJobID() : 
"null");
+    }
+
+    public static Builder builder() {
+        return new Builder();
+    }
+
+    public static class Builder {
+        private JobExecutionResult jobExecutionResult;
+        private long jobStartTime;
+        private long jobEndTime;
+
+        private Builder() {}
+
+        public Builder jobExecutionResult(JobExecutionResult 
jobExecutionResult) {
+            this.jobExecutionResult = jobExecutionResult;
+            return this;
+        }
+
+        public Builder jobStartTime(long jobStartTime) {
+            this.jobStartTime = jobStartTime;
+            return this;
+        }
+
+        public Builder jobEndTime(long jobEndTime) {
+            this.jobEndTime = jobEndTime;
+            return this;
+        }
+
+        public FlinkJobMetricsSummary build() {
+            return new FlinkJobMetricsSummary(
+                    jobExecutionResult,
+                    DateTimeUtils.parse(jobStartTime),
+                    DateTimeUtils.parse(jobEndTime));
+        }
+    }
+
+    public Map<String, Object> getMetrics() {
+        Map<String, Object> metrics = new HashMap<>();
+
+        if (jobExecutionResult == null) {
+            log.warn("JobExecutionResult is null, cannot get metrics");
+            return metrics;
+        }
+
+        try {
+            Map<String, Object> accumulatorResults = 
jobExecutionResult.getAllAccumulatorResults();
+
+            for (Map.Entry<String, Object> entry : 
accumulatorResults.entrySet()) {
+                String key = entry.getKey();
+                Object value = entry.getValue();
+
+                if (value instanceof Number) {
+                    long longValue = ((Number) value).longValue();
+
+                    if (key.equals(MetricNames.SINK_WRITE_COUNT)
+                            || key.contains("SinkWriteCount")) {

Review Comment:
   > when key.equals(MetricNames.SINK_WRITE_COUNT) is true. The 
key.contains("SinkWriteCount") also is true.
   
   Removed the equals branch and uniformly use contains(...), which covers both 
standard names and compatible notations.



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