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

feat(inputs.prometheus): pod_annotation_template and pod_label_template #10946

Conversation

imranismail
Copy link
Contributor

@imranismail imranismail commented Apr 7, 2022

Required for all PRs:

Closes 10945

@imranismail imranismail changed the title Add pod_annotation_template and pod_label_template feat(inputs.prometheus): pod_annotation_template and pod_label_template Apr 7, 2022
@imranismail imranismail force-pushed the chore/10945-pod-label-annotation-template branch 25 times, most recently from 7192d18 to 61b53d5 Compare April 7, 2022 20:56
@sspaink sspaink added the ready for final review This pull request has been reviewed and/or tested by multiple users and is ready for a final review. label Apr 27, 2022
@sspaink
Copy link
Contributor

sspaink commented Apr 27, 2022

@imranismail thank you for the pull request, could you resolve the merge conflict?

Comment on lines 60 to 61
# pod_label_template = "pod.label/{{ . }}"
# pod_annotation_template = "pod.annotation/{{ . }}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be simpler to make these prefixes instead of templates? That way users wouldn't need to worry about template syntax when they're prepending static strings.

@imranismail imranismail force-pushed the chore/10945-pod-label-annotation-template branch from fb3251e to 4dbdd47 Compare May 18, 2022 03:29
@telegraf-tiger
Copy link
Contributor

Copy link
Member

@srebhan srebhan 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 your contribution @imranismail! I have some comments and second @reimda's question regarding only using a prefix string instead of a whole template. Furthermore, I suggest to manipulate the tag-key at the origin instead of looping the logic though the code.

Comment on lines +57 to +61
## Pod label & annotation tag template
## Default is "{{ . }}"
## Useful to glob match labels & annotations in "tagexclude" or "taginclude"
# pod_label_template = "{{ . }}"
# pod_annotation_template = "{{ . }}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it really necessary to make this a template or can we get away with defining a prefix? I'm asking because this adds complexity that might not be required and furthermore it's not completely intuitive to use a template, usually use to generate stuff, for parsing...

Comment on lines +195 to +196
+ pod_label_template = 'pod.label/{{ . }}'
+ pod_annotation_template = 'pod.annotation/{{ . }}'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above, we could cover this with just

  pod_label_prefix = 'pod.label'
  pod_annotation_prefix = 'pod.annotation'

extraTags[tagName] = buffer.String()
extraTags[tagName] = Tag{Value: buffer.String()}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this necessary?

Comment on lines +371 to +380
tags := map[string]Tag{}
tags["pod_name"] = Tag{Value: pod.Name}
tags["namespace"] = Tag{Value: pod.Namespace}
// add annotation as metrics tags
tags := pod.Annotations
if tags == nil {
tags = map[string]string{}
for k, v := range pod.Annotations {
tags[k] = Tag{Value: v, Template: p.podAnnotationTmpl}
}
tags["pod_name"] = pod.Name
tags["namespace"] = pod.Namespace
// add labels as metrics tags
for k, v := range pod.Labels {
tags[k] = v
tags[k] = Tag{Value: v, Template: p.podLabelTmpl}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it be better to directly apply the modification here instead of looping this through all the code?

@srebhan srebhan self-assigned this May 20, 2022
@reimda reimda added waiting for response waiting for response from contributor and removed ready for final review This pull request has been reviewed and/or tested by multiple users and is ready for a final review. labels Jun 6, 2022
@reimda
Copy link
Contributor

reimda commented Jun 6, 2022

Hi @imranismail are you able to work on the changes @srebhan and I requested? Thanks!

@telegraf-tiger telegraf-tiger bot removed the waiting for response waiting for response from contributor label Jun 6, 2022
@sspaink sspaink added the waiting for response waiting for response from contributor label Sep 28, 2022
@telegraf-tiger
Copy link
Contributor

Hello! I am closing this issue due to inactivity. I hope you were able to resolve your problem, if not please try posting this question in our Community Slack or Community Page. Thank you!

@telegraf-tiger telegraf-tiger bot closed this Oct 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
waiting for response waiting for response from contributor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Prefix pod labels and annotations scraped by prometheus input plugin
4 participants