-
Notifications
You must be signed in to change notification settings - Fork 3.1k
[k8sprocessor] Add ability to associate metadata tags using pod UID rather than just IP #2199
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
[k8sprocessor] Add ability to associate metadata tags using pod UID rather than just IP #2199
Conversation
d90e3af
to
44c8f1e
Compare
Codecov Report
@@ Coverage Diff @@
## main #2199 +/- ##
=======================================
Coverage 90.45% 90.46%
=======================================
Files 397 397
Lines 19563 19614 +51
=======================================
+ Hits 17695 17743 +48
- Misses 1406 1408 +2
- Partials 462 463 +1
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
… rather than just IP Signed-off-by: Patryk Matyjasek <[email protected]>
44c8f1e
to
9725609
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.
Looks really nice!
return | ||
} | ||
} | ||
c.Pods[pod.Status.PodIP] = newPod |
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.
Do I get it right that the same pod will exist twice in the list, once keyed by the IP and once by the ID?
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 actually discussed this with @pmatyjasek-sumo while he was working on the extension :) Having a single map and two references to the pod just makes the things easier, since this are different domains that have no risk of conflicts
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.
@jpkrohling as @pmm-sumo mentioned we had some discussion on that and we decided that it should be ok if 2 keys from map will point to the same reference. With this we avoid to use two loops to iterate through two lists of Pods (one by IP and second by UID)
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.
Sure, that's fine, but you might want to add the current size of this map in a metric somewhere: this is the kind of data that can easily explode in terms of number of elements. It's not unusual to have tens of thousands of pods in a given cluster, so, having this info would help people running the processor to identify any possible memory issue.
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.
Was this done? If you don't to do it in this PR, create an issue to track this.
Co-authored-by: Juraci Paixão Kröhling <[email protected]>
- Add more tests for added code - Refactor Association table - Remove unnecessary annonymous function
…static checks (#2199) Signed-off-by: Bogdan Drutu <[email protected]>
This PR was marked stale due to lack of activity. It will be closed in 7 days. |
What's the current state of this PR? Is this ready to be reviews again? |
@jpkrohling yes it is ready for review. I've addressed previous comments in latest commit. |
I have only one concern about the size the map might get, as it grows twice the rate of the number of pods being used. I believe the size of this map should be part of the set of metrics for the collector, as it would help correlate a possible increase in memory usage with the number of items in this map. |
@jpkrohling that is a good idea, I'll put this metric soon |
otelsvc/k8s/pod_table_size Signed-off-by: Patryk Matyjasek <[email protected]>
I've updated PR |
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, just a minor comment about the metrics. If you don't want to work on them here, let me know and I'll approve the PR once the tracking issue is created.
mPodsUpdated = stats.Int64("otelsvc/k8s/pod_updated", "Number of pod update events received", "1") | ||
mPodsAdded = stats.Int64("otelsvc/k8s/pod_added", "Number of pod add events received", "1") | ||
mPodsDeleted = stats.Int64("otelsvc/k8s/pod_deleted", "Number of pod delete events received", "1") | ||
mPodTableSize = stats.Int64("otelsvc/k8s/pod_table_size", "Size of table containing pod info", "1") |
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.
Looks good, but is there a list of those metrics somewhere, telling users of this processor what they actually mean? Also, it would be a good opportunity to:
- s/otelsvc/otelcol
- replace the slashes by underscores, as it seems to be the standard at other metrics
If you don't want to do them here, feel free to open a tracking issue.
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.
@jpkrohling I've created an issue and also I'll start work on it #2322
@tigrannajaryan this is the PR we discussed during Log SIG yesterday. It will allow us to tag logs with K8s metadata |
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 with a couple of minor comments.
My understanding is that if a user does not update config to specify the new pod association rules, the processor will continue to work with connection/attribute IP, right?
id: string(pod.UID), | ||
name: pod.Name, | ||
ts: time.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.
nit: looks very repetitive. could be extracted into a 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.
good catch
processor/k8sprocessor/processor.go
Outdated
|
||
// If IP is still not available by this point, nothing can be tagged here. Return. | ||
if podIP == "" { | ||
podAttributes := k8sPodAssociationFromAttributes(ctx, resource.Attributes(), kp.podAssociations) |
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 another attrsToAdd := kp.getAttributesForPod()
below and this one is named podAttributes
as well. This could be a bit confusing to follow. IIRC, podAttributes
here is actually a map of pod identifiers, such as IP, UID, etc, right? If so, let's name it podIdentifiers
or something similar.
Yes it will work as previous |
processor/k8sprocessor/doc.go
Outdated
// If a match is found, the cached metadata is added to the data as resource attributes. | ||
// extracted metadata to the relevant spans, metrics and logs. The processor uses the kubernetes API to discover all pods | ||
// running in a cluster, keeps a record of their IP addresses, pod UIDs and interesting metadata. | ||
// The rules for associating the source record with specific Pod Metadata are configured via "pod_association" key. |
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.
"source record" is not an entirely clear term. Does this refer to the telemetry in pdata that is passing through the processor?
processor/k8sprocessor/doc.go
Outdated
// It represents a list of rules that are executed in order until the first one is able to do the match. | ||
// Each rule is specified as a pair of from (representing the rule type) and name (representing the extracted key name). | ||
// Following rule types are available: | ||
// from: "labels" - takes the attribute from resource attributes (the value can contain either IP address or Pod UID) |
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.
Does "resource" here refer to pdata.Resource or to the pod? Is this pdata.Resource attributes or pod labels? I am confused by mixed usage of "labels" and "attributes" here.
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 I'll clarify that
Description:
Add ability to associate metadata tags in k8s processor using pod UID rather than just IP
Link to tracking Issue: #1146
Testing:
Unit tests
Documentation:
In-code comments