-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
feat(logging): reopen on sighup #7140
base: master
Are you sure you want to change the base?
Conversation
ArtifactsThese changes are published for testing on Buildkite, DockerHub and GitHub Container Registry. Docker Container
|
WalkthroughThe changes introduce a new logging feature that allows the application to reopen its log files upon receiving specific signals. This enhancement includes new methods in the Changes
Sequence Diagram(s) (Beta)sequenceDiagram
participant User
participant SignalService
participant Logger
User ->> SignalService: Send Signal (e.g., -HUP)
SignalService ->> Logger: Call Reopen Function
Logger ->> File: Reopen Log File
File ->> Logger: Confirm Reopen
Logger ->> SignalService: Confirm Reopen Success
SignalService ->> User: Acknowledge Signal Handling
Assessment against linked issues
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
6bf365e
to
92b5857
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #7140 +/- ##
==========================================
- Coverage 73.68% 73.62% -0.07%
==========================================
Files 346 347 +1
Lines 30022 30109 +87
Branches 839 839
==========================================
+ Hits 22123 22169 +46
- Misses 7026 7069 +43
+ Partials 873 871 -2
Flags with carried forward coverage won't be shown. Click here to find out more.
|
92b5857
to
a77b0fa
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
@@ -59,9 +59,9 @@ func ConfigureLogger(config schema.Log, log bool) (err error) { | |||
|
|||
switch { | |||
case config.FilePath != "": | |||
var file *os.File | |||
file = NewFile(config.FilePath) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Declare the file
variable before using it to avoid scope issues.
+ var file *FileHandler
file = NewFile(config.FilePath)
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
file = NewFile(config.FilePath) | |
var file *FileHandler | |
file = NewFile(config.FilePath) |
// Reopen handles safely reopening the log file. | ||
func Reopen() (err error) { | ||
if file == nil { | ||
return fmt.Errorf("error reopening log file: file is not configured") | ||
} | ||
|
||
return file.Open() | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider encapsulating the file
variable within a struct to manage its scope and lifecycle more effectively.
type Logger struct {
file *FileHandler
}
func (l *Logger) Reopen() error {
if l.file == nil {
return fmt.Errorf("error reopening log file: file is not configured")
}
return l.file.Open()
}
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
// Reopen handles safely reopening the log file. | |
func Reopen() (err error) { | |
if file == nil { | |
return fmt.Errorf("error reopening log file: file is not configured") | |
} | |
return file.Open() | |
} | |
type Logger struct { | |
file *FileHandler | |
} | |
func (l *Logger) Reopen() error { | |
if l.file == nil { | |
return fmt.Errorf("error reopening log file: file is not configured") | |
} | |
return l.file.Open() | |
} |
a77b0fa
to
47d049a
Compare
Signed-off-by: James Elliott <[email protected]>
ecad805
to
0d186d4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (6)
- internal/commands/const.go (1 hunks)
- internal/commands/context.go (1 hunks)
- internal/commands/services.go (7 hunks)
- internal/logging/const.go (1 hunks)
- internal/logging/file.go (1 hunks)
- internal/logging/logger.go (3 hunks)
Files skipped from review due to trivial changes (1)
- internal/commands/const.go
Additional comments not posted (5)
internal/logging/file.go (1)
9-59
: The implementation of file handling methods (Open
,Close
,Write
) correctly uses mutexes to ensure thread safety.internal/logging/logger.go (2)
62-64
: Duplicate comment: Ensure proper scope and lifecycle management for thefile
variable.
89-96
: Duplicate comment: Encapsulate thefile
variable within a struct to manage its scope and lifecycle more effectively.internal/commands/services.go (1)
Line range hint
89-375
: The implementation ofSignalService
and its methods (Run
,Shutdown
) correctly handle signals and actions, demonstrating effective use of Go's concurrency patterns.internal/commands/context.go (1)
86-97
: The addition of getter methods (GetLogger
,GetProviders
,GetConfiguration
) to theCmdCtx
struct enhances modularity and maintainability.
@@ -53,4 +53,5 @@ const ( | |||
var ( | |||
stacktrace sync.Once | |||
reFormatFilePath = regexp.MustCompile(`(%d|\{datetime(:([^}]+))?})`) | |||
file *File |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tip
Codebase Verification
The search results indicate multiple usages of the file
variable within the internal/logging
package. However, there is no evidence of synchronization mechanisms around its access, which could lead to potential issues with concurrent access.
internal/logging/logger.go
: Thefile
variable is used for opening, writing, and reopening the log file.internal/logging/file.go
: Thefile
variable is used for managing file operations such as opening, closing, and writing to the file.
To ensure thread-safety, it is crucial to implement synchronization mechanisms (e.g., mutexes) around the access to the file
variable.
internal/logging/logger.go
internal/logging/file.go
Analysis chain
Verify thread-safety for the global file
variable.
Narrow down the search to the internal/logging
package and check for synchronization mechanisms around the file
variable.
Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Search for all usages of the global `file` variable to ensure it is accessed in a thread-safe manner.
# Test: Search for the variable usage. Expect: Proper synchronization mechanisms around its access.
rg --type go $'file'
Length of output: 142520
Script:
#!/bin/bash
# Description: Search for all usages of the global `file` variable in the `internal/logging` package to ensure it is accessed in a thread-safe manner.
# Test: Search for the variable usage within the `internal/logging` package. Expect: Proper synchronization mechanisms around its access.
rg --type go --glob 'internal/logging/**' $'file'
Length of output: 1333
This implements a method to send Authelia a SIGHUP signal to indicate it should reload the configuration file. This can be used in two ways. If using an external logrotate service you can tell Authelia to reopen the file and create it if it doesn't exist. Secondly if you use the existing time date replacements this will create a brand new log file with the current time.
Closes #4964