From fe5c42134deb0556a437e181b55e0860cd0e2d5e Mon Sep 17 00:00:00 2001 From: Ryan Davis Date: Fri, 27 Dec 2024 13:58:31 -0500 Subject: [PATCH] chore: improve some variable names Existing names were really similar to imported package names or other variables. --- .../watcher/instance/nginx_process_parser.go | 39 +++++++++---------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/internal/watcher/instance/nginx_process_parser.go b/internal/watcher/instance/nginx_process_parser.go index 72bea842f..7a9514652 100644 --- a/internal/watcher/instance/nginx_process_parser.go +++ b/internal/watcher/instance/nginx_process_parser.go @@ -66,21 +66,20 @@ func (npp *NginxProcessParser) Parse(ctx context.Context, processes []*nginxproc instanceMap := make(map[string]*mpi.Instance) // key is instanceID workers := make(map[int32][]*mpi.InstanceChild) // key is ppid of process - nginxProcesses := convertToMap(processes) + processesByPID := convertToMap(processes) - for _, nginxProcess := range nginxProcesses { - // Here we are determining if the nginxProcess is a worker process - if nginxProcess.IsWorker() { + for _, proc := range processesByPID { + if proc.IsWorker() { // Here we are determining if the worker process has a master - if masterProcess, ok := nginxProcesses[nginxProcess.PPID]; ok { + if masterProcess, ok := processesByPID[proc.PPID]; ok { workers[masterProcess.PID] = append(workers[masterProcess.PID], - &mpi.InstanceChild{ProcessId: nginxProcess.PID}) + &mpi.InstanceChild{ProcessId: proc.PID}) continue } - nginxInfo, err := npp.getInfo(ctx, nginxProcess) + nginxInfo, err := npp.getInfo(ctx, proc) if err != nil { - slog.DebugContext(ctx, "Unable to get NGINX info", "pid", nginxProcess.PID, "error", err) + slog.DebugContext(ctx, "Unable to get NGINX info", "pid", proc.PID, "error", err) continue } @@ -91,23 +90,23 @@ func (npp *NginxProcessParser) Parse(ctx context.Context, processes []*nginxproc if foundInstance, ok := instanceMap[instance.GetInstanceMeta().GetInstanceId()]; ok { foundInstance.GetInstanceRuntime().InstanceChildren = append(foundInstance.GetInstanceRuntime(). - GetInstanceChildren(), &mpi.InstanceChild{ProcessId: nginxProcess.PID}) + GetInstanceChildren(), &mpi.InstanceChild{ProcessId: proc.PID}) continue } instance.GetInstanceRuntime().InstanceChildren = append(instance.GetInstanceRuntime(). - GetInstanceChildren(), &mpi.InstanceChild{ProcessId: nginxProcess.PID}) + GetInstanceChildren(), &mpi.InstanceChild{ProcessId: proc.PID}) instanceMap[instance.GetInstanceMeta().GetInstanceId()] = instance continue } - // Here we are determining if the nginxProcess is a master process - nginxInfo, err := npp.getInfo(ctx, nginxProcess) + // proc is a master process + nginxInfo, err := npp.getInfo(ctx, proc) if err != nil { - slog.DebugContext(ctx, "Unable to get NGINX info", "pid", nginxProcess.PID, "error", err) + slog.DebugContext(ctx, "Unable to get NGINX info", "pid", proc.PID, "error", err) continue } @@ -125,13 +124,13 @@ func (npp *NginxProcessParser) Parse(ctx context.Context, processes []*nginxproc return instanceMap } -func (npp *NginxProcessParser) getInfo(ctx context.Context, nginxProcess *nginxprocess.Process) (*Info, error) { - exePath := nginxProcess.Exe +func (npp *NginxProcessParser) getInfo(ctx context.Context, proc *nginxprocess.Process) (*Info, error) { + exePath := proc.Exe if exePath == "" { exePath = npp.getExe(ctx) if exePath == "" { - return nil, fmt.Errorf("unable to find NGINX exe for process %d", nginxProcess.PID) + return nil, fmt.Errorf("unable to find NGINX exe for process %d", proc.PID) } } @@ -145,7 +144,7 @@ func (npp *NginxProcessParser) getInfo(ctx context.Context, nginxProcess *nginxp nginxInfo = parseNginxVersionCommandOutput(ctx, outputBuffer) nginxInfo.ExePath = exePath - nginxInfo.ProcessID = nginxProcess.PID + nginxInfo.ProcessID = proc.PID loadableModules := getLoadableModules(nginxInfo) nginxInfo.LoadableModules = loadableModules @@ -383,11 +382,11 @@ func readDirectory(dir, extension string) (files []string, err error) { } func convertToMap(processes []*nginxprocess.Process) map[int32]*nginxprocess.Process { - nginxProcesses := make(map[int32]*nginxprocess.Process) + processesByPID := make(map[int32]*nginxprocess.Process) for _, p := range processes { - nginxProcesses[p.PID] = p + processesByPID[p.PID] = p } - return nginxProcesses + return processesByPID }