You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@samza.apache.org by GitBox <gi...@apache.org> on 2020/08/18 18:25:22 UTC

[GitHub] [samza] vishwajith-s opened a new pull request #1418: SAMZA-2583: Fix NPE in update SamzaHistogram Gauge values

vishwajith-s opened a new pull request #1418:
URL: https://github.com/apache/samza/pull/1418


   SamzaHistogram gauges are instantiated via passed in metric registry
   newGauge api. The new Gauge api in turn tries to instantiate
   HistogramGauge. The newGauge api calls getValue on HistogramGauge
   which in turn tries to update the Histogram Gauge values. This means
   we are updating Histogram Gauge values in process of creating it.
   As a fix, we add  null check in Gauge getValue to avoid NPE.


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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [samza] mynameborat commented on a change in pull request #1418: SAMZA-2583: Fix NPE in update SamzaHistogram Gauge values

Posted by GitBox <gi...@apache.org>.
mynameborat commented on a change in pull request #1418:
URL: https://github.com/apache/samza/pull/1418#discussion_r473145107



##########
File path: samza-api/src/test/java/org/apache/samza/metrics/TestSamzaHistogram.java
##########
@@ -0,0 +1,46 @@
+/*
+ * 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.samza.metrics;
+
+import org.junit.Test;
+import org.mockito.stubbing.Answer;
+
+import static org.junit.Assert.*;
+import static org.mockito.Mockito.*;

Review comment:
       minor: can you put the actual imports instead of the start imports? 




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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [samza] prateekm commented on pull request #1418: SAMZA-2583: Fix NPE in update SamzaHistogram Gauge values

Posted by GitBox <gi...@apache.org>.
prateekm commented on pull request #1418:
URL: https://github.com/apache/samza/pull/1418#issuecomment-675641967


   @vishwajith-s Can you please add a unit test for this issue so that you fix doesn't get refactored away. Thanks for the quick fix!


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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [samza] prateekm commented on pull request #1418: SAMZA-2583: Fix NPE in update SamzaHistogram Gauge values

Posted by GitBox <gi...@apache.org>.
prateekm commented on pull request #1418:
URL: https://github.com/apache/samza/pull/1418#issuecomment-675801703


   @vishwajith-s LGTM, thanks. Can you check why the build failed?


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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [samza] prateekm merged pull request #1418: SAMZA-2583: Fix NPE in update SamzaHistogram Gauge values

Posted by GitBox <gi...@apache.org>.
prateekm merged pull request #1418:
URL: https://github.com/apache/samza/pull/1418


   


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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [samza] prateekm commented on a change in pull request #1418: SAMZA-2583: Fix NPE in update SamzaHistogram Gauge values

Posted by GitBox <gi...@apache.org>.
prateekm commented on a change in pull request #1418:
URL: https://github.com/apache/samza/pull/1418#discussion_r472397514



##########
File path: samza-api/src/main/java/org/apache/samza/metrics/SamzaHistogram.java
##########
@@ -81,6 +81,10 @@ public void visit(MetricsVisitor visitor) {
      * and do not have MetricsReporter to update the values.
      */
     public Double getValue() {
+      if (gauges == null) {

Review comment:
       Please add an inline comment for when this can happen.




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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [samza] vishwajith-s commented on pull request #1418: SAMZA-2583: Fix NPE in update SamzaHistogram Gauge values

Posted by GitBox <gi...@apache.org>.
vishwajith-s commented on pull request #1418:
URL: https://github.com/apache/samza/pull/1418#issuecomment-675866718


   > > > @vishwajith-s Can you please add a unit test for this issue so that you fix doesn't get refactored away. Thanks for the quick fix!
   > > 
   > > 
   > > Had to add implement MockMetricRegistry class instead of using Mockito framework as we had to ensure getValue is being called as part of newGauge creation.
   > 
   > Would stubbing the call to mockMetricsRegistry and respond with an answer that invokes `value.getValue()` work? You can use the invocationContext to get the actual arguments.
   
   Thanks! This simplified the test a lot!


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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [samza] vishwajith-s commented on pull request #1418: SAMZA-2583: Fix NPE in update SamzaHistogram Gauge values

Posted by GitBox <gi...@apache.org>.
vishwajith-s commented on pull request #1418:
URL: https://github.com/apache/samza/pull/1418#issuecomment-675774956


   > @vishwajith-s Can you please add a unit test for this issue so that you fix doesn't get refactored away. Thanks for the quick fix!
   
   Had to add implement MockMetricRegistry class instead of using Mockito framework as we had to ensure getValue is being called as part of newGauge creation.


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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [samza] vishwajith-s commented on pull request #1418: SAMZA-2583: Fix NPE in update SamzaHistogram Gauge values

Posted by GitBox <gi...@apache.org>.
vishwajith-s commented on pull request #1418:
URL: https://github.com/apache/samza/pull/1418#issuecomment-675774036


   > @vishwajith-s Can you please add a unit test for this issue so that you fix doesn't get refactored away. Thanks for the quick fix!
   
   Done.


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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [samza] mynameborat commented on pull request #1418: SAMZA-2583: Fix NPE in update SamzaHistogram Gauge values

Posted by GitBox <gi...@apache.org>.
mynameborat commented on pull request #1418:
URL: https://github.com/apache/samza/pull/1418#issuecomment-675803613


   > > @vishwajith-s Can you please add a unit test for this issue so that you fix doesn't get refactored away. Thanks for the quick fix!
   > 
   > Had to add implement MockMetricRegistry class instead of using Mockito framework as we had to ensure getValue is being called as part of newGauge creation.
   
   Would stubbing the call to mockMetricsRegistry and respond with an answer that invokes `value.getValue()` work? You can use the invocationContext to get the actual arguments.


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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [samza] mynameborat commented on pull request #1418: SAMZA-2583: Fix NPE in update SamzaHistogram Gauge values

Posted by GitBox <gi...@apache.org>.
mynameborat commented on pull request #1418:
URL: https://github.com/apache/samza/pull/1418#issuecomment-675804785


   > > > @vishwajith-s Can you please add a unit test for this issue so that you fix doesn't get refactored away. Thanks for the quick fix!
   > > 
   > > 
   > > Had to add implement MockMetricRegistry class instead of using Mockito framework as we had to ensure getValue is being called as part of newGauge creation.
   > 
   > Would stubbing the call to mockMetricsRegistry and respond with an answer that invokes `value.getValue()` work? You can use the invocationContext to get the actual arguments.
   
   Here is an example - https://github.com/apache/samza/blob/216a87fe4c6fa8e0ed48ad7488e296a88d41376e/samza-core/src/test/java/org/apache/samza/clustermanager/TestContainerPlacementActions.java#L193


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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org