massakam opened a new pull request #1567: Fix bug that WebSocket proxy returns 
empty metrics
URL: https://github.com/apache/incubator-pulsar/pull/1567
 
 
   ### Motivation
   
   WebSocket proxy provides an endpoint for obtaining metrics.
   ```
   /admin/proxy-stats/metrics
   ```
   However, I realized that the endpoint almost always returns empty JSON `[]`.
   There are two causes for this.
   
   First, there is a possibility that NullPointerException occurs in this line:
   
https://github.com/apache/incubator-pulsar/blob/5fc4d536d76b1d73c6be7b9238bf14b210ee095f/pulsar-websocket/src/main/java/org/apache/pulsar/websocket/stats/ProxyStats.java#L119
   `publishMsgLatency` is not initialized unless at least one producer is 
connected.
   
https://github.com/apache/incubator-pulsar/blob/5fc4d536d76b1d73c6be7b9238bf14b210ee095f/pulsar-websocket/src/main/java/org/apache/pulsar/websocket/stats/ProxyStats.java#L72-L74
   
   Seccond, `tempMetricsCollection` is not an local variable but an instance 
variable:
   
https://github.com/apache/incubator-pulsar/blob/5fc4d536d76b1d73c6be7b9238bf14b210ee095f/pulsar-websocket/src/main/java/org/apache/pulsar/websocket/stats/ProxyStats.java#L44
   As a result, the three variables `tempMetricsCollection`, `tempRef` and 
`metricsCollection` always refer to the same instance, and `metricsCollection` 
is cleared each time after the second and subsequent execution of `generate()`.
   
   
   ### Modifications
   
   * Initialize `publishMsgLatency` in the constructor of `ProxyNamespaceStats`
   * Declare `tempMetricsCollection` as local variable
   
   ### Result
   
   WebSocket proxy no longer returns empty metrics.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to