Skip to content
This repository has been archived by the owner on Jan 26, 2022. It is now read-only.

Commit

Permalink
Adds dea/app tags for router varz data and router.total_requests
Browse files Browse the repository at this point in the history
  • Loading branch information
David Sabeti and Jeff Schnitzer committed May 30, 2013
1 parent ec64db4 commit 78378d2
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 42 deletions.
15 changes: 12 additions & 3 deletions collector/lib/collector/handlers/router.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,15 @@ def process
return unless varz["tags"]
varz["tags"].each do |key, values|
values.each do |value, metrics|
tags = {key => value}
# Add synthetic tag so we can isolate all the apps
tags["component"] = "apps" if key == "framework"
if key == "component" && value.start_with?("dea-")

# Sorry for this gem. We want to grab the DEA's number instead of its guid
# i.e. dea-1-deadbeef should be parsed out to 1. The dea- is there by convention
dea_id = value.split("-")[1]
tags = {"component" => "app", "dea" => dea_id }
else
tags = {key => value}
end

send_metric("router.requests", metrics["requests"], tags)
send_latency_metric("router.latency.1m", metrics["latency"], tags)
Expand All @@ -20,6 +26,9 @@ def process
end
end
end

send_metric("router.total_requests", varz["requests"])

end
end
end
Expand Down
132 changes: 93 additions & 39 deletions collector/spec/unit/collector/handlers/router_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

describe Collector::Handler::Router do
describe "#process" do
it "processes" do
varz = JSON.parse <<-JSON
let(:varz) do
JSON.parse <<-JSON
{
"latency": {
"50": 0.0250225,
Expand All @@ -29,49 +29,103 @@
"start": "2013-05-28 22:01:19 +0000",
"tags": {
"component": {
"component-1": {
"latency": {
"50": 0.025036,
"75": 0.034314,
"90": 0.0791451,
"95": 0.1607238499999999,
"99": 1.1623077700000013,
"samples": 1,
"value": 5
},
"rate": [
0.22490272672626982,
0.4771015543892108,
0.8284101734116986
],
"requests": 1234,
"responses_2xx": 200,
"responses_3xx": 300,
"responses_4xx": 400,
"responses_5xx": 500,
"responses_xxx": 1000
}
},
"framework": {
},
"runtime": {
}
}
}
JSON
end

subject { Collector::Handler::Router.new(nil, nil, nil, nil, varz) }

describe "normal components" do
let (:component) do
JSON.parse <<-JSON
{
"latency": {
"50": 0.025036,
"75": 0.034314,
"90": 0.0791451,
"95": 0.1607238499999999,
"99": 1.1623077700000013,
"samples": 1,
"value": 5
},
"rate": [
0.22490272672626982,
0.4771015543892108,
0.8284101734116986
],
"requests": 1234,
"responses_2xx": 200,
"responses_3xx": 300,
"responses_4xx": 400,
"responses_5xx": 500,
"responses_xxx": 1000
}
JSON
end

it "processes" do
varz['tags']['component']['component-1'] = component

tags = {"component" => "component-1"}

subject.should_receive(:send_metric).with("router.requests", 1234, tags)
component_latency = varz["tags"]["component"]["component-1"]["latency"]
subject.should_receive(:send_latency_metric).with("router.latency.1m", component_latency, tags)
subject.should_receive(:send_metric).with("router.responses", 200, tags.merge("status" => "2xx"))
subject.should_receive(:send_metric).with("router.responses", 300, tags.merge("status" => "3xx"))
subject.should_receive(:send_metric).with("router.responses", 400, tags.merge("status" => "4xx"))
subject.should_receive(:send_metric).with("router.responses", 500, tags.merge("status" => "5xx"))
subject.should_receive(:send_metric).with("router.responses", 1000, tags.merge("status" => "xxx"))

subject.should_receive(:send_metric).with("router.total_requests", 68213)

subject.process
end
end


describe "dea-related components (i.e., apps)" do
let (:component) do
JSON.parse <<-JSON
{
"latency": {
"50": 0.025036,
"75": 0.034314,
"90": 0.0791451,
"95": 0.1607238499999999,
"99": 1.1623077700000013,
"samples": 1,
"value": 5
},
"rate": [
0.22490272672626982,
0.4771015543892108,
0.8284101734116986
],
"requests": 5678,
"responses_2xx": 200,
"responses_3xx": 300,
"responses_4xx": 400,
"responses_5xx": 500,
"responses_xxx": 1000
}
JSON
end

it "sends metrics tagged with component:app and dea:foo" do
varz['tags']['component']['dea-1-blahblah'] = component

tags = {"component" => "app", "dea" => "1"}

tags = {"component" => "component-1"}
handler = Collector::Handler::Router.new(nil, nil, nil, nil, varz)
handler.should_receive(:send_metric).with("router.requests", 1234, tags)
component_latency = varz["tags"]["component"]["component-1"]["latency"]
handler.should_receive(:send_latency_metric).with("router.latency.1m", component_latency, tags)
handler.should_receive(:send_metric).with("router.responses", 200, tags.merge("status" => "2xx"))
handler.should_receive(:send_metric).with("router.responses", 300, tags.merge("status" => "3xx"))
handler.should_receive(:send_metric).with("router.responses", 400, tags.merge("status" => "4xx"))
handler.should_receive(:send_metric).with("router.responses", 500, tags.merge("status" => "5xx"))
handler.should_receive(:send_metric).with("router.responses", 1000, tags.merge("status" => "xxx"))
subject.should_receive(:send_metric).with("router.requests", 5678, tags)
subject.stub(:send_latency_metric)
subject.stub(:send_metric).with("router.responses", anything, anything)
subject.should_receive(:send_metric).with("router.total_requests", 68213)

handler.process
subject.process
end
end
end
end

0 comments on commit 78378d2

Please sign in to comment.