This repository has been archived by the owner on Aug 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 105
Fix backslash escaping for all affected http endpoints (render and index.json) #410
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ cd api $ go test -run=. -bench=HttpResp ./... PASS ok github.com/raintank/metrictank/api 0.017s ? github.com/raintank/metrictank/api/middleware [no test files] --- FAIL: TestJsonMarshal (0.00s) series_test.go:88: bad json output. expected:[{"target":"a\\b","datapoints":[]}] got: [{"target":"a\b","datapoints":[]}] FAIL FAIL github.com/raintank/metrictank/api/models 0.003s BenchmarkHttpRespFastJsonEmptySeries-8 10000000 194 ns/op BenchmarkHttpRespFastJsonEmptySeriesNeedsEscaping-8 10000000 188 ns/op BenchmarkHttpRespFastJsonIntegers-8 10000 179669 ns/op 66.79 MB/s BenchmarkHttpRespFastJsonFloats-8 5000 246102 ns/op 48.76 MB/s BenchmarkHttpRespFastJsonNulls-8 50000 32903 ns/op 364.70 MB/s BenchmarkHttpRespJsonEmptySeries-8 1000000 1052 ns/op BenchmarkHttpRespJsonEmptySeriesNeedsEscaping-8 1000000 1170 ns/op BenchmarkHttpRespJsonIntegers-8 5000 382437 ns/op 31.38 MB/s BenchmarkHttpRespJsonFloats-8 3000 441587 ns/op 27.17 MB/s BenchmarkHttpRespJsonNulls-8 10000 177121 ns/op 67.75 MB/s PASS ok github.com/raintank/metrictank/api/response 16.638s
only a marginal 130ns slower per series. no-one will notice :) $ cd api $ go test -run=. -bench=HttpResp ./... PASS ok github.com/raintank/metrictank/api 0.019s ? github.com/raintank/metrictank/api/middleware [no test files] PASS ok github.com/raintank/metrictank/api/models 0.003s BenchmarkHttpRespFastJsonEmptySeries-8 5000000 328 ns/op BenchmarkHttpRespFastJsonEmptySeriesNeedsEscaping-8 5000000 315 ns/op BenchmarkHttpRespFastJsonIntegers-8 10000 176419 ns/op 68.02 MB/s BenchmarkHttpRespFastJsonFloats-8 5000 245955 ns/op 48.79 MB/s BenchmarkHttpRespFastJsonNulls-8 50000 32080 ns/op 374.06 MB/s BenchmarkHttpRespJsonEmptySeries-8 1000000 1190 ns/op BenchmarkHttpRespJsonEmptySeriesNeedsEscaping-8 1000000 1155 ns/op BenchmarkHttpRespJsonIntegers-8 5000 381486 ns/op 31.46 MB/s BenchmarkHttpRespJsonFloats-8 3000 440396 ns/op 27.25 MB/s BenchmarkHttpRespJsonNulls-8 10000 177833 ns/op 67.48 MB/s PASS ok github.com/raintank/metrictank/api/response 16.347s
with a failure for backslash escaping $ cd api $ go test -run=. -bench='HttpResp.*MetricNames' ./... PASS ok github.com/raintank/metrictank/api 0.017s ? github.com/raintank/metrictank/api/middleware [no test files] --- FAIL: TestGraphiteNames (0.00s) graphite_test.go:55: bad json output. expected:["a\\b"] got: ["a\b"] FAIL FAIL github.com/raintank/metrictank/api/models 0.003s BenchmarkHttpRespFastJson1MMetricNames-8 2 803494085 ns/op BenchmarkHttpRespFastJson1MMetricNamesNeedEscaping-8 2 790286769 ns/op BenchmarkHttpRespJson1MMetricNames-8 1 1169526068 ns/op BenchmarkHttpRespJson1MMetricNamesNeedEscaping-8 2 838954849 ns/op PASS ok github.com/raintank/metrictank/api/response 10.122s
this one does have a rather significant (>50%) performance impact though.. clocking at 1.2seconds to fast-json encode 1M series names. But I still think it's acceptable. There will always be people who send backslashes and expect things to work. $ cd api $ go test -run=. -bench='HttpResp.*MetricNames' ./... PASS ok github.com/raintank/metrictank/api 0.016s ? github.com/raintank/metrictank/api/middleware [no test files] PASS ok github.com/raintank/metrictank/api/models 0.003s BenchmarkHttpRespFastJson1MMetricNames-8 1 1244703440 ns/op BenchmarkHttpRespFastJson1MMetricNamesNeedEscaping-8 1 1270512142 ns/op BenchmarkHttpRespJson1MMetricNames-8 1 1566750909 ns/op BenchmarkHttpRespJson1MMetricNamesNeedEscaping-8 1 1621836336 ns/op PASS ok github.com/raintank/metrictank/api/response 6.619s
Dieterbe
changed the title
Fix render
Fix backslash escaping for all affected http endpoints (render and index.json)
Nov 26, 2016
woodsaj
approved these changes
Nov 28, 2016
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
No description provided.