| 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 "sync" | 8 "sync" |
| 9 | 9 |
| 10 "github.com/golang/protobuf/proto" |
| 10 "golang.org/x/net/context" | 11 "golang.org/x/net/context" |
| 11 | 12 |
| 12 "github.com/luci/luci-go/common/tsmon/monitor" | 13 "github.com/luci/luci-go/common/tsmon/monitor" |
| 13 "github.com/luci/luci-go/common/tsmon/store" | 14 "github.com/luci/luci-go/common/tsmon/store" |
| 14 "github.com/luci/luci-go/common/tsmon/target" | 15 "github.com/luci/luci-go/common/tsmon/target" |
| 15 "github.com/luci/luci-go/common/tsmon/types" | 16 "github.com/luci/luci-go/common/tsmon/types" |
| 16 ) | 17 ) |
| 17 | 18 |
| 18 // State holds the configuration of the tsmon library. There is one global | 19 // State holds the configuration of the tsmon library. There is one global |
| 19 // instance of State, but it can be overridden in a Context by tests. | 20 // instance of State, but it can be overridden in a Context by tests. |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 return WithState(c, &State{ | 60 return WithState(c, &State{ |
| 60 S: s, | 61 S: s, |
| 61 M: m, | 62 M: m, |
| 62 RegisteredMetrics: map[string]types.Metric{}, | 63 RegisteredMetrics: map[string]types.Metric{}, |
| 63 }), s, m | 64 }), s, m |
| 64 } | 65 } |
| 65 | 66 |
| 66 // WithDummyInMemory returns a new context holding a new State with a new in- | 67 // WithDummyInMemory returns a new context holding a new State with a new in- |
| 67 // memory store and a fake monitor. | 68 // memory store and a fake monitor. |
| 68 func WithDummyInMemory(c context.Context) (context.Context, *monitor.Fake) { | 69 func WithDummyInMemory(c context.Context) (context.Context, *monitor.Fake) { |
| 69 » s := store.NewInMemory(&target.Task{}) | 70 » s := store.NewInMemory(&target.Task{ServiceName: proto.String("")}) |
| 70 m := &monitor.Fake{} | 71 m := &monitor.Fake{} |
| 71 return WithState(c, &State{ | 72 return WithState(c, &State{ |
| 72 S: s, | 73 S: s, |
| 73 M: m, | 74 M: m, |
| 74 RegisteredMetrics: map[string]types.Metric{}, | 75 RegisteredMetrics: map[string]types.Metric{}, |
| 75 }), m | 76 }), m |
| 76 } | 77 } |
| 77 | 78 |
| 78 type key int | 79 type key int |
| 79 | 80 |
| 80 var ( | 81 var ( |
| 81 globalState = &State{ | 82 globalState = &State{ |
| 82 S: store.NewNilStore(), | 83 S: store.NewNilStore(), |
| 83 M: monitor.NewNilMonitor(), | 84 M: monitor.NewNilMonitor(), |
| 84 RegisteredMetrics: map[string]types.Metric{}, | 85 RegisteredMetrics: map[string]types.Metric{}, |
| 85 } | 86 } |
| 86 stateKey key = 1 | 87 stateKey key = 1 |
| 87 ) | 88 ) |
| OLD | NEW |