-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
Kubernetes input plugin PodLabels #6764
Kubernetes input plugin PodLabels #6764
Conversation
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.
Thanks for the pull request, I think we just need a few tweaks.
|
||
for i := 0; i < len(podapi.Items); i++ { | ||
var meta PodInfo | ||
err = json.Unmarshal(podapi.Items[i]["metadata"], &meta) |
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.
Add the PodInfo to the Podlist object, then you can skip this second phase of parsing. Keep all the labels at this point and we can see if they match the filter later when we add the tags.
|
||
type PodInfo struct { | ||
Name string `json:"name"` | ||
NameSpace string `json:"namespace"` |
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.
Nitpick: Namespace
|
||
import "encoding/json" | ||
|
||
type Podlist 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.
Suggest naming this Pods
since this contains a list.
@@ -42,6 +48,11 @@ var sampleConfig = ` | |||
## OR | |||
# bearer_token_string = "abc_123" | |||
|
|||
# Labels to include and exclude | |||
# An empty array for include and exclude will include all labels | |||
label_include = [] |
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 deviates from other existing plugins, but in order to avoid adding unwanted data I think we need to default to exclude all labels. In order to make this work, initialize the exclude filter in the init()
function "*"
:
func init() {
inputs.Add("kubernetes", func() telegraf.Input {
return &Kubernetes{
LabelInclude: []string{},
LabelExclude: []string{"*"},
}
})
}
Then, comment out the default values here:
# label_include = []
# label_exclude = ["*"]
If a user defines them again like so it will still include all, this is okay:
label_include = []
label_exclude = []
@@ -209,6 +263,14 @@ func buildPodMetrics(summaryMetrics *SummaryMetrics, acc telegraf.Accumulator) { | |||
"container_name": container.Name, | |||
"pod_name": pod.PodRef.Name, | |||
} | |||
for i := range podInfo { |
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.
Use the named range variables: for _, info := range podInfo {
If fixed the problems you mentioned. |
By calling the Endpoint
/pods
i added a function that collects the Labels of all Pods and adds them to their tags.Required for all PRs: