Switch to github.com/golang/dep for vendoring
Signed-off-by: Mrunal Patel <mrunalp@gmail.com>
This commit is contained in:
parent
d6ab91be27
commit
8e5b17cf13
15431 changed files with 3971413 additions and 8881 deletions
20
vendor/golang.org/x/net/trace/events.go
generated
vendored
20
vendor/golang.org/x/net/trace/events.go
generated
vendored
|
@ -21,11 +21,6 @@ import (
|
|||
"time"
|
||||
)
|
||||
|
||||
var eventsTmpl = template.Must(template.New("events").Funcs(template.FuncMap{
|
||||
"elapsed": elapsed,
|
||||
"trimSpace": strings.TrimSpace,
|
||||
}).Parse(eventsHTML))
|
||||
|
||||
const maxEventsPerLog = 100
|
||||
|
||||
type bucket struct {
|
||||
|
@ -101,7 +96,7 @@ func RenderEvents(w http.ResponseWriter, req *http.Request, sensitive bool) {
|
|||
|
||||
famMu.RLock()
|
||||
defer famMu.RUnlock()
|
||||
if err := eventsTmpl.Execute(w, data); err != nil {
|
||||
if err := eventsTmpl().Execute(w, data); err != nil {
|
||||
log.Printf("net/trace: Failed executing template: %v", err)
|
||||
}
|
||||
}
|
||||
|
@ -421,6 +416,19 @@ func freeEventLog(el *eventLog) {
|
|||
}
|
||||
}
|
||||
|
||||
var eventsTmplCache *template.Template
|
||||
var eventsTmplOnce sync.Once
|
||||
|
||||
func eventsTmpl() *template.Template {
|
||||
eventsTmplOnce.Do(func() {
|
||||
eventsTmplCache = template.Must(template.New("events").Funcs(template.FuncMap{
|
||||
"elapsed": elapsed,
|
||||
"trimSpace": strings.TrimSpace,
|
||||
}).Parse(eventsHTML))
|
||||
})
|
||||
return eventsTmplCache
|
||||
}
|
||||
|
||||
const eventsHTML = `
|
||||
<html>
|
||||
<head>
|
||||
|
|
15
vendor/golang.org/x/net/trace/histogram.go
generated
vendored
15
vendor/golang.org/x/net/trace/histogram.go
generated
vendored
|
@ -12,6 +12,7 @@ import (
|
|||
"html/template"
|
||||
"log"
|
||||
"math"
|
||||
"sync"
|
||||
|
||||
"golang.org/x/net/internal/timeseries"
|
||||
)
|
||||
|
@ -320,15 +321,20 @@ func (h *histogram) newData() *data {
|
|||
|
||||
func (h *histogram) html() template.HTML {
|
||||
buf := new(bytes.Buffer)
|
||||
if err := distTmpl.Execute(buf, h.newData()); err != nil {
|
||||
if err := distTmpl().Execute(buf, h.newData()); err != nil {
|
||||
buf.Reset()
|
||||
log.Printf("net/trace: couldn't execute template: %v", err)
|
||||
}
|
||||
return template.HTML(buf.String())
|
||||
}
|
||||
|
||||
// Input: data
|
||||
var distTmpl = template.Must(template.New("distTmpl").Parse(`
|
||||
var distTmplCache *template.Template
|
||||
var distTmplOnce sync.Once
|
||||
|
||||
func distTmpl() *template.Template {
|
||||
distTmplOnce.Do(func() {
|
||||
// Input: data
|
||||
distTmplCache = template.Must(template.New("distTmpl").Parse(`
|
||||
<table>
|
||||
<tr>
|
||||
<td style="padding:0.25em">Count: {{.Count}}</td>
|
||||
|
@ -354,3 +360,6 @@ var distTmpl = template.Must(template.New("distTmpl").Parse(`
|
|||
{{end}}
|
||||
</table>
|
||||
`))
|
||||
})
|
||||
return distTmplCache
|
||||
}
|
||||
|
|
325
vendor/golang.org/x/net/trace/histogram_test.go
generated
vendored
Normal file
325
vendor/golang.org/x/net/trace/histogram_test.go
generated
vendored
Normal file
|
@ -0,0 +1,325 @@
|
|||
// Copyright 2015 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package trace
|
||||
|
||||
import (
|
||||
"math"
|
||||
"testing"
|
||||
)
|
||||
|
||||
type sumTest struct {
|
||||
value int64
|
||||
sum int64
|
||||
sumOfSquares float64
|
||||
total int64
|
||||
}
|
||||
|
||||
var sumTests = []sumTest{
|
||||
{100, 100, 10000, 1},
|
||||
{50, 150, 12500, 2},
|
||||
{50, 200, 15000, 3},
|
||||
{50, 250, 17500, 4},
|
||||
}
|
||||
|
||||
type bucketingTest struct {
|
||||
in int64
|
||||
log int
|
||||
bucket int
|
||||
}
|
||||
|
||||
var bucketingTests = []bucketingTest{
|
||||
{0, 0, 0},
|
||||
{1, 1, 0},
|
||||
{2, 2, 1},
|
||||
{3, 2, 1},
|
||||
{4, 3, 2},
|
||||
{1000, 10, 9},
|
||||
{1023, 10, 9},
|
||||
{1024, 11, 10},
|
||||
{1000000, 20, 19},
|
||||
}
|
||||
|
||||
type multiplyTest struct {
|
||||
in int64
|
||||
ratio float64
|
||||
expectedSum int64
|
||||
expectedTotal int64
|
||||
expectedSumOfSquares float64
|
||||
}
|
||||
|
||||
var multiplyTests = []multiplyTest{
|
||||
{15, 2.5, 37, 2, 562.5},
|
||||
{128, 4.6, 758, 13, 77953.9},
|
||||
}
|
||||
|
||||
type percentileTest struct {
|
||||
fraction float64
|
||||
expected int64
|
||||
}
|
||||
|
||||
var percentileTests = []percentileTest{
|
||||
{0.25, 48},
|
||||
{0.5, 96},
|
||||
{0.6, 109},
|
||||
{0.75, 128},
|
||||
{0.90, 205},
|
||||
{0.95, 230},
|
||||
{0.99, 256},
|
||||
}
|
||||
|
||||
func TestSum(t *testing.T) {
|
||||
var h histogram
|
||||
|
||||
for _, test := range sumTests {
|
||||
h.addMeasurement(test.value)
|
||||
sum := h.sum
|
||||
if sum != test.sum {
|
||||
t.Errorf("h.Sum = %v WANT: %v", sum, test.sum)
|
||||
}
|
||||
|
||||
sumOfSquares := h.sumOfSquares
|
||||
if sumOfSquares != test.sumOfSquares {
|
||||
t.Errorf("h.SumOfSquares = %v WANT: %v", sumOfSquares, test.sumOfSquares)
|
||||
}
|
||||
|
||||
total := h.total()
|
||||
if total != test.total {
|
||||
t.Errorf("h.Total = %v WANT: %v", total, test.total)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestMultiply(t *testing.T) {
|
||||
var h histogram
|
||||
for i, test := range multiplyTests {
|
||||
h.addMeasurement(test.in)
|
||||
h.Multiply(test.ratio)
|
||||
if h.sum != test.expectedSum {
|
||||
t.Errorf("#%v: h.sum = %v WANT: %v", i, h.sum, test.expectedSum)
|
||||
}
|
||||
if h.total() != test.expectedTotal {
|
||||
t.Errorf("#%v: h.total = %v WANT: %v", i, h.total(), test.expectedTotal)
|
||||
}
|
||||
if h.sumOfSquares != test.expectedSumOfSquares {
|
||||
t.Errorf("#%v: h.SumOfSquares = %v WANT: %v", i, test.expectedSumOfSquares, h.sumOfSquares)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestBucketingFunctions(t *testing.T) {
|
||||
for _, test := range bucketingTests {
|
||||
log := log2(test.in)
|
||||
if log != test.log {
|
||||
t.Errorf("log2 = %v WANT: %v", log, test.log)
|
||||
}
|
||||
|
||||
bucket := getBucket(test.in)
|
||||
if bucket != test.bucket {
|
||||
t.Errorf("getBucket = %v WANT: %v", bucket, test.bucket)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestAverage(t *testing.T) {
|
||||
a := new(histogram)
|
||||
average := a.average()
|
||||
if average != 0 {
|
||||
t.Errorf("Average of empty histogram was %v WANT: 0", average)
|
||||
}
|
||||
|
||||
a.addMeasurement(1)
|
||||
a.addMeasurement(1)
|
||||
a.addMeasurement(3)
|
||||
const expected = float64(5) / float64(3)
|
||||
average = a.average()
|
||||
|
||||
if !isApproximate(average, expected) {
|
||||
t.Errorf("Average = %g WANT: %v", average, expected)
|
||||
}
|
||||
}
|
||||
|
||||
func TestStandardDeviation(t *testing.T) {
|
||||
a := new(histogram)
|
||||
add(a, 10, 1<<4)
|
||||
add(a, 10, 1<<5)
|
||||
add(a, 10, 1<<6)
|
||||
stdDev := a.standardDeviation()
|
||||
const expected = 19.95
|
||||
|
||||
if !isApproximate(stdDev, expected) {
|
||||
t.Errorf("StandardDeviation = %v WANT: %v", stdDev, expected)
|
||||
}
|
||||
|
||||
// No values
|
||||
a = new(histogram)
|
||||
stdDev = a.standardDeviation()
|
||||
|
||||
if !isApproximate(stdDev, 0) {
|
||||
t.Errorf("StandardDeviation = %v WANT: 0", stdDev)
|
||||
}
|
||||
|
||||
add(a, 1, 1<<4)
|
||||
if !isApproximate(stdDev, 0) {
|
||||
t.Errorf("StandardDeviation = %v WANT: 0", stdDev)
|
||||
}
|
||||
|
||||
add(a, 10, 1<<4)
|
||||
if !isApproximate(stdDev, 0) {
|
||||
t.Errorf("StandardDeviation = %v WANT: 0", stdDev)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPercentileBoundary(t *testing.T) {
|
||||
a := new(histogram)
|
||||
add(a, 5, 1<<4)
|
||||
add(a, 10, 1<<6)
|
||||
add(a, 5, 1<<7)
|
||||
|
||||
for _, test := range percentileTests {
|
||||
percentile := a.percentileBoundary(test.fraction)
|
||||
if percentile != test.expected {
|
||||
t.Errorf("h.PercentileBoundary (fraction=%v) = %v WANT: %v", test.fraction, percentile, test.expected)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestCopyFrom(t *testing.T) {
|
||||
a := histogram{5, 25, []int64{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18,
|
||||
19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38}, 4, -1}
|
||||
b := histogram{6, 36, []int64{2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
|
||||
20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39}, 5, -1}
|
||||
|
||||
a.CopyFrom(&b)
|
||||
|
||||
if a.String() != b.String() {
|
||||
t.Errorf("a.String = %s WANT: %s", a.String(), b.String())
|
||||
}
|
||||
}
|
||||
|
||||
func TestClear(t *testing.T) {
|
||||
a := histogram{5, 25, []int64{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18,
|
||||
19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38}, 4, -1}
|
||||
|
||||
a.Clear()
|
||||
|
||||
expected := "0, 0.000000, 0, 0, []"
|
||||
if a.String() != expected {
|
||||
t.Errorf("a.String = %s WANT %s", a.String(), expected)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNew(t *testing.T) {
|
||||
a := histogram{5, 25, []int64{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18,
|
||||
19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38}, 4, -1}
|
||||
b := a.New()
|
||||
|
||||
expected := "0, 0.000000, 0, 0, []"
|
||||
if b.(*histogram).String() != expected {
|
||||
t.Errorf("b.(*histogram).String = %s WANT: %s", b.(*histogram).String(), expected)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAdd(t *testing.T) {
|
||||
// The tests here depend on the associativity of addMeasurement and Add.
|
||||
// Add empty observation
|
||||
a := histogram{5, 25, []int64{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18,
|
||||
19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38}, 4, -1}
|
||||
b := a.New()
|
||||
|
||||
expected := a.String()
|
||||
a.Add(b)
|
||||
if a.String() != expected {
|
||||
t.Errorf("a.String = %s WANT: %s", a.String(), expected)
|
||||
}
|
||||
|
||||
// Add same bucketed value, no new buckets
|
||||
c := new(histogram)
|
||||
d := new(histogram)
|
||||
e := new(histogram)
|
||||
c.addMeasurement(12)
|
||||
d.addMeasurement(11)
|
||||
e.addMeasurement(12)
|
||||
e.addMeasurement(11)
|
||||
c.Add(d)
|
||||
if c.String() != e.String() {
|
||||
t.Errorf("c.String = %s WANT: %s", c.String(), e.String())
|
||||
}
|
||||
|
||||
// Add bucketed values
|
||||
f := new(histogram)
|
||||
g := new(histogram)
|
||||
h := new(histogram)
|
||||
f.addMeasurement(4)
|
||||
f.addMeasurement(12)
|
||||
f.addMeasurement(100)
|
||||
g.addMeasurement(18)
|
||||
g.addMeasurement(36)
|
||||
g.addMeasurement(255)
|
||||
h.addMeasurement(4)
|
||||
h.addMeasurement(12)
|
||||
h.addMeasurement(100)
|
||||
h.addMeasurement(18)
|
||||
h.addMeasurement(36)
|
||||
h.addMeasurement(255)
|
||||
f.Add(g)
|
||||
if f.String() != h.String() {
|
||||
t.Errorf("f.String = %q WANT: %q", f.String(), h.String())
|
||||
}
|
||||
|
||||
// add buckets to no buckets
|
||||
i := new(histogram)
|
||||
j := new(histogram)
|
||||
k := new(histogram)
|
||||
j.addMeasurement(18)
|
||||
j.addMeasurement(36)
|
||||
j.addMeasurement(255)
|
||||
k.addMeasurement(18)
|
||||
k.addMeasurement(36)
|
||||
k.addMeasurement(255)
|
||||
i.Add(j)
|
||||
if i.String() != k.String() {
|
||||
t.Errorf("i.String = %q WANT: %q", i.String(), k.String())
|
||||
}
|
||||
|
||||
// add buckets to single value (no overlap)
|
||||
l := new(histogram)
|
||||
m := new(histogram)
|
||||
n := new(histogram)
|
||||
l.addMeasurement(0)
|
||||
m.addMeasurement(18)
|
||||
m.addMeasurement(36)
|
||||
m.addMeasurement(255)
|
||||
n.addMeasurement(0)
|
||||
n.addMeasurement(18)
|
||||
n.addMeasurement(36)
|
||||
n.addMeasurement(255)
|
||||
l.Add(m)
|
||||
if l.String() != n.String() {
|
||||
t.Errorf("l.String = %q WANT: %q", l.String(), n.String())
|
||||
}
|
||||
|
||||
// mixed order
|
||||
o := new(histogram)
|
||||
p := new(histogram)
|
||||
o.addMeasurement(0)
|
||||
o.addMeasurement(2)
|
||||
o.addMeasurement(0)
|
||||
p.addMeasurement(0)
|
||||
p.addMeasurement(0)
|
||||
p.addMeasurement(2)
|
||||
if o.String() != p.String() {
|
||||
t.Errorf("o.String = %q WANT: %q", o.String(), p.String())
|
||||
}
|
||||
}
|
||||
|
||||
func add(h *histogram, times int, val int64) {
|
||||
for i := 0; i < times; i++ {
|
||||
h.addMeasurement(val)
|
||||
}
|
||||
}
|
||||
|
||||
func isApproximate(x, y float64) bool {
|
||||
return math.Abs(x-y) < 1e-2
|
||||
}
|
49
vendor/golang.org/x/net/trace/trace.go
generated
vendored
49
vendor/golang.org/x/net/trace/trace.go
generated
vendored
|
@ -91,9 +91,10 @@ var DebugUseAfterFinish = false
|
|||
// It returns two bools; the first indicates whether the page may be viewed at all,
|
||||
// and the second indicates whether sensitive events will be shown.
|
||||
//
|
||||
// AuthRequest may be replaced by a program to customise its authorisation requirements.
|
||||
// AuthRequest may be replaced by a program to customize its authorization requirements.
|
||||
//
|
||||
// The default AuthRequest function returns (true, true) iff the request comes from localhost/127.0.0.1/[::1].
|
||||
// The default AuthRequest function returns (true, true) if and only if the request
|
||||
// comes from localhost/127.0.0.1/[::1].
|
||||
var AuthRequest = func(req *http.Request) (any, sensitive bool) {
|
||||
// RemoteAddr is commonly in the form "IP" or "IP:port".
|
||||
// If it is in the form "IP:port", split off the port.
|
||||
|
@ -237,7 +238,7 @@ func Render(w io.Writer, req *http.Request, sensitive bool) {
|
|||
|
||||
completedMu.RLock()
|
||||
defer completedMu.RUnlock()
|
||||
if err := pageTmpl.ExecuteTemplate(w, "Page", data); err != nil {
|
||||
if err := pageTmpl().ExecuteTemplate(w, "Page", data); err != nil {
|
||||
log.Printf("net/trace: Failed executing template: %v", err)
|
||||
}
|
||||
}
|
||||
|
@ -332,7 +333,8 @@ func New(family, title string) Trace {
|
|||
tr.ref()
|
||||
tr.Family, tr.Title = family, title
|
||||
tr.Start = time.Now()
|
||||
tr.events = make([]event, 0, maxEventsPerTrace)
|
||||
tr.maxEvents = maxEventsPerTrace
|
||||
tr.events = tr.eventsBuf[:0]
|
||||
|
||||
activeMu.RLock()
|
||||
s := activeTraces[tr.Family]
|
||||
|
@ -649,8 +651,8 @@ type event struct {
|
|||
Elapsed time.Duration // since previous event in trace
|
||||
NewDay bool // whether this event is on a different day to the previous event
|
||||
Recyclable bool // whether this event was passed via LazyLog
|
||||
What interface{} // string or fmt.Stringer
|
||||
Sensitive bool // whether this event contains sensitive information
|
||||
What interface{} // string or fmt.Stringer
|
||||
}
|
||||
|
||||
// WhenString returns a string representation of the elapsed time of the event.
|
||||
|
@ -691,14 +693,17 @@ type trace struct {
|
|||
IsError bool
|
||||
|
||||
// Append-only sequence of events (modulo discards).
|
||||
mu sync.RWMutex
|
||||
events []event
|
||||
mu sync.RWMutex
|
||||
events []event
|
||||
maxEvents int
|
||||
|
||||
refs int32 // how many buckets this is in
|
||||
recycler func(interface{})
|
||||
disc discarded // scratch space to avoid allocation
|
||||
|
||||
finishStack []byte // where finish was called, if DebugUseAfterFinish is set
|
||||
|
||||
eventsBuf [4]event // preallocated buffer in case we only log a few events
|
||||
}
|
||||
|
||||
func (tr *trace) reset() {
|
||||
|
@ -710,11 +715,15 @@ func (tr *trace) reset() {
|
|||
tr.traceID = 0
|
||||
tr.spanID = 0
|
||||
tr.IsError = false
|
||||
tr.maxEvents = 0
|
||||
tr.events = nil
|
||||
tr.refs = 0
|
||||
tr.recycler = nil
|
||||
tr.disc = 0
|
||||
tr.finishStack = nil
|
||||
for i := range tr.eventsBuf {
|
||||
tr.eventsBuf[i] = event{}
|
||||
}
|
||||
}
|
||||
|
||||
// delta returns the elapsed time since the last event or the trace start,
|
||||
|
@ -743,7 +752,7 @@ func (tr *trace) addEvent(x interface{}, recyclable, sensitive bool) {
|
|||
and very unlikely to be the fault of this code.
|
||||
|
||||
The most likely scenario is that some code elsewhere is using
|
||||
a requestz.Trace after its Finish method is called.
|
||||
a trace.Trace after its Finish method is called.
|
||||
You can temporarily set the DebugUseAfterFinish var
|
||||
to help discover where that is; do not leave that var set,
|
||||
since it makes this package much less efficient.
|
||||
|
@ -752,11 +761,11 @@ func (tr *trace) addEvent(x interface{}, recyclable, sensitive bool) {
|
|||
e := event{When: time.Now(), What: x, Recyclable: recyclable, Sensitive: sensitive}
|
||||
tr.mu.Lock()
|
||||
e.Elapsed, e.NewDay = tr.delta(e.When)
|
||||
if len(tr.events) < cap(tr.events) {
|
||||
if len(tr.events) < tr.maxEvents {
|
||||
tr.events = append(tr.events, e)
|
||||
} else {
|
||||
// Discard the middle events.
|
||||
di := int((cap(tr.events) - 1) / 2)
|
||||
di := int((tr.maxEvents - 1) / 2)
|
||||
if d, ok := tr.events[di].What.(*discarded); ok {
|
||||
(*d)++
|
||||
} else {
|
||||
|
@ -776,7 +785,7 @@ func (tr *trace) addEvent(x interface{}, recyclable, sensitive bool) {
|
|||
go tr.recycler(tr.events[di+1].What)
|
||||
}
|
||||
copy(tr.events[di+1:], tr.events[di+2:])
|
||||
tr.events[cap(tr.events)-1] = e
|
||||
tr.events[tr.maxEvents-1] = e
|
||||
}
|
||||
tr.mu.Unlock()
|
||||
}
|
||||
|
@ -802,7 +811,7 @@ func (tr *trace) SetTraceInfo(traceID, spanID uint64) {
|
|||
func (tr *trace) SetMaxEvents(m int) {
|
||||
// Always keep at least three events: first, discarded count, last.
|
||||
if len(tr.events) == 0 && m > 3 {
|
||||
tr.events = make([]event, 0, m)
|
||||
tr.maxEvents = m
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -893,10 +902,18 @@ func elapsed(d time.Duration) string {
|
|||
return string(b)
|
||||
}
|
||||
|
||||
var pageTmpl = template.Must(template.New("Page").Funcs(template.FuncMap{
|
||||
"elapsed": elapsed,
|
||||
"add": func(a, b int) int { return a + b },
|
||||
}).Parse(pageHTML))
|
||||
var pageTmplCache *template.Template
|
||||
var pageTmplOnce sync.Once
|
||||
|
||||
func pageTmpl() *template.Template {
|
||||
pageTmplOnce.Do(func() {
|
||||
pageTmplCache = template.Must(template.New("Page").Funcs(template.FuncMap{
|
||||
"elapsed": elapsed,
|
||||
"add": func(a, b int) int { return a + b },
|
||||
}).Parse(pageHTML))
|
||||
})
|
||||
return pageTmplCache
|
||||
}
|
||||
|
||||
const pageHTML = `
|
||||
{{template "Prolog" .}}
|
||||
|
|
178
vendor/golang.org/x/net/trace/trace_test.go
generated
vendored
Normal file
178
vendor/golang.org/x/net/trace/trace_test.go
generated
vendored
Normal file
|
@ -0,0 +1,178 @@
|
|||
// Copyright 2015 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package trace
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"reflect"
|
||||
"testing"
|
||||
)
|
||||
|
||||
type s struct{}
|
||||
|
||||
func (s) String() string { return "lazy string" }
|
||||
|
||||
// TestReset checks whether all the fields are zeroed after reset.
|
||||
func TestReset(t *testing.T) {
|
||||
tr := New("foo", "bar")
|
||||
tr.LazyLog(s{}, false)
|
||||
tr.LazyPrintf("%d", 1)
|
||||
tr.SetRecycler(func(_ interface{}) {})
|
||||
tr.SetTraceInfo(3, 4)
|
||||
tr.SetMaxEvents(100)
|
||||
tr.SetError()
|
||||
tr.Finish()
|
||||
|
||||
tr.(*trace).reset()
|
||||
|
||||
if !reflect.DeepEqual(tr, new(trace)) {
|
||||
t.Errorf("reset didn't clear all fields: %+v", tr)
|
||||
}
|
||||
}
|
||||
|
||||
// TestResetLog checks whether all the fields are zeroed after reset.
|
||||
func TestResetLog(t *testing.T) {
|
||||
el := NewEventLog("foo", "bar")
|
||||
el.Printf("message")
|
||||
el.Errorf("error")
|
||||
el.Finish()
|
||||
|
||||
el.(*eventLog).reset()
|
||||
|
||||
if !reflect.DeepEqual(el, new(eventLog)) {
|
||||
t.Errorf("reset didn't clear all fields: %+v", el)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAuthRequest(t *testing.T) {
|
||||
testCases := []struct {
|
||||
host string
|
||||
want bool
|
||||
}{
|
||||
{host: "192.168.23.1", want: false},
|
||||
{host: "192.168.23.1:8080", want: false},
|
||||
{host: "malformed remote addr", want: false},
|
||||
{host: "localhost", want: true},
|
||||
{host: "localhost:8080", want: true},
|
||||
{host: "127.0.0.1", want: true},
|
||||
{host: "127.0.0.1:8080", want: true},
|
||||
{host: "::1", want: true},
|
||||
{host: "[::1]:8080", want: true},
|
||||
}
|
||||
for _, tt := range testCases {
|
||||
req := &http.Request{RemoteAddr: tt.host}
|
||||
any, sensitive := AuthRequest(req)
|
||||
if any != tt.want || sensitive != tt.want {
|
||||
t.Errorf("AuthRequest(%q) = %t, %t; want %t, %t", tt.host, any, sensitive, tt.want, tt.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TestParseTemplate checks that all templates used by this package are valid
|
||||
// as they are parsed on first usage
|
||||
func TestParseTemplate(t *testing.T) {
|
||||
if tmpl := distTmpl(); tmpl == nil {
|
||||
t.Error("invalid template returned from distTmpl()")
|
||||
}
|
||||
if tmpl := pageTmpl(); tmpl == nil {
|
||||
t.Error("invalid template returned from pageTmpl()")
|
||||
}
|
||||
if tmpl := eventsTmpl(); tmpl == nil {
|
||||
t.Error("invalid template returned from eventsTmpl()")
|
||||
}
|
||||
}
|
||||
|
||||
func benchmarkTrace(b *testing.B, maxEvents, numEvents int) {
|
||||
numSpans := (b.N + numEvents + 1) / numEvents
|
||||
|
||||
for i := 0; i < numSpans; i++ {
|
||||
tr := New("test", "test")
|
||||
tr.SetMaxEvents(maxEvents)
|
||||
for j := 0; j < numEvents; j++ {
|
||||
tr.LazyPrintf("%d", j)
|
||||
}
|
||||
tr.Finish()
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkTrace_Default_2(b *testing.B) {
|
||||
benchmarkTrace(b, 0, 2)
|
||||
}
|
||||
|
||||
func BenchmarkTrace_Default_10(b *testing.B) {
|
||||
benchmarkTrace(b, 0, 10)
|
||||
}
|
||||
|
||||
func BenchmarkTrace_Default_100(b *testing.B) {
|
||||
benchmarkTrace(b, 0, 100)
|
||||
}
|
||||
|
||||
func BenchmarkTrace_Default_1000(b *testing.B) {
|
||||
benchmarkTrace(b, 0, 1000)
|
||||
}
|
||||
|
||||
func BenchmarkTrace_Default_10000(b *testing.B) {
|
||||
benchmarkTrace(b, 0, 10000)
|
||||
}
|
||||
|
||||
func BenchmarkTrace_10_2(b *testing.B) {
|
||||
benchmarkTrace(b, 10, 2)
|
||||
}
|
||||
|
||||
func BenchmarkTrace_10_10(b *testing.B) {
|
||||
benchmarkTrace(b, 10, 10)
|
||||
}
|
||||
|
||||
func BenchmarkTrace_10_100(b *testing.B) {
|
||||
benchmarkTrace(b, 10, 100)
|
||||
}
|
||||
|
||||
func BenchmarkTrace_10_1000(b *testing.B) {
|
||||
benchmarkTrace(b, 10, 1000)
|
||||
}
|
||||
|
||||
func BenchmarkTrace_10_10000(b *testing.B) {
|
||||
benchmarkTrace(b, 10, 10000)
|
||||
}
|
||||
|
||||
func BenchmarkTrace_100_2(b *testing.B) {
|
||||
benchmarkTrace(b, 100, 2)
|
||||
}
|
||||
|
||||
func BenchmarkTrace_100_10(b *testing.B) {
|
||||
benchmarkTrace(b, 100, 10)
|
||||
}
|
||||
|
||||
func BenchmarkTrace_100_100(b *testing.B) {
|
||||
benchmarkTrace(b, 100, 100)
|
||||
}
|
||||
|
||||
func BenchmarkTrace_100_1000(b *testing.B) {
|
||||
benchmarkTrace(b, 100, 1000)
|
||||
}
|
||||
|
||||
func BenchmarkTrace_100_10000(b *testing.B) {
|
||||
benchmarkTrace(b, 100, 10000)
|
||||
}
|
||||
|
||||
func BenchmarkTrace_1000_2(b *testing.B) {
|
||||
benchmarkTrace(b, 1000, 2)
|
||||
}
|
||||
|
||||
func BenchmarkTrace_1000_10(b *testing.B) {
|
||||
benchmarkTrace(b, 1000, 10)
|
||||
}
|
||||
|
||||
func BenchmarkTrace_1000_100(b *testing.B) {
|
||||
benchmarkTrace(b, 1000, 100)
|
||||
}
|
||||
|
||||
func BenchmarkTrace_1000_1000(b *testing.B) {
|
||||
benchmarkTrace(b, 1000, 1000)
|
||||
}
|
||||
|
||||
func BenchmarkTrace_1000_10000(b *testing.B) {
|
||||
benchmarkTrace(b, 1000, 10000)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue