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

Set log level from a new LOG_LEVEL env var. #106

Merged
merged 3 commits into from
Feb 13, 2023

Conversation

athamark
Copy link
Contributor

@athamark athamark commented Jan 13, 2023

During live debug sessions we realized that the AuthService logs are way too verbose and thus not helpful for debugging. Since all requests are passed through AuthService for authentication we have a chunk of logs for every one of the requests, even for requests to whitelisted URLs.

Related upstream PR

As you can see in the repo there is an upstream PR which dates back to 2019 (#3). This PR introduces a new LOG_LEVEL envvar that expects one of the following values:

  • warn
  • info
  • debug

The functionality that the contributor has added seems to be in the right direction. But a lot has changed since they submitted this PR. So we had better start fresh and lay out a plan that complies with the latest oidc-authservice.

Proposed Plan

We need to re-categorize our log messages in the available log level categories. Right now the log level which we use in oidc-authservice are:

  • fatal
  • error
  • warn
  • info
  • debug

The current log messages that belong to either one of the first three log levels should remain in these log levels. The same goes for the log messages that belong to the debug log level.

The challenge is to revise the log messages of the info log level which is currently way too verbose and leads to unreadable logs. The plan is to distinguish which of the info log messages should belong to the debug log level instead. As we will expose later on, we will also transfer a few settings-related info logs to the warn log level.

Good to have

It would be beneficial to isolate the dependency to the "github.com/siroupsen/logrus" (https://github.com/sirupsen/logrus) package inside the common package. For this we will need a new and simple function that sets up a StandardLogger():

func StandardLogger() *log.Logger {
	return log.StandardLogger()
}

This will make our code more maintainable and also it will allow us to enforce a single log level across our code.

Regarding the order of the log levels

As exposed in the README.md of the "github.com/sirupsen/logrus" library (https://github.com/sirupsen/logrus):

You can set the logging level on a Logger, then it will only log entries with that severity or anything above it:
// Will log anything that is info or above (warn, error, fatal, panic). Default.

   log.SetLevel(log.InfoLevel)

It may be useful to set log.Level = logrus.DebugLevel in a debug or verbose environment if your application has that.

From this I deduce that the ordering is:

  1. panic (we have no such log message in AuthService)
  2. fatal
  3. error
  4. warn
  5. info
  6. debug

Setting the log level to the i-th item means that all the log messages that belong to the {1, .., i} set will be logged. If a log message belongs to {i+1, ..., 6} then it will not be logged. So the bigger the configured log level is, the more verbose the logs of AuthService will be.

Let's default to info log level.

Testing

I made a rather simple test to quantify the impact of these changes in the AuthService logs. The 5-minute experiment I did was the following:

  1. start AuthService pod (0:00)
  2. login as [email protected] (2:00)
  3. keep the UI as an active browser window
  4. logout (4:00)
  5. stop the AuthService logs

I did this for both an old and the new image. The comparison is:

  • old image logged 452 lines
  • new image logged 70 lines.

Thanks for your time!

athamark pushed a commit that referenced this pull request Feb 8, 2023
Isolated the "github.com/siroupsen/logrus" inside the common package.
All the other package import the common package. To initiate a logger
we have introduced a new LoggerStardard() function, so depending on
what the scope of the log message is, the caller can use either one of:
* common.LoggerForRequest()
* common.LoggerStandard()

GitHub-PR: #106

Signed-off-by: Athanasios Markou <[email protected]>
athamark pushed a commit that referenced this pull request Feb 8, 2023
Change the log levels of certain messages to make the oidc-authservice
logs less verbose.

GitHub-PR: #106

Signed-off-by: Athanasios Markou <[email protected]>
athamark pushed a commit that referenced this pull request Feb 8, 2023
User will be able to configure the level of the log messages they want
to receive. They can configure the new 'LOG_LEVEL' envvar to one of the
following (string) values:
* fatal: for fatal log messages only
* error: for error and fatal log messages
* warn: for warn, error, fatal log messages
* info: for info, warn, error, fatal log messages
* debug: for messages of all the available log levels

GitHub-PR: #106

Signed-off-by: Athanasios Markou <[email protected]>
@athamark athamark force-pushed the feature-athamark-set-log-level branch from 2e1a22b to 977367e Compare February 8, 2023 09:07
athamark pushed a commit that referenced this pull request Feb 13, 2023
Isolated the "github.com/siroupsen/logrus" inside the common package.
All the other package import the common package. To initiate a logger
we have introduced a new LoggerStardard() function, so depending on
what the scope of the log message is, the caller can use either one of:
* common.LoggerForRequest()
* common.LoggerStandard()

GitHub-PR: #106

Signed-off-by: Athanasios Markou <[email protected]>
athamark pushed a commit that referenced this pull request Feb 13, 2023
Change the log levels of certain messages to make the oidc-authservice
logs less verbose.

GitHub-PR: #106

Signed-off-by: Athanasios Markou <[email protected]>
athamark pushed a commit that referenced this pull request Feb 13, 2023
User will be able to configure the level of the log messages they want
to receive. They can configure the new 'LOG_LEVEL' envvar to one of the
following (string) values:
* fatal: for fatal log messages only
* error: for error and fatal log messages
* warn: for warn, error, fatal log messages
* info: for info, warn, error, fatal log messages
* debug: for messages of all the available log levels

GitHub-PR: #106

Signed-off-by: Athanasios Markou <[email protected]>
elikatsis pushed a commit that referenced this pull request Feb 13, 2023
* Restrict the "github.com/siroupsen/logrus" import in the common
  package and have all other packages import common to initialize a
  logger
* Rename the 'LoggerForRequest()' helper to 'RequestLogger()'
* Introduce a new 'common.StardardLogger()' helper to initialize a
  StandardLogger. Depending on the scope of the log message, the caller
  can use either one of 'StandardLogger()' or 'RequestLogger()'.

GitHub-PR: #106

Signed-off-by: Athanasios Markou <[email protected]>
elikatsis pushed a commit that referenced this pull request Feb 13, 2023
Change the log levels of certain messages to make logs less verbose.

GitHub-PR: #106

Signed-off-by: Athanasios Markou <[email protected]>
elikatsis pushed a commit that referenced this pull request Feb 13, 2023
Enable to configure the level of the log messages. Expose the setting
via a new 'LOG_LEVEL' envvar to one of the following (string) values:

* FATAL: for fatal log messages only
* ERROR: for error and fatal log messages
* WARN: for warn, error, fatal log messages
* INFO: for info, warn, error, fatal log messages
* DEBUG: for messages of all the available log levels

GitHub-PR: #106

Signed-off-by: Athanasios Markou <[email protected]>
Athanasios Markou added 3 commits February 13, 2023 17:57
* Restrict the "github.com/siroupsen/logrus" import in the common
  package and have all other packages import common to initialize a
  logger
* Rename the 'LoggerForRequest()' helper to 'RequestLogger()'
* Introduce a new 'common.StardardLogger()' helper to initialize a
  StandardLogger. Depending on the scope of the log message, the caller
  can use either one of 'StandardLogger()' or 'RequestLogger()'.

GitHub-PR: #106

Signed-off-by: Athanasios Markou <[email protected]>
Reviewed-by: Ilias Katsakioris <[email protected]>
Change the log levels of certain messages to make logs less verbose.

GitHub-PR: #106

Signed-off-by: Athanasios Markou <[email protected]>
Reviewed-by: Ilias Katsakioris <[email protected]>
Enable to configure the level of the log messages. Expose the setting
via a new 'LOG_LEVEL' envvar to one of the following (string) values:

* FATAL: for fatal log messages only
* ERROR: for error and fatal log messages
* WARN: for warn, error, fatal log messages
* INFO: for info, warn, error, fatal log messages
* DEBUG: for messages of all the available log levels

GitHub-PR: #106

Signed-off-by: Athanasios Markou <[email protected]>
Reviewed-by: Ilias Katsakioris <[email protected]>
@elikatsis elikatsis force-pushed the feature-athamark-set-log-level branch from 977367e to 58427f7 Compare February 13, 2023 16:11
@elikatsis elikatsis merged commit 58427f7 into master Feb 13, 2023
@elikatsis elikatsis deleted the feature-athamark-set-log-level branch February 13, 2023 16:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants