Github user zentol commented on a diff in the pull request:

    https://github.com/apache/flink/pull/4826#discussion_r145114263
  
    --- Diff: 
flink-streaming-java/src/main/java/org/apache/flink/streaming/util/latency/LatencyStats.java
 ---
    @@ -0,0 +1,67 @@
    +/*
    + * 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.flink.streaming.util.latency;
    +
    +import org.apache.flink.metrics.MetricGroup;
    +import org.apache.flink.streaming.runtime.streamrecord.LatencyMarker;
    +
    +import java.util.HashMap;
    +import java.util.Map;
    +
    +/**
    + * The {@link LatencyStats} objects are used to track and report on the 
behavior of latencies across measurements.
    + */
    +public class LatencyStats {
    +   private final Map<String, LatencyHistogram> latencyStats = new 
HashMap<>();
    +   private final MetricGroup metricGroup;
    +   private final int historySize;
    +
    +   public LatencyStats(MetricGroup metricGroup, int historySize) {
    +           this.metricGroup = metricGroup;
    +           this.historySize = historySize;
    +   }
    +
    +   public void reportLatency(LatencyMarker marker, boolean isSink) {
    +           String latencyMetricName = identifyLatencySource(marker, 
!isSink);
    +           LatencyHistogram latencyHistogram = 
this.latencyStats.get(latencyMetricName);
    +           if (latencyHistogram == null) {
    +                   latencyHistogram = new 
LatencyHistogram(this.historySize);
    +                   this.latencyStats.put(latencyMetricName, 
latencyHistogram);
    +                   this.metricGroup.histogram(latencyMetricName, 
latencyHistogram);
    +           }
    +
    +           long now = System.currentTimeMillis();
    +           latencyHistogram.update(now - marker.getMarkedTime());
    +   }
    +
    +   /**
    +    * Creates a Identifier for a latency source. from a given {@code 
LatencyMarker}.
    --- End diff --
    
    "an identifier"


---

Reply via email to