Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 4 additions & 0 deletions config/initializers/opentelemetry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
endpoint: otel_config[:traces_endpoint]
)

# we configure the exporter ourselves
ENV['OTEL_LOGS_EXPORTER'] = 'none'
ENV['OTEL_METRICS_EXPORTER'] = 'none'

OpenTelemetry::SDK.configure do |c|
c.resource = otel_resource
c.add_span_processor(
Expand Down
2 changes: 1 addition & 1 deletion lib/sagittarius/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def self.config
memoize(:config) do
configured_files = ENV.fetch(CONFIG_FILES_ENV, nil)
config_files(configured_files).reduce(defaults) do |config, config_file|
file_config = YAML.safe_load_file(config_file).deep_symbolize_keys
file_config = YAML.safe_load_file(config_file, fallback: {}).deep_symbolize_keys
config.deep_merge(file_config)
end
rescue Errno::ENOENT
Expand Down
23 changes: 13 additions & 10 deletions spec/lib/sagittarius/configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
end

it 'loads the default config file' do
allow(YAML).to receive(:safe_load_file).with(default_config_file).and_return(
allow(YAML).to receive(:safe_load_file).with(default_config_file, fallback: {}).and_return(
'rails' => {
'web' => { 'threads' => 4 },
'grpc' => { 'threads' => 8 },
Expand All @@ -29,7 +29,7 @@
end

it 'uses built-in defaults when the default config file does not exist' do
allow(YAML).to receive(:safe_load_file).with(default_config_file).and_raise(Errno::ENOENT)
allow(YAML).to receive(:safe_load_file).with(default_config_file, fallback: {}).and_raise(Errno::ENOENT)

expect(described_class.config).to eq(described_class.defaults)
end
Expand All @@ -39,19 +39,19 @@
configured_files = ' config/base.yml,config/environment.yml, config/runtime.yml '
allow(ENV).to receive(:fetch).with('SAGITTARIUS_CONFIG_FILES', nil)
.and_return(configured_files)
allow(YAML).to receive(:safe_load_file).with('config/base.yml').and_return(
allow(YAML).to receive(:safe_load_file).with('config/base.yml', fallback: {}).and_return(
'rails' => {
'web' => { 'threads' => 4, 'port' => 4000 },
'grpc' => { 'threads' => 4 },
}
)
allow(YAML).to receive(:safe_load_file).with('config/environment.yml').and_return(
allow(YAML).to receive(:safe_load_file).with('config/environment.yml', fallback: {}).and_return(
'rails' => {
'web' => { 'threads' => 8 },
'grpc' => { 'host' => 'environment:50051' },
}
)
allow(YAML).to receive(:safe_load_file).with('config/runtime.yml').and_return(
allow(YAML).to receive(:safe_load_file).with('config/runtime.yml', fallback: {}).and_return(
'rails' => {
'web' => { 'threads' => 16 },
}
Expand All @@ -70,13 +70,13 @@
it 'loads each configured file in order' do
described_class.config

expect(YAML).to have_received(:safe_load_file).ordered.with('config/base.yml')
expect(YAML).to have_received(:safe_load_file).ordered.with('config/environment.yml')
expect(YAML).to have_received(:safe_load_file).ordered.with('config/runtime.yml')
expect(YAML).to have_received(:safe_load_file).ordered.with('config/base.yml', fallback: {})
expect(YAML).to have_received(:safe_load_file).ordered.with('config/environment.yml', fallback: {})
expect(YAML).to have_received(:safe_load_file).ordered.with('config/runtime.yml', fallback: {})
end

it 'raises when a configured file does not exist' do
allow(YAML).to receive(:safe_load_file).with('config/environment.yml').and_raise(Errno::ENOENT)
allow(YAML).to receive(:safe_load_file).with('config/environment.yml', fallback: {}).and_raise(Errno::ENOENT)

expect { described_class.config }.to raise_error(Errno::ENOENT)
end
Expand All @@ -85,7 +85,10 @@

describe '.defaults' do
it 'matches the example config' do
example_config = YAML.safe_load_file(Rails.root.join('config/sagittarius.example.yml')).deep_symbolize_keys
example_config = YAML.safe_load_file(
Rails.root.join('config/sagittarius.example.yml'),
fallback: {}
).deep_symbolize_keys
expect(example_config).to eq(described_class.defaults)
end
end
Expand Down