zentol commented on a change in pull request #18566: URL: https://github.com/apache/flink/pull/18566#discussion_r799532804
########## File path: flink-runtime/src/main/java/org/apache/flink/runtime/scheduler/metrics/StateTimeMetric.java ########## @@ -0,0 +1,72 @@ +/* + * 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.runtime.scheduler.metrics; + +import org.apache.flink.annotation.VisibleForTesting; +import org.apache.flink.configuration.MetricOptions; +import org.apache.flink.metrics.MetricGroup; + +/** Utility to define metrics that capture the time that some component spends in a state. */ +public interface StateTimeMetric { + + /** + * Returns the time, in milliseconds, that have elapsed since we transitioned to the targeted + * state. Returns 0 if we are not in the targeted state. + */ + public long getCurrentTime(); + + /** Returns the total time, in milliseconds, that we have spent in the targeted state. */ + public long getTotalTime(); + + /** Returns 1 if we are in the targeted state, otherwise 0. */ + public long getBinary(); Review comment: Reads always happen from a different thread than writes, and are usually not synchronized. Reporters have no control over this. When a reporter accesses a metric there are no guarantees as to how up-to-date or correct it is. In practice this seems to work just fine, likely because the components doing writes do plenty of synchronization on their own and reporters access a given metric quite rarely. -- 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]
