Skip to content

Commit 702caed

Browse files
committed
refactor(observability): normalize request context field naming in middleware
1 parent 0e62f43 commit 702caed

5 files changed

Lines changed: 6 additions & 5 deletions

File tree

app/account_manager.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def mutex
7272
def build_snapshot
7373
raw_accounts = LocalConfig.global.dig(:auth, :accounts)
7474
accounts = Array(raw_accounts).map { |account| account.transform_keys(&:to_sym).freeze }.freeze
75-
token_index = accounts.each_with_object({}) { |account, hash| hash[account[:token]] = account }.freeze
75+
token_index = accounts.to_h { |account| [account[:token], account] }.freeze
7676

7777
SecurityLogger.log_cache_lifecycle('account_manager', 'build', accounts_count: accounts.length)
7878
{ accounts: accounts, token_index: token_index }.freeze

app/request_context.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ module Web
77
module RequestContext
88
##
99
# Immutable request context model.
10-
Context = Data.define(:request_id, :path, :method, :route_group, :actor, :strategy, :started_at)
10+
Context = Data.define(:request_id, :path, :http_method, :route_group, :actor, :strategy, :started_at)
1111

1212
class << self
1313
# @param context [Context]
@@ -41,7 +41,7 @@ def context_hash(context)
4141
{
4242
request_id: context.request_id,
4343
path: context.path,
44-
method: context.method,
44+
method: context.http_method,
4545
route_group: context.route_group,
4646
actor: context.actor,
4747
strategy: context.strategy,

app/request_context_middleware.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def build_context(request)
6060
RequestContext::Context.new(
6161
request_id: request_id_for(request),
6262
path: path,
63-
method: request.request_method.to_s.upcase,
63+
http_method: request.request_method.to_s.upcase,
6464
route_group: route_group_for(path),
6565
actor: nil,
6666
strategy: request.params['strategy'],

spec/html2rss/web/request_context_middleware_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
def middleware_app
2424
app = lambda do |_env|
2525
context = Html2rss::Web::RequestContext.current
26-
[200, { 'Content-Type' => 'text/plain' }, ["#{context.route_group}:#{context.method}"]]
26+
[200, { 'Content-Type' => 'text/plain' }, ["#{context.route_group}:#{context.http_method}"]]
2727
end
2828
described_class.new(app)
2929
end

spec/spec_helper.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
# Only reset if SecurityLogger is defined (loaded)
5151
Html2rss::Web::SecurityLogger.reset_logger! if defined?(Html2rss::Web::SecurityLogger)
5252
Html2rss::Web::AccountManager.reload! if defined?(Html2rss::Web::AccountManager)
53+
Html2rss::Web::LocalConfig.reload! if defined?(Html2rss::Web::LocalConfig)
5354
end
5455

5556
# rspec-expectations config goes here. You can use an alternate

0 commit comments

Comments
 (0)