-
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
* Add more descriptive in-code comments for PodAssociation, * Simplify PodAssociation logic * Update tests Signed-off-by: Patryk Matyjasek <[email protected]>
@tigrannajaryan I've addressed Your comments. Please check if it is clean 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.
Thank you @pmatyjasek-sumo
I think I understand the code a bit bitter, but would like a bit more clarifications if possible.
) | ||
|
||
// k8sPodAssociationFromAttributes extracts IP and pod UID from attributes | ||
func k8sPodAssociationFromAttributes(ctx context.Context, attrs pdata.AttributeMap, associations []kube.Association) map[string]string { |
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.
+1. Or alternatively remove that case from this function and handle it separately.
processor/k8sprocessor/config.go
Outdated
// Allowed values are connection and labels | ||
From string `mapstructure:"from"` | ||
|
||
// Name represents the name of the association. |
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.
In the answer below you wrote:
name (representing the extracted key name).
If "name" is extracted key name (which I think means the attribute name if I understand correctly) then what is "name of association"?
Co-authored-by: Tigran Najaryan <[email protected]>
* add custom type PodIdentifier * fix tags adding behavior * update comments * refactor pod association extracting Signed-off-by: Patryk Matyjasek <[email protected]>
@tigrannajaryan I've provided some refactor to IDs extraction and association metadata tags. I hope it is clean now |
processor/k8sprocessor/doc.go
Outdated
// - from: connection | ||
// name: ip | ||
// - from: labels | ||
// name: 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.
I may be wrong but if I understand correctly we cannot expect to see "pod_uid" as a Resource attribute in normal use cases. Let's use an attribute name that is realistic, even if it is just an example.
processor/k8sprocessor/processor.go
Outdated
|
||
// If IP is still not available by this point, nothing can be tagged here. Return. | ||
if podIP == "" { | ||
podIdentifierLabel, podIdentifierValue := extractPodIds(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.
I think it is best not to use the term "label" in this context. OpenTelemetry's vocabulary for Resources is "attribute name" or "attribute key". I think the following would be clear:
podIdentifierLabel, podIdentifierValue := extractPodIds(ctx, resource.Attributes(), kp.podAssociations) | |
podIdentifierKey, podIdentifierValue := extractPodIds(ctx, resource.Attributes(), kp.podAssociations) |
@pmatyjasek-sumo yes, it looks much better, thanks. Please address the remaining comments. |
* Additional comments, * Rename methods, * fix misspells Signed-off-by: Patryk Matyjasek <[email protected]>
@tigrannajaryan please take a 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.
LGTM.
Thank you @pmatyjasek-sumo
…rnal/tools (#2199) * Bump github.com/golangci/golangci-lint in /internal/tools Bumps [github.com/golangci/golangci-lint](https://github.com/golangci/golangci-lint) from 1.41.1 to 1.42.0. - [Release notes](https://github.com/golangci/golangci-lint/releases) - [Changelog](https://github.com/golangci/golangci-lint/blob/master/CHANGELOG.md) - [Commits](golangci/golangci-lint@v1.41.1...v1.42.0) --- updated-dependencies: - dependency-name: github.com/golangci/golangci-lint dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <[email protected]> * Auto-fix go.sum changes in dependent modules Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: MrAlias <[email protected]>
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