Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug that WebSocket proxy returns empty metrics #1567

Merged
merged 2 commits into from
Apr 14, 2018

Conversation

massakam
Copy link
Contributor

@massakam massakam commented Apr 13, 2018

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 executions of generate().
https://github.com/apache/incubator-pulsar/blob/5fc4d536d76b1d73c6be7b9238bf14b210ee095f/pulsar-websocket/src/main/java/org/apache/pulsar/websocket/stats/ProxyStats.java#L97-L99

Modifications

  • Initialize publishMsgLatency in the constructor of ProxyNamespaceStats
  • Declare tempMetricsCollection as local variable

Result

WebSocket proxy no longer returns empty metrics.

@massakam massakam self-assigned this Apr 13, 2018
@massakam massakam added the type/bug The PR fixed a bug or issue reported a bug label Apr 13, 2018
@massakam massakam added this to the 2.0.0-incubating milestone Apr 13, 2018
Copy link
Contributor

@merlimat merlimat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@merlimat merlimat merged commit aa9e306 into apache:master Apr 14, 2018
@massakam massakam deleted the fix-ws-metrics branch April 14, 2018 02:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/bug The PR fixed a bug or issue reported a bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants