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.procstat): Add child level tag #16105

Open
wants to merge 14 commits into
base: master
Choose a base branch
from

Conversation

tguenneguez
Copy link
Contributor

@tguenneguez tguenneguez commented Oct 29, 2024

Summary

Add tag for children process to be able to have information by level

Checklist

  • No AI generated code was used in this PR

Related issues

resolves #16104

@telegraf-tiger telegraf-tiger bot added area/procstat feat Improvement on an existing feature such as adding a new setting/mode to an existing plugin plugin/input 1. Request for new input plugins 2. Issues/PRs that are related to input plugins labels Oct 29, 2024
Copy link
Member

@DStrand1 DStrand1 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 PR! I have one code question, but also does this close issue #16104? If so could you update the PR description to close the issue? Thanks!

@@ -202,6 +202,7 @@ func (f *Filter) ApplyFilter() ([]processGroup, error) {
tags[k] = v
}
tags["parent_pid"] = strconv.FormatInt(int64(p.Pid), 10)
tags["child_level"] = strconv.FormatInt(int64(depth), 10)
Copy link
Member

Choose a reason for hiding this comment

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

I think this should be a configuration option since it is a new tag

Copy link
Member

Choose a reason for hiding this comment

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

I agree as it will also likely produce high cardinality. How about adding this as a field instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think the cardinality is higher on the parent_pid field so this change is less impactful than one might think.

Copy link
Member

Choose a reason for hiding this comment

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

In any case, we cannot add a new tag unconditionally...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, I understand your point of view.
What option would you suggest to add this tag?
Is there a naming rule?
It also means that for each plugin each time new tags are added, an option is needed. Is this likely to create plugins with long configurations?
We could put:
tag_child_level.
If not defined, the tag is not added.
If tag_child_level=toto then the level is added in the tag "toto"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

up ? ;-)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think this should be a configuration option since it is a new tag
@DStrand1 Have you a name recommanded for activate new tag ?

Copy link
Member

Choose a reason for hiding this comment

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

[...] It also means that for each plugin each time new tags are added, an option is needed. Is this likely to create plugins with long configurations? [...]

That's why we prefer "lists" of what to add instead of boolean options. This way we have one option with many potential values. For this plugin there actually already is the tag_with option, so why don't you just add the child-level there?
Check the code for how this option is used to conditionally add tags...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks.
I tryed, but I have 2 errors that I doesn't understand ...

@DStrand1 DStrand1 self-assigned this Oct 29, 2024
@tguenneguez
Copy link
Contributor Author

Thanks for the PR! I have one code question, but also does this close issue #16104?

Yes it's the same. The issue is in the PR description.

What do you understand exactly by :

If so could you update the PR description to close the issue? Thanks!

@srebhan
Copy link
Member

srebhan commented Dec 9, 2024

@tguenneguez the error means that the sample.conf file does not match what is in the README.md.

You need to add the option documentation to sample.conf and then run make docs to embed that sample.conf file into the README.md. This is done to ensure that the config options documented in the README do match the ones in the example config produced by Telegraf...

@tguenneguez
Copy link
Contributor Author

tguenneguez commented Dec 9, 2024

@tguenneguez the error means that the sample.conf file does not match what is in the README.md.

You need to add the option documentation to sample.conf and then run make docs to embed that sample.conf file into the README.md. This is done to ensure that the config options documented in the README do match the ones in the example config produced by Telegraf...

Thank you very much, I don't know how you found the cause, if you can tell me I will be more independent next time ;-)

@tguenneguez
Copy link
Contributor Author

I understand my error ;-)
tag_with is for procstat metric and not for procstat_lookup metrics
Also, the level is not internal information for process, but additionnal information of grouping procstat_lookup...

So I thing it will be great to have possibility to generate "procstat_lookup" for different level...

@telegraf-tiger
Copy link
Contributor

Download PR build artifacts for linux_amd64.tar.gz, darwin_arm64.tar.gz, and windows_amd64.zip.
Downloads for additional architectures and packages are available below.

⚠️ This pull request increases the Telegraf binary size by 1.79 % for linux amd64 (new size: 273.6 MB, nightly size 268.8 MB)

📦 Click here to get additional PR build artifacts

Artifact URLs

DEB RPM TAR GZ ZIP
amd64.deb aarch64.rpm darwin_amd64.tar.gz windows_amd64.zip
arm64.deb armel.rpm darwin_arm64.tar.gz windows_arm64.zip
armel.deb armv6hl.rpm freebsd_amd64.tar.gz windows_i386.zip
armhf.deb i386.rpm freebsd_armv7.tar.gz
i386.deb ppc64le.rpm freebsd_i386.tar.gz
mips.deb riscv64.rpm linux_amd64.tar.gz
mipsel.deb s390x.rpm linux_arm64.tar.gz
ppc64el.deb x86_64.rpm linux_armel.tar.gz
riscv64.deb linux_armhf.tar.gz
s390x.deb linux_i386.tar.gz
linux_mips.tar.gz
linux_mipsel.tar.gz
linux_ppc64le.tar.gz
linux_riscv64.tar.gz
linux_s390x.tar.gz

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.

@tguenneguez thanks for the update. I do have some comments. The most important one is to only add the child_level tag if the option is actually set. The code adds it unconditionally still.

Comment on lines +67 to +71
## cmdline -- full commandline
## pid -- ID of the process
## ppid -- ID of the process' parent
## status -- state of the process
## user -- username owning the process
Copy link
Member

Choose a reason for hiding this comment

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

Why are you changing the indentation level here?

Comment on lines +80 to +81
## tag only available for procstat_lookup
## level -- level of the process filtering
Copy link
Member

Choose a reason for hiding this comment

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

Could you please indent the option similar to the ones above?

Comment on lines -38 to +42
## cmdline -- full commandline
## pid -- ID of the process
## ppid -- ID of the process' parent
## status -- state of the process
## user -- username owning the process
## cmdline -- full commandline
## pid -- ID of the process
## ppid -- ID of the process' parent
## status -- state of the process
## user -- username owning the process
Copy link
Member

Choose a reason for hiding this comment

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

See my comments in README.md...

@@ -201,10 +200,11 @@ func (f *Filter) ApplyFilter() ([]processGroup, error) {
for k, v := range group.tags {
tags[k] = v
}
tags["parent_pid"] = strconv.FormatInt(int64(p.Pid), 10)
Copy link
Member

Choose a reason for hiding this comment

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

Why are you removing this here?

@@ -180,7 +179,7 @@ func (f *Filter) ApplyFilter() ([]processGroup, error) {

matched = append(matched, p)
}
result = append(result, processGroup{processes: matched, tags: g.tags})
result = append(result, processGroup{processes: matched, tags: g.tags, level: 0})
Copy link
Member

Choose a reason for hiding this comment

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

level will be 0 without explicitly setting it. Please revert to the previous code.

Comment on lines +417 to +425
tags := map[string]interface{}{
"pid_count": count,
"running": len(running),
"result_code": 0,
}
// Add lookup statistics-metric
acc.AddFields(
"procstat_lookup",
map[string]interface{}{
"pid_count": count,
"running": len(running),
"result_code": 0,
},
tags,
Copy link
Member

Choose a reason for hiding this comment

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

Please revert as this has nothing to do with your feature I think.

@@ -494,7 +513,7 @@ func (p *Procstat) findSupervisorUnits() ([]PidsTags, error) {
if err != nil {
return nil, fmt.Errorf("getting children for %d failed: %w", pid, err)
}
tags := map[string]string{"pattern": p.Pattern, "parent_pid": p.Pattern}
tags := map[string]string{"pattern": p.Pattern, "parent_pid": p.Pattern, "child_level": p.Pattern}
Copy link
Member

Choose a reason for hiding this comment

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

You need to conditionally add the child_level here!

@@ -103,6 +103,15 @@ Debug](https://grokdebug.herokuapp.com) application quite useful!
## %{COMBINED_LOG_FORMAT} (access logs + referrer & agent)
grok_patterns = ["%{COMBINED_LOG_FORMAT}"]

## This is a list of patterns to count the given log file(s) for.
Copy link
Member

Choose a reason for hiding this comment

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

Please move changes to the GROK parser to a separate PR!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/procstat feat Improvement on an existing feature such as adding a new setting/mode to an existing plugin plugin/input 1. Request for new input plugins 2. Issues/PRs that are related to input plugins
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feat(inputs.procstat): Add child level tag
3 participants