-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from 3scale/buddhi-metric-counter-api
Buddhi metric reporter service api
- Loading branch information
Showing
14 changed files
with
290 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
require 'csv' | ||
|
||
module AMP | ||
module Toolkit | ||
module Buddhi | ||
class MetricReporter | ||
attr_reader :test_plan | ||
def initialize(test_plan) | ||
@test_plan = test_plan | ||
end | ||
|
||
def report(data) | ||
# hash default value will always be one and the same object | ||
# initializing with a block like that, | ||
# hash['key'].merge!(some_hash) will keep updates in hash | ||
CSV.parse(data).map(&method(:parse)).each_with_object(Hash.new { |hash, key| hash[key] = {} }) do |(service_id, path), acc| | ||
acc[service_id].merge!(test_plan.metric_report(service_id, path)) { |_, old, new| old + new } | ||
end | ||
end | ||
|
||
private | ||
|
||
def parse(row) | ||
host, full_path = row.map(&:strip) | ||
[host.split('.')[0], URI(full_path).path] | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
require 'amp/toolkit/buddhi' | ||
RSpec.describe AMP::Toolkit::Buddhi::MetricReporter do | ||
let(:test_plan) { instance_double(AMP::Toolkit::Buddhi::Simple::TestPlan) } | ||
subject { described_class.new test_plan } | ||
describe 'report' do | ||
it 'should return empty hash when empty input' do | ||
expect(test_plan).not_to receive(:metric_report) | ||
expect(subject.report('')).to eq({}) | ||
end | ||
|
||
it 'should return aggregated results' do | ||
data = %("a533908aa896.benchmark.3sca.net","/1?app_id=4cc&app_key=fcc" | ||
"cb0a88b8da15.benchmark.3sca.net","/1?app_id=74ac&app_key=22" | ||
"a533908aa896.benchmark.3sca.net","/11?app_id=6ba&app_key=ff" | ||
) | ||
expect(test_plan).to receive(:metric_report).with('a533908aa896', '/1').and_return('base' => 1, 'metric_1' => 3) | ||
expect(test_plan).to receive(:metric_report).with('cb0a88b8da15', '/1').and_return('base' => 1, 'metric_2' => 2) | ||
expect(test_plan).to receive(:metric_report).with('a533908aa896', '/11').and_return('base' => 2, 'metric_1' => 3, 'metric_3' => 1) | ||
expect(subject.report(data)).to eq( | ||
'a533908aa896' => { | ||
'base' => 3, | ||
'metric_1' => 6, | ||
'metric_3' => 1 | ||
}, | ||
'cb0a88b8da15' => { | ||
'base' => 1, | ||
'metric_2' => 2 | ||
} | ||
) | ||
end | ||
end | ||
end |
Oops, something went wrong.