Skip to content

Commit 1e806ce

Browse files
authored
Merge pull request #70 from github/config-prod-fixes
Config prod fixes and better logging
2 parents 7fd6100 + dd0f87d commit 1e806ce

File tree

8 files changed

+17
-23
lines changed

8 files changed

+17
-23
lines changed

Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
hooks-ruby (0.6.2)
4+
hooks-ruby (0.6.3)
55
dry-schema (~> 1.14, >= 1.14.1)
66
grape (~> 2.3)
77
puma (~> 6.6)

lib/hooks/app/api.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class << self
3131
# Create a new configured API class
3232
def self.create(config:, endpoints:, log:)
3333
# :nocov:
34+
@production = config[:environment].downcase.strip == "production"
3435
@server_start_time = Time.now
3536

3637
api_class = Class.new(Grape::API) do
@@ -157,9 +158,9 @@ def self.create(config:, endpoints:, log:)
157158
}
158159

159160
# enrich the error response with details if not in production
160-
error_response[:backtrace] = e.backtrace.join("\n") unless config[:production]
161-
error_response[:message] = e.message unless config[:production]
162-
error_response[:handler] = handler_class_name unless config[:production]
161+
error_response[:backtrace] = e.backtrace.join("\n") unless @production
162+
error_response[:message] = e.message unless @production
163+
error_response[:handler] = handler_class_name unless @production
163164

164165
status determine_error_code(e)
165166
error_response

lib/hooks/app/endpoints/catchall.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,9 @@ def self.route_block(captured_config, captured_logger)
103103
}
104104

105105
# enrich the error response with details if not in production
106-
error_response[:backtrace] = e.backtrace.join("\n") unless config[:production]
107-
error_response[:message] = e.message unless config[:production]
108-
error_response[:handler] = handler_class_name unless config[:production]
106+
error_response[:backtrace] = e.backtrace.join("\n") unless @production
107+
error_response[:message] = e.message unless @production
108+
error_response[:handler] = handler_class_name unless @production
109109

110110
status determine_error_code(e)
111111
error_response

lib/hooks/core/builder.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ def build
3737
)
3838
end
3939

40+
@log.debug("global config loaded: #{config.inspect}")
41+
4042
Hooks::Log.instance = @log
4143

4244
# Register user-defined components globally
@@ -55,7 +57,6 @@ def build
5557
@log.info "starting hooks server v#{Hooks::VERSION}"
5658
@log.info "config: #{endpoints.size} endpoints loaded"
5759
@log.info "environment: #{config[:environment]}"
58-
@log.info "production mode: #{config[:production]}"
5960
@log.info "available endpoints: #{endpoints.map { |e| e[:path] }.join(', ')}"
6061

6162
# Build and return Grape API class

lib/hooks/core/config_loader.rb

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,6 @@ def self.load(config_path: nil)
6969
# Convert string keys to symbols for consistency
7070
config = symbolize_keys(config)
7171

72-
if config[:environment].downcase == "production"
73-
config[:production] = true
74-
else
75-
config[:production] = false
76-
end
77-
7872
# Log overrides if any were made
7973
if overrides.any?
8074
puts "INFO: Configuration overrides applied from: #{overrides.join(', ')}" unless SILENCE_CONFIG_LOADER_MESSAGES

lib/hooks/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44
module Hooks
55
# Current version of the Hooks webhook framework
66
# @return [String] The version string following semantic versioning
7-
VERSION = "0.6.2".freeze
7+
VERSION = "0.6.3".freeze
88
end

spec/unit/lib/hooks/core/builder_spec.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@
141141
end
142142

143143
context "with custom logger" do
144-
let(:custom_logger) { double("Logger", info: nil) }
144+
let(:custom_logger) { double("Logger", info: nil, debug: nil) }
145145
let(:builder) { described_class.new(log: custom_logger) }
146146

147147
before do
@@ -216,6 +216,7 @@
216216
let(:mock_logger) { double("Logger", info: nil) }
217217

218218
before do
219+
allow(mock_logger).to receive(:debug)
219220
allow(Hooks::Core::ConfigLoader).to receive(:load).and_return({
220221
log_level: "debug",
221222
environment: "test"
@@ -244,6 +245,7 @@
244245
expect(mock_logger).to receive(:info).with("config: 0 endpoints loaded")
245246
expect(mock_logger).to receive(:info).with("environment: test")
246247
expect(mock_logger).to receive(:info).with("available endpoints: ")
248+
expect(mock_logger).to receive(:debug).with(/global config loaded: /)
247249

248250
builder.build
249251
end
@@ -258,6 +260,7 @@
258260

259261
expect(mock_logger).to receive(:info).with("config: 2 endpoints loaded")
260262
expect(mock_logger).to receive(:info).with("available endpoints: /webhook/test1, /webhook/test2")
263+
expect(mock_logger).to receive(:debug).with(/global config loaded: /)
261264

262265
builder.build
263266
end

spec/unit/lib/hooks/core/config_loader_spec.rb

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333

3434
expect(config[:log_level]).to eq("debug")
3535
expect(config[:environment]).to eq("test")
36-
expect(config[:production]).to be false # should be false when environment is test
3736
expect(config[:handler_plugin_dir]).to eq("./plugins/handlers") # defaults should remain
3837
end
3938
end
@@ -69,7 +68,6 @@
6968
expect(config[:log_level]).to eq("debug")
7069
expect(config[:environment]).to eq("development")
7170
expect(config[:request_timeout]).to eq(60)
72-
expect(config[:production]).to be false
7371
expect(config[:handler_plugin_dir]).to eq("./plugins/handlers") # defaults should remain
7472
end
7573
end
@@ -94,7 +92,6 @@
9492
expect(config[:log_level]).to eq("warn")
9593
expect(config[:environment]).to eq("staging")
9694
expect(config[:endpoints_dir]).to eq("./custom/endpoints")
97-
expect(config[:production]).to be false
9895
end
9996
end
10097

@@ -157,7 +154,6 @@
157154
expect(config[:environment]).to eq("development")
158155
expect(config[:request_limit]).to eq(2_097_152)
159156
expect(config[:request_timeout]).to eq(45)
160-
expect(config[:production]).to be false
161157
end
162158

163159
it "handles partial environment variable overrides" do
@@ -167,7 +163,6 @@
167163

168164
expect(config[:log_level]).to eq("warn")
169165
expect(config[:environment]).to eq("production") # should remain default
170-
expect(config[:production]).to be true
171166
# Ensure other ENV vars are not set from previous examples in this context
172167
expect(ENV["HOOKS_ENVIRONMENT"]).to be_nil
173168
expect(ENV["HOOKS_REQUEST_LIMIT"]).to be_nil
@@ -240,14 +235,14 @@
240235
it "sets production to true when environment is production" do
241236
config = described_class.load(config_path: { environment: "production" })
242237

243-
expect(config[:production]).to be true
238+
expect(config[:environment]).to eq("production")
244239
end
245240

246241
it "sets production to false when environment is not production" do
247242
["development", "test", "staging", "custom"].each do |env|
248243
config = described_class.load(config_path: { environment: env })
249244

250-
expect(config[:production]).to be false
245+
expect(config[:environment]).to eq(env)
251246
end
252247
end
253248
end

0 commit comments

Comments
 (0)