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

type coercion for configuration parameters #2878

Merged
merged 17 commits into from
Oct 18, 2024
Merged

type coercion for configuration parameters #2878

merged 17 commits into from
Oct 18, 2024

Conversation

fallwith
Copy link
Contributor

@fallwith fallwith commented Oct 1, 2024

Rework the processing of configuration parameters to address #2852.

  • nils to produce errors when user-supplied for params that don't support them
  • introduce a common shared type coercion layer for all config values so that things like environment variable and YAML values are both consistently coerced
  • allow type coercion to Array/Hash to replace all of the equivalent default source based:transform entries
  • lay the foundation for increased server side and env var based support for certain params that are currently marked as YAML source only (functionally ready now, updating tests and docs for each affected param to be handled later)
  • permit Integer values for Float params (using #to_f) and Float values for Integer params (using #round)
  • prevent fatal interruptions and log warnings when a default value can be found to replace a given bogus input value
  • leverage default source's :allow_nil setting to enforce non-nil values for params that don't support nil

resolves #2852

An initial pass at reworking the processing of configuration parameters
to address #2852.

- nils to produce errors when user-supplied for params that don't
  support them
- introduce a common shared type coercion layer for all config values so
  that things like environment variable and YAML values are both
  consistently coerced
- boolean coercion is no longer special cased and handled by the
  coercion layer
- use `#call` instead of `instance_eval` on procs (benchmark supported)
- fix `raw_value` -> `string_array` variable rename needed for one
  remaining instance
- anticipate a default value being a proc and call it before yielding
  the value
- explicitly check for `#nil?` instead of truthiness, as `false` is
  certainly a valid non-nil config value
for legacy reasons...

1. permit tests to specify invalid configuration
2. permit `manual_start` to specify invalid configuration
3. permit int values for float based params and vice versa
4. permit string values for symbol based params and vice versa

and also...

5. fix calls to `evaluate_and_apply_transformations` that were broken
   when the method was updated to accept a config category argument
- treat :app_name as a special case. technically it should be classified
  as an `Array` type with a custom (semicolon) delimiter override but
  for backwards compatibility just make the transform dynamic
- allow unit tests to do screwy things users shouldn't be permitted to
  do
* remove orphaned type map content from environment source
* for bools convert symbols to strings before converting to true/false
* rework unit tests to match lib changes
* revert from `call` back to `instance_eval` so that the original
  intended scope is preserved
* update tests to match lib changes
trust the config manager tests to handle these situations
config manager test updates
float args for int params will be rounded, so use an int to help with
setting accurate expectations
- don't bother with calculations if a callback isn't registered
- assume the cached value has been evaluated already
* optimisation: don't bother with empty manual source opts hashes
* restoration of legacy behavior: permit config params like
  :web_transactions_apdex to behave as expected (permit them to not have
  any entry in default source for things like a class type or a default
  value
* use `#[]` instead of `#fetch` on the @cache hash to light up its
  functionality properly
* update default source test to perform a cache lookup call (previously
  a now-skipped callback call would have performed it)
rejecting empty hashes apparently wipes previously set values from
non-empty hashes, so for now allow the empties to flow through as before
if the given value is already of the type the transform is expected to
produce, then just let it pass through
update the test to expect a default value to be used
Copy link

SimpleCov Report

Coverage Threshold
Line 93.74% 93%
Branch 69.8% 50%

@fallwith fallwith marked this pull request as ready for review October 10, 2024 21:15
Copy link
Contributor

@tannalynn tannalynn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think things look good, thanks for going over all of this with us. Could you add a changelog entry for this?

@fallwith fallwith changed the base branch from dev to lab October 18, 2024 18:38
@fallwith fallwith merged commit fb3836a into lab Oct 18, 2024
34 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Code Complete/Done
Development

Successfully merging this pull request may close these issues.

Type coercion behavior inconsistencies and flaws between configuration formats and between APM and CSEC
2 participants