Skip to content
This repository has been archived by the owner on Aug 23, 2023. It is now read-only.

Fix backslash escaping for all affected http endpoints (render and index.json) #410

Merged
merged 6 commits into from
Nov 28, 2016

Conversation

Dieterbe
Copy link
Contributor

No description provided.

$ 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 Dieterbe changed the title Fix render Fix backslash escaping for all affected http endpoints (render and index.json) Nov 26, 2016
@woodsaj woodsaj assigned Dieterbe and unassigned woodsaj Nov 28, 2016
@Dieterbe Dieterbe merged commit 43fc7f0 into master Nov 28, 2016
@Dieterbe Dieterbe deleted the fix-render branch December 15, 2017 22:05
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants