From 381b02653295beca6f9e0fc9db56bcf6e967e43b Mon Sep 17 00:00:00 2001 From: Omeed Rabani Date: Tue, 28 Nov 2023 11:38:00 -0800 Subject: [PATCH 1/4] non-production update readme with targeting best practices: Update README with targeting best practices --- CHANGELOG.md | 4 ++++ Gemfile.lock | 28 ++++++++++++++++++++-------- README.md | 30 ++++++++++++++++++++++++++++++ lib/process_settings/version.rb | 2 +- 4 files changed, 55 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 81d90d9..635b8ff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ Inspired by [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). Note: this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.19.2] - 2023-11-28 +### Updated +- Updated README to include ProcessSetting lookup best practices when using `targets` in settings. + ## [0.19.1] - 2022-12-16 ### Fixed - Fixed a bug in `ProcessSettings::Watchdog` preventing it from raising out of sync errors diff --git a/Gemfile.lock b/Gemfile.lock index ad84fe7..6bfff58 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - process_settings (0.19.1) + process_settings (0.19.2) activesupport json listen (~> 3.0) @@ -10,30 +10,41 @@ PATH GEM remote: http://rubygems.org/ specs: - activesupport (7.0.4) + activesupport (7.1.2) + base64 + bigdecimal concurrent-ruby (~> 1.0, >= 1.0.2) + connection_pool (>= 2.2.5) + drb i18n (>= 1.6, < 2) minitest (>= 5.1) + mutex_m tzinfo (~> 2.0) appraisal (2.4.1) bundler rake thor (>= 0.14.0) ast (2.4.2) + base64 (0.2.0) + bigdecimal (3.1.4) bump (0.6.1) coderay (1.1.3) - concurrent-ruby (1.1.10) + concurrent-ruby (1.2.2) + connection_pool (2.4.1) diff-lcs (1.5.0) docile (1.4.0) - ffi (1.15.5) - i18n (1.12.0) + drb (2.2.0) + ruby2_keywords + ffi (1.16.3) + i18n (1.14.1) concurrent-ruby (~> 1.0) json (2.6.3) - listen (3.7.1) + listen (3.8.0) rb-fsevent (~> 0.10, >= 0.10.3) rb-inotify (~> 0.9, >= 0.9.10) method_source (1.0.0) - minitest (5.16.3) + minitest (5.20.0) + mutex_m (0.2.0) parallel (1.22.1) parser (3.1.1.0) ast (~> 2.4.1) @@ -75,6 +86,7 @@ GEM ruby-prof-flamegraph (0.3.0) ruby-prof (~> 0.13) ruby-progressbar (1.11.0) + ruby2_keywords (0.0.5) simplecov (0.21.2) docile (~> 1.1) simplecov-html (~> 0.11) @@ -83,7 +95,7 @@ GEM simplecov-lcov (0.8.0) simplecov_json_formatter (0.1.4) thor (1.2.1) - tzinfo (2.0.5) + tzinfo (2.0.6) concurrent-ruby (~> 1.0) unicode-display_width (1.8.0) diff --git a/README.md b/README.md index 843c6fd..dab86e3 100644 --- a/README.md +++ b/README.md @@ -167,6 +167,36 @@ This will be applied in any process that has (`service_name == "frontend"` OR `s ### Precedence The settings YAML files are always combined in alphabetical order by file path. Later settings take precedence over the earlier ones. +Settings are **not** merged, so make sure to review best practices when using targets. + +#### Process Setting Lookup Best Practices When Using Targeting + +1. In your business logic, lookup process settings as granularly as possible. + 1. E.g. Instead of querying `ProcessSettings['cat_calendar_config']` and then getting the `'cats_per_calender_minimum'` key from the resulting hash, do `ProcessSettings['cat_calendar_config', 'cats_per_calendar_minimum']`. +2. If you can't do granular process setting lookups, make sure any files with targets redefine all required keys in the process settings config. + +Example for 2: If your business logic is looking up `ProcessSettings['general_calendar_config']` to use the output like a generic hash, you should define target overrides like the `eu_general_calendar_override.yml` example below: + +For an example `all.yml` file like this: + +``` +settings: + general_calendar_config: + turtle_calendar_color: "blue" + parrot_calendar_color: "red" +``` + +Make sure your target file redefines all required keys like this `eu_general_calendar_override.yml` example: + +``` +target: + data_silo: eu +settings: + general_calendar_config: + turtle_calendar_color: "yellow" + parrot_calendar_color: "red" +``` + ### Forked Processes When using `ProcessSettings` within an environment that is forking threads (like `unicorn` web servers), you can restart the `FileMonitor` after the fork with `restart_after_fork`. diff --git a/lib/process_settings/version.rb b/lib/process_settings/version.rb index 22daea7..8fdc6c4 100644 --- a/lib/process_settings/version.rb +++ b/lib/process_settings/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module ProcessSettings - VERSION = '0.19.1' + VERSION = '0.19.2' end From 2e45946557ec11927a7bd0fbcfb7f29149c45190 Mon Sep 17 00:00:00 2001 From: Omeed Rabani Date: Tue, 28 Nov 2023 11:46:04 -0800 Subject: [PATCH 2/4] non-production update readme with targeting best practices: Add require 'active_support/core_ext' to spec_helper.rb --- spec/spec_helper.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 270ff87..fd8b45d 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -2,6 +2,7 @@ require 'rspec_junit_formatter' require 'process_settings' +require 'active_support/core_ext' require 'pry' From 1d06cd4f12bf7f2870f0909cee22bc8072abf45a Mon Sep 17 00:00:00 2001 From: Omeed Rabani Date: Tue, 28 Nov 2023 11:52:17 -0800 Subject: [PATCH 3/4] non-production update readme with targeting best practices: Remove usage of activesupport's 'presence' method to get tests to not fail with activesupport 7.1.2 --- spec/spec_helper.rb | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index fd8b45d..8f0201d 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -2,11 +2,10 @@ require 'rspec_junit_formatter' require 'process_settings' -require 'active_support/core_ext' require 'pry' -if ENV['GITHUB_ACTIONS'].presence +if ENV['GITHUB_ACTIONS'] && !ENV['GITHUB_ACTIONS'].strip.empty? require 'simplecov' require 'simplecov-lcov' @@ -23,8 +22,15 @@ end RSpec.configure do |config| + formatter_outpath_path = + if ENV['JUNIT_OUTPUT'] && !ENV['JUNIT_OUTPUT'].strip.empty? + ENV['JUNIT_OUTPUT'] + else + 'spec/reports/rspec.xml' + end + config.add_formatter :progress - config.add_formatter RspecJunitFormatter, ENV['JUNIT_OUTPUT'].presence || 'spec/reports/rspec.xml' + config.add_formatter RspecJunitFormatter, formatter_outpath_path config.expect_with :rspec do |expectations| expectations.include_chain_clauses_in_custom_matcher_descriptions = true From 895f3d6cf140be02bc8f1c4178c4c1a7b9a66646 Mon Sep 17 00:00:00 2001 From: Omeed Rabani Date: Tue, 28 Nov 2023 12:09:46 -0800 Subject: [PATCH 4/4] non-production update readme with targeting best practices: Require activesupport/core_ext/object/blank in spec_helper.rb --- spec/spec_helper.rb | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 8f0201d..4fbb519 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -2,10 +2,11 @@ require 'rspec_junit_formatter' require 'process_settings' +require 'active_support/core_ext/object/blank' require 'pry' -if ENV['GITHUB_ACTIONS'] && !ENV['GITHUB_ACTIONS'].strip.empty? +if ENV['GITHUB_ACTIONS'].presence require 'simplecov' require 'simplecov-lcov' @@ -22,15 +23,8 @@ end RSpec.configure do |config| - formatter_outpath_path = - if ENV['JUNIT_OUTPUT'] && !ENV['JUNIT_OUTPUT'].strip.empty? - ENV['JUNIT_OUTPUT'] - else - 'spec/reports/rspec.xml' - end - config.add_formatter :progress - config.add_formatter RspecJunitFormatter, formatter_outpath_path + config.add_formatter RspecJunitFormatter, ENV['JUNIT_OUTPUT'].presence || 'spec/reports/rspec.xml' config.expect_with :rspec do |expectations| expectations.include_chain_clauses_in_custom_matcher_descriptions = true