foundations icon indicating copy to clipboard operation
foundations copied to clipboard

ZTC-1545: Log a warning when parsing settings if yaml contains unused keys

Open OmegaJak opened this issue 10 months ago • 1 comments

This uses serde_ignored while deserializing settings from YAML to log a warning if keys are unused. This could help prevent accidental misconfigurations of services. For example, if the setting is reverted in code without also changing the name in the YAML, a warning will be logged for that key.

There were three things complicating this implementation:

  1. Settings deserialization generally occurs before the log is initialized. This is why I changed the logger used before initialization from a Discard logger to one using the default LoggingSettings. This way, warnings can be logged to stdout at least, following the usual format, while deserializing settings.
  2. Dependencies of foundations may be serializing and re-deserializing their Settings with omitted fields to remove data from copies of the settings. In this case, we do not want warnings logged for those omitted fields. Thus, an additional method was added to deserialize from a yaml string with an option controlling what action is taken when an ignored field is encountered.
  3. YAML fields that are only used as an anchor & merge key will appear as unused. To let applications avoid this false positive, there is a suffix that can be added to keys that will prevent the warning from being logged.

OmegaJak avatar May 03 '24 19:05 OmegaJak