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

Fix net/http adapter and an issue with nil responses #23

Merged
merged 5 commits into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from 4 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
7 changes: 4 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ if (rails_version = ENV["RAILS_VERSION"])
end
# standard: enable Bundler/DuplicatedGem

gem "rails", "~> 7.1"
gem "rake", "~> 13.0"
gem "rspec", "~> 3.0"
gem "rspec-rails", "~> 5.0"
gem "rspec", "~> 3.13.0"
gem "rspec-rails", "~> 7.1"
gem "with_model", "~> 2.0"
gem "database_cleaner-active_record", "~> 2.0"
gem "standard", "~> 1.18.0"
Expand All @@ -29,4 +30,4 @@ gem "pry"
gem "webmock", "~> 3.14"

# Dummy app dependencies
gem "sqlite3", "~> 1.4"
gem "sqlite3", ">= 2.1"
2 changes: 1 addition & 1 deletion lib/io_monitor/controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def append_info_to_payload(payload)
data[source] = aggregator.get(source)
end

data[:response] = payload[:response].body.bytesize
data[:response] = payload[:response]&.body&.bytesize || 0
end

private
Expand Down
4 changes: 2 additions & 2 deletions lib/io_monitor/patches/net_http_adapter_patch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
module IoMonitor
module NetHttpAdapterPatch
def request(*args, &block)
super do |response|
if response.body && IoMonitor.aggregator.active?
super.tap do |response|
if response&.body && IoMonitor.aggregator.active?
IoMonitor.aggregator.increment(NetHttpAdapter.kind, response.body.bytesize)
end
end
Expand Down
9 changes: 9 additions & 0 deletions spec/dummy/app/controllers/fake_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# frozen_string_literal: true

class FakeController < ApplicationController
include IoMonitor::Controller

def fake
raise ActionController::RoutingError.new("Fake")
end
end
1 change: 1 addition & 0 deletions spec/dummy/config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

Rails.application.routes.draw do
get "/fake", to: "fake#fake"
end
8 changes: 8 additions & 0 deletions spec/io_monitor/controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,11 @@ def show
end
end
end

RSpec.describe "when response is nil", type: :request do
it "does not fail" do
get "/fake"

expect(response).to be_not_found
end
end
Loading