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

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

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