This repository was archived by the owner on Jul 31, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathmeasure.rb
100 lines (81 loc) · 2.42 KB
/
measure.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# frozen_string_literal: true
require "opencensus/stats/measurement"
module OpenCensus
module Stats
# Measure
#
# The definition of the Measurement. Describes the type of the individual
# values/measurements recorded by an application. It includes information
# such as the type of measurement, the units of measurement and descriptive
# names for the data. This provides th fundamental type used for recording
# data.
class Measure
# Describes the unit used for the Measure.
# Should follows the format described by
# http://unitsofmeasure.org/ucum.html
# Unit name for general counts
# @return [String]
UNIT_NONE = "1".freeze
# Unit name for bytes
# @return [String]
BYTE = "By".freeze
# Unit name for Kilobytes
# @return [String]
KBYTE = "kb".freeze
# Unit name for Seconds
# @return [String]
SEC = "s".freeze
# Unit name for Milli seconds
# @return [String]
MS = "ms".freeze
# Unit name for Micro seconds
# @return [String]
US = "us".freeze
# Unit name for Nano seconds
# @return [String]
NS = "ns".freeze
# Measure int64 type
# @return [String]
INT64_TYPE = "INT64".freeze
# Measure double type
# @return [String]
DOUBLE_TYPE = "DOUBLE".freeze
# @return [String]
attr_reader :name
# @return [String]
attr_reader :description
# Unit type of the measurement. i.e "kb", "ms" etc
# @return [String]
attr_reader :unit
# Data type of the measure.
# @return [String] Valid types are {INT64_TYPE}, {DOUBLE_TYPE}.
attr_reader :type
# @private
# Create instance of the measure.
def initialize name:, unit:, type:, description: nil
@name = name
@unit = unit
@type = type
@description = description
end
# Create new measurement
#
# @param [Integer, Float] value
# @param [Tags::TagMap] tags Tags to which the value is recorded
# @return [Measurement]
def create_measurement value:, tags:
Measurement.new measure: self, value: value, tags: tags
end
# Is int64 data type
# @return [Boolean]
def int64?
type == INT64_TYPE
end
# Is float data type
# @return [Boolean]
def double?
type == DOUBLE_TYPE
end
end
end
end