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

fix: Logger not correctly applying named config #696

Merged
merged 4 commits into from
Jul 31, 2022

Conversation

jsimnz
Copy link
Member

@jsimnz jsimnz commented Jul 29, 2022

Relevant issue(s)

Resolves #693 #694

Description

There was a bug in the #658 that got merged which effectively broke the entire feature. Tests didn't catch it as they were accidentally poorly defined, as they would pass with the default logger settings as well as the custom ones set in the test.

There are two fixes in this PR that resolves the problem. During review, we decided to switch back the Config.Log from Config.Logger, but the viper Bind calls were still using Bind(logger.loglevel) (old name). Additionally, the validate call on the config.Log struct previously always returned nil (no errors), but was changed recently to validate the available options. But, if the --loglevel option is provided it will set the config.Log.Level to error,defra.cli=info,... for example, which would fail validation. I have no moved the validation rules, as it will be validated anyways later in the call stack (in the ToLoggerConfig).

Lastly, it fixes #694, as an accidental oversight, potentially during a rebase/merge-conflict.

Tasks

  • I made sure the code is well commented, particularly hard-to-understand areas.
  • I made sure the repository-held documentation is changed accordingly.
  • I made sure the pull request title adheres to the conventional commit style (the subset used in the project can be found in tools/configs/chglog/config.yml).
  • I made sure to discuss its limitations such as threats to validity, vulnerability to mistake and misuse, robustness to invalidation of assumptions, resource requirements, ...

How has this been tested?

Better defined integration tests that don't overlap with defaults.

Specify the platform(s) on which this was tested:

  • (modify the list accordingly)
  • Ubuntu Linux via WSL2

@jsimnz jsimnz added bug Something isn't working action/no-benchmark Skips the action that runs the benchmark. area/cli Related to the CLI binary area/config Related to configuration labels Jul 29, 2022
@jsimnz jsimnz added this to the DefraDB v0.3 milestone Jul 29, 2022
@jsimnz jsimnz self-assigned this Jul 29, 2022
@codecov
Copy link

codecov bot commented Jul 29, 2022

Codecov Report

Merging #696 (8d76845) into develop (23e728e) will increase coverage by 0.18%.
The diff coverage is 45.45%.

❗ Current head 8d76845 differs from pull request most recent head 27aa302. Consider uploading reports for the commit 27aa302 to get more accurate results

Impacted file tree graph

@@             Coverage Diff             @@
##           develop     #696      +/-   ##
===========================================
+ Coverage    57.24%   57.42%   +0.18%     
===========================================
  Files          143      143              
  Lines        16393    16396       +3     
===========================================
+ Hits          9384     9416      +32     
+ Misses        6127     6098      -29     
  Partials       882      882              
Impacted Files Coverage Δ
cli/cli.go 18.75% <0.00%> (+0.71%) ⬆️
cli/root.go 47.67% <100.00%> (ø)
config/config.go 74.60% <100.00%> (+6.65%) ⬆️
logging/config.go 88.19% <0.00%> (+10.41%) ⬆️

Copy link
Collaborator

@fredcarle fredcarle left a comment

Choose a reason for hiding this comment

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

Tested and seems to work as expected. Thanks for fixing.

Copy link
Member

@shahzadlone shahzadlone left a comment

Choose a reason for hiding this comment

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

LGTM

@orpheuslummis
Copy link
Contributor

orpheuslummis commented Jul 30, 2022

suggestion: additionally support caller key-value for --logger flag.

defradb/cli/cli.go

Lines 145 to 167 in 2e378dd

// handle field
switch param := strings.ToLower(parsedKV[0]); param {
case "level": // string
logcfg.Level = parsedKV[1]
case "format": // string
logcfg.Format = parsedKV[1]
case "output": // string
logcfg.OutputPath = parsedKV[1]
case "stacktrace": // bool
boolValue, err := strconv.ParseBool(parsedKV[1])
if err != nil {
return fmt.Errorf("couldn't parse kv bool: %w", err)
}
logcfg.Stacktrace = boolValue
case "nocolor": // bool
boolValue, err := strconv.ParseBool(parsedKV[1])
if err != nil {
return fmt.Errorf("couldn't parse kv bool: %w", err)
}
logcfg.NoColor = boolValue
default:
return fmt.Errorf("unknown parameter for logger: %s", param)
}

@jsimnz jsimnz force-pushed the jsimnz/fix/named-logger-config branch from 8d76845 to 27aa302 Compare July 30, 2022 08:45
Copy link
Contributor

@orpheuslummis orpheuslummis left a comment

Choose a reason for hiding this comment

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

LGTM

@jsimnz jsimnz merged commit fd88444 into develop Jul 31, 2022
@jsimnz jsimnz deleted the jsimnz/fix/named-logger-config branch July 31, 2022 08:44
shahzadlone pushed a commit to shahzadlone/defradb that referenced this pull request Feb 23, 2024
There was a bug in the sourcenetwork#658 that got merged which effectively broke the entire feature. Tests didn't catch it as they were accidentally poorly defined, as they would pass with the default logger settings as well as the custom ones set in the test.

There are two fixes in this PR that resolves the problem. During review, we decided to switch back the Config.Log from Config.Logger, but the viper Bind calls were still using Bind(logger.loglevel) (old name). Additionally, the validate call on the config.Log struct previously always returned nil (no errors), but was changed recently to validate the available options. But, if the --loglevel option is provided it will set the config.Log.Level to error,defra.cli=info,... for example, which would fail validation. I have no moved the validation rules, as it will be validated anyways later in the call stack (in the ToLoggerConfig).

Lastly, it fixes sourcenetwork#694, as an accidental oversight, potentially during a rebase/merge-conflict.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
action/no-benchmark Skips the action that runs the benchmark. area/cli Related to the CLI binary area/config Related to configuration bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ToLoggerConfig() not exporting Caller option --loglevel not applying desired log level(s)
4 participants