From a4cbb781159cb394fe01253e00c0ea421e0710b0 Mon Sep 17 00:00:00 2001 From: Eric Chlebek Date: Wed, 13 Nov 2024 11:43:31 -0700 Subject: [PATCH] [extension/sumologicextension] Replace go-ps with gopsutil go-ps is no longer maintained. Signed-off-by: Eric Chlebek --- extension/sumologicextension/extension.go | 20 ++++++++++++-------- extension/sumologicextension/go.mod | 1 - extension/sumologicextension/go.sum | 2 -- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/extension/sumologicextension/extension.go b/extension/sumologicextension/extension.go index 13904c184cdc..a29191cbc7cd 100644 --- a/extension/sumologicextension/extension.go +++ b/extension/sumologicextension/extension.go @@ -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" @@ -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) { 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) } @@ -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 } @@ -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 } diff --git a/extension/sumologicextension/go.mod b/extension/sumologicextension/go.mod index 18ff99e24c94..cf0ab4546f87 100644 --- a/extension/sumologicextension/go.mod +++ b/extension/sumologicextension/go.mod @@ -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.0 diff --git a/extension/sumologicextension/go.sum b/extension/sumologicextension/go.sum index 276a9c04459b..7815a3175095 100644 --- a/extension/sumologicextension/go.sum +++ b/extension/sumologicextension/go.sum @@ -40,8 +40,6 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 h1:6E+4a0GO5zZEnZ81pIr0yLvtUWk2if982qA3F3QD6H4= github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0/go.mod h1:zJYVVT2jmtg6P3p1VtQj7WsuWi/y4VnjVBn7F8KPB3I= -github.com/mitchellh/go-ps v1.0.0 h1:i6ampVEEF4wQFF+bkYfwYgY+F/uYJDktmvLPf7qIgjc= -github.com/mitchellh/go-ps v1.0.0/go.mod h1:J4lOc8z8yJs6vUwklHw2XEIiT4z4C40KtWVN3nvg8Pg= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=