-
Notifications
You must be signed in to change notification settings - Fork 762
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
Gracefully shutdown analytics module/runner #3335
Gracefully shutdown analytics module/runner #3335
Conversation
func (ea enabledAnalytics) Shutdown() { | ||
for _, module := range ea { | ||
module.Shutdown() | ||
} | ||
} |
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.
This code block isn't covered by tests, can you update this?
router/router.go
Outdated
|
||
analyticsRunner := analyticsBuild.New(&cfg.Analytics) | ||
|
||
// todo(zachbadgett): better shutdown |
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.
Can this TODO be removed?
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.
i did not remove this because i do not have context of TODO - is it okay to remove this line ? @zachbadgett
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.
i will just remove it - i think i figured out what is a better shutdown
router/router.go
Outdated
r.Shutdown = func() { | ||
shutdown() | ||
analyticsRunner.Shutdown() | ||
} |
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.
Is it possible to cover this code with tests? I know a lot of code in this file is uncovered already, so no worries if not.
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.
let me see what i can do
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.
it might work, but requires a big refactoring effort, as the router itself is not fully dependency inverted - that means i have to figure out how to pass a proper mock to test this function early.
ideally, i think we should apply dependency inversion pattern to the initialization process of the router to make it easier to test.
cc @bsardo
let me know if you think it is necessary as part of the PR to start invert analytic runner and storedRequestsConf.NewStoredRequests
or we should do full dependency inversion as the prebid server 3.0 ( i am all in refactoring the code for better design pattern )
analytics/filesystem/file_module.go
Outdated
@@ -85,6 +85,9 @@ func (f *FileLogger) LogNotificationEventObject(ne *analytics.NotificationEvent) | |||
f.Logger.Flush() | |||
} | |||
|
|||
// Shutdown the logger - No-op Implementation | |||
func (f *FileLogger) Shutdown() {} |
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.
Should we call flush in order to output all pending buffered data just in case there's any?
88 // Shutdown the logger - No-op Implementation
89 - func (f *FileLogger) Shutdown() {}
+ func (f *FileLogger) Shutdown() {
+ f.Logger.Flush()
+ }
90
91 // Method to initialize the analytic module
92 func NewFileLogger(filename string) (analytics.Module, error) {
analytics/filesystem/file_module.go
@@ -200,6 +200,8 @@ func (p *PubstackModule) LogAmpObject(ao *analytics.AmpObject) { | |||
p.eventChannels[amp].Push(payload) | |||
} | |||
|
|||
func (p *PubstackModule) Shutdown() {} |
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.
Should we closeAllEventChannels()
or close(p.stopCh)
?
202
203 - func (p *PubstackModule) Shutdown() {}
+ func (p *PubstackModule) Shutdown() {
+ }
+ p.closeAllEventChannels()
+ close(p.stopCh)
+ }
204
205 func (p *PubstackModule) start(c <-chan *Configuration) {
analytics/pubstack/pubstack_module.go
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.
@guscarreon after inspection, i would say, leave it no-op, see the comments
Just a friendly ping, are you still working on this? |
@hhhjort yes, sorry for the late rely, i am slowing working on this, you can expect next week i will update the commit |
going to resume the work today |
1f0b6b0
to
4452580
Compare
For future reference, can you not force push as it squashes the commits from the past making it harder to review. Thank you! |
@AlexBVolcy thanks for pointing it out, the reason i force-push it is because the PR is based upon a very old version so i did I will try to use merge back from |
@@ -261,6 +261,11 @@ func (l *AgmaLogger) LogVideoObject(event *analytics.VideoObject) { | |||
l.bufferCh <- data | |||
} | |||
|
|||
func (l *AgmaLogger) Shutdown() { |
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.
Is it possible to add tests to cover these lines
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.
@AlexBVolcy updated the unit test for it
@@ -85,6 +85,12 @@ func (f *FileLogger) LogNotificationEventObject(ne *analytics.NotificationEvent) | |||
f.Logger.Flush() | |||
} | |||
|
|||
// Shutdown the logger | |||
func (f *FileLogger) Shutdown() { |
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.
Can you add test to cover these line?
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.
@AlexBVolcy updated unit test for it
@@ -85,6 +85,12 @@ func (f *FileLogger) LogNotificationEventObject(ne *analytics.NotificationEvent) | |||
f.Logger.Flush() | |||
} | |||
|
|||
// Shutdown the logger | |||
func (f *FileLogger) Shutdown() { | |||
// clear all pending buffered data in case there is any |
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.
Just to follow the same pattern of the agma module, should we glog.Infof
?
88 // Shutdown the logger
89 func (f *FileLogger) Shutdown() {
90 // clear all pending buffered data in case there is any
+ glog.Infof("[FileLogger] Shutdown, trying to flush buffer")
91 f.Logger.Flush()
92 }
analytics/filesystem/file_module.go
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.
there is no additional args to template the log message, so glog.Info
is sufficient.
@zhongshixi Hey! Just checking in on the status of this PR? I want to be clear that the code coverage comments that I left aren't critical to be implemented for approval as those |
@AlexBVolcy thanks for the update, i am trying to see if i can really do it without introducing too much hassles, i will give you an update on the PR before EOW. i have urgent task to deal with this week for my company so sorry for the delay |
still working on it |
@AlexBVolcy have added some unit test according to your requests, let me know if they look good |
cc @bsardo |
func (mw *MockLogger) Debug(v ...interface{}) { | ||
mw.Called(v) | ||
} | ||
|
||
func (mw *MockLogger) Flush() { |
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.
Nitpick: Could you update the name of this variable to be ml
?
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.
fixed
Just like it was done in the
and
|
@guscarreon |
analytics/filesystem/file_module.go
Outdated
@@ -93,6 +94,7 @@ func (f *FileLogger) LogNotificationEventObject(ne *analytics.NotificationEvent) | |||
// Shutdown the logger | |||
func (f *FileLogger) Shutdown() { | |||
// clear all pending buffered data in case there is any | |||
gglog.Info("[FileLogger] Shutdown, trying to flush buffer") |
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.
Nitpick: can we reference this library as glog
as it's done in other parts of the code?
analytics/filesystem/file_module.go
Outdated
@@ -5,6 +5,7 @@ import ( | |||
"fmt" | |||
|
|||
"github.com/chasex/glog" | |||
gglog "github.com/golang/glog" |
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.
Nitpick: can we reference this library as glog
as it's done in other parts of the code?
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.
we have two glogs here
the code uses two glogs and the existing implementation uses glog
to refer github.com/chasex/glog
github.com/chasex/glog
github.com/golang/glog
if we use glog
to refer to github.com/golang/glog
, then we have to name "github.com/chasex/glog" to gglog
or other proper name.
let me know your thought on it
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.
It seems like github.com/chasex/glog
last commit was 8 years ago and we should probably move on to use github.com/golang/glog
. If it gets complicated and it's too far out of the scope of this PR, I'm ready to approve. If we don't fix it, it'd be desirable to create an issue for later fix. Thank you for your updates @zhongshixi
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.
i agree, i do not think it is actually complicated. let me change it so you can take a another look
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.
@guscarreon take another look, i aliased github.com/chasex/glog
as clog
so i do not change the critical implementation, the module now uses glog
to output log information
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.
LGTM
@zhongshixi sorry I'm coming in a bit late here. I was about to merge this but I noticed that we are introducing another logging library |
@bsardo i am not introducing a new log, i am simply renaming the existing library you could refer to this comment chain for details |
Ah gotcha. Thanks for the clarification. |
Problem
Solution
Shutdown()
so different analytic module could implement their own way of shutting down their module, if a module does not require a graceful shutdown, then just provide no-op implementation