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

Adding a configuration for setting audit logs level #3512

Merged
merged 10 commits into from
Jun 19, 2022

Conversation

idanovo
Copy link
Contributor

@idanovo idanovo commented Jun 15, 2022

No description provided.

@idanovo idanovo added the include-changelog PR description should be included in next release changelog label Jun 15, 2022
@idanovo idanovo marked this pull request as ready for review June 16, 2022 11:37
@idanovo idanovo requested review from nopcoder and ortz June 16, 2022 11:37
@@ -13,7 +13,7 @@ has_children: false
{% include toc.html %}

Configuring lakeFS is done using a yaml configuration file and/or environment variable.
The configuration file location can be set with the '--config' flag. If not specified, the the first file found in the following order will be used:
The configuration file location can be set with the '--config' flag. If not specified, the first file found in the following order will be used:
Copy link
Contributor

Choose a reason for hiding this comment

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

nice :)

"took": time.Since(startTime),
"status_code": writer.StatusCode,
"sent_bytes": writer.ResponseSize,
}).Debug("HTTP call ended")
}
endLogMsg := "HTTP call ended"
Copy link
Contributor

Choose a reason for hiding this comment

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

const

}
endLogMsg := "HTTP call ended"

switch strings.ToLower(middlewareLogLevel) {
Copy link
Contributor

Choose a reason for hiding this comment

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

})
}
}

func LoggingMiddleware(requestIDHeaderName string, fields logging.Fields, traceRequestHeaders bool) func(next http.Handler) http.Handler {
if logging.Level() == "trace" {
loggingMiddlewareLevel := viper.GetString(config.LoggingAuditLogLevel)
Copy link
Contributor

Choose a reason for hiding this comment

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

Usually, we extract the configuration value from the config structure. The config structure also expose a method in this case it can also parse the string and return the logging level

@@ -63,6 +66,7 @@ func DebugLoggingMiddleware(requestIDHeaderName string, fields logging.Fields) f
logging.MethodFieldKey: r.Method,
logging.HostFieldKey: r.Host,
logging.RequestIDFieldKey: reqID,
logging.LoggerName: "MiddlewareLog",
Copy link
Contributor

Choose a reason for hiding this comment

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

  1. Usually we have property called "service".
  2. How is this property is used? Because we didn't really create another logger and having a name can be confusing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's just my way to add a kind of "tag" for logs coming from the audit logger. Maybe I'll change it to something like log_source?

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe "audit": "api"

@idanovo idanovo requested a review from nopcoder June 16, 2022 13:56
Copy link
Contributor

@nopcoder nopcoder left a comment

Choose a reason for hiding this comment

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

Couple of minor suggestions - looks good.

@@ -13,6 +14,7 @@ type contextKey string

const (
RequestIDContextKey contextKey = "request_id"
AuditLogEndMessage string = "HTTP call ended"
Copy link
Contributor

Choose a reason for hiding this comment

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

  1. No need the type - constant will get the type while using it.
  2. You can update the message to include API call information or something like that if it make more sense.
Suggested change
AuditLogEndMessage string = "HTTP call ended"
AuditLogEndMessage = "HTTP call ended"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@nopcoder this change leads to this

@@ -52,6 +52,10 @@ func (d DummyLogger) Panic(args ...interface{}) {

}

func (d DummyLogger) Log(level string, args ...interface{}) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Think it is time to have also level as part of the logging abstraction so we will not work with strings.

@@ -63,6 +66,7 @@ func DebugLoggingMiddleware(requestIDHeaderName string, fields logging.Fields) f
logging.MethodFieldKey: r.Method,
logging.HostFieldKey: r.Host,
logging.RequestIDFieldKey: reqID,
logging.LoggerName: "MiddlewareLog",
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe "audit": "api"

@@ -63,6 +65,7 @@ func DebugLoggingMiddleware(requestIDHeaderName string, fields logging.Fields) f
logging.MethodFieldKey: r.Method,
logging.HostFieldKey: r.Host,
logging.RequestIDFieldKey: reqID,
logging.LogSource: "MiddlewareLogger",
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider "audit" with value "api"

Copy link
Contributor

@ortz ortz left a comment

Choose a reason for hiding this comment

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

Nice!
Thank you!

@idanovo idanovo merged commit 946e3e9 into master Jun 19, 2022
@idanovo idanovo deleted the feature/audit-logs-config branch June 19, 2022 08:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
include-changelog PR description should be included in next release changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants