Skip to content
This repository has been archived by the owner on Dec 17, 2017. It is now read-only.

Commit

Permalink
Bugfix - select2 style metrics needs to be sourced from each backend
Browse files Browse the repository at this point in the history
Previously the logic for working out which backend library to call the styling
function was based on the first backend in the returned list. This does not
hold for when multiple backends exist. Now, the list of pure metrics and their
styled form per backend is obtained, and culled based on the feedback type
(raw, or stylized for select2)

Also updated the descartes backend to handle encoding where the key/value pairs
may contain delimiter characters.
  • Loading branch information
Katie McLaughlin committed Apr 15, 2014
1 parent 8fc7058 commit 2ae135a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
9 changes: 5 additions & 4 deletions app/controllers/metrics_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ def list

b.each do |x|
begin
list << ((init_backend x).search_metric_list search, page.to_i)
be = init_backend x
ret = be.search_metric_list(search, page.to_i)
list << ret.map{|r| {id: r, text: be.style_metric(:pretty, r)}}
rescue Backend::Error => e
unless params[:callback] then
render json: { error: e.to_s }
Expand All @@ -56,10 +58,9 @@ def list
list.flatten!

if params[:callback] then
be = init_backend list.first
render json: "#{params[:callback]}({metrics:#{list.map{|x| {id: x, text: (be.style_metric :pretty, x)}}.to_json}});"
render json: "#{params[:callback]}({metrics:#{list.to_json}});"
else
render json: list
render json: list.map{|x| x[:id]}.to_json
end

end
Expand Down
5 changes: 3 additions & 2 deletions lib/backend/descartes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,10 @@ def get_json url
def style_metric style, metric
if style == :pretty then
if @origin == "LMRH8C" || @origin == "R82KX1" then
type, x = URI.decode(metric).split(SEP)
type, x = metric.split(SEP) #URI.decode(metric).split(SEP)

keys = Hash[*x.split(DELIM).map{|y| y.split(KVP)}.flatten]
keys = Hash[keys.map{|k,v| [URI.decode(k), URI.decode(v)] }]

nice = [type]
nice << keys["hostname"]
Expand All @@ -118,7 +119,7 @@ def style_metric style, metric
end
return URI.decode(nice.join(" - "))
else
return metric.gsub(SEP, " - ") #metric
return URI.decode(metric).gsub(SEP, " - ") #metric

end
elsif style == :table then
Expand Down

0 comments on commit 2ae135a

Please sign in to comment.