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

Use pointer for processRootevent #153

Merged
Merged
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
4 changes: 2 additions & 2 deletions metric/system/process/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func (procStats *Stats) Get() ([]mapstr.M, []mapstr.M, error) {
// Add the RSS pct memory first
process.Memory.Rss.Pct = GetProcMemPercentage(process, totalPhyMem)
// Create the root event
rootMap := processRootEvent(process)
rootMap := processRootEvent(&process)

proc, err := procStats.getProcessEvent(&process)
if err != nil {
Expand Down Expand Up @@ -163,7 +163,7 @@ func (procStats *Stats) GetOneRootEvent(pid int) (mapstr.M, mapstr.M, error) {
return nil, nil, fmt.Errorf("error formatting process %d: %w", pid, err)
}

rootMap := processRootEvent(pidStat)
rootMap := processRootEvent(&pidStat)

return procMap, rootMap, err
}
Expand Down
2 changes: 1 addition & 1 deletion metric/system/process/process_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ func (procStats *Stats) Init() error {
}

// processRootEvent formats the process state event for the ECS root fields used by the system/process metricsets
func processRootEvent(process ProcState) mapstr.M {
func processRootEvent(process *ProcState) mapstr.M {
// Create the root event
root := process.FormatForRoot()
rootMap := mapstr.M{}
Expand Down
16 changes: 16 additions & 0 deletions metric/system/process/process_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,22 @@ import (
"github.com/elastic/elastic-agent-system-metrics/metric/system/resolve"
)

func TestProcessEvent(t *testing.T) {
proc := ProcState{Args: []string{"-b", "-c"},
Name: "test",
Username: "user",
Memory: ProcMemInfo{Rss: MemBytePct{Pct: opt.FloatWith(4.5)}},
}

root := processRootEvent(&proc)

require.Empty(t, proc.Name)
require.Empty(t, proc.Username)
require.Empty(t, proc.Args)

require.NotNil(t, root["process"].(map[string]interface{})["memory"])
}

// BenchmarkGetProcess runs a benchmark of the GetProcess method with caching
// of the command line and environment variables.
func BenchmarkGetProcess(b *testing.B) {
Expand Down
Loading