|
95 | 95 | expect(registry.get(metric).get(labels: labels)).to include("0.1" => 0, "0.5" => 1) |
96 | 96 | end |
97 | 97 |
|
| 98 | + it 'handles consecutive path segments containing IDs' do |
| 99 | + expect(Benchmark).to receive(:realtime).and_yield.and_return(0.3) |
| 100 | + |
| 101 | + get '/foo/42/24' |
| 102 | + |
| 103 | + metric = :http_server_requests_total |
| 104 | + labels = { method: 'get', path: '/foo/:id/:id', code: '200' } |
| 105 | + expect(registry.get(metric).get(labels: labels)).to eql(1.0) |
| 106 | + |
| 107 | + metric = :http_server_request_duration_seconds |
| 108 | + labels = { method: 'get', path: '/foo/:id/:id' } |
| 109 | + expect(registry.get(metric).get(labels: labels)).to include("0.1" => 0, "0.5" => 1) |
| 110 | + end |
| 111 | + |
| 112 | + it 'handles consecutive path segments containing UUIDs' do |
| 113 | + expect(Benchmark).to receive(:realtime).and_yield.and_return(0.3) |
| 114 | + |
| 115 | + get '/foo/5180349d-a491-4d73-af30-4194a46bdff3/5180349d-a491-4d73-af30-4194a46bdff2' |
| 116 | + |
| 117 | + metric = :http_server_requests_total |
| 118 | + labels = { method: 'get', path: '/foo/:uuid/:uuid', code: '200' } |
| 119 | + expect(registry.get(metric).get(labels: labels)).to eql(1.0) |
| 120 | + |
| 121 | + metric = :http_server_request_duration_seconds |
| 122 | + labels = { method: 'get', path: '/foo/:uuid/:uuid' } |
| 123 | + expect(registry.get(metric).get(labels: labels)).to include("0.1" => 0, "0.5" => 1) |
| 124 | + end |
| 125 | + |
| 126 | + it 'prefers sinatra.route to PATH_INFO' do |
| 127 | + metric = :http_server_requests_total |
| 128 | + |
| 129 | + env('sinatra.route', 'GET /foo/:named_param') |
| 130 | + get '/foo/7' |
| 131 | + env('sinatra.route', nil) |
| 132 | + expect(registry.get(metric).values.keys.last[:path]).to eql("/foo/:named_param") |
| 133 | + end |
| 134 | + |
| 135 | + it 'prefers grape.routing_args to PATH_INFO' do |
| 136 | + metric = :http_server_requests_total |
| 137 | + |
| 138 | + # request.env["grape.routing_args"][:route_info].pattern.origin |
| 139 | + # |
| 140 | + # Yes, this is the object you have to traverse to get the path. |
| 141 | + # |
| 142 | + # No, I'm not happy about it either. |
| 143 | + grape_routing_args = { |
| 144 | + route_info: double(:route_info, |
| 145 | + pattern: double(:pattern, |
| 146 | + origin: '/foo/:named_param' |
| 147 | + ) |
| 148 | + ) |
| 149 | + } |
| 150 | + |
| 151 | + env('grape.routing_args', grape_routing_args) |
| 152 | + get '/foo/7' |
| 153 | + env('grape.routing_args', nil) |
| 154 | + expect(registry.get(metric).values.keys.last[:path]).to eql("/foo/:named_param") |
| 155 | + end |
| 156 | + |
| 157 | + it "falls back to PATH_INFO if the structure of grape.routing_args changes" do |
| 158 | + metric = :http_server_requests_total |
| 159 | + |
| 160 | + grape_routing_args = { |
| 161 | + route_info: double(:route_info, |
| 162 | + pattern: double(:pattern, |
| 163 | + origin_but_different: '/foo/:named_param' |
| 164 | + ) |
| 165 | + ) |
| 166 | + } |
| 167 | + |
| 168 | + env('grape.routing_args', grape_routing_args) |
| 169 | + get '/foo/7' |
| 170 | + env('grape.routing_args', nil) |
| 171 | + expect(registry.get(metric).values.keys.last[:path]).to eql("/foo/:id") |
| 172 | + end |
| 173 | + |
98 | 174 | context 'when the app raises an exception' do |
99 | 175 | let(:original_app) do |
100 | 176 | lambda do |env| |
|
0 commit comments