This repository has been archived by the owner on Jul 31, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 329
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
zpages: fix Snapshot int->*int64 changes + tests on count
The signature for countFormatter's arguments was changed in PR #948 from int to int64 but unfortunately we forgot to update the int fields from int to the new type. Issue #948's recommendation was to use uint64 since that affords us more time to overflow e.g. even at 25QPs it'd take a couple of millenia to overflow with uint64. This change completes the change of types of the int variables but also adds tests that make use of the template functions and a snapshot and then compare the output or fail. Previously the tests complained but since they were HTTP tests not attached to an output buffer that could be inspected, the bug innocently crept away in standard output and the tests incorrectly passed as in: * https://ci.appveyor.com/project/opencensusgoteam/opencensus-go/builds/19498802#L700 * https://travis-ci.org/census-instrumentation/opencensus-go/builds/441324783#L1183 This problem was reported by an OpenCensus-Service user in * census-instrumentation/opencensus-service#123 Fixes #895 Fixes #951
- Loading branch information
Showing
5 changed files
with
112 additions
and
14 deletions.
There are no files selected for viewing
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
// Copyright 2018, OpenCensus Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package zpages | ||
|
||
import ( | ||
"bytes" | ||
"html/template" | ||
"testing" | ||
) | ||
|
||
const tmplBody = ` | ||
<td><b>{{.Method}}</b></td> | ||
<td></td> | ||
<td align="right">{{.CountMinute|count}}</td> | ||
<td align="right">{{.CountHour|count}}</td> | ||
<td align="right">{{.CountTotal|count}}</td><td></td> | ||
<td align="right">{{.AvgLatencyMinute|ms}}</td> | ||
<td align="right">{{.AvgLatencyHour|ms}}</td> | ||
<td align="right">{{.AvgLatencyTotal|ms}}</td><td></td> | ||
<td align="right">{{.RPCRateMinute|rate}}</td> | ||
<td align="right">{{.RPCRateHour|rate}}</td> | ||
<td align="right">{{.RPCRateTotal|rate}}</td><td></td> | ||
<td align="right">{{.InputRateMinute|datarate}}</td> | ||
<td align="right">{{.InputRateHour|datarate}}</td> | ||
<td align="right">{{.InputRateTotal|datarate}}</td><td></td> | ||
<td align="right">{{.OutputRateMinute|datarate}}</td> | ||
<td align="right">{{.OutputRateHour|datarate}}</td> | ||
<td align="right">{{.OutputRateTotal|datarate}}</td><td></td> | ||
<td align="right">{{.ErrorsMinute|count}}</td> | ||
<td align="right">{{.ErrorsHour|count}}</td> | ||
<td align="right">{{.ErrorsTotal|count}}</td><td></td> | ||
` | ||
|
||
var tmpl = template.Must(template.New("countTest").Funcs(templateFunctions).Parse(tmplBody)) | ||
|
||
func TestTemplateFuncs(t *testing.T) { | ||
buf := new(bytes.Buffer) | ||
sshot := &statSnapshot{ | ||
Method: "Foo", | ||
CountMinute: 1e9, | ||
CountHour: 5000, | ||
CountTotal: 1e12, | ||
AvgLatencyMinute: 10000, | ||
AvgLatencyHour: 1000, | ||
AvgLatencyTotal: 20000, | ||
RPCRateMinute: 2000, | ||
RPCRateHour: 5000, | ||
RPCRateTotal: 75000, | ||
InputRateMinute: 75000, | ||
InputRateHour: 75000, | ||
InputRateTotal: 75000, | ||
OutputRateMinute: 75000, | ||
OutputRateHour: 75000, | ||
OutputRateTotal: 75000, | ||
ErrorsMinute: 120000000, | ||
ErrorsHour: 75000000, | ||
ErrorsTotal: 7500000, | ||
} | ||
if err := tmpl.Execute(buf, sshot); err != nil { | ||
t.Fatalf("Failed to execute template: %v", err) | ||
} | ||
want := ` | ||
<td><b>Foo</b></td> | ||
<td></td> | ||
<td align="right">1.000 G </td> | ||
<td align="right">5000</td> | ||
<td align="right">1.000 T </td><td></td> | ||
<td align="right">0.010</td> | ||
<td align="right">0.001</td> | ||
<td align="right">0.020</td><td></td> | ||
<td align="right">2000.000</td> | ||
<td align="right">5000.000</td> | ||
<td align="right">75000.000</td><td></td> | ||
<td align="right">0.075</td> | ||
<td align="right">0.075</td> | ||
<td align="right">0.075</td><td></td> | ||
<td align="right">0.075</td> | ||
<td align="right">0.075</td> | ||
<td align="right">0.075</td><td></td> | ||
<td align="right">120.000 M </td> | ||
<td align="right">75.000 M </td> | ||
<td align="right">7.500 M </td><td></td> | ||
` | ||
if g, w := buf.String(), want; g != w { | ||
t.Errorf("Output mismatch:\nGot:\n\t%s\nWant:\n\t%s", g, w) | ||
} | ||
} |