apoorvmittal10 commented on code in PR #14575:
URL: https://github.com/apache/kafka/pull/14575#discussion_r1366842840


##########
clients/src/main/java/org/apache/kafka/common/telemetry/internals/Emitter.java:
##########
@@ -0,0 +1,107 @@
+/*
+ * 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.kafka.common.telemetry.internals;
+
+import java.util.Collections;
+import java.util.List;
+
+import java.io.Closeable;
+
+/**
+ * An {@code Emitter} emits the values held by the {@link SinglePointMetric}, 
likely first converting them
+ * to a format suitable for exposure, storage, or transmission. The telemetry 
reporter is likely
+ * the entity that is familiar with the underlying method of making the 
metrics visible to the
+ * broker. Thus, it is the primary place in the code where the implementation 
details are known.
+ *
+ * <p>
+ *
+ * An {@code Emitter} is stateless and the telemetry reporter should assume 
that the object is
+ * not thread safe and thus concurrent access to either the
+ * {@link #shouldEmitMetric(MetricKeyable)} or {@link 
#emitMetric(SinglePointMetric)} should be avoided.
+ *
+ * Regarding threading, the {@link #init()} and {@link #close()} methods may 
be called from
+ * different threads and so proper care should be taken by implementations of 
the
+ * {@code MetricsCollector} interface to be thread-safe. However, the 
telemetry reporter must
+ * ensure that the {@link #emitMetric(SinglePointMetric)} method should only 
be invoked in a synchronous
+ * manner.
+ */
+public interface Emitter extends Closeable {
+
+    /**
+     * Performs the necessary logic to determine if the metric is to be 
emitted. The telemetry
+     * reporter should respect this and not just call the {@link 
#emitMetric(SinglePointMetric)} directly.
+     *
+     * @param metricKeyable Object from which to get the {@link MetricKey}
+     * @return {@code true} if the metric should be emitted, {@code false} 
otherwise
+     */
+    boolean shouldEmitMetric(MetricKeyable metricKeyable);
+
+    /**
+     * Emits the metric in an implementation-specific fashion. Depending on 
the implementation,
+     * calls made to this after {@link #close()} has been invoked will fail.
+     *
+     * @param metric {@code SinglePointMetric}
+     * @return {@code true} if the metric was emitted, {@code false} otherwise
+     */
+    boolean emitMetric(SinglePointMetric metric);

Review Comment:
   Depends on the implementation, where it might if metrics emitted directly to 
external system then there is some issue or anything else. I think it will be 
better to signal if emit was not possible for certain metric and log error but 
continue emitting what's possible.



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