-
Notifications
You must be signed in to change notification settings - Fork 39
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
fix(k8sprocessor): keep pod's services information up to date #710
fix(k8sprocessor): keep pod's services information up to date #710
Conversation
6b2b5dd
to
e64808c
Compare
} else { | ||
c.updatePodServices(pod) | ||
return pod, ok |
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 put it outside of if-else
@@ -380,6 +377,14 @@ func (c *WatchClient) extractPodAttributes(pod *api_v1.Pod) map[string]string { | |||
return tags | |||
} | |||
|
|||
func (c *WatchClient) updatePodServices(pod *Pod) { | |||
if c.Rules.ServiceName { | |||
if services := c.op.GetServices(pod.Name); len(services) > 0 { |
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.
if there is no services, we should set empty string or remove the attribute
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 for scenario when the service has been 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.
Out of curiosity. can we shorten it to just
pod.Attributes[c.Rules.Tags.ServiceName] = strings.Join(services, c.delimiter)
?
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.
According to the implementation, yes: https://cs.opensource.google/go/go/+/refs/tags/go1.19:src/strings/strings.go;l=430
I did not change it, because I was unsure if such way of coding is idiomatic in Go. But I also like it better.
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 go with it
105272f
to
aae8774
Compare
What do you think of doing this for all owner metadata? As in, we'd skip calculating owner metadata on Pod updates, and only calculate it in |
Actually, this is a question of "where do we draw the line". We can do this only for service data, only for owner metadata (including services) or even for all data. However, removing this feature completely would require some more changes. However, are you sure you mean only owner metadata? There is not that much owner metadata, so I don't think this would affect performance and memory usage. In terms of performance, are there any ready benchmarks or tools for making them? |
I'd like to do it for all owner metadata. Singling out Services is a bit arbitrary, and I think doing a write on every records as we are in this PR is going to be slower than calculating the tags on the fly. I'm actually not that concerned about performance - I primarily want to do this to simplify the code. We should check what the peformance impact is, but I don't expect it to be much either way.
There's some commented out benchmarks here:
Generally speaking, what you'd want is a test where we seed the client with, say, 1000 Pods and then benchmark |
I ran it against 1000 pods, like you suggested. Five consecutive runs before changes (current main):
Four consecutive runs after changes (I was sure I put 5 in here, but one got lost somehow...):
|
The benchmarks have been run on the newest commit (with added adding all owner metadata to a pod) |
Hm, so around 20% more CPU time per operation on average, it looks like. @SumoLogic/open-source-collection-team WDYT, is this worth the added reliability? Or should we try to keep the more efficient approach, and make it more complex to account for the Owner updates? |
20% is something. Will the more complex approach be much more effective? |
I'm sorry, I have made a mistake while running the benchmarks ( Current main:
HEAD~1 of this branch (update only services in
HEAD of this branch (update all owner metadata):
|
So more like 5-10%, then. |
7b94dcf
to
f66084c
Compare
Info about pod's metadata can arrive late, i.e. the service info can arrive after the pod has been marked as ready. This commit removes caching this information and updates it with every query instead. Translate all owner metadata
f66084c
to
e50f21f
Compare
Information about pod's services can arrive late, i.e. after the pod has been marked as ready. If that happens, the data won't be marked with this information until another update of that pod.
This PR changes this behavior - information about services is no longer cached and is recalculated every time when
GetPod
is called.This is a less intrusive solution for this problem - an alternative is to remove the whole
map[string]*Pod
fromWatchClient
and recalculate all the attributes every time.cc: @swiatekm-sumo