From bfcbf627df0f2a3650c7c933bba83a8dad962f8f Mon Sep 17 00:00:00 2001 From: Tim Chan Date: Wed, 13 Nov 2024 14:27:59 -0800 Subject: [PATCH] Added new products to auto discovery for sumo otel collector --- .chloggen/chan-tim_autoDiscovery.yaml | 27 +++++++++++++ extension/sumologicextension/extension.go | 48 ++++++++++++++++++++--- extension/sumologicextension/go.mod | 1 - extension/sumologicextension/go.sum | 2 - 4 files changed, 70 insertions(+), 8 deletions(-) create mode 100644 .chloggen/chan-tim_autoDiscovery.yaml diff --git a/.chloggen/chan-tim_autoDiscovery.yaml b/.chloggen/chan-tim_autoDiscovery.yaml new file mode 100644 index 000000000000..36ef5884fa18 --- /dev/null +++ b/.chloggen/chan-tim_autoDiscovery.yaml @@ -0,0 +1,27 @@ +# Use this changelog template to create an entry for release notes. + +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: enhancement + +# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver) +component: sumologicexporter + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: adding new products for auto discovery + +# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. +issues: [35622] + +# (Optional) One or more lines of additional information to render under the primary note. +# These lines will be padded with 2 spaces and then inserted directly into the document. +# Use pipe (|) for multiline entries. +subtext: + +# If your change doesn't affect end users or the exported elements of any package, +# you should instead start your pull request title with [chore] or use the "Skip Changelog" label. +# Optional: The change log or logs in which this entry should be included. +# e.g. '[user]' or '[user, api]' +# Include 'user' if the change is relevant to end users. +# Include 'api' if there is a change to a library API. +# Default: '[user]' +change_logs: [] diff --git a/extension/sumologicextension/extension.go b/extension/sumologicextension/extension.go index 13904c184cdc..87bd58beee80 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" @@ -698,7 +698,7 @@ var sumoAppProcesses = map[string]string{ "apache": "apache", "apache2": "apache", "httpd": "apache", - "docker": "docker", + "docker": "docker", // docker cli "elasticsearch": "elasticsearch", "mysql-server": "mysql", "mysqld": "mysql", @@ -709,21 +709,59 @@ var sumoAppProcesses = map[string]string{ "redis": "redis", "tomcat": "tomcat", "kafka-server-start.sh": "kafka", // Need to test this, most common shell wrapper. + "redis-server": "redis", + "mongod": "mongodb", + "cassandra": "cassandra", + "jmx": "jmx", + "activemq": "activemq", + "memcached": "memcached", + "haproxy": "haproxy", + "dockerd": "docker-ce", // docker engine, for when process runs natively + "com.docker.backend": "docker-ce", // docker daemon runs on a VM in Docker Desktop, process doesn't show on mac + "sqlservr": "mssql", // linux SQL Server process } func filteredProcessList() ([]string, error) { var pl []string - p, err := ps.Processes() + processes, err := process.Processes() if err != nil { return pl, err } - for _, v := range p { - e := strings.ToLower(v.Executable()) + for _, v := range processes { + // Get process executable name + e, err := v.Name() + if err != nil { + return nil, fmt.Errorf("Error getting executable name: %w", err) + } + e = strings.ToLower(e) + if a, i := sumoAppProcesses[e]; i { pl = append(pl, a) } + + // handling for Docker Desktop + if e == "com.docker.backend" { + pl = append(pl, "docker-ce") + } + + // handling Java background processes + if e == "java" { + cmdline, err := v.Cmdline() + if err != nil { + return nil, fmt.Errorf("error getting executable name for PID %d: %w", v.Pid, err) + } + + switch { + case strings.Contains(cmdline, "org.apache.cassandra.service.CassandraDaemon"): + pl = append(pl, "cassandra") + case strings.Contains(cmdline, "com.sun.management.jmxremote"): + pl = append(pl, "jmx") + case strings.Contains(cmdline, "activemq.jar"): + pl = append(pl, "activemq") + } + } } return pl, nil 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=