-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
add internal queue for kubernetes watcher updates #2123
Conversation
pkg/serializer/func_serializer.go
Outdated
|
||
// NewFuncSerializer returns a funcSerializer that will be used to execute | ||
// functions in the same order they are enqueued. | ||
func NewFuncSerializer(size uint) *funcSerializer { |
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.
exported func NewFuncSerializer returns unexported type *serializer.funcSerializer, which can be annoying to use
d9d27f9
to
bd4cad2
Compare
pkg/serializer/func_serializer.go
Outdated
|
||
// NewFuncSerializer returns a funcSerializer that will be used to execute | ||
// functions in the same order they are enqueued. | ||
func NewFuncSerializer(size uint) *funcSerializer { |
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.
s/size/queueSize/
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.
Done
pkg/serializer/func_serializer.go
Outdated
|
||
// NewFuncSerializer returns a funcSerializer that will be used to execute | ||
// functions in the same order they are enqueued. | ||
func NewFuncSerializer(size uint) *funcSerializer { |
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 would call the whole thing FunctionQueue
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.
Done
pkg/serializer/func_serializer.go
Outdated
// The waitFunc will be executed with the number of times `f` had returned an | ||
// error, in case `f` returns an error. waitFunc should return either true or | ||
// false depending if `f` should be executed again or not. | ||
func (fs *funcSerializer) Enqueue(f func() error, waitFunc func(int) bool) { |
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.
Please define a documented type for waitFunc
which explains what int
will be and what it has to return
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.
Done.
pkg/serializer/func_serializer.go
Outdated
// amount of functions queued, this function can block until the function | ||
// serializer is ready to receive more requests. In case `f` returns an error, | ||
// `f` won't be executed again. | ||
func (fs *funcSerializer) EnqueueOrDie(f func() error) { |
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 is not needed, just expose the NoRetry
function
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.
Done.
pkg/serializer/func_serializer.go
Outdated
} | ||
|
||
// Run starts the funcSerializer internal worker. It will be stopped once | ||
// `stopCh` is closed or receives a value. |
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 is very misleading, stopped
indicates that this is a go routine which it is not. Why not just spawn the routine in NewFuncSerializer
? I would also store the stop channel in the funcSerializer
struct and provide a Stop()
API so the channel is hidden.
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.
Done
pkg/serializer/func_serializer.go
Outdated
noRetry = func(i int) bool { return false } | ||
) | ||
|
||
type funcProp struct { |
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.
Call this queuedFunction
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.
Done
pkg/serializer/func_serializer.go
Outdated
} | ||
|
||
type funcSerializer struct { | ||
funcs chan funcProp |
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.
Call this queue
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.
Done
pkg/serializer/func_serializer.go
Outdated
default: | ||
} | ||
retries++ | ||
if err := f.f(); err != nil { |
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 want to log these errors, right?
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 don't think it's a good idea to do it here since this might be used on different places of the code. When calling the Enqueue
function it should be done as follow:
serNodes.Enqueue(func() error {
err := d.updateK8sNodeV1(oldK8sNode, newK8sNode)
if err != nil {
log.Debugf("this is a dedicated k8s function that failed")
}
return err
}, serializer.NoRetry)
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.
OK, that's fine, but then document that the error will only be used to determine failure if non-nil and that it is the responsibility of the function to log the error.
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.
Done.
bd4cad2
to
1952aba
Compare
pkg/serializer/func_serializer.go
Outdated
|
||
// NewFunctionQueue returns a functionQueue that will be used to execute | ||
// functions in the same order they are enqueued. | ||
func NewFunctionQueue(queueSize uint) *functionQueue { |
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.
exported func NewFunctionQueue returns unexported type *serializer.functionQueue, which can be annoying to use
pkg/serializer/func_serializer.go
Outdated
|
||
// NewFunctionQueue returns a functionQueue that will be used to execute | ||
// functions in the same order they are enqueued. | ||
func NewFunctionQueue(queueSize uint) *functionQueue { |
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.
exported func NewFunctionQueue returns unexported type *serializer.functionQueue, which can be annoying to use
1952aba
to
8d73ae9
Compare
|
||
// NewFunctionQueue returns a functionQueue that will be used to execute | ||
// functions in the same order they are enqueued. | ||
func NewFunctionQueue(queueSize uint) *functionQueue { |
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.
exported func NewFunctionQueue returns unexported type *serializer.functionQueue, which can be annoying to use
8d73ae9
to
a46e3ed
Compare
pkg/serializer/func_queue.go
Outdated
package serializer | ||
|
||
var ( | ||
// NoRetry always returns false independently the number of retries. |
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.
independently of the number
pkg/serializer/func_queue.go
Outdated
NoRetry = func(int) bool { return false } | ||
) | ||
|
||
// WaitFunc will be executed with the number of times `f` had returned an |
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.
f is undocumented so I would rewrite this as follows:
WaitFunc will be invoked each time a queued function has returned an error. nRetries will be set to the number of consecutive execution failures that have occurred so far. The WaitFunc must return true if execution must be retried or false if the function must be returned from the queue.
Add function serializer that allows functions to be executed in order with the ability to retry the execution in case of failure. Signed-off-by: André Martins <andre@cilium.io>
Signed-off-by: André Martins <andre@cilium.io>
a46e3ed
to
1543401
Compare
Summary of changes:
Created a function serializer that will execute the functions the same order as they were received. This will allow us to retry those same functions in case of a failure.
Fixes: #1966