nastra commented on code in PR #5268:
URL: https://github.com/apache/iceberg/pull/5268#discussion_r921892961


##########
api/src/main/java/org/apache/iceberg/metrics/Timer.java:
##########
@@ -0,0 +1,136 @@
+/*
+ * 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.iceberg.metrics;
+
+import java.time.Duration;
+import java.util.concurrent.Callable;
+import java.util.concurrent.TimeUnit;
+import java.util.function.Supplier;
+
+/**
+ * Generalized Timer interface for creating telemetry related instances for 
measuring duration of operations.
+ */
+public interface Timer {
+
+  /**
+   * The number of times {@link Timer#record(Duration)} was called.
+   *
+   * @return The number of times {@link Timer#record(Duration)} was called.
+   */
+  long count();
+
+  /**
+   * The total duration that was recorded.
+   *
+   * @return The total duration that was recorded.
+   */
+  Duration totalDuration();
+
+  /**
+   * Starts the timer
+   */
+  void startTimer();
+
+  /**
+   * Stops the timer and records the total duration up until {@link 
Timer#startTimer()} was called.
+   */
+  void stopTimer();
+
+  /**
+   * Records a custom amount in the given time unit.
+   *
+   * @param amount The amount to record
+   * @param unit   The time unit of the amount
+   */
+  void record(long amount, TimeUnit unit);
+
+  /**
+   * The duration to record
+   *
+   * @param duration The duration to record
+   */
+  default void record(Duration duration) {
+    record(duration.toNanos(), TimeUnit.NANOSECONDS);
+  }
+
+  /**
+   * Executes and measures the given {@link Runnable} instance.
+   *
+   * @param runnable The {@link Runnable} to execute and measure.
+   */
+  void record(Runnable runnable);

Review Comment:
   I was broadly following how Micrometer defines their 
[Timer](https://www.javadoc.io/doc/io.micrometer/micrometer-core/latest/io/micrometer/core/instrument/Timer.html)
 interface and I had the exact same thought as you mentioned here. 
   That being said, `time()` makes also sense to me as a verb for measuring a 
Runnable/Callable/Supplier, but I think `record(long amount, TimeUnit unit)` / 
`record(Duration duration)` reads nicer than `time(long amount, TimeUnit unit)` 
/ `time(Duration duration)` and in order to keep method names aligned I decided 
to go with `record()` across the board. 
   



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to