| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package tsmon | 5 package tsmon |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "net/http" | 8 "net/http" |
| 9 "net/http/httptest" | 9 "net/http/httptest" |
| 10 "testing" | 10 "testing" |
| 11 "time" | 11 "time" |
| 12 | 12 |
| 13 "github.com/golang/protobuf/proto" | |
| 14 "github.com/julienschmidt/httprouter" | 13 "github.com/julienschmidt/httprouter" |
| 15 "github.com/luci/gae/service/datastore" | 14 "github.com/luci/gae/service/datastore" |
| 16 "github.com/luci/luci-go/common/tsmon" | 15 "github.com/luci/luci-go/common/tsmon" |
| 17 "github.com/luci/luci-go/common/tsmon/field" | 16 "github.com/luci/luci-go/common/tsmon/field" |
| 18 "github.com/luci/luci-go/common/tsmon/monitor" | 17 "github.com/luci/luci-go/common/tsmon/monitor" |
| 19 "github.com/luci/luci-go/common/tsmon/store" | 18 "github.com/luci/luci-go/common/tsmon/store" |
| 20 "github.com/luci/luci-go/common/tsmon/target" | 19 "github.com/luci/luci-go/common/tsmon/target" |
| 21 "github.com/luci/luci-go/common/tsmon/types" | 20 "github.com/luci/luci-go/common/tsmon/types" |
| 22 "golang.org/x/net/context" | 21 "golang.org/x/net/context" |
| 23 | 22 |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 | 97 |
| 99 lastFlushed.Time = clock.Now().Add(-2 * time.Minute) | 98 lastFlushed.Time = clock.Now().Add(-2 * time.Minute) |
| 100 | 99 |
| 101 rec := httptest.NewRecorder() | 100 rec := httptest.NewRecorder() |
| 102 Middleware(func(c context.Context, rw http.ResponseWriter, r *ht
tp.Request, p httprouter.Params) { | 101 Middleware(func(c context.Context, rw http.ResponseWriter, r *ht
tp.Request, p httprouter.Params) { |
| 103 f(c, rw, r, p) | 102 f(c, rw, r, p) |
| 104 | 103 |
| 105 // Override the TaskNum here - it's created just before
this handler runs | 104 // Override the TaskNum here - it's created just before
this handler runs |
| 106 // and used just after. | 105 // and used just after. |
| 107 tar := tsmon.Store(c).DefaultTarget().(*target.Task) | 106 tar := tsmon.Store(c).DefaultTarget().(*target.Task) |
| 108 » » » tar.TaskNum = proto.Int32(int32(0)) | 107 » » » tar.TaskNum = 0 |
| 109 tsmon.Store(c).SetDefaultTarget(tar) | 108 tsmon.Store(c).SetDefaultTarget(tar) |
| 110 })(c, rec, &http.Request{}, nil) | 109 })(c, rec, &http.Request{}, nil) |
| 111 So(rec.Code, ShouldEqual, http.StatusOK) | 110 So(rec.Code, ShouldEqual, http.StatusOK) |
| 112 | 111 |
| 113 So(len(tsmon.GetState(c).RegisteredMetrics), ShouldEqual, 1) | 112 So(len(tsmon.GetState(c).RegisteredMetrics), ShouldEqual, 1) |
| 114 | 113 |
| 115 monitor := tsmon.GetState(c).M.(*monitor.Fake) | 114 monitor := tsmon.GetState(c).M.(*monitor.Fake) |
| 116 So(len(monitor.Cells), ShouldEqual, 0) | 115 So(len(monitor.Cells), ShouldEqual, 0) |
| 117 | 116 |
| 118 // Value should be reset. | 117 // Value should be reset. |
| 119 value, err := tsmon.Store(c).Get(c, metric, time.Time{}, []inter
face{}{}) | 118 value, err := tsmon.Store(c).Get(c, metric, time.Time{}, []inter
face{}{}) |
| 120 So(err, ShouldBeNil) | 119 So(err, ShouldBeNil) |
| 121 So(value, ShouldBeNil) | 120 So(value, ShouldBeNil) |
| 122 }) | 121 }) |
| 123 } | 122 } |
| OLD | NEW |