-
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
daemon: Simplify k8sErrorHandler time management #1899
Conversation
Your PR description says Edit: heh, I commented on this right as you added the |
gah, I just realised I need separate instances of the Once object. I shall fix this and ping again. Ignore this PR for now! |
d726c9d
to
54e174c
Compare
@ianvernon ha, yeah, that's what I get for being distracted I have updated it. |
54e174c
to
9bc884d
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.
When an error appears multiple times, for example every second, how are you skipping it? It seems that you're always incrementing the unmuteDeadline
daemon/k8s_watcher.go
Outdated
// k8sErrMsg stores a timer for each k8s error message received | ||
k8sErrMsg = map[string]*time.Timer{} | ||
// k8sErrMsgMU guards additions and removals to k8sErrMsg | ||
k8sErrMsgMU lock.Mutex |
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've read it somewhere but I can't find it now there is a convention that defines the mutexes should be right before the variables they are protecting.
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.
Seems like a good idea anyway. Done.
daemon/k8s_watcher.go
Outdated
} | ||
|
||
k8sErrMsg[errstr] = unmuteDeadline.Add(k8sErrLogTimeout) | ||
return unmuteDeadline |
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 you wanted to do this because Add
doesn't add the time to the receiver, it returns a new value. For this reason you should return the assigned value.
k8sErrMsg[errstr] = unmuteDeadline.Add(k8sErrLogTimeout)
// k8sErrMsg[errstr] == unmuteDeadline // since it's false we need to return the assigned value
return k8sErrMsg[errstr]
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 had meant to return the original, looked up value but my logic was wrong as you mentioned above. I wasn't doing the rate-limiting correctly. This is fixed up.
daemon/k8s_watcher.go
Outdated
} | ||
return | ||
|
||
case (strings.Contains(errstr, "Unable to decode an event from the watch stream: unable to decode watch event") || |
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't you replace the ||
with a ,
?
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 didn't realise I could do that! done.
9bc884d
to
90365a0
Compare
ok, @aanm now it has a test! It's probably correct :/ |
90365a0
to
2496a54
Compare
@tgraf I added a release note about the only user-visible change. Is this what you had in mind? |
2496a54
to
f0ed2a6
Compare
@aanm fixed the "connection refused" limiting, it now has the same rate-limit as the other special cases. |
daemon/k8s_watcher.go
Outdated
} | ||
return | ||
|
||
case strings.Contains(errstr, "Failed to list *v1.NetworkPolicy: the server could not find the requested resource"): | ||
if k8sErrorUpdateCheckUnmuteTime(errstr, now) { |
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.
You can remove this if
since we want this message to be printed as it occurs.
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
f0ed2a6
to
b295322
Compare
b295322
to
66444b0
Compare
This function was difficult to follow and had side-effects that happened only once because of the code flow. In one case, this was an accident. The new code is more explicit about what is a one-time side-effect and what isn't. Signed-off-by: Ray Bejjani <ray@covalent.io>
66444b0
to
128632c
Compare
This function is hard :(
I tried to keep the same behaviour as before, but also tried to be very explicit about each scenario (to the point of repeating code).
time.Time
is a struct and not a uint64, which makes this assertion less true :/