Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update get_data API with additional parameters #36

Merged
merged 1 commit into from
Mar 23, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ CyclomaticComplexity:
Severity: refactor
Metrics/LineLength:
Max: 120

Metrics/ParameterLists:
Max: 8
#
# Enabled/Disabled
#
Expand Down
9 changes: 7 additions & 2 deletions lib/metrics/metric_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,15 @@ def push_data(id, data)
# @param starts [Integer] optional timestamp (default now - 8h)
# @param ends [Integer] optional timestamp (default now)
# @param bucketDuration [String] optional interval (default no aggregation)
# @param percentiles [String] optional percentiles to calculate
# @param limit [Integer] optional limit the number of data points returned
# @param order [String] optional Data point sort order, based on timestamp (ASC, DESC)
# @return [Array[Hash]] datapoints
# @see #push_data #push_data for datapoint detail
def get_data(id, starts: nil, ends: nil, bucketDuration: nil, buckets: nil)
params = { start: starts, end: ends, bucketDuration: bucketDuration, buckets: buckets }
def get_data(id, starts: nil, ends: nil, bucketDuration: nil, buckets: nil, percentiles: nil, limit: nil,
order: nil)
params = { start: starts, end: ends, bucketDuration: bucketDuration, buckets: buckets,
percentiles: percentiles, limit: limit, order: order }
resp = @client.http_get("/#{@resource}/#{ERB::Util.url_encode(id)}/data/?" +
encode_params(params))
resp.is_a?(Array) ? resp : [] # API returns no content (empty Hash) instead of empty array
Expand Down
2 changes: 1 addition & 1 deletion spec/endpoint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
url: "http://localhost:8080/hawkular/metrics"
# authentication is not yet supported in hawkular-metrics 0.5.0
# user: "jdoe"
# password: "jdoe"
# password: "password"
36 changes: 36 additions & 0 deletions spec/integration/metric_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,42 @@ def update_metric_by_tags(endpoint, id)
end
end

it 'Should get metrics with limit and order' do
@client = setup_client(username: 'jdoe', password: 'password')
id = '33c6a285-495a-4442-a818-974b03408a6f'
now = 1_458_666_669_263

VCR.use_cassette('Counter_metrics/Should get metrics with limit and order',
erb: { id: id, ends: now - t4h, starts: now - (2 * t4h),
minus20: now - 20, minus30: now - 30, minus10: now - 10,
now: now }, record: :none
) do
# create counter
@client.counters.create(id: id)

# push 3 values with timestamps
@client.counters.push_data(id, [{ value: 1, timestamp: now - 30 },
{ value: 2, timestamp: now - 20 },
{ value: 3, timestamp: now - 10 }])

data = @client.counters.get_data(id)
expect(data.size).to be 3

# push one value without timestamp (which means now)
@client.counters.push_data(id, value: 4)
data = @client.counters.get_data(id)
expect(data.size).to be 4

# retrieve values with limit
data = @client.counters.get_data(id, limit: 1)
expect(data.size).to be 1

# retrieve values from past
data = @client.counters.get_data(id, starts: now - (2 * t4h), ends: now - t4h)
expect(data.empty?).to be true
end
end

it 'Should push metric data to non-existing counter' do
id = SecureRandom.uuid

Expand Down
4 changes: 2 additions & 2 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
module Hawkular::Metrics::RSpec
def setup_client(options = {})
credentials = {
username: config['user'],
password: config['password']
username: options[:username].nil? ? config['user'] : options[:username],
password: options[:password].nil? ? config['password'] : options[:password]
}
@client = Hawkular::Metrics::Client.new(config['url'],
credentials, options)
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.