-
Notifications
You must be signed in to change notification settings - Fork 825
Changes to HTTPMetricHandler to fix Issue #732 #738
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
Conversation
d10e4fa to
696a036
Compare
fstab
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thaks a lot for the PR! I like the idea of refactoring the request() methods to make the test clearer.
However, it would be good if after the refactoring the test had less lines of code, because the new HttpRequest / HttpResponse classes allowed expressing the test more concisely. Currently, the test grew from 576 lines to 724 lines even though all the request() methods are removed. With a bit of refactoring we could reduce the boiler plate:
Assert.assertTrue(
(httpResponse.getHeader("content-length") == null)
^ (httpResponse.getHeader("transfer-encoding") == null));This is copied 16 times. It would be good to have one test to make sure that the content-length and transfer-encoding headers are correct, and not to copy-and-paste this to all tests.
HttpRequest httpRequest = new HttpRequest.Builder()
.withURL("http://localhost:" + httpServer.getPort() + "/metrics?x")
.build();
HttpResponse httpResponse = httpRequest.execute();
String body = httpRequest.execute().getBody();The relevant part here is the ?x URL parameter. This was easier to see in the previous single line String body = request(s, "?x").body;. Maybe we can add a helper method request(HTTPServer, String) that returns the initialized Builder? Then we could cover the simple case with request(httpServer, "?x").build().execute().getBody(). To reduce this even further, we could just move the Builder methods directly into the HttpRequest, then you could write request(httpServer, "?x").execute().getBody().
For more complex tests we could still write something like
request(httpServer, "?x")
.withHeader(...)
.withAuthorization(...)
.execute().getBody();
simpleclient_httpserver/src/test/java/io/prometheus/client/exporter/TestHTTPServer.java
Outdated
Show resolved
Hide resolved
simpleclient_httpserver/src/test/java/io/prometheus/client/exporter/TestHTTPServer.java
Outdated
Show resolved
Hide resolved
|
@fstab I have refactored the code to mostly align with your suggestions. |
fstab
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's looking great, thanks a lot! I added two little nitpick remarks, apart from that it's ready to be merged.
simpleclient_httpserver/src/test/java/io/prometheus/client/exporter/HttpResponse.java
Outdated
Show resolved
Hide resolved
simpleclient_httpserver/src/test/java/io/prometheus/client/exporter/TestHTTPServer.java
Outdated
Show resolved
Hide resolved
|
Forgot to push? |
…t-Length=0 when Transfer-Encoding=chunked. Refactored test classes for easier/cleaner testing. Signed-off-by: Doug Hoard <doug.hoard@gmail.com>
Yep. pushed. Apologies. |
|
Thanks a lot! |
Changes to HTTPServer and HTTPMetricHandler to resolve getting Content-Length=0 when Transfer-Encoding=chunked. Refactored TestHTTPTest for cleaner testing.
Signed-off-by: Doug Hoard doug.hoard@gmail.com