hawkular-client 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +17 -0
- data/.rubocop.yml +14 -0
- data/.travis.yml +5 -0
- data/CHANGES.rdoc +6 -0
- data/Gemfile +1 -1
- data/README.rdoc +2 -1
- data/Rakefile +6 -3
- data/hawkularclient.gemspec +17 -11
- data/lib/hawkularclient.rb +91 -98
- data/lib/metrics/metric_api.rb +83 -66
- data/lib/metrics/tenant_api.rb +3 -4
- data/lib/metrics/types.rb +9 -11
- data/lib/metrics/version.rb +1 -1
- data/spec/{endpoint.yml.example → endpoint.yml} +0 -0
- data/spec/integration/metric_spec.rb +223 -131
- data/spec/spec_helper.rb +14 -10
- data/spec/unit/client_spec.rb +24 -19
- data/spec/vcr/vcr_setup.rb +16 -0
- data/spec/vcr_cassettes/Availability_metrics/Should_create_Availability_definition_using_MetricDefinition_parameter.yml +87 -0
- data/spec/vcr_cassettes/Availability_metrics/Should_create_and_return_Availability_using_Hash_parameter.yml +87 -0
- data/spec/vcr_cassettes/Availability_metrics/Should_push_metric_data_to_non-existing_Availability.yml +126 -0
- data/spec/vcr_cassettes/Availability_metrics/Should_update_tags_for_Availability_definition.yml +210 -0
- data/spec/vcr_cassettes/Counter_metrics/Should_create_and_return_counter_using_Hash_parameter.yml +87 -0
- data/spec/vcr_cassettes/Counter_metrics/Should_create_counter_definition_using_MetricDefinition_parameter.yml +87 -0
- data/spec/vcr_cassettes/Counter_metrics/Should_push_metric_data_to_existing_counter.yml +249 -0
- data/spec/vcr_cassettes/Counter_metrics/Should_push_metric_data_to_non-existing_counter.yml +126 -0
- data/spec/vcr_cassettes/Gauge_metrics/Should_create_gauge_definition_using_Hash.yml +87 -0
- data/spec/vcr_cassettes/Gauge_metrics/Should_create_gauge_definition_using_MetricDefinition.yml +87 -0
- data/spec/vcr_cassettes/Gauge_metrics/Should_push_metric_data_to_existing_gauge.yml +249 -0
- data/spec/vcr_cassettes/Gauge_metrics/Should_push_metric_data_to_non-existing_gauge.yml +126 -0
- data/spec/vcr_cassettes/Gauge_metrics/Should_return_periods.yml +85 -0
- data/spec/vcr_cassettes/Gauge_metrics/Should_update_tags_for_gauge_definition.yml +210 -0
- data/spec/vcr_cassettes/Mixed_metrics/Should_send_mixed_metric_request.yml +284 -0
- data/spec/vcr_cassettes/Mixed_metrics/Should_send_mixed_metric_request_of_a_single_type.yml +249 -0
- data/spec/vcr_cassettes/Simple/Should_be_Cool.yml +208 -0
- data/spec/vcr_cassettes/Tenants/Should_create_and_return_tenant.yml +79 -0
- metadata +111 -25
data/lib/metrics/tenant_api.rb
CHANGED
@@ -2,24 +2,23 @@ module Hawkular::Metrics
|
|
2
2
|
class Client
|
3
3
|
# Provides access to tenants API
|
4
4
|
class Tenants
|
5
|
-
|
6
5
|
# @param client [Client]
|
7
6
|
def initialize(client)
|
8
7
|
@client = client
|
9
|
-
@resource =
|
8
|
+
@resource = 'tenants'
|
10
9
|
end
|
11
10
|
|
12
11
|
# Create new tenant
|
13
12
|
# @param id [String] tenant ID/Name
|
14
13
|
def create(id)
|
15
|
-
@client.http_post("/#{@resource}",
|
14
|
+
@client.http_post("/#{@resource}", id: id)
|
16
15
|
end
|
17
16
|
|
18
17
|
# Query existing tenants
|
19
18
|
# @return [Array[Tenant]]
|
20
19
|
def query
|
21
20
|
@client.http_get("/#{@resource}").map do |t|
|
22
|
-
Hawkular::Metrics::Tenant
|
21
|
+
Hawkular::Metrics::Tenant.new(t)
|
23
22
|
end
|
24
23
|
end
|
25
24
|
end
|
data/lib/metrics/types.rb
CHANGED
@@ -6,9 +6,7 @@ module Hawkular
|
|
6
6
|
|
7
7
|
def initialize(json)
|
8
8
|
@json = json
|
9
|
-
|
10
|
-
@id = @json['id']
|
11
|
-
end
|
9
|
+
@id = @json['id'] unless json.nil?
|
12
10
|
end
|
13
11
|
end
|
14
12
|
|
@@ -16,23 +14,23 @@ module Hawkular
|
|
16
14
|
end
|
17
15
|
|
18
16
|
class MetricDefinition < BaseObject
|
19
|
-
attr_accessor :
|
17
|
+
attr_accessor :tenant_id, :data_retention, :tags
|
20
18
|
|
21
|
-
def initialize(json=nil)
|
19
|
+
def initialize(json = nil)
|
22
20
|
super(json)
|
23
|
-
|
24
|
-
@
|
25
|
-
@
|
21
|
+
unless json.nil? # rubocop:disable Style/GuardClause
|
22
|
+
@tenant_id = @json['tenantId']
|
23
|
+
@data_retention = @json['dataRetention']
|
26
24
|
@tags = @json['tags']
|
27
25
|
end
|
28
26
|
end
|
29
27
|
|
30
28
|
def hash
|
31
|
-
h = {:
|
32
|
-
|
29
|
+
h = { id: @id, tenantId: @tenant_id,
|
30
|
+
dataRetention: @data_retention, tags: @tags }
|
31
|
+
h.delete_if { |_k, v| v.nil? }
|
33
32
|
h
|
34
33
|
end
|
35
|
-
|
36
34
|
end
|
37
35
|
end
|
38
36
|
end
|
data/lib/metrics/version.rb
CHANGED
File without changes
|
@@ -1,243 +1,335 @@
|
|
1
|
+
require "#{File.dirname(__FILE__)}/../vcr/vcr_setup"
|
1
2
|
require "#{File.dirname(__FILE__)}/../spec_helper"
|
2
|
-
require
|
3
|
+
require 'securerandom'
|
3
4
|
|
4
5
|
# examples related to Hawkular Metrics
|
5
6
|
|
6
|
-
|
7
7
|
# time constants
|
8
8
|
t4h = 4 * 60 * 60 * 1000
|
9
9
|
|
10
|
-
# more or less generic
|
11
|
-
def create_metric_using_hash(endpoint)
|
12
|
-
id
|
13
|
-
endpoint.create({:id => id, :dataRetention => 123, :tags => {:some => "value"}, :tenantId => @tenant})
|
10
|
+
# more or less generic method common for all metric types (counters, gauges, availabilities)
|
11
|
+
def create_metric_using_hash(endpoint, id)
|
12
|
+
endpoint.create(id: id, dataRetention: 123, tags: { some: 'value' }, tenantId: @tenant)
|
14
13
|
metric = endpoint.get(id)
|
15
14
|
|
16
15
|
expect(metric).to be_a(Hawkular::Metrics::MetricDefinition)
|
17
16
|
expect(metric.id).to eql(id)
|
18
|
-
expect(metric.
|
19
|
-
expect(metric.
|
17
|
+
expect(metric.data_retention).to eql(123)
|
18
|
+
expect(metric.tenant_id).to eql(@tenant)
|
20
19
|
end
|
21
20
|
|
22
|
-
def create_metric_using_md(endpoint)
|
23
|
-
metric = Hawkular::Metrics::MetricDefinition
|
24
|
-
metric.id =
|
25
|
-
metric.
|
26
|
-
metric.tags = {:
|
21
|
+
def create_metric_using_md(endpoint, id)
|
22
|
+
metric = Hawkular::Metrics::MetricDefinition.new
|
23
|
+
metric.id = id
|
24
|
+
metric.data_retention = 90
|
25
|
+
metric.tags = { tag: 'value' }
|
27
26
|
endpoint.create(metric)
|
28
27
|
|
29
28
|
created = endpoint.get(metric.id)
|
30
29
|
expect(created).to be_a(Hawkular::Metrics::MetricDefinition)
|
31
30
|
expect(created.id).to eql(metric.id)
|
32
|
-
expect(created.
|
31
|
+
expect(created.data_retention).to eql(metric.data_retention)
|
33
32
|
end
|
34
33
|
|
35
|
-
def push_data_to_non_existing_metric(endpoint, data)
|
36
|
-
id = SecureRandom.uuid
|
34
|
+
def push_data_to_non_existing_metric(endpoint, data, id)
|
37
35
|
# push one value without timestamp (which means now)
|
38
36
|
endpoint.push_data(id, data)
|
39
37
|
|
40
38
|
data = endpoint.get_data(id)
|
41
39
|
expect(data.size).to be 1
|
42
40
|
|
43
|
-
#verify metric was auto-created
|
41
|
+
# verify metric was auto-created
|
44
42
|
counter = endpoint.get(id)
|
45
43
|
expect(counter).to be_a(Hawkular::Metrics::MetricDefinition)
|
46
44
|
expect(counter.id).to eql(id)
|
47
45
|
end
|
48
46
|
|
49
|
-
def update_metric_by_tags(endpoint)
|
50
|
-
id
|
51
|
-
endpoint.create({:id => id, :tags => {:myTag => id}})
|
47
|
+
def update_metric_by_tags(endpoint, id)
|
48
|
+
endpoint.create(id: id, tags: { myTag: id })
|
52
49
|
metric = endpoint.get(id)
|
53
|
-
metric.tags = {:
|
50
|
+
metric.tags = { newTag: 'newValue' }
|
54
51
|
endpoint.update_tags(metric)
|
55
52
|
|
56
53
|
metric = endpoint.get(id)
|
57
|
-
expect(metric.tags).to include(
|
54
|
+
expect(metric.tags).to include('newTag' => 'newValue', 'myTag' => id)
|
58
55
|
|
59
56
|
# query API for a metric with given tag
|
60
|
-
data = endpoint.query(
|
57
|
+
data = endpoint.query(myTag: id)
|
61
58
|
expect(data.size).to be 1
|
62
59
|
end
|
63
60
|
|
64
|
-
describe
|
61
|
+
describe 'Simple', :vcr do
|
62
|
+
it 'Should be Cool' do
|
63
|
+
Net::HTTP.get_response(URI('http://localhost:8080/'))
|
64
|
+
end
|
65
|
+
end
|
65
66
|
|
67
|
+
describe 'Tenants', vcr: { match_requests_on: [:uri, :method], record: :none } do
|
66
68
|
before(:all) do
|
67
69
|
setup_client
|
68
70
|
end
|
69
71
|
|
70
|
-
it
|
72
|
+
it 'Should create and return tenant' do
|
71
73
|
tenant = SecureRandom.uuid
|
72
74
|
@client.tenants.create(tenant)
|
73
|
-
created = @client.tenants.query.select { |t|
|
74
|
-
t.id == tenant
|
75
|
-
}
|
75
|
+
created = @client.tenants.query.select { |t| t.id == tenant }
|
76
76
|
expect(created).not_to be nil
|
77
77
|
end
|
78
78
|
end
|
79
79
|
|
80
|
-
describe
|
81
|
-
|
80
|
+
describe 'Mixed metrics' do
|
82
81
|
before(:all) do
|
83
82
|
setup_client_new_tenant
|
84
83
|
end
|
85
84
|
|
86
|
-
it
|
85
|
+
it 'Should send mixed metric request of a single type' do
|
87
86
|
id = SecureRandom.uuid
|
88
|
-
@client.push_data(counters:[{:id => id, :data => [{:value => 1}]} ] )
|
89
|
-
data = @client.counters.get_data(id)
|
90
|
-
expect(data.size).to be 1
|
91
|
-
|
92
|
-
@client.push_data(availabilities:[{:id => id, :data => [{:value => "down"}]} ] )
|
93
|
-
data = @client.avail.get_data(id)
|
94
|
-
expect(data.size).to be 1
|
95
87
|
|
96
|
-
|
97
|
-
|
98
|
-
|
88
|
+
VCR.use_cassette('Mixed_metrics/Should send mixed metric request of a single type',
|
89
|
+
erb: { id: id }, record: :none
|
90
|
+
) do
|
91
|
+
@client.push_data(counters: [{ id: id, data: [{ value: 1 }] }])
|
92
|
+
data = @client.counters.get_data(id)
|
93
|
+
expect(data.size).to be 1
|
94
|
+
|
95
|
+
@client.push_data(availabilities: [{ id: id, data: [{ value: 'down' }] }])
|
96
|
+
data = @client.avail.get_data(id)
|
97
|
+
expect(data.size).to be 1
|
98
|
+
|
99
|
+
@client.push_data(gauges: [{ id: id, data: [{ value: 1.1 }] }])
|
100
|
+
data = @client.gauges.get_data(id)
|
101
|
+
expect(data.size).to be 1
|
102
|
+
end
|
99
103
|
end
|
104
|
+
# end
|
100
105
|
|
101
|
-
it
|
106
|
+
it 'Should send mixed metric request' do
|
102
107
|
id = SecureRandom.uuid
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
108
|
+
VCR.use_cassette('Mixed_metrics/Should send mixed metric request',
|
109
|
+
erb: { id: id }, record: :none
|
110
|
+
) do
|
111
|
+
expect(@client.counters.get_data(id).size).to be 0
|
112
|
+
expect(@client.gauges.get_data(id).size).to be 0
|
113
|
+
expect(@client.avail.get_data(id).size).to be 0
|
114
|
+
|
115
|
+
@client.push_data(
|
116
|
+
counters: [{ id: id, data: [{ value: 1 }] }],
|
117
|
+
availabilities: [{ id: id, data: [{ value: 'down' }] }],
|
118
|
+
gauges: [{ id: id, data: [{ value: 1.1 }] }]
|
119
|
+
)
|
120
|
+
|
121
|
+
expect(@client.counters.get_data(id).size).to be 1
|
122
|
+
expect(@client.gauges.get_data(id).size).to be 1
|
123
|
+
expect(@client.avail.get_data(id).size).to be 1
|
124
|
+
end
|
117
125
|
end
|
118
126
|
end
|
119
127
|
|
120
|
-
describe
|
121
|
-
|
128
|
+
describe 'Counter metrics' do
|
122
129
|
before(:all) do
|
123
130
|
setup_client_new_tenant
|
124
131
|
end
|
125
132
|
|
126
|
-
it
|
127
|
-
|
133
|
+
it 'Should create and return counter using Hash parameter' do
|
134
|
+
id = SecureRandom.uuid
|
135
|
+
VCR.use_cassette('Counter_metrics/Should create and return counter using Hash parameter',
|
136
|
+
erb: { id: id }, record: :none
|
137
|
+
) do
|
138
|
+
create_metric_using_hash @client.counters, id
|
139
|
+
end
|
128
140
|
end
|
129
141
|
|
130
|
-
it
|
131
|
-
|
142
|
+
it 'Should create counter definition using MetricDefinition parameter' do
|
143
|
+
id = SecureRandom.uuid
|
144
|
+
VCR.use_cassette(
|
145
|
+
'Counter_metrics/Should create counter definition using MetricDefinition parameter',
|
146
|
+
erb: { id: id }, record: :none
|
147
|
+
) do
|
148
|
+
create_metric_using_md @client.counters, id
|
149
|
+
end
|
132
150
|
end
|
133
151
|
|
134
|
-
it
|
152
|
+
it 'Should push metric data to existing counter' do
|
135
153
|
id = SecureRandom.uuid
|
136
|
-
#create counter
|
137
|
-
@client.counters.create({:id => id})
|
138
154
|
now = @client.now
|
139
155
|
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
156
|
+
VCR.use_cassette('Counter_metrics/Should push metric data to existing counter',
|
157
|
+
erb: { id: id, ends: now - t4h, starts: now - (2 * t4h),
|
158
|
+
minus20: now - 20, minus30: now - 30, minus10: now - 10,
|
159
|
+
now: now }, record: :none
|
160
|
+
) do
|
161
|
+
# create counter
|
162
|
+
@client.counters.create(id: id)
|
163
|
+
|
164
|
+
# push 3 values with timestamps
|
165
|
+
@client.counters.push_data(id, [{ value: 1, timestamp: now - 30 },
|
166
|
+
{ value: 2, timestamp: now - 20 },
|
167
|
+
{ value: 3, timestamp: now - 10 }])
|
168
|
+
|
169
|
+
data = @client.counters.get_data(id)
|
170
|
+
expect(data.size).to be 3
|
171
|
+
|
172
|
+
# push one value without timestamp (which means now)
|
173
|
+
@client.counters.push_data(id, value: 4)
|
174
|
+
data = @client.counters.get_data(id)
|
175
|
+
expect(data.size).to be 4
|
176
|
+
|
177
|
+
# retrieve values from past
|
178
|
+
data = @client.counters.get_data(id, starts: now - (2 * t4h), ends: now - t4h)
|
179
|
+
expect(data.empty?).to be true
|
180
|
+
end
|
154
181
|
end
|
155
182
|
|
156
|
-
it
|
157
|
-
|
158
|
-
end
|
183
|
+
it 'Should push metric data to non-existing counter' do
|
184
|
+
id = SecureRandom.uuid
|
159
185
|
|
186
|
+
VCR.use_cassette('Counter_metrics/Should push metric data to non-existing counter',
|
187
|
+
erb: { id: id }, record: :none
|
188
|
+
) do
|
189
|
+
push_data_to_non_existing_metric @client.counters, { value: 4 }, id
|
190
|
+
end
|
191
|
+
end
|
160
192
|
end
|
161
193
|
|
162
|
-
describe
|
163
|
-
|
194
|
+
describe 'Availability metrics' do
|
164
195
|
before(:all) do
|
165
196
|
setup_client_new_tenant
|
166
197
|
end
|
167
198
|
|
168
|
-
it
|
169
|
-
|
199
|
+
it 'Should create and return Availability using Hash parameter' do
|
200
|
+
id = SecureRandom.uuid
|
201
|
+
VCR.use_cassette(
|
202
|
+
'Availability_metrics/Should create and return Availability using Hash parameter',
|
203
|
+
erb: { id: id }, record: :none
|
204
|
+
) do
|
205
|
+
create_metric_using_hash @client.avail, id
|
206
|
+
end
|
170
207
|
end
|
171
208
|
|
172
|
-
it
|
173
|
-
|
209
|
+
it 'Should create Availability definition using MetricDefinition parameter' do
|
210
|
+
id = SecureRandom.uuid
|
211
|
+
VCR.use_cassette(
|
212
|
+
'Availability_metrics/Should create Availability definition using MetricDefinition parameter',
|
213
|
+
erb: { id: id }, record: :none
|
214
|
+
) do
|
215
|
+
create_metric_using_md @client.avail, id
|
216
|
+
end
|
174
217
|
end
|
175
218
|
|
176
|
-
it
|
177
|
-
|
219
|
+
it 'Should push metric data to non-existing Availability' do
|
220
|
+
id = SecureRandom.uuid
|
221
|
+
|
222
|
+
VCR.use_cassette('Availability_metrics/Should push metric data to non-existing Availability',
|
223
|
+
erb: { id: id }, record: :none
|
224
|
+
) do
|
225
|
+
push_data_to_non_existing_metric @client.avail, { value: 'UP' }, id
|
226
|
+
end
|
178
227
|
end
|
179
|
-
|
180
|
-
|
228
|
+
|
229
|
+
it 'Should update tags for Availability definition' do
|
230
|
+
id = SecureRandom.uuid
|
231
|
+
|
232
|
+
VCR.use_cassette('Availability_metrics/Should update tags for Availability definition',
|
233
|
+
erb: { id: id }, record: :none
|
234
|
+
) do
|
235
|
+
update_metric_by_tags @client.avail, id
|
236
|
+
end
|
181
237
|
end
|
182
238
|
end
|
183
239
|
|
184
|
-
describe
|
185
|
-
|
240
|
+
describe 'Gauge metrics' do
|
186
241
|
before(:all) do
|
187
242
|
setup_client_new_tenant
|
188
243
|
end
|
189
244
|
|
190
|
-
it
|
191
|
-
|
192
|
-
end
|
245
|
+
it 'Should create gauge definition using MetricDefinition' do
|
246
|
+
id = SecureRandom.uuid
|
193
247
|
|
194
|
-
|
195
|
-
|
248
|
+
VCR.use_cassette('Gauge_metrics/Should create gauge definition using MetricDefinition',
|
249
|
+
erb: { id: id }, record: :none
|
250
|
+
) do
|
251
|
+
create_metric_using_md @client.gauges, id
|
252
|
+
end
|
196
253
|
end
|
197
254
|
|
198
|
-
it
|
199
|
-
|
255
|
+
it 'Should create gauge definition using Hash' do
|
256
|
+
id = SecureRandom.uuid
|
257
|
+
|
258
|
+
VCR.use_cassette('Gauge_metrics/Should create gauge definition using Hash',
|
259
|
+
erb: { id: id }, record: :none
|
260
|
+
) do
|
261
|
+
create_metric_using_hash @client.gauges, id
|
262
|
+
end
|
200
263
|
end
|
201
264
|
|
202
|
-
it
|
265
|
+
it 'Should push metric data to non-existing gauge' do
|
203
266
|
id = SecureRandom.uuid
|
204
|
-
#create gauge
|
205
|
-
@client.gauges.create({:id => id})
|
206
|
-
now = @client.now
|
207
267
|
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
268
|
+
VCR.use_cassette('Gauge_metrics/Should push metric data to non-existing gauge',
|
269
|
+
erb: { id: id }, record: :none
|
270
|
+
) do
|
271
|
+
push_data_to_non_existing_metric @client.gauges, { value: 3.1415926 }, id
|
272
|
+
end
|
273
|
+
end
|
213
274
|
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
expect(data.size).to be 4
|
275
|
+
it 'Should push metric data to existing gauge' do
|
276
|
+
id = SecureRandom.uuid
|
277
|
+
now = @client.now
|
218
278
|
|
219
|
-
|
220
|
-
|
221
|
-
|
279
|
+
VCR.use_cassette('Gauge_metrics/Should push metric data to existing gauge',
|
280
|
+
erb: { id: id, ends: now - t4h, starts: now - (2 * t4h) }, record: :none
|
281
|
+
) do
|
282
|
+
# create gauge
|
283
|
+
@client.gauges.create(id: id)
|
284
|
+
|
285
|
+
# push 3 values with timestamps
|
286
|
+
@client.gauges.push_data(id,
|
287
|
+
[{ value: 1, timestamp: now - 30 },
|
288
|
+
{ value: 2, timestamp: now - 20 },
|
289
|
+
{ value: 3, timestamp: now - 10 }])
|
290
|
+
|
291
|
+
data = @client.gauges.get_data(id)
|
292
|
+
expect(data.size).to be 3
|
293
|
+
|
294
|
+
# push one value without timestamp (which means now)
|
295
|
+
@client.gauges.push_data(id, value: 4)
|
296
|
+
data = @client.gauges.get_data(id)
|
297
|
+
expect(data.size).to be 4
|
298
|
+
|
299
|
+
# retrieve values from past
|
300
|
+
data = @client.counters.get_data(id, starts: now - (2 * t4h), ends: now - t4h)
|
301
|
+
expect(data.empty?).to be true
|
302
|
+
end
|
222
303
|
end
|
223
304
|
|
224
|
-
it
|
225
|
-
|
305
|
+
it 'Should update tags for gauge definition' do
|
306
|
+
id = SecureRandom.uuid
|
307
|
+
|
308
|
+
VCR.use_cassette('Gauge_metrics/Should update tags for gauge definition',
|
309
|
+
erb: { id: id }, record: :none
|
310
|
+
) do
|
311
|
+
update_metric_by_tags @client.gauges, id
|
312
|
+
end
|
226
313
|
end
|
227
314
|
|
228
|
-
it
|
315
|
+
it 'Should return periods' do
|
229
316
|
id = SecureRandom.uuid
|
230
317
|
now = @client.now
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
318
|
+
before4h = now - t4h
|
319
|
+
|
320
|
+
VCR.use_cassette('Gauge_metrics/Should return periods',
|
321
|
+
erb: { id: id, start: now, before4h: before4h,
|
322
|
+
minus20: now - 20, minus30: now - 30 },
|
323
|
+
record: :none) do
|
324
|
+
# push 3 values with timestamps
|
325
|
+
@client.gauges.push_data(id, [{ value: 1, timestamp: now - 30 },
|
326
|
+
{ value: 2, timestamp: now - 20 },
|
327
|
+
{ value: 3, timestamp: now }])
|
328
|
+
|
329
|
+
data = @client.gauges.get_periods(id, operation: 'lte', threshold: 4, starts: before4h)
|
330
|
+
expect(data.size).to be 1
|
331
|
+
expect(data[0][0]).to eql(now - 30)
|
332
|
+
expect(data[0][1]).to eql(now)
|
333
|
+
end
|
239
334
|
end
|
240
|
-
|
241
335
|
end
|
242
|
-
|
243
|
-
|