asafm commented on code in PR #20498:
URL: https://github.com/apache/pulsar/pull/20498#discussion_r1221748203


##########
pulsar-io/elastic-search/src/main/java/org/apache/pulsar/io/elasticsearch/ElasticSearchMetrics.java:
##########
@@ -0,0 +1,52 @@
+/*
+ * 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.pulsar.io.elasticsearch;
+
+import org.apache.pulsar.io.core.SinkContext;
+
+/*
+ * Metrics class for ElasticSearchSink
+ */
+public class ElasticSearchMetrics {
+
+    private SinkContext sinkContext;
+    // sink metrics
+    public static final String INCOMING = "_elasticsearch_incoming_";

Review Comment:
   static final goes before private variables



##########
pulsar-io/elastic-search/src/main/java/org/apache/pulsar/io/elasticsearch/ElasticSearchMetrics.java:
##########
@@ -0,0 +1,52 @@
+/*
+ * 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.pulsar.io.elasticsearch;
+
+import org.apache.pulsar.io.core.SinkContext;
+
+/*
+ * Metrics class for ElasticSearchSink
+ */
+public class ElasticSearchMetrics {
+
+    private SinkContext sinkContext;
+    // sink metrics
+    public static final String INCOMING = "_elasticsearch_incoming_";
+
+    // INCOMING = SUCCESS + FAILURE + SKIP + NULLVALUE_IGNORE
+    public static final String SUCCESS = "_elasticsearch_success_";
+
+    // DELETE is an attempt to delete a document by id
+    public static final String DELETE = "elasticsearch_delete_";
+    public static final String FAILURE = "elasticsearch_failure_";
+    public static final String SKIP = "elasticsearch_skip_";
+    public static final String WARN = "elasticsearch_warn_";
+    public static final String MALFORMED_IGNORE = 
"elasticsearch_malformed_ignore_";
+    public static final String NULLVALUE_IGNORE = 
"elasticsearch_nullvalue_ignore_";
+
+    public ElasticSearchMetrics(SinkContext sinkContext) {
+        this.sinkContext = sinkContext;
+    }
+
+    public void incrementCounter(String counter, double value) {
+        if (sinkContext != null) {

Review Comment:
   1. Why can sinkContext be null at all?
   2. Not here for sure. Put in ctor.



##########
pulsar-io/elastic-search/src/main/java/org/apache/pulsar/io/elasticsearch/ElasticSearchClient.java:
##########
@@ -90,8 +82,8 @@ public void afterBulk(long executionId, 
List<BulkProcessor.BulkOperationRequest>
                         record.fail();
                         checkForIrrecoverableError(record, result);
                     } else {
-                        incrementCounter(METRICS_TOTAL_SUCCESS, index);
                         record.ack();
+                        metrics.incrementCounter(ElasticSearchMetrics.SUCCESS, 
index);

Review Comment:
   If you already did the work, wouldn't you prefer to go all the way?
   `metrics.incrementCounter(ElasticSearchMetrics.SUCCESS, index);` ---> 
`metrics.recordRecordIndexedSuccess()`?
   



##########
pulsar-io/elastic-search/src/main/java/org/apache/pulsar/io/elasticsearch/ElasticSearchSink.java:
##########
@@ -120,22 +123,21 @@ public void write(Record<GenericObject> record) throws 
Exception {
                     switch (elasticSearchConfig.getNullValueAction()) {
                         case DELETE:
                             if (idAndDoc.getLeft() != null) {
+                                
metrics.incrementCounter(ElasticSearchMetrics.DELETE, 1);

Review Comment:
   `bulkDelete` or `deleteDocument` can fail and increment failure, but you 
increase it anyway- double counting.



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