Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(45)

Side by Side Diff: common/tsmon/monitor/acq_test.go

Issue 1857643003: Revert of Migrate tsmon protos to proto3 (Closed) Base URL: git@github.com:luci/luci-go.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « common/tsmon/monitor/acq.go ('k') | common/tsmon/store/inmemory_test.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 monitor 5 package monitor
6 6
7 import ( 7 import (
8 "fmt" 8 "fmt"
9 "math" 9 "math"
10 "testing" 10 "testing"
11 "time" 11 "time"
12 12
13 "github.com/golang/protobuf/proto"
13 "github.com/luci/luci-go/common/tsmon/distribution" 14 "github.com/luci/luci-go/common/tsmon/distribution"
14 "github.com/luci/luci-go/common/tsmon/field" 15 "github.com/luci/luci-go/common/tsmon/field"
15 "github.com/luci/luci-go/common/tsmon/target" 16 "github.com/luci/luci-go/common/tsmon/target"
16 "github.com/luci/luci-go/common/tsmon/types" 17 "github.com/luci/luci-go/common/tsmon/types"
17 18
18 pb "github.com/luci/luci-go/common/tsmon/ts_mon_proto" 19 pb "github.com/luci/luci-go/common/tsmon/ts_mon_proto"
19 . "github.com/smartystreets/goconvey/convey" 20 . "github.com/smartystreets/goconvey/convey"
20 ) 21 )
21 22
22 func TestRunningZeroes(t *testing.T) { 23 func TestRunningZeroes(t *testing.T) {
(...skipping 29 matching lines...) Expand all
52 }) 53 })
53 } 54 }
54 } 55 }
55 56
56 func TestSerializeDistribution(t *testing.T) { 57 func TestSerializeDistribution(t *testing.T) {
57 Convey("Fixed width params", t, func() { 58 Convey("Fixed width params", t, func() {
58 d := distribution.New(distribution.FixedWidthBucketer(10, 20)) 59 d := distribution.New(distribution.FixedWidthBucketer(10, 20))
59 dpb := serializeDistribution(d) 60 dpb := serializeDistribution(d)
60 61
61 So(*dpb, ShouldResemble, pb.PrecomputedDistribution{ 62 So(*dpb, ShouldResemble, pb.PrecomputedDistribution{
62 » » » SpecType: pb.PrecomputedDistribution_CUSTOM_PARAMETE RIZED, 63 » » » SpecType: pb.PrecomputedDistribution_CUSTOM_PARAMETE RIZED.Enum(),
63 » » » Width: 10, 64 » » » Width: proto.Float64(10),
64 » » » GrowthFactor: 0, 65 » » » GrowthFactor: proto.Float64(0),
65 » » » NumBuckets: 20, 66 » » » NumBuckets: proto.Int32(20),
66 }) 67 })
67 }) 68 })
68 69
69 Convey("Growth factor 2 params", t, func() { 70 Convey("Growth factor 2 params", t, func() {
70 d := distribution.New(distribution.GeometricBucketer(2, 20)) 71 d := distribution.New(distribution.GeometricBucketer(2, 20))
71 dpb := serializeDistribution(d) 72 dpb := serializeDistribution(d)
72 73
73 So(*dpb, ShouldResemble, pb.PrecomputedDistribution{ 74 So(*dpb, ShouldResemble, pb.PrecomputedDistribution{
74 » » » SpecType: pb.PrecomputedDistribution_CANONICAL_POWERS_OF _2, 75 » » » SpecType: pb.PrecomputedDistribution_CANONICAL_POWERS_OF _2.Enum(),
75 }) 76 })
76 }) 77 })
77 78
78 Convey("Growth factor 10^0.2 params", t, func() { 79 Convey("Growth factor 10^0.2 params", t, func() {
79 d := distribution.New(distribution.GeometricBucketer(math.Pow(10 , 0.2), 20)) 80 d := distribution.New(distribution.GeometricBucketer(math.Pow(10 , 0.2), 20))
80 dpb := serializeDistribution(d) 81 dpb := serializeDistribution(d)
81 82
82 So(*dpb, ShouldResemble, pb.PrecomputedDistribution{ 83 So(*dpb, ShouldResemble, pb.PrecomputedDistribution{
83 » » » SpecType: pb.PrecomputedDistribution_CANONICAL_POWERS_OF _10_P_0_2, 84 » » » SpecType: pb.PrecomputedDistribution_CANONICAL_POWERS_OF _10_P_0_2.Enum(),
84 }) 85 })
85 }) 86 })
86 87
87 Convey("Growth factor 10 params", t, func() { 88 Convey("Growth factor 10 params", t, func() {
88 d := distribution.New(distribution.GeometricBucketer(10, 20)) 89 d := distribution.New(distribution.GeometricBucketer(10, 20))
89 dpb := serializeDistribution(d) 90 dpb := serializeDistribution(d)
90 91
91 So(*dpb, ShouldResemble, pb.PrecomputedDistribution{ 92 So(*dpb, ShouldResemble, pb.PrecomputedDistribution{
92 » » » SpecType: pb.PrecomputedDistribution_CANONICAL_POWERS_OF _10, 93 » » » SpecType: pb.PrecomputedDistribution_CANONICAL_POWERS_OF _10.Enum(),
93 }) 94 })
94 }) 95 })
95 96
96 Convey("Custom geometric params", t, func() { 97 Convey("Custom geometric params", t, func() {
97 d := distribution.New(distribution.GeometricBucketer(4, 20)) 98 d := distribution.New(distribution.GeometricBucketer(4, 20))
98 dpb := serializeDistribution(d) 99 dpb := serializeDistribution(d)
99 100
100 So(*dpb, ShouldResemble, pb.PrecomputedDistribution{ 101 So(*dpb, ShouldResemble, pb.PrecomputedDistribution{
101 » » » SpecType: pb.PrecomputedDistribution_CUSTOM_PARAMETE RIZED, 102 » » » SpecType: pb.PrecomputedDistribution_CUSTOM_PARAMETE RIZED.Enum(),
102 » » » Width: 0, 103 » » » Width: proto.Float64(0),
103 » » » GrowthFactor: 4, 104 » » » GrowthFactor: proto.Float64(4),
104 » » » NumBuckets: 20, 105 » » » NumBuckets: proto.Int32(20),
105 }) 106 })
106 }) 107 })
107 108
108 Convey("Populates buckets", t, func() { 109 Convey("Populates buckets", t, func() {
109 d := distribution.New(distribution.FixedWidthBucketer(10, 2)) 110 d := distribution.New(distribution.FixedWidthBucketer(10, 2))
110 d.Add(0) 111 d.Add(0)
111 d.Add(1) 112 d.Add(1)
112 d.Add(2) 113 d.Add(2)
113 d.Add(20) 114 d.Add(20)
114 115
115 dpb := serializeDistribution(d) 116 dpb := serializeDistribution(d)
116 So(*dpb, ShouldResemble, pb.PrecomputedDistribution{ 117 So(*dpb, ShouldResemble, pb.PrecomputedDistribution{
117 » » » SpecType: pb.PrecomputedDistribution_CUSTOM_PARAMETE RIZED, 118 » » » SpecType: pb.PrecomputedDistribution_CUSTOM_PARAMETE RIZED.Enum(),
118 » » » Width: 10, 119 » » » Width: proto.Float64(10),
119 » » » GrowthFactor: 0, 120 » » » GrowthFactor: proto.Float64(0),
120 » » » NumBuckets: 2, 121 » » » NumBuckets: proto.Int32(2),
121 122
122 Bucket: []int64{3}, 123 Bucket: []int64{3},
123 » » » Underflow: 0, 124 » » » Underflow: proto.Int64(0),
124 » » » Overflow: 1, 125 » » » Overflow: proto.Int64(1),
125 » » » Mean: 5.75, 126 » » » Mean: proto.Float64(5.75),
126 }) 127 })
127 }) 128 })
128 } 129 }
129 130
130 func TestSerializeCell(t *testing.T) { 131 func TestSerializeCell(t *testing.T) {
131 Convey("Int", t, func() { 132 Convey("Int", t, func() {
132 ret := SerializeCell(types.Cell{ 133 ret := SerializeCell(types.Cell{
133 types.MetricInfo{ 134 types.MetricInfo{
134 Name: "foo", 135 Name: "foo",
135 Description: "bar", 136 Description: "bar",
136 Fields: []field.Field{}, 137 Fields: []field.Field{},
137 ValueType: types.NonCumulativeIntType, 138 ValueType: types.NonCumulativeIntType,
138 }, 139 },
139 types.CellData{ 140 types.CellData{
140 FieldVals: []interface{}{}, 141 FieldVals: []interface{}{},
141 Target: &target.Task{}, 142 Target: &target.Task{},
142 ResetTime: time.Date(2000, 1, 2, 3, 4, 5, 6, tim e.UTC), 143 ResetTime: time.Date(2000, 1, 2, 3, 4, 5, 6, tim e.UTC),
143 Value: int64(42), 144 Value: int64(42),
144 }, 145 },
145 }) 146 })
146 So(ret, ShouldResemble, &pb.MetricsData{ 147 So(ret, ShouldResemble, &pb.MetricsData{
147 » » » Name: "foo", 148 » » » Name: proto.String("foo"),
148 » » » Description: "bar", 149 » » » Description: proto.String("bar"),
149 » » » MetricNamePrefix: "/chrome/infra/", 150 » » » MetricNamePrefix: proto.String("/chrome/infra/"),
150 Fields: []*pb.MetricsField{}, 151 Fields: []*pb.MetricsField{},
151 » » » StartTimestampUs: 946782245000000, 152 » » » StartTimestampUs: proto.Uint64(946782245000000),
152 Task: &pb.Task{}, 153 Task: &pb.Task{},
153 » » » Gauge: 42, 154 » » » Gauge: proto.Int64(42),
154 }) 155 })
155 }) 156 })
156 157
157 Convey("Counter", t, func() { 158 Convey("Counter", t, func() {
158 ret := SerializeCell(types.Cell{ 159 ret := SerializeCell(types.Cell{
159 types.MetricInfo{ 160 types.MetricInfo{
160 Name: "foo", 161 Name: "foo",
161 Description: "bar", 162 Description: "bar",
162 Fields: []field.Field{}, 163 Fields: []field.Field{},
163 ValueType: types.CumulativeIntType, 164 ValueType: types.CumulativeIntType,
164 }, 165 },
165 types.CellData{ 166 types.CellData{
166 FieldVals: []interface{}{}, 167 FieldVals: []interface{}{},
167 Target: &target.Task{}, 168 Target: &target.Task{},
168 ResetTime: time.Date(2000, 1, 2, 3, 4, 5, 6, tim e.UTC), 169 ResetTime: time.Date(2000, 1, 2, 3, 4, 5, 6, tim e.UTC),
169 Value: int64(42), 170 Value: int64(42),
170 }, 171 },
171 }) 172 })
172 So(ret, ShouldResemble, &pb.MetricsData{ 173 So(ret, ShouldResemble, &pb.MetricsData{
173 » » » Name: "foo", 174 » » » Name: proto.String("foo"),
174 » » » Description: "bar", 175 » » » Description: proto.String("bar"),
175 » » » MetricNamePrefix: "/chrome/infra/", 176 » » » MetricNamePrefix: proto.String("/chrome/infra/"),
176 Fields: []*pb.MetricsField{}, 177 Fields: []*pb.MetricsField{},
177 » » » StartTimestampUs: 946782245000000, 178 » » » StartTimestampUs: proto.Uint64(946782245000000),
178 Task: &pb.Task{}, 179 Task: &pb.Task{},
179 » » » Counter: 42, 180 » » » Counter: proto.Int64(42),
180 }) 181 })
181 }) 182 })
182 183
183 Convey("Float", t, func() { 184 Convey("Float", t, func() {
184 ret := SerializeCell(types.Cell{ 185 ret := SerializeCell(types.Cell{
185 types.MetricInfo{ 186 types.MetricInfo{
186 Name: "foo", 187 Name: "foo",
187 Description: "bar", 188 Description: "bar",
188 Fields: []field.Field{}, 189 Fields: []field.Field{},
189 ValueType: types.NonCumulativeFloatType, 190 ValueType: types.NonCumulativeFloatType,
190 }, 191 },
191 types.CellData{ 192 types.CellData{
192 FieldVals: []interface{}{}, 193 FieldVals: []interface{}{},
193 Target: &target.Task{}, 194 Target: &target.Task{},
194 ResetTime: time.Date(2000, 1, 2, 3, 4, 5, 6, tim e.UTC), 195 ResetTime: time.Date(2000, 1, 2, 3, 4, 5, 6, tim e.UTC),
195 Value: float64(42), 196 Value: float64(42),
196 }, 197 },
197 }) 198 })
198 So(ret, ShouldResemble, &pb.MetricsData{ 199 So(ret, ShouldResemble, &pb.MetricsData{
199 » » » Name: "foo", 200 » » » Name: proto.String("foo"),
200 » » » Description: "bar", 201 » » » Description: proto.String("bar"),
201 » » » MetricNamePrefix: "/chrome/infra/", 202 » » » MetricNamePrefix: proto.String("/chrome/infra/"),
202 Fields: []*pb.MetricsField{}, 203 Fields: []*pb.MetricsField{},
203 » » » StartTimestampUs: 946782245000000, 204 » » » StartTimestampUs: proto.Uint64(946782245000000),
204 Task: &pb.Task{}, 205 Task: &pb.Task{},
205 » » » NoncumulativeDoubleValue: 42, 206 » » » NoncumulativeDoubleValue: proto.Float64(42),
206 }) 207 })
207 }) 208 })
208 209
209 Convey("FloatCounter", t, func() { 210 Convey("FloatCounter", t, func() {
210 ret := SerializeCell(types.Cell{ 211 ret := SerializeCell(types.Cell{
211 types.MetricInfo{ 212 types.MetricInfo{
212 Name: "foo", 213 Name: "foo",
213 Description: "bar", 214 Description: "bar",
214 Fields: []field.Field{}, 215 Fields: []field.Field{},
215 ValueType: types.CumulativeFloatType, 216 ValueType: types.CumulativeFloatType,
216 }, 217 },
217 types.CellData{ 218 types.CellData{
218 FieldVals: []interface{}{}, 219 FieldVals: []interface{}{},
219 Target: &target.Task{}, 220 Target: &target.Task{},
220 ResetTime: time.Date(2000, 1, 2, 3, 4, 5, 6, tim e.UTC), 221 ResetTime: time.Date(2000, 1, 2, 3, 4, 5, 6, tim e.UTC),
221 Value: float64(42), 222 Value: float64(42),
222 }, 223 },
223 }) 224 })
224 So(ret, ShouldResemble, &pb.MetricsData{ 225 So(ret, ShouldResemble, &pb.MetricsData{
225 » » » Name: "foo", 226 » » » Name: proto.String("foo"),
226 » » » Description: "bar", 227 » » » Description: proto.String("bar"),
227 » » » MetricNamePrefix: "/chrome/infra/", 228 » » » MetricNamePrefix: proto.String("/chrome/infra/"),
228 Fields: []*pb.MetricsField{}, 229 Fields: []*pb.MetricsField{},
229 » » » StartTimestampUs: 946782245000000, 230 » » » StartTimestampUs: proto.Uint64(946782245000000),
230 Task: &pb.Task{}, 231 Task: &pb.Task{},
231 » » » CumulativeDoubleValue: 42, 232 » » » CumulativeDoubleValue: proto.Float64(42),
232 }) 233 })
233 }) 234 })
234 235
235 Convey("String", t, func() { 236 Convey("String", t, func() {
236 ret := SerializeCell(types.Cell{ 237 ret := SerializeCell(types.Cell{
237 types.MetricInfo{ 238 types.MetricInfo{
238 Name: "foo", 239 Name: "foo",
239 Description: "bar", 240 Description: "bar",
240 Fields: []field.Field{}, 241 Fields: []field.Field{},
241 ValueType: types.StringType, 242 ValueType: types.StringType,
242 }, 243 },
243 types.CellData{ 244 types.CellData{
244 FieldVals: []interface{}{}, 245 FieldVals: []interface{}{},
245 Target: &target.Task{}, 246 Target: &target.Task{},
246 ResetTime: time.Date(2000, 1, 2, 3, 4, 5, 6, tim e.UTC), 247 ResetTime: time.Date(2000, 1, 2, 3, 4, 5, 6, tim e.UTC),
247 Value: "hello", 248 Value: "hello",
248 }, 249 },
249 }) 250 })
250 So(ret, ShouldResemble, &pb.MetricsData{ 251 So(ret, ShouldResemble, &pb.MetricsData{
251 » » » Name: "foo", 252 » » » Name: proto.String("foo"),
252 » » » Description: "bar", 253 » » » Description: proto.String("bar"),
253 » » » MetricNamePrefix: "/chrome/infra/", 254 » » » MetricNamePrefix: proto.String("/chrome/infra/"),
254 Fields: []*pb.MetricsField{}, 255 Fields: []*pb.MetricsField{},
255 » » » StartTimestampUs: 946782245000000, 256 » » » StartTimestampUs: proto.Uint64(946782245000000),
256 Task: &pb.Task{}, 257 Task: &pb.Task{},
257 » » » StringValue: "hello", 258 » » » StringValue: proto.String("hello"),
258 }) 259 })
259 }) 260 })
260 261
261 Convey("Boolean", t, func() { 262 Convey("Boolean", t, func() {
262 ret := SerializeCell(types.Cell{ 263 ret := SerializeCell(types.Cell{
263 types.MetricInfo{ 264 types.MetricInfo{
264 Name: "foo", 265 Name: "foo",
265 Description: "bar", 266 Description: "bar",
266 Fields: []field.Field{}, 267 Fields: []field.Field{},
267 ValueType: types.BoolType, 268 ValueType: types.BoolType,
268 }, 269 },
269 types.CellData{ 270 types.CellData{
270 FieldVals: []interface{}{}, 271 FieldVals: []interface{}{},
271 Target: &target.Task{}, 272 Target: &target.Task{},
272 ResetTime: time.Date(2000, 1, 2, 3, 4, 5, 6, tim e.UTC), 273 ResetTime: time.Date(2000, 1, 2, 3, 4, 5, 6, tim e.UTC),
273 Value: true, 274 Value: true,
274 }, 275 },
275 }) 276 })
276 So(ret, ShouldResemble, &pb.MetricsData{ 277 So(ret, ShouldResemble, &pb.MetricsData{
277 » » » Name: "foo", 278 » » » Name: proto.String("foo"),
278 » » » Description: "bar", 279 » » » Description: proto.String("bar"),
279 » » » MetricNamePrefix: "/chrome/infra/", 280 » » » MetricNamePrefix: proto.String("/chrome/infra/"),
280 Fields: []*pb.MetricsField{}, 281 Fields: []*pb.MetricsField{},
281 » » » StartTimestampUs: 946782245000000, 282 » » » StartTimestampUs: proto.Uint64(946782245000000),
282 Task: &pb.Task{}, 283 Task: &pb.Task{},
283 » » » BooleanValue: true, 284 » » » BooleanValue: proto.Bool(true),
284 }) 285 })
285 }) 286 })
286 287
287 Convey("NonDefaultTarget", t, func() { 288 Convey("NonDefaultTarget", t, func() {
288 target := target.Task{ 289 target := target.Task{
289 » » » ServiceName: "hello", 290 » » » ServiceName: proto.String("hello"),
290 » » » JobName: "world", 291 » » » JobName: proto.String("world"),
291 } 292 }
292 293
293 ret := SerializeCell(types.Cell{ 294 ret := SerializeCell(types.Cell{
294 types.MetricInfo{ 295 types.MetricInfo{
295 Name: "foo", 296 Name: "foo",
296 Description: "bar", 297 Description: "bar",
297 Fields: []field.Field{}, 298 Fields: []field.Field{},
298 ValueType: types.NonCumulativeIntType, 299 ValueType: types.NonCumulativeIntType,
299 }, 300 },
300 types.CellData{ 301 types.CellData{
301 FieldVals: []interface{}{}, 302 FieldVals: []interface{}{},
302 Target: &target, 303 Target: &target,
303 ResetTime: time.Date(2000, 1, 2, 3, 4, 5, 6, tim e.UTC), 304 ResetTime: time.Date(2000, 1, 2, 3, 4, 5, 6, tim e.UTC),
304 Value: int64(42), 305 Value: int64(42),
305 }, 306 },
306 }) 307 })
307 So(ret, ShouldResemble, &pb.MetricsData{ 308 So(ret, ShouldResemble, &pb.MetricsData{
308 » » » Name: "foo", 309 » » » Name: proto.String("foo"),
309 » » » Description: "bar", 310 » » » Description: proto.String("bar"),
310 » » » MetricNamePrefix: "/chrome/infra/", 311 » » » MetricNamePrefix: proto.String("/chrome/infra/"),
311 Fields: []*pb.MetricsField{}, 312 Fields: []*pb.MetricsField{},
312 » » » StartTimestampUs: 946782245000000, 313 » » » StartTimestampUs: proto.Uint64(946782245000000),
313 Task: &pb.Task{ 314 Task: &pb.Task{
314 » » » » ServiceName: "hello", 315 » » » » ServiceName: proto.String("hello"),
315 » » » » JobName: "world", 316 » » » » JobName: proto.String("world"),
316 }, 317 },
317 » » » Gauge: 42, 318 » » » Gauge: proto.Int64(42),
318 }) 319 })
319 }) 320 })
320 } 321 }
OLDNEW
« no previous file with comments | « common/tsmon/monitor/acq.go ('k') | common/tsmon/store/inmemory_test.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698