Skip to content
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

Merged
merged 6 commits into from
Dec 12, 2019

Conversation

linalinn
Copy link
Contributor

@linalinn linalinn commented Dec 6, 2019

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:

  • Signed CLA.
  • Associated README.md updated.
  • Has appropriate unit tests.

Copy link
Contributor

@danielnelson danielnelson left a 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)
Copy link
Contributor

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"`
Copy link
Contributor

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 {
Copy link
Contributor

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 = []
Copy link
Contributor

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 {
Copy link
Contributor

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 {

@danielnelson danielnelson added area/k8s feat Improvement on an existing feature such as adding a new setting/mode to an existing plugin labels Dec 6, 2019
@linalinn
Copy link
Contributor Author

linalinn commented Dec 9, 2019

If fixed the problems you mentioned.

@linalinn linalinn requested a review from danielnelson December 9, 2019 10:51
@danielnelson danielnelson added this to the 1.14.0 milestone Dec 12, 2019
@danielnelson danielnelson merged commit f79ba10 into influxdata:master Dec 12, 2019
athoune pushed a commit to bearstech/telegraf that referenced this pull request Apr 17, 2020
idohalevi pushed a commit to idohalevi/telegraf that referenced this pull request Sep 29, 2020
arstercz pushed a commit to arstercz/telegraf that referenced this pull request Mar 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/k8s feat Improvement on an existing feature such as adding a new setting/mode to an existing plugin
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants