Skip to content

Commit

Permalink
refactor to gopsutil
Browse files Browse the repository at this point in the history
  • Loading branch information
dpaasman00 committed Oct 16, 2024
1 parent cb418a5 commit 6068188
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 277 deletions.
2 changes: 1 addition & 1 deletion extension/opampextension/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ require (
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/net v0.28.0 // indirect
golang.org/x/sys v0.25.0 // indirect
golang.org/x/text v0.17.0 // indirect
golang.org/x/text v0.17.0
google.golang.org/genproto/googleapis/rpc v0.0.0-20240814211410-ddb44dafa142 // indirect
google.golang.org/grpc v1.67.1 // indirect
google.golang.org/protobuf v1.35.1 // indirect
Expand Down
14 changes: 0 additions & 14 deletions extension/opampextension/internal/util/package_test.go

This file was deleted.

51 changes: 0 additions & 51 deletions extension/opampextension/internal/util/parse.go

This file was deleted.

128 changes: 0 additions & 128 deletions extension/opampextension/internal/util/parse_test.go

This file was deleted.

39 changes: 14 additions & 25 deletions extension/opampextension/opamp_agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"fmt"
"net/http"
"os"
"os/exec"
"runtime"
"sort"
"strings"
Expand All @@ -27,10 +26,12 @@ import (
semconv "go.opentelemetry.io/collector/semconv/v1.27.0"
"go.uber.org/zap"
"golang.org/x/exp/maps"
"golang.org/x/text/cases"
"golang.org/x/text/language"
"gopkg.in/yaml.v3"

"github.com/open-telemetry/opentelemetry-collector-contrib/extension/opampcustommessages"
"github.com/open-telemetry/opentelemetry-collector-contrib/extension/opampextension/internal/util"
"github.com/shirou/gopsutil/v4/host"
)

type opampAgent struct {
Expand Down Expand Up @@ -255,9 +256,7 @@ func (o *opampAgent) createAgentDescription() error {
nonIdentifyingAttributeMap[semconv.AttributeOSType] = runtime.GOOS
nonIdentifyingAttributeMap[semconv.AttributeHostArch] = runtime.GOARCH
nonIdentifyingAttributeMap[semconv.AttributeHostName] = hostname
if description != "" {
nonIdentifyingAttributeMap[semconv.AttributeOSDescription] = description
}
nonIdentifyingAttributeMap[semconv.AttributeOSDescription] = description

for k, v := range o.cfg.AgentDescription.NonIdentifyingAttributes {
nonIdentifyingAttributeMap[k] = v
Expand Down Expand Up @@ -328,29 +327,19 @@ func (o *opampAgent) onMessage(_ context.Context, msg *types.MessageData) {
}

func getOSDescription(logger *zap.Logger) string {
info, err := host.Info()
if err != nil {
logger.Error("failed getting host info", zap.Error(err))
return runtime.GOOS
}
switch runtime.GOOS {
case "darwin":
output, err := exec.Command("sw_vers").Output()
if err != nil {
logger.Error("get darwin OS details using 'sw_vers'", zap.Error(err))
return ""
}
return util.ParseDarwinDescription(string(output))
return "macOS " + info.PlatformVersion
case "linux":
output, err := exec.Command("lsb_release", "-d").Output()
if err != nil {
logger.Error("get linux OS details using 'lsb_release -d'", zap.Error(err))
return ""
}
return util.ParseLinuxDescription(string(output))
return cases.Title(language.English).String(info.Platform) + " " + info.PlatformVersion
case "windows":
output, err := exec.Command("cmd", "/c", "ver").Output()
if err != nil {
logger.Error("get windows OS details using 'cmd /c ver'", zap.Error(err))
return ""
}
return util.ParseWindowsDescription(string(output))
return info.Platform + " " + info.PlatformVersion
default:
return runtime.GOOS
}
logger.Error("unrecognized OS to parse details from")
return ""
}
Loading

0 comments on commit 6068188

Please sign in to comment.