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

Side by Side Diff: common/tsmon/types/metricdataunits.go

Issue 2123853002: Added unit annotation supports onto tsmon in go. (Closed) Base URL: https://chromium.googlesource.com/external/github.com/luci/luci-go@master
Patch Set: Specify the unit of logdog/collector/subscription/processing_time_ms with types.Milliseconds Created 4 years, 5 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/types/metric.go ('k') | server/cmd/logdog_archivist/main.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2016 The LUCI Authors. All rights reserved.
2 // Use of this source code is governed under the Apache License, Version 2.0
3 // that can be found in the LICENSE file.
4
5 package types
6
7 import (
8 "fmt"
9
10 pb "github.com/luci/luci-go/common/tsmon/ts_mon_proto"
11 )
12
13 // MetricDataUnits are enums for the units of metrics data.
14 type MetricDataUnits int32
15
16 // Units of metrics data.
17 const (
18 // NotSpecified is a magic value to skip Units property
19 // in a MetricsData proto message.
20 // Note that this should be defined with 0 so that all the existing
21 // codes without units specified would be given NotSpecified
22 // for the Units property automatically.
23 NotSpecified MetricDataUnits = iota
24 Unknown
25 Seconds
26 Milliseconds
27 Microseconds
28 Nanoseconds
29 Bits
30 Bytes
31
32 Kilobytes // 1000 bytes (not 1024).
33 Megabytes // 1e6 (1,000,000) bytes.
34 Gigabytes // 1e9 (1,000,000,000) bytes.
35 Kibibytes // 1024 bytes.
36 Mebibytes // 1024^2 (1,048,576) bytes.
37 Gibibytes // 1024^3 (1,073,741,824) bytes.
38
39 // * Extended Units
40 AmpUnit
41 MilliampUnit
42 DegreeCelsiusUnit
43 )
44
45 // IsSpecified returns true if a unit annotation has been specified
46 // for a given metric.
47 func (units MetricDataUnits) IsSpecified() bool {
48 return units != NotSpecified
49 }
50
51 // AsProto returns the protobuf representation of a given MetricDataUnits
52 // object.
53 func (units MetricDataUnits) AsProto() *pb.MetricsData_Units {
54 switch units {
55 case Unknown:
56 return pb.MetricsData_UNKNOWN_UNITS.Enum()
57 case Seconds:
58 return pb.MetricsData_SECONDS.Enum()
59 case Milliseconds:
60 return pb.MetricsData_MILLISECONDS.Enum()
61 case Microseconds:
62 return pb.MetricsData_MICROSECONDS.Enum()
63 case Nanoseconds:
64 return pb.MetricsData_NANOSECONDS.Enum()
65 case Bits:
66 return pb.MetricsData_BITS.Enum()
67 case Bytes:
68 return pb.MetricsData_BYTES.Enum()
69 case Kilobytes:
70 return pb.MetricsData_KILOBYTES.Enum()
71 case Megabytes:
72 return pb.MetricsData_MEGABYTES.Enum()
73 case Gigabytes:
74 return pb.MetricsData_GIGABYTES.Enum()
75 case Kibibytes:
76 return pb.MetricsData_KIBIBYTES.Enum()
77 case Mebibytes:
78 return pb.MetricsData_MEBIBYTES.Enum()
79 case Gibibytes:
80 return pb.MetricsData_GIBIBYTES.Enum()
81 case AmpUnit:
82 return pb.MetricsData_AMPS.Enum()
83 case MilliampUnit:
84 return pb.MetricsData_MILLIAMPS.Enum()
85 case DegreeCelsiusUnit:
86 return pb.MetricsData_DEGREES_CELSIUS.Enum()
87 }
88 panic(fmt.Sprintf("unknown MetricDataUnits %d", units))
89 }
OLDNEW
« no previous file with comments | « common/tsmon/types/metric.go ('k') | server/cmd/logdog_archivist/main.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698