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

[extension/sumologicextension] Replace go-ps with gopsutil #36358

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions extension/sumologicextension/extension.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import (

"github.com/Showmax/go-fqdn"
"github.com/cenkalti/backoff/v4"
ps "github.com/mitchellh/go-ps"
"github.com/shirou/gopsutil/v4/host"
"github.com/shirou/gopsutil/v4/process"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/component/componenttest"
"go.opentelemetry.io/collector/config/confighttp"
Expand Down Expand Up @@ -711,16 +711,20 @@ var sumoAppProcesses = map[string]string{
"kafka-server-start.sh": "kafka", // Need to test this, most common shell wrapper.
}

func filteredProcessList() ([]string, error) {
func filteredProcessList(ctx context.Context) ([]string, error) {
Copy link
Contributor

@chan-tim-sumo chan-tim-sumo Nov 13, 2024

Choose a reason for hiding this comment

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

is there a reason why context was added here? because what this function basically do is loop through the the map above this ^^

only asking cause i'm working on the extension that have this change included (removing go-ps and using gopsutil) 😆

#35622

Copy link
Author

Choose a reason for hiding this comment

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

It's just to allow context values to be propagated to ExeWithContext, which calls other functions that can make use of those values further down the call stack. At the moment, those values are not being passed, however.

var pl []string

p, err := ps.Processes()
p, err := process.Processes()
if err != nil {
return pl, err
return nil, fmt.Errorf("error performing process discovery: %s", err)
}

for _, v := range p {
e := strings.ToLower(v.Executable())
execName, err := v.ExeWithContext(ctx)
if err != nil {
return nil, fmt.Errorf("error performing process discovery: %s", err)
}
e := strings.ToLower(execName)
if a, i := sumoAppProcesses[e]; i {
pl = append(pl, a)
}
Expand All @@ -729,12 +733,12 @@ func filteredProcessList() ([]string, error) {
return pl, nil
}

func discoverTags() (map[string]any, error) {
func discoverTags(ctx context.Context) (map[string]any, error) {
t := map[string]any{
"sumo.disco.enabled": "true",
}

pl, err := filteredProcessList()
pl, err := filteredProcessList(ctx)
if err != nil {
return t, err
}
Expand Down Expand Up @@ -770,7 +774,7 @@ func (se *SumologicExtension) updateMetadataWithHTTPClient(ctx context.Context,
td := map[string]any{}

if se.conf.DiscoverCollectorTags {
td, err = discoverTags()
td, err = discoverTags(ctx)
if err != nil {
return err
}
Expand Down
1 change: 0 additions & 1 deletion extension/sumologicextension/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ go 1.22.0
require (
github.com/Showmax/go-fqdn v1.0.0
github.com/cenkalti/backoff/v4 v4.3.0
github.com/mitchellh/go-ps v1.0.0
github.com/shirou/gopsutil/v4 v4.24.10
github.com/stretchr/testify v1.9.0
go.opentelemetry.io/collector/component v0.113.1-0.20241115165626-8b99b8023ca3
Expand Down
2 changes: 0 additions & 2 deletions extension/sumologicextension/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading