From 4747879d9ee7d578000910ed5b9b625c5fbff9ed Mon Sep 17 00:00:00 2001 From: aphralG <108004222+aphralG@users.noreply.github.com> Date: Wed, 20 Sep 2023 11:51:47 +0100 Subject: [PATCH] Fix integration tests (#478) * fix integration test --------- Co-authored-by: Oliver O'Mahony --- .github/workflows/ci.yml | 2 +- go.mod | 6 +- go.sum | 14 ++-- main.go | 23 +++---- src/core/pipe.go | 4 +- src/plugins/nginx.go | 13 ++-- src/plugins/nginx_test.go | 48 +++++++++---- test/docker/Dockerfile | 3 + test/integration/go.mod | 6 +- test/integration/go.sum | 14 ++-- .../nginx/agent/v2/src/core/pipe.go | 4 +- .../shirou/gopsutil/v3/cpu/cpu_linux.go | 3 +- .../shirou/gopsutil/v3/disk/disk_linux.go | 6 +- .../shirou/gopsutil/v3/disk/disk_windows.go | 64 +++++++++-------- .../shirou/gopsutil/v3/host/host_linux.go | 16 ++--- .../gopsutil/v3/internal/common/common.go | 24 +++++++ .../v3/internal/common/common_linux.go | 69 +++++++++++-------- .../shirou/gopsutil/v3/mem/mem_linux.go | 8 +-- .../gopsutil/v3/process/process_darwin.go | 2 - .../gopsutil/v3/process/process_freebsd.go | 2 - .../gopsutil/v3/process/process_linux.go | 2 - .../gopsutil/v3/process/process_openbsd.go | 2 - .../tklauser/go-sysconf/.cirrus.yml | 2 +- .../tklauser/go-sysconf/sysconf_darwin.go | 45 +++++++++--- .../go-sysconf/zsysconf_defs_darwin.go | 4 +- .../github.com/tklauser/numcpus/.cirrus.yml | 2 +- test/integration/vendor/modules.txt | 6 +- test/performance/go.mod | 6 +- test/performance/go.sum | 15 ++-- .../nginx/agent/v2/src/core/pipe.go | 4 +- .../nginx/agent/v2/src/plugins/nginx.go | 13 ++-- .../shirou/gopsutil/v3/cpu/cpu_linux.go | 3 +- .../shirou/gopsutil/v3/disk/disk_linux.go | 6 +- .../shirou/gopsutil/v3/disk/disk_windows.go | 64 +++++++++-------- .../shirou/gopsutil/v3/host/host_linux.go | 16 ++--- .../gopsutil/v3/internal/common/common.go | 24 +++++++ .../v3/internal/common/common_linux.go | 69 +++++++++++-------- .../shirou/gopsutil/v3/mem/mem_linux.go | 8 +-- .../gopsutil/v3/process/process_darwin.go | 2 - .../gopsutil/v3/process/process_freebsd.go | 2 - .../gopsutil/v3/process/process_linux.go | 2 - .../gopsutil/v3/process/process_openbsd.go | 2 - .../tklauser/go-sysconf/.cirrus.yml | 2 +- .../tklauser/go-sysconf/sysconf_darwin.go | 45 +++++++++--- .../go-sysconf/zsysconf_defs_darwin.go | 4 +- .../github.com/tklauser/numcpus/.cirrus.yml | 2 +- test/performance/vendor/modules.txt | 6 +- .../shirou/gopsutil/v3/cpu/cpu_linux.go | 3 +- .../shirou/gopsutil/v3/disk/disk_linux.go | 6 +- .../shirou/gopsutil/v3/disk/disk_windows.go | 64 +++++++++-------- .../shirou/gopsutil/v3/host/host_linux.go | 16 ++--- .../gopsutil/v3/internal/common/common.go | 24 +++++++ .../v3/internal/common/common_linux.go | 69 +++++++++++-------- .../shirou/gopsutil/v3/mem/mem_linux.go | 8 +-- .../gopsutil/v3/process/process_darwin.go | 2 - .../gopsutil/v3/process/process_freebsd.go | 2 - .../gopsutil/v3/process/process_linux.go | 2 - .../gopsutil/v3/process/process_openbsd.go | 2 - .../tklauser/go-sysconf/.cirrus.yml | 2 +- .../tklauser/go-sysconf/sysconf_darwin.go | 45 +++++++++--- .../go-sysconf/zsysconf_defs_darwin.go | 4 +- .../github.com/tklauser/numcpus/.cirrus.yml | 2 +- vendor/modules.txt | 6 +- 63 files changed, 577 insertions(+), 369 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b4deaa092..cc96a862d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -114,7 +114,7 @@ jobs: go install github.com/goreleaser/nfpm/v2/cmd/nfpm@${{ env.NFPM_VERSION }} OS_RELEASE="${{ matrix.container.image }}" OS_VERSION="${{ matrix.container.version }}" \ make integration-test - - name: Output Logs + - name: Container Output Logs if: failure() run: | docker ps -a diff --git a/go.mod b/go.mod index 4480957ad..31ede336b 100644 --- a/go.mod +++ b/go.mod @@ -19,7 +19,7 @@ require ( github.com/nxadm/tail v1.4.8 github.com/orcaman/concurrent-map v1.0.0 github.com/shirou/gopsutil v3.21.11+incompatible - github.com/shirou/gopsutil/v3 v3.23.6 + github.com/shirou/gopsutil/v3 v3.23.8 github.com/sirupsen/logrus v1.9.3 github.com/spf13/cobra v1.7.0 github.com/spf13/pflag v1.0.5 @@ -295,8 +295,8 @@ require ( github.com/tetratelabs/wazero v1.2.1 // indirect github.com/timakin/bodyclose v0.0.0-20221125081123-e39cf3fc478e // indirect github.com/timonwong/loggercheck v0.9.4 // indirect - github.com/tklauser/go-sysconf v0.3.11 // indirect - github.com/tklauser/numcpus v0.6.0 // indirect + github.com/tklauser/go-sysconf v0.3.12 // indirect + github.com/tklauser/numcpus v0.6.1 // indirect github.com/tomarrell/wrapcheck/v2 v2.8.1 // indirect github.com/tommy-muehle/go-mnd/v2 v2.5.1 // indirect github.com/toqueteos/webbrowser v1.2.0 // indirect diff --git a/go.sum b/go.sum index 0a804775e..c1901dee0 100644 --- a/go.sum +++ b/go.sum @@ -824,8 +824,8 @@ github.com/shazow/go-diff v0.0.0-20160112020656-b6b7b6733b8c h1:W65qqJCIOVP4jpqP github.com/shazow/go-diff v0.0.0-20160112020656-b6b7b6733b8c/go.mod h1:/PevMnwAxekIXwN8qQyfc5gl2NlkB3CQlkizAbOkeBs= github.com/shirou/gopsutil v3.21.11+incompatible h1:+1+c1VGhc88SSonWP6foOcLhvnKlUeu/erjjvaPEYiI= github.com/shirou/gopsutil v3.21.11+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA= -github.com/shirou/gopsutil/v3 v3.23.6 h1:5y46WPI9QBKBbK7EEccUPNXpJpNrvPuTD0O2zHEHT08= -github.com/shirou/gopsutil/v3 v3.23.6/go.mod h1:j7QX50DrXYggrpN30W0Mo+I4/8U2UUIQrnrhqUeWrAU= +github.com/shirou/gopsutil/v3 v3.23.8 h1:xnATPiybo6GgdRoC4YoGnxXZFRc3dqQTGi73oLvvBrE= +github.com/shirou/gopsutil/v3 v3.23.8/go.mod h1:7hmCaBn+2ZwaZOr6jmPBZDfawwMGuo1id3C6aM8EDqQ= github.com/shoenig/go-m1cpu v0.1.6 h1:nxdKQNcEB6vzgA2E2bvzKIYRuNj7XNJ4S/aRSwKzFtM= github.com/shoenig/go-m1cpu v0.1.6/go.mod h1:1JJMcUBvfNwpq05QDQVAnx3gUHr9IYF7GNg9SUEw2VQ= github.com/shoenig/test v0.6.4 h1:kVTaSd7WLz5WZ2IaoM0RSzRsUD+m8wRR+5qvntpn4LU= @@ -919,10 +919,10 @@ github.com/timakin/bodyclose v0.0.0-20221125081123-e39cf3fc478e h1:MV6KaVu/hzByH github.com/timakin/bodyclose v0.0.0-20221125081123-e39cf3fc478e/go.mod h1:27bSVNWSBOHm+qRp1T9qzaIpsWEP6TbUnei/43HK+PQ= github.com/timonwong/loggercheck v0.9.4 h1:HKKhqrjcVj8sxL7K77beXh0adEm6DLjV/QOGeMXEVi4= github.com/timonwong/loggercheck v0.9.4/go.mod h1:caz4zlPcgvpEkXgVnAJGowHAMW2NwHaNlpS8xDbVhTg= -github.com/tklauser/go-sysconf v0.3.11 h1:89WgdJhk5SNwJfu+GKyYveZ4IaJ7xAkecBo+KdJV0CM= -github.com/tklauser/go-sysconf v0.3.11/go.mod h1:GqXfhXY3kiPa0nAXPDIQIWzJbMCB7AmcWpGR8lSZfqI= -github.com/tklauser/numcpus v0.6.0 h1:kebhY2Qt+3U6RNK7UqpYNA+tJ23IBEGKkB7JQBfDYms= -github.com/tklauser/numcpus v0.6.0/go.mod h1:FEZLMke0lhOUG6w2JadTzp0a+Nl8PF/GFkQ5UVIcaL4= +github.com/tklauser/go-sysconf v0.3.12 h1:0QaGUFOdQaIVdPgfITYzaTegZvdCjmYO52cSFAEVmqU= +github.com/tklauser/go-sysconf v0.3.12/go.mod h1:Ho14jnntGE1fpdOqQEEaiKRpvIavV0hSfmBq8nJbHYI= +github.com/tklauser/numcpus v0.6.1 h1:ng9scYS7az0Bk4OZLvrNXNSAO2Pxr1XXRAPyjhIx+Fk= +github.com/tklauser/numcpus v0.6.1/go.mod h1:1XfjsgE2zo8GVw7POkMbHENHzVg3GzmoZ9fESEdAacY= github.com/tomarrell/wrapcheck/v2 v2.8.1 h1:HxSqDSN0sAt0yJYsrcYVoEeyM4aI9yAm3KQpIXDJRhQ= github.com/tomarrell/wrapcheck/v2 v2.8.1/go.mod h1:/n2Q3NZ4XFT50ho6Hbxg+RV1uyo2Uow/Vdm9NQcl5SE= github.com/tommy-muehle/go-mnd/v2 v2.5.1 h1:NowYhSdyE/1zwK9QCLeRb6USWdoif80Ie+v+yU8u1Zw= @@ -1221,7 +1221,7 @@ golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.4.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.9.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.11.0 h1:eG7RXZHdqOJ1i+0lgLgCpSXAp6M3LYlAo6osgSi0xOM= golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= diff --git a/main.go b/main.go index eea2e7d0c..a8ce38504 100644 --- a/main.go +++ b/main.go @@ -29,6 +29,7 @@ var ( // set at buildtime commit = "" version = "" + env = &core.EnvironmentType{} ) func init() { @@ -40,13 +41,20 @@ func main() { ctx, cancel := context.WithCancel(context.Background()) defer cancel() - env := &core.EnvironmentType{} - loadedConfig, err := config.GetConfig(env.GetSystemUUID()) if err != nil { log.Fatalf("Failed to load configuration: %v", err) } + eventMeta := events.NewAgentEventMeta( + config.MODULE, + version, + strconv.Itoa(os.Getpid()), + env.GetHostname(), + env.GetSystemUUID(), + loadedConfig.InstanceGroup, + loadedConfig.Tags) + logger.SetLogLevel(loadedConfig.Log.Level) logFile := logger.SetLogFile(loadedConfig.Log.Path) if logFile != nil { @@ -79,16 +87,7 @@ func main() { pipe := core.InitializePipe(ctx, corePlugins, extensionPlugins, agent_config.DefaultPluginSize) - event := events.NewAgentEventMeta( - config.MODULE, - version, - strconv.Itoa(os.Getpid()), - env.GetHostname(), - env.GetSystemUUID(), - loadedConfig.InstanceGroup, - loadedConfig.Tags) - - pipe.Process(core.NewMessage(core.AgentStarted, event)) + defer pipe.Process(core.NewMessage(core.AgentStarted, eventMeta)) core.HandleSignals(ctx, commander, loadedConfig, env, pipe, cancel, controller) pipe.Run() diff --git a/src/core/pipe.go b/src/core/pipe.go index 1ded89e02..657f57283 100644 --- a/src/core/pipe.go +++ b/src/core/pipe.go @@ -194,11 +194,11 @@ func (p *MessagePipe) GetExtensionPlugins() []ExtensionPlugin { func (p *MessagePipe) initPlugins() { for _, r := range p.plugins { - r.Init(p) + go r.Init(p) } for _, r := range p.extensionPlugins { - r.Init(p) + go r.Init(p) } } diff --git a/src/plugins/nginx.go b/src/plugins/nginx.go index 3c5dd16e0..bfbdad3c1 100644 --- a/src/plugins/nginx.go +++ b/src/plugins/nginx.go @@ -113,17 +113,17 @@ func (n *Nginx) Init(pipeline core.MessagePipeInterface) { log.Info("NginxBinary initializing") n.messagePipeline = pipeline n.nginxBinary.UpdateNginxDetailsFromProcesses(n.getNginxProccessInfo()) - nginxDetails := n.nginxBinary.GetNginxDetailsMapFromProcesses(n.getNginxProccessInfo()) - - pipeline.Process( - core.NewMessage(core.NginxPluginConfigured, n), - core.NewMessage(core.NginxInstancesFound, nginxDetails), - ) } // Process processes the messages from the messaging pipe func (n *Nginx) Process(message *core.Message) { switch message.Topic() { + case core.AgentStarted: + nginxDetails := n.nginxBinary.GetNginxDetailsMapFromProcesses(n.getNginxProccessInfo()) + n.messagePipeline.Process( + core.NewMessage(core.NginxPluginConfigured, n), + core.NewMessage(core.NginxInstancesFound, nginxDetails), + ) case core.CommNginxConfig: switch cmd := message.Data().(type) { case *proto.Command: @@ -208,6 +208,7 @@ func (n *Nginx) Subscriptions() []string { core.NginxConfigValidationPending, core.NginxConfigValidationSucceeded, core.NginxConfigValidationFailed, + core.AgentStarted, } } diff --git a/src/plugins/nginx_test.go b/src/plugins/nginx_test.go index 57bc84049..b94ef3b5a 100644 --- a/src/plugins/nginx_test.go +++ b/src/plugins/nginx_test.go @@ -162,6 +162,7 @@ func TestNginxConfigApply(t *testing.T) { DirectoryMap: &proto.DirectoryMap{}, }, msgTopics: []string{ + core.AgentStarted, core.CommNginxConfig, core.NginxPluginConfigured, core.NginxInstancesFound, @@ -195,6 +196,7 @@ func TestNginxConfigApply(t *testing.T) { DirectoryMap: &proto.DirectoryMap{}, }, msgTopics: []string{ + core.AgentStarted, core.CommNginxConfig, core.NginxPluginConfigured, core.NginxInstancesFound, @@ -228,6 +230,7 @@ func TestNginxConfigApply(t *testing.T) { DirectoryMap: &proto.DirectoryMap{}, }, msgTopics: []string{ + core.AgentStarted, core.CommNginxConfig, core.NginxPluginConfigured, core.NginxInstancesFound, @@ -281,6 +284,7 @@ func TestNginxConfigApply(t *testing.T) { }, }, msgTopics: []string{ + core.AgentStarted, core.CommNginxConfig, core.NginxPluginConfigured, core.NginxInstancesFound, @@ -318,6 +322,7 @@ func TestNginxConfigApply(t *testing.T) { DirectoryMap: &proto.DirectoryMap{}, }, msgTopics: []string{ + core.AgentStarted, core.CommNginxConfig, core.NginxPluginConfigured, core.NginxInstancesFound, @@ -351,6 +356,7 @@ func TestNginxConfigApply(t *testing.T) { DirectoryMap: &proto.DirectoryMap{}, }, msgTopics: []string{ + core.AgentStarted, core.CommNginxConfig, core.NginxPluginConfigured, core.NginxInstancesFound, @@ -404,6 +410,7 @@ func TestNginxConfigApply(t *testing.T) { }, }, msgTopics: []string{ + core.AgentStarted, core.CommNginxConfig, core.NginxPluginConfigured, core.NginxInstancesFound, @@ -458,6 +465,7 @@ func TestNginxConfigApply(t *testing.T) { }, }, msgTopics: []string{ + core.AgentStarted, core.CommNginxConfig, core.NginxPluginConfigured, core.NginxInstancesFound, @@ -547,7 +555,7 @@ func TestNginxConfigApply(t *testing.T) { Nginx: loadedConfig.Nginx{ ConfigReloadMonitoringPeriod: 5 * time.Second, }, - Features: []string{agent_config.FeatureNginxConfig}, + Features: []string{agent_config.FeatureNginxConfigAsync}, Extensions: []string{agent_config.NginxAppProtectExtensionPlugin}, } @@ -561,7 +569,7 @@ func TestNginxConfigApply(t *testing.T) { } messagePipe := core.SetupMockMessagePipe(t, ctx, []core.Plugin{pluginUnderTest}, []core.ExtensionPlugin{}) - + messagePipe.Process(core.NewMessage(core.AgentStarted, nil)) messagePipe.Process(core.NewMessage(core.CommNginxConfig, cmd)) go messagePipe.Run() @@ -613,11 +621,10 @@ func TestUploadConfigs(t *testing.T) { } msgTopics := []string{ + core.AgentStarted, core.NginxPluginConfigured, core.NginxInstancesFound, core.DataplaneChanged, - core.NginxPluginConfigured, - core.NginxInstancesFound, } env := tutils.GetMockEnvWithProcess() @@ -631,12 +638,18 @@ func TestUploadConfigs(t *testing.T) { cmdr := tutils.NewMockCommandClient() cmdr.On("Upload", mock.Anything, mock.Anything).Return(nil) - conf := &loadedConfig.Config{Server: loadedConfig.Server{Host: "127.0.0.1", GrpcPort: 9092}, Features: []string{agent_config.FeatureNginxConfig}} + conf := &loadedConfig.Config{Server: loadedConfig.Server{Host: "127.0.0.1", GrpcPort: 9092}, Features: []string{agent_config.FeatureNginxConfigAsync}} pluginUnderTest := NewNginx(cmdr, binary, env, conf) messagePipe := core.SetupMockMessagePipe(t, context.TODO(), []core.Plugin{pluginUnderTest}, []core.ExtensionPlugin{}) pluginUnderTest.Init(messagePipe) + + // calling Run x 2 means AgentStarted finishes before the DataplaneChanged event gets processed. + // This is the expected order of the real MessagePipe + messagePipe.Process(core.NewMessage(core.AgentStarted, nil)) + messagePipe.Run() + messagePipe.Process(core.NewMessage(core.DataplaneChanged, nil)) messagePipe.Run() @@ -649,11 +662,10 @@ func TestUploadConfigs(t *testing.T) { func TestDisableUploadConfigs(t *testing.T) { msgTopics := []string{ + core.AgentStarted, core.NginxPluginConfigured, core.NginxInstancesFound, core.DataplaneChanged, - core.NginxPluginConfigured, - core.NginxInstancesFound, } env := tutils.GetMockEnvWithProcess() @@ -668,6 +680,11 @@ func TestDisableUploadConfigs(t *testing.T) { messagePipe := core.SetupMockMessagePipe(t, context.TODO(), []core.Plugin{pluginUnderTest}, []core.ExtensionPlugin{}) pluginUnderTest.Init(messagePipe) + // calling Run x 2 means AgentStarted finishes before the DataplaneChanged event gets processed. + // This is the expected order of the real MessagePipe + messagePipe.Process(core.NewMessage(core.AgentStarted, nil)) + messagePipe.Run() + messagePipe.Process(core.NewMessage(core.DataplaneChanged, nil)) messagePipe.Run() @@ -691,6 +708,8 @@ func TestNginxDetailProcUpdate(t *testing.T) { messagePipe := core.SetupMockMessagePipe(t, context.TODO(), []core.Plugin{pluginUnderTest}, []core.ExtensionPlugin{}) pluginUnderTest.Init(messagePipe) + messagePipe.Process(core.NewMessage(core.AgentStarted, nil)) + messagePipe.Process(core.NewMessage(core.NginxDetailProcUpdate, tutils.GetProcesses())) messagePipe.Run() @@ -707,7 +726,7 @@ func TestNginxDetailProcUpdate(t *testing.T) { foundMessage = true } } - assert.Len(t, processedMessages, 5) + assert.Len(t, processedMessages, 4) assert.True(t, foundMessage) } @@ -736,7 +755,7 @@ func TestNginx_Process_NginxConfigUpload(t *testing.T) { binary.On("ReadConfig", "/var/conf", "12345", "12345678").Return(config, nil) env := tutils.GetMockEnvWithProcess() - conf := &loadedConfig.Config{Server: loadedConfig.Server{Host: "127.0.0.1", GrpcPort: 9092}, Features: []string{agent_config.FeatureNginxConfig}} + conf := &loadedConfig.Config{Server: loadedConfig.Server{Host: "127.0.0.1", GrpcPort: 9092}, Features: []string{agent_config.FeatureNginxConfigAsync}} pluginUnderTest := NewNginx(cmdr, binary, env, conf) pluginUnderTest.Process(core.NewMessage(core.NginxConfigUpload, configDesc)) @@ -761,6 +780,7 @@ func TestNginx_Subscriptions(t *testing.T) { core.NginxConfigValidationPending, core.NginxConfigValidationSucceeded, core.NginxConfigValidationFailed, + core.AgentStarted, } pluginUnderTest := NewNginx(nil, nil, tutils.GetMockEnvWithProcess(), &loadedConfig.Config{}) @@ -800,7 +820,7 @@ func TestNginx_validateConfig(t *testing.T) { binary.On("ReadConfig", mock.Anything, mock.Anything, mock.Anything).Return(&proto.NginxConfig{}, nil) binary.On("GetNginxDetailsMapFromProcesses", env.Processes()).Return(tutils.GetDetailsMap()) binary.On("UpdateNginxDetailsFromProcesses", env.Processes()) - conf := &loadedConfig.Config{Server: loadedConfig.Server{Host: "127.0.0.1", GrpcPort: 9092}, Features: []string{agent_config.FeatureNginxConfig}} + conf := &loadedConfig.Config{Server: loadedConfig.Server{Host: "127.0.0.1", GrpcPort: 9092}, Features: []string{agent_config.FeatureNginxConfigAsync}} pluginUnderTest := NewNginx(&tutils.MockCommandClient{}, binary, env, conf) @@ -830,6 +850,7 @@ func TestNginx_validateConfig(t *testing.T) { func TestNginx_completeConfigApply(t *testing.T) { expectedTopics := []string{ + core.AgentStarted, core.NginxConfigValidationSucceeded, core.NginxPluginConfigured, core.NginxInstancesFound, @@ -883,7 +904,7 @@ func TestNginx_completeConfigApply(t *testing.T) { Host: "127.0.0.1", GrpcPort: 9092, }, - Features: []string{agent_config.FeatureNginxConfig}, + Features: []string{agent_config.FeatureNginxConfigAsync}, Nginx: loadedConfig.Nginx{ ConfigReloadMonitoringPeriod: 5 * time.Second, }, @@ -919,6 +940,7 @@ func TestNginx_completeConfigApply(t *testing.T) { } messagePipe := core.SetupMockMessagePipe(t, context.TODO(), []core.Plugin{pluginUnderTest}, []core.ExtensionPlugin{}) + messagePipe.Process(core.NewMessage(core.AgentStarted, nil)) messagePipe.Process(core.NewMessage(core.NginxConfigValidationSucceeded, response)) go messagePipe.Run() @@ -941,6 +963,7 @@ func TestNginx_completeConfigApply(t *testing.T) { func TestNginx_rollbackConfigApply(t *testing.T) { expectedTopics := []string{ + core.AgentStarted, core.NginxConfigValidationFailed, core.NginxPluginConfigured, core.NginxInstancesFound, @@ -980,7 +1003,7 @@ func TestNginx_rollbackConfigApply(t *testing.T) { }, ) - conf := &loadedConfig.Config{Server: loadedConfig.Server{Host: "127.0.0.1", GrpcPort: 9092}, Features: []string{agent_config.FeatureNginxConfig}} + conf := &loadedConfig.Config{Server: loadedConfig.Server{Host: "127.0.0.1", GrpcPort: 9092}, Features: []string{agent_config.FeatureNginxConfigAsync}} pluginUnderTest := NewNginx(commandClient, binary, env, conf) @@ -1012,6 +1035,7 @@ func TestNginx_rollbackConfigApply(t *testing.T) { } messagePipe := core.SetupMockMessagePipe(t, context.TODO(), []core.Plugin{pluginUnderTest}, []core.ExtensionPlugin{}) + messagePipe.Process(core.NewMessage(core.AgentStarted, nil)) messagePipe.Process(core.NewMessage(core.NginxConfigValidationFailed, response)) messagePipe.Run() diff --git a/test/docker/Dockerfile b/test/docker/Dockerfile index 28f0ebfcb..51b3eebef 100644 --- a/test/docker/Dockerfile +++ b/test/docker/Dockerfile @@ -15,6 +15,7 @@ LABEL maintainer="NGINX Docker Maintainers " # https://askubuntu.com/questions/909277/avoiding-user-interaction-with-tzdata-when-installing-certbot-in-a-docker-contai ARG DEBIAN_FRONTEND=noninteractive + RUN --mount=type=secret,id=nginx-crt,dst=nginx-repo.crt \ --mount=type=secret,id=nginx-key,dst=nginx-repo.key \ set -x \ @@ -82,6 +83,8 @@ EXPOSE 80 STOPSIGNAL SIGQUIT +RUN git config --global --add safe.directory /home/nginx + # Install Go RUN wget https://go.dev/dl/go1.21.0.linux-amd64.tar.gz \ && tar -xvf go1.21.0.linux-amd64.tar.gz \ diff --git a/test/integration/go.mod b/test/integration/go.mod index 65d1f5075..4106d2cbf 100644 --- a/test/integration/go.mod +++ b/test/integration/go.mod @@ -137,7 +137,7 @@ require ( github.com/secure-systems-lab/go-securesystemslib v0.7.0 // indirect github.com/serialx/hashring v0.0.0-20200727003509-22c0c7ab6b1b // indirect github.com/shibumi/go-pathspec v1.3.0 // indirect - github.com/shirou/gopsutil/v3 v3.23.6 // indirect + github.com/shirou/gopsutil/v3 v3.23.8 // indirect github.com/shoenig/go-m1cpu v0.1.6 // indirect github.com/spf13/afero v1.9.5 // indirect github.com/spf13/cast v1.5.1 // indirect @@ -149,8 +149,8 @@ require ( github.com/subosito/gotenv v1.4.2 // indirect github.com/theupdateframework/notary v0.7.0 // indirect github.com/tilt-dev/fsnotify v1.4.8-0.20220602155310-fff9c274a375 // indirect - github.com/tklauser/go-sysconf v0.3.11 // indirect - github.com/tklauser/numcpus v0.6.0 // indirect + github.com/tklauser/go-sysconf v0.3.12 // indirect + github.com/tklauser/numcpus v0.6.1 // indirect github.com/tonistiigi/fsutil v0.0.0-20230629203738-36ef4d8c0dbb // indirect github.com/tonistiigi/units v0.0.0-20180711220420-6950e57a87ea // indirect github.com/tonistiigi/vt100 v0.0.0-20230623042737-f9a4f7ef6531 // indirect diff --git a/test/integration/go.sum b/test/integration/go.sum index 212ce313c..88ebb8cb4 100644 --- a/test/integration/go.sum +++ b/test/integration/go.sum @@ -571,8 +571,8 @@ github.com/serialx/hashring v0.0.0-20200727003509-22c0c7ab6b1b h1:h+3JX2VoWTFuyQ github.com/serialx/hashring v0.0.0-20200727003509-22c0c7ab6b1b/go.mod h1:/yeG0My1xr/u+HZrFQ1tOQQQQrOawfyMUH13ai5brBc= github.com/shibumi/go-pathspec v1.3.0 h1:QUyMZhFo0Md5B8zV8x2tesohbb5kfbpTi9rBnKh5dkI= github.com/shibumi/go-pathspec v1.3.0/go.mod h1:Xutfslp817l2I1cZvgcfeMQJG5QnU2lh5tVaaMCl3jE= -github.com/shirou/gopsutil/v3 v3.23.6 h1:5y46WPI9QBKBbK7EEccUPNXpJpNrvPuTD0O2zHEHT08= -github.com/shirou/gopsutil/v3 v3.23.6/go.mod h1:j7QX50DrXYggrpN30W0Mo+I4/8U2UUIQrnrhqUeWrAU= +github.com/shirou/gopsutil/v3 v3.23.8 h1:xnATPiybo6GgdRoC4YoGnxXZFRc3dqQTGi73oLvvBrE= +github.com/shirou/gopsutil/v3 v3.23.8/go.mod h1:7hmCaBn+2ZwaZOr6jmPBZDfawwMGuo1id3C6aM8EDqQ= github.com/shoenig/go-m1cpu v0.1.6 h1:nxdKQNcEB6vzgA2E2bvzKIYRuNj7XNJ4S/aRSwKzFtM= github.com/shoenig/go-m1cpu v0.1.6/go.mod h1:1JJMcUBvfNwpq05QDQVAnx3gUHr9IYF7GNg9SUEw2VQ= github.com/shoenig/test v0.6.4 h1:kVTaSd7WLz5WZ2IaoM0RSzRsUD+m8wRR+5qvntpn4LU= @@ -630,10 +630,10 @@ github.com/theupdateframework/notary v0.7.0 h1:QyagRZ7wlSpjT5N2qQAh/pN+DVqgekv4D github.com/theupdateframework/notary v0.7.0/go.mod h1:c9DRxcmhHmVLDay4/2fUYdISnHqbFDGRSlXPO0AhYWw= github.com/tilt-dev/fsnotify v1.4.8-0.20220602155310-fff9c274a375 h1:QB54BJwA6x8QU9nHY3xJSZR2kX9bgpZekRKGkLTmEXA= github.com/tilt-dev/fsnotify v1.4.8-0.20220602155310-fff9c274a375/go.mod h1:xRroudyp5iVtxKqZCrA6n2TLFRBf8bmnjr1UD4x+z7g= -github.com/tklauser/go-sysconf v0.3.11 h1:89WgdJhk5SNwJfu+GKyYveZ4IaJ7xAkecBo+KdJV0CM= -github.com/tklauser/go-sysconf v0.3.11/go.mod h1:GqXfhXY3kiPa0nAXPDIQIWzJbMCB7AmcWpGR8lSZfqI= -github.com/tklauser/numcpus v0.6.0 h1:kebhY2Qt+3U6RNK7UqpYNA+tJ23IBEGKkB7JQBfDYms= -github.com/tklauser/numcpus v0.6.0/go.mod h1:FEZLMke0lhOUG6w2JadTzp0a+Nl8PF/GFkQ5UVIcaL4= +github.com/tklauser/go-sysconf v0.3.12 h1:0QaGUFOdQaIVdPgfITYzaTegZvdCjmYO52cSFAEVmqU= +github.com/tklauser/go-sysconf v0.3.12/go.mod h1:Ho14jnntGE1fpdOqQEEaiKRpvIavV0hSfmBq8nJbHYI= +github.com/tklauser/numcpus v0.6.1 h1:ng9scYS7az0Bk4OZLvrNXNSAO2Pxr1XXRAPyjhIx+Fk= +github.com/tklauser/numcpus v0.6.1/go.mod h1:1XfjsgE2zo8GVw7POkMbHENHzVg3GzmoZ9fESEdAacY= github.com/tonistiigi/fsutil v0.0.0-20230629203738-36ef4d8c0dbb h1:uUe8rNyVXM8moActoBol6Xf6xX2GMr7SosR2EywMvGg= github.com/tonistiigi/fsutil v0.0.0-20230629203738-36ef4d8c0dbb/go.mod h1:SxX/oNQ/ag6Vaoli547ipFK9J7BZn5JqJG0JE8lf8bA= github.com/tonistiigi/units v0.0.0-20180711220420-6950e57a87ea h1:SXhTLE6pb6eld/v/cCndK0AMpt1wiVFb/YYmqB3/QG0= @@ -887,11 +887,9 @@ golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.9.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.11.0 h1:eG7RXZHdqOJ1i+0lgLgCpSXAp6M3LYlAo6osgSi0xOM= golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= diff --git a/test/integration/vendor/github.com/nginx/agent/v2/src/core/pipe.go b/test/integration/vendor/github.com/nginx/agent/v2/src/core/pipe.go index 1ded89e02..657f57283 100644 --- a/test/integration/vendor/github.com/nginx/agent/v2/src/core/pipe.go +++ b/test/integration/vendor/github.com/nginx/agent/v2/src/core/pipe.go @@ -194,11 +194,11 @@ func (p *MessagePipe) GetExtensionPlugins() []ExtensionPlugin { func (p *MessagePipe) initPlugins() { for _, r := range p.plugins { - r.Init(p) + go r.Init(p) } for _, r := range p.extensionPlugins { - r.Init(p) + go r.Init(p) } } diff --git a/test/integration/vendor/github.com/shirou/gopsutil/v3/cpu/cpu_linux.go b/test/integration/vendor/github.com/shirou/gopsutil/v3/cpu/cpu_linux.go index 1b64241ce..b5a20e366 100644 --- a/test/integration/vendor/github.com/shirou/gopsutil/v3/cpu/cpu_linux.go +++ b/test/integration/vendor/github.com/shirou/gopsutil/v3/cpu/cpu_linux.go @@ -259,8 +259,7 @@ func InfoWithContext(ctx context.Context) ([]InfoStat, error) { } case "Model Name", "model name", "cpu": c.ModelName = value - if strings.Contains(value, "POWER8") || - strings.Contains(value, "POWER7") { + if strings.Contains(value, "POWER") { c.Model = strings.Split(value, " ")[0] c.Family = "POWER" c.VendorID = "IBM" diff --git a/test/integration/vendor/github.com/shirou/gopsutil/v3/disk/disk_linux.go b/test/integration/vendor/github.com/shirou/gopsutil/v3/disk/disk_linux.go index 2a8c50ae4..5015c34ae 100644 --- a/test/integration/vendor/github.com/shirou/gopsutil/v3/disk/disk_linux.go +++ b/test/integration/vendor/github.com/shirou/gopsutil/v3/disk/disk_linux.go @@ -474,7 +474,11 @@ func IOCountersWithContext(ctx context.Context, names ...string) (map[string]IOC } d.Name = name - d.SerialNumber, _ = SerialNumberWithContext(ctx, name) + // Names passed in can be full paths (/dev/sda) or just device names (sda). + // Since `name` here is already a basename, re-add the /dev path. + // This is not ideal, but we may break the API by changing how SerialNumberWithContext + // works. + d.SerialNumber, _ = SerialNumberWithContext(ctx, common.HostDevWithContext(ctx, name)) d.Label, _ = LabelWithContext(ctx, name) ret[name] = d diff --git a/test/integration/vendor/github.com/shirou/gopsutil/v3/disk/disk_windows.go b/test/integration/vendor/github.com/shirou/gopsutil/v3/disk/disk_windows.go index 8a1a28d69..e17db3e5b 100644 --- a/test/integration/vendor/github.com/shirou/gopsutil/v3/disk/disk_windows.go +++ b/test/integration/vendor/github.com/shirou/gopsutil/v3/disk/disk_windows.go @@ -7,7 +7,6 @@ import ( "bytes" "context" "fmt" - "sync" "syscall" "unsafe" @@ -51,6 +50,7 @@ func init() { key, err := registry.OpenKey(registry.LOCAL_MACHINE, `SYSTEM\CurrentControlSet\Services\PartMgr`, registry.SET_VALUE) if err == nil { key.SetDWordValue("EnableCounterForIoctl", 1) + key.Close() } } @@ -86,28 +86,22 @@ func PartitionsWithContext(ctx context.Context, all bool) ([]PartitionStat, erro warnings := Warnings{ Verbose: true, } - var ret []PartitionStat - retChan := make(chan []PartitionStat) - errChan := make(chan error) - lpBuffer := make([]byte, 254) - - var waitgrp sync.WaitGroup - waitgrp.Add(1) - defer waitgrp.Done() - - f := func() { - defer func() { - waitgrp.Wait() - // fires when this func and the outside func finishes. - close(errChan) - close(retChan) - }() + + var errLogicalDrives error + retChan := make(chan PartitionStat) + quitChan := make(chan struct{}) + defer close(quitChan) + + getPartitions := func() { + defer close(retChan) + + lpBuffer := make([]byte, 254) diskret, _, err := procGetLogicalDriveStringsW.Call( uintptr(len(lpBuffer)), uintptr(unsafe.Pointer(&lpBuffer[0]))) if diskret == 0 { - errChan <- err + errLogicalDrives = err return } for _, v := range lpBuffer { @@ -153,27 +147,37 @@ func PartitionsWithContext(ctx context.Context, all bool) ([]PartitionStat, erro opts = append(opts, "compress") } - d := PartitionStat{ + select { + case retChan <- PartitionStat{ Mountpoint: path, Device: path, - Fstype: string(bytes.Replace(lpFileSystemNameBuffer, []byte("\x00"), []byte(""), -1)), + Fstype: string(bytes.ReplaceAll(lpFileSystemNameBuffer, []byte("\x00"), []byte(""))), Opts: opts, + }: + case <-quitChan: + return } - ret = append(ret, d) } } } - retChan <- ret } - go f() - select { - case err := <-errChan: - return ret, err - case ret := <-retChan: - return ret, warnings.Reference() - case <-ctx.Done(): - return ret, ctx.Err() + go getPartitions() + + var ret []PartitionStat + for { + select { + case p, ok := <-retChan: + if !ok { + if errLogicalDrives != nil { + return ret, errLogicalDrives + } + return ret, warnings.Reference() + } + ret = append(ret, p) + case <-ctx.Done(): + return ret, ctx.Err() + } } } diff --git a/test/integration/vendor/github.com/shirou/gopsutil/v3/host/host_linux.go b/test/integration/vendor/github.com/shirou/gopsutil/v3/host/host_linux.go index 62a4b3ca9..e6ac63a39 100644 --- a/test/integration/vendor/github.com/shirou/gopsutil/v3/host/host_linux.go +++ b/test/integration/vendor/github.com/shirou/gopsutil/v3/host/host_linux.go @@ -138,13 +138,13 @@ func getlsbStruct(ctx context.Context) (*lsbStruct, error) { } switch field[0] { case "DISTRIB_ID": - ret.ID = field[1] + ret.ID = strings.ReplaceAll(field[1], `"`, ``) case "DISTRIB_RELEASE": - ret.Release = field[1] + ret.Release = strings.ReplaceAll(field[1], `"`, ``) case "DISTRIB_CODENAME": - ret.Codename = field[1] + ret.Codename = strings.ReplaceAll(field[1], `"`, ``) case "DISTRIB_DESCRIPTION": - ret.Description = field[1] + ret.Description = strings.ReplaceAll(field[1], `"`, ``) } } } else if common.PathExists("/usr/bin/lsb_release") { @@ -159,13 +159,13 @@ func getlsbStruct(ctx context.Context) (*lsbStruct, error) { } switch field[0] { case "Distributor ID": - ret.ID = field[1] + ret.ID = strings.ReplaceAll(field[1], `"`, ``) case "Release": - ret.Release = field[1] + ret.Release = strings.ReplaceAll(field[1], `"`, ``) case "Codename": - ret.Codename = field[1] + ret.Codename = strings.ReplaceAll(field[1], `"`, ``) case "Description": - ret.Description = field[1] + ret.Description = strings.ReplaceAll(field[1], `"`, ``) } } diff --git a/test/integration/vendor/github.com/shirou/gopsutil/v3/internal/common/common.go b/test/integration/vendor/github.com/shirou/gopsutil/v3/internal/common/common.go index 9bfece362..7a31d251b 100644 --- a/test/integration/vendor/github.com/shirou/gopsutil/v3/internal/common/common.go +++ b/test/integration/vendor/github.com/shirou/gopsutil/v3/internal/common/common.go @@ -114,6 +114,30 @@ func ReadLines(filename string) ([]string, error) { return ReadLinesOffsetN(filename, 0, -1) } +// ReadLine reads a file and returns the first occurrence of a line that is prefixed with prefix. +func ReadLine(filename string, prefix string) (string, error) { + f, err := os.Open(filename) + if err != nil { + return "", err + } + defer f.Close() + r := bufio.NewReader(f) + for { + line, err := r.ReadString('\n') + if err != nil { + if err == io.EOF { + break + } + return "", err + } + if strings.HasPrefix(line, prefix) { + return line, nil + } + } + + return "", nil +} + // ReadLinesOffsetN reads contents from file and splits them by new line. // The offset tells at which line number to start. // The count determines the number of lines to read (starting from offset): diff --git a/test/integration/vendor/github.com/shirou/gopsutil/v3/internal/common/common_linux.go b/test/integration/vendor/github.com/shirou/gopsutil/v3/internal/common/common_linux.go index b58edbeb0..a644687ba 100644 --- a/test/integration/vendor/github.com/shirou/gopsutil/v3/internal/common/common_linux.go +++ b/test/integration/vendor/github.com/shirou/gopsutil/v3/internal/common/common_linux.go @@ -62,17 +62,38 @@ func BootTimeWithContext(ctx context.Context) (uint64, error) { return 0, err } - statFile := "stat" + useStatFile := true if system == "lxc" && role == "guest" { // if lxc, /proc/uptime is used. - statFile = "uptime" + useStatFile = false } else if system == "docker" && role == "guest" { // also docker, guest - statFile = "uptime" + useStatFile = false } - filename := HostProcWithContext(ctx, statFile) + if useStatFile { + return readBootTimeStat(ctx) + } + + filename := HostProcWithContext(ctx, "uptime") lines, err := ReadLines(filename) + if err != nil { + return handleBootTimeFileReadErr(err) + } + if len(lines) != 1 { + return 0, fmt.Errorf("wrong uptime format") + } + f := strings.Fields(lines[0]) + b, err := strconv.ParseFloat(f[0], 64) + if err != nil { + return 0, err + } + currentTime := float64(time.Now().UnixNano()) / float64(time.Second) + t := currentTime - b + return uint64(t), nil +} + +func handleBootTimeFileReadErr(err error) (uint64, error) { if os.IsPermission(err) { var info syscall.Sysinfo_t err := syscall.Sysinfo(&info) @@ -84,39 +105,27 @@ func BootTimeWithContext(ctx context.Context) (uint64, error) { t := currentTime - int64(info.Uptime) return uint64(t), nil } + return 0, err +} + +func readBootTimeStat(ctx context.Context) (uint64, error) { + filename := HostProcWithContext(ctx, "stat") + line, err := ReadLine(filename, "btime") if err != nil { - return 0, err + return handleBootTimeFileReadErr(err) } - - if statFile == "stat" { - for _, line := range lines { - if strings.HasPrefix(line, "btime") { - f := strings.Fields(line) - if len(f) != 2 { - return 0, fmt.Errorf("wrong btime format") - } - b, err := strconv.ParseInt(f[1], 10, 64) - if err != nil { - return 0, err - } - t := uint64(b) - return t, nil - } - } - } else if statFile == "uptime" { - if len(lines) != 1 { - return 0, fmt.Errorf("wrong uptime format") + if strings.HasPrefix(line, "btime") { + f := strings.Fields(line) + if len(f) != 2 { + return 0, fmt.Errorf("wrong btime format") } - f := strings.Fields(lines[0]) - b, err := strconv.ParseFloat(f[0], 64) + b, err := strconv.ParseInt(f[1], 10, 64) if err != nil { return 0, err } - currentTime := float64(time.Now().UnixNano()) / float64(time.Second) - t := currentTime - b - return uint64(t), nil + t := uint64(b) + return t, nil } - return 0, fmt.Errorf("could not find btime") } diff --git a/test/integration/vendor/github.com/shirou/gopsutil/v3/mem/mem_linux.go b/test/integration/vendor/github.com/shirou/gopsutil/v3/mem/mem_linux.go index 361d06bcc..935331728 100644 --- a/test/integration/vendor/github.com/shirou/gopsutil/v3/mem/mem_linux.go +++ b/test/integration/vendor/github.com/shirou/gopsutil/v3/mem/mem_linux.go @@ -371,25 +371,25 @@ func SwapMemoryWithContext(ctx context.Context) (*SwapMemoryStat, error) { continue } ret.Sout = value * 4 * 1024 - case "pgpgIn": + case "pgpgin": value, err := strconv.ParseUint(fields[1], 10, 64) if err != nil { continue } ret.PgIn = value * 4 * 1024 - case "pgpgOut": + case "pgpgout": value, err := strconv.ParseUint(fields[1], 10, 64) if err != nil { continue } ret.PgOut = value * 4 * 1024 - case "pgFault": + case "pgfault": value, err := strconv.ParseUint(fields[1], 10, 64) if err != nil { continue } ret.PgFault = value * 4 * 1024 - case "pgMajFault": + case "pgmajfault": value, err := strconv.ParseUint(fields[1], 10, 64) if err != nil { continue diff --git a/test/integration/vendor/github.com/shirou/gopsutil/v3/process/process_darwin.go b/test/integration/vendor/github.com/shirou/gopsutil/v3/process/process_darwin.go index 55c31962a..176661cbd 100644 --- a/test/integration/vendor/github.com/shirou/gopsutil/v3/process/process_darwin.go +++ b/test/integration/vendor/github.com/shirou/gopsutil/v3/process/process_darwin.go @@ -82,8 +82,6 @@ func (p *Process) NameWithContext(ctx context.Context) (string, error) { extendedName := filepath.Base(cmdName) if strings.HasPrefix(extendedName, p.name) { name = extendedName - } else { - name = cmdName } } } diff --git a/test/integration/vendor/github.com/shirou/gopsutil/v3/process/process_freebsd.go b/test/integration/vendor/github.com/shirou/gopsutil/v3/process/process_freebsd.go index a123ccf9b..85134b7ee 100644 --- a/test/integration/vendor/github.com/shirou/gopsutil/v3/process/process_freebsd.go +++ b/test/integration/vendor/github.com/shirou/gopsutil/v3/process/process_freebsd.go @@ -55,8 +55,6 @@ func (p *Process) NameWithContext(ctx context.Context) (string, error) { extendedName := filepath.Base(cmdlineSlice[0]) if strings.HasPrefix(extendedName, p.name) { name = extendedName - } else { - name = cmdlineSlice[0] } } } diff --git a/test/integration/vendor/github.com/shirou/gopsutil/v3/process/process_linux.go b/test/integration/vendor/github.com/shirou/gopsutil/v3/process/process_linux.go index 29c447390..37cb7ca44 100644 --- a/test/integration/vendor/github.com/shirou/gopsutil/v3/process/process_linux.go +++ b/test/integration/vendor/github.com/shirou/gopsutil/v3/process/process_linux.go @@ -845,8 +845,6 @@ func (p *Process) fillFromStatusWithContext(ctx context.Context) error { extendedName := filepath.Base(cmdlineSlice[0]) if strings.HasPrefix(extendedName, p.name) { p.name = extendedName - } else { - p.name = cmdlineSlice[0] } } } diff --git a/test/integration/vendor/github.com/shirou/gopsutil/v3/process/process_openbsd.go b/test/integration/vendor/github.com/shirou/gopsutil/v3/process/process_openbsd.go index cbb1a77f6..a58c5eb11 100644 --- a/test/integration/vendor/github.com/shirou/gopsutil/v3/process/process_openbsd.go +++ b/test/integration/vendor/github.com/shirou/gopsutil/v3/process/process_openbsd.go @@ -60,8 +60,6 @@ func (p *Process) NameWithContext(ctx context.Context) (string, error) { extendedName := filepath.Base(cmdlineSlice[0]) if strings.HasPrefix(extendedName, p.name) { name = extendedName - } else { - name = cmdlineSlice[0] } } } diff --git a/test/integration/vendor/github.com/tklauser/go-sysconf/.cirrus.yml b/test/integration/vendor/github.com/tklauser/go-sysconf/.cirrus.yml index 6be2c3548..1b27f1962 100644 --- a/test/integration/vendor/github.com/tklauser/go-sysconf/.cirrus.yml +++ b/test/integration/vendor/github.com/tklauser/go-sysconf/.cirrus.yml @@ -1,6 +1,6 @@ env: CIRRUS_CLONE_DEPTH: 1 - GO_VERSION: go1.19.1 + GO_VERSION: go1.20 freebsd_12_task: freebsd_instance: diff --git a/test/integration/vendor/github.com/tklauser/go-sysconf/sysconf_darwin.go b/test/integration/vendor/github.com/tklauser/go-sysconf/sysconf_darwin.go index 4a5197b2f..3f5d83f69 100644 --- a/test/integration/vendor/github.com/tklauser/go-sysconf/sysconf_darwin.go +++ b/test/integration/vendor/github.com/tklauser/go-sysconf/sysconf_darwin.go @@ -5,6 +5,10 @@ package sysconf import ( + "strconv" + "strings" + "sync" + "golang.org/x/sys/unix" ) @@ -14,8 +18,14 @@ const ( _SYMLOOP_MAX = _MAXSYMLINKS ) -// sysconf implements sysconf(3) as in the Darwin libc, version 1244.30.3 -// (derived from the FreeBSD libc). +var uname struct { + sync.Once + macOSMajor int +} + +// sysconf implements sysconf(4) as in the Darwin libc (derived from the FreeBSD +// libc), version 1534.81.1. +// See https://github.com/apple-oss-distributions/Libc/tree/Libc-1534.81.1. func sysconf(name int) (int64, error) { switch name { case SC_AIO_LISTIO_MAX: @@ -54,12 +64,16 @@ func sysconf(name int) (int64, error) { return sysctl32("kern.ngroups"), nil case SC_OPEN_MAX, SC_STREAM_MAX: var rlim unix.Rlimit - if err := unix.Getrlimit(unix.RLIMIT_NOFILE, &rlim); err == nil { - if rlim.Cur != unix.RLIM_INFINITY { - return int64(rlim.Cur), nil - } + if err := unix.Getrlimit(unix.RLIMIT_NOFILE, &rlim); err != nil { + return -1, nil } - return -1, nil + if rlim.Cur > unix.RLIM_INFINITY { + return -1, nil + } + if rlim.Cur > _LONG_MAX { + return -1, unix.EOVERFLOW + } + return int64(rlim.Cur), nil case SC_RTSIG_MAX: return -1, nil case SC_SEM_NSEMS_MAX: @@ -126,7 +140,22 @@ func sysconf(name int) (int64, error) { } return _POSIX_SEMAPHORES, nil case SC_SPAWN: - return _POSIX_SPAWN, nil + uname.Once.Do(func() { + var u unix.Utsname + err := unix.Uname(&u) + if err != nil { + return + } + rel := unix.ByteSliceToString(u.Release[:]) + ver := strings.Split(rel, ".") + maj, _ := strconv.Atoi(ver[0]) + uname.macOSMajor = maj + }) + if uname.macOSMajor < 22 { + return -1, nil + } + // macOS 13 (Ventura) and later + return 200112, nil case SC_SPIN_LOCKS: return _POSIX_SPIN_LOCKS, nil case SC_SPORADIC_SERVER: diff --git a/test/integration/vendor/github.com/tklauser/go-sysconf/zsysconf_defs_darwin.go b/test/integration/vendor/github.com/tklauser/go-sysconf/zsysconf_defs_darwin.go index 6fa7fde8a..6fadf3db1 100644 --- a/test/integration/vendor/github.com/tklauser/go-sysconf/zsysconf_defs_darwin.go +++ b/test/integration/vendor/github.com/tklauser/go-sysconf/zsysconf_defs_darwin.go @@ -181,7 +181,6 @@ const ( _POSIX_SHARED_MEMORY_OBJECTS = -0x1 _POSIX_SHELL = 0x30db0 _POSIX_SIGQUEUE_MAX = 0x20 - _POSIX_SPAWN = -0x1 _POSIX_SPIN_LOCKS = -0x1 _POSIX_SPORADIC_SERVER = -0x1 _POSIX_SS_REPL_MAX = 0x4 @@ -248,7 +247,8 @@ const ( const ( _CHAR_BIT = 0x8 - _INT_MAX = 0x7fffffff + _INT_MAX = 0x7fffffff + _LONG_MAX = 0x7fffffffffffffff sizeofOffT = 0x8 ) diff --git a/test/integration/vendor/github.com/tklauser/numcpus/.cirrus.yml b/test/integration/vendor/github.com/tklauser/numcpus/.cirrus.yml index 53c0110b5..69c6ced5c 100644 --- a/test/integration/vendor/github.com/tklauser/numcpus/.cirrus.yml +++ b/test/integration/vendor/github.com/tklauser/numcpus/.cirrus.yml @@ -1,6 +1,6 @@ env: CIRRUS_CLONE_DEPTH: 1 - GO_VERSION: go1.19.1 + GO_VERSION: go1.20 freebsd_12_task: freebsd_instance: diff --git a/test/integration/vendor/modules.txt b/test/integration/vendor/modules.txt index fde2702a6..90eb66298 100644 --- a/test/integration/vendor/modules.txt +++ b/test/integration/vendor/modules.txt @@ -748,7 +748,7 @@ github.com/serialx/hashring # github.com/shibumi/go-pathspec v1.3.0 ## explicit; go 1.17 github.com/shibumi/go-pathspec -# github.com/shirou/gopsutil/v3 v3.23.6 +# github.com/shirou/gopsutil/v3 v3.23.8 ## explicit; go 1.15 github.com/shirou/gopsutil/v3/common github.com/shirou/gopsutil/v3/cpu @@ -834,10 +834,10 @@ github.com/theupdateframework/notary/tuf/validation # github.com/tilt-dev/fsnotify v1.4.8-0.20220602155310-fff9c274a375 ## explicit; go 1.16 github.com/tilt-dev/fsnotify -# github.com/tklauser/go-sysconf v0.3.11 +# github.com/tklauser/go-sysconf v0.3.12 ## explicit; go 1.13 github.com/tklauser/go-sysconf -# github.com/tklauser/numcpus v0.6.0 +# github.com/tklauser/numcpus v0.6.1 ## explicit; go 1.13 github.com/tklauser/numcpus # github.com/tonistiigi/fsutil v0.0.0-20230629203738-36ef4d8c0dbb diff --git a/test/performance/go.mod b/test/performance/go.mod index 1b75668e2..7a7ae8107 100644 --- a/test/performance/go.mod +++ b/test/performance/go.mod @@ -56,7 +56,7 @@ require ( github.com/prometheus/procfs v0.11.1 // indirect github.com/rs/cors v1.9.0 // indirect github.com/shirou/gopsutil v3.21.11+incompatible // indirect - github.com/shirou/gopsutil/v3 v3.23.6 // indirect + github.com/shirou/gopsutil/v3 v3.23.8 // indirect github.com/shoenig/go-m1cpu v0.1.6 // indirect github.com/spf13/afero v1.9.5 // indirect github.com/spf13/cast v1.5.1 // indirect @@ -66,8 +66,8 @@ require ( github.com/spf13/viper v1.16.0 // indirect github.com/stretchr/objx v0.5.0 // indirect github.com/subosito/gotenv v1.4.2 // indirect - github.com/tklauser/go-sysconf v0.3.11 // indirect - github.com/tklauser/numcpus v0.6.0 // indirect + github.com/tklauser/go-sysconf v0.3.12 // indirect + github.com/tklauser/numcpus v0.6.1 // indirect github.com/trivago/grok v1.0.0 // indirect github.com/vardius/message-bus v1.1.5 // indirect github.com/yusufpapurcu/wmi v1.2.3 // indirect diff --git a/test/performance/go.sum b/test/performance/go.sum index 20ce3dedf..7bf059698 100644 --- a/test/performance/go.sum +++ b/test/performance/go.sum @@ -246,8 +246,8 @@ github.com/sclevine/spec v1.4.0 h1:z/Q9idDcay5m5irkZ28M7PtQM4aOISzOpj4bUPkDee8= github.com/sclevine/spec v1.4.0/go.mod h1:LvpgJaFyvQzRvc1kaDs0bulYwzC70PbiYjC4QnFHkOM= github.com/shirou/gopsutil v3.21.11+incompatible h1:+1+c1VGhc88SSonWP6foOcLhvnKlUeu/erjjvaPEYiI= github.com/shirou/gopsutil v3.21.11+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA= -github.com/shirou/gopsutil/v3 v3.23.6 h1:5y46WPI9QBKBbK7EEccUPNXpJpNrvPuTD0O2zHEHT08= -github.com/shirou/gopsutil/v3 v3.23.6/go.mod h1:j7QX50DrXYggrpN30W0Mo+I4/8U2UUIQrnrhqUeWrAU= +github.com/shirou/gopsutil/v3 v3.23.8 h1:xnATPiybo6GgdRoC4YoGnxXZFRc3dqQTGi73oLvvBrE= +github.com/shirou/gopsutil/v3 v3.23.8/go.mod h1:7hmCaBn+2ZwaZOr6jmPBZDfawwMGuo1id3C6aM8EDqQ= github.com/shoenig/go-m1cpu v0.1.6 h1:nxdKQNcEB6vzgA2E2bvzKIYRuNj7XNJ4S/aRSwKzFtM= github.com/shoenig/go-m1cpu v0.1.6/go.mod h1:1JJMcUBvfNwpq05QDQVAnx3gUHr9IYF7GNg9SUEw2VQ= github.com/shoenig/test v0.6.4 h1:kVTaSd7WLz5WZ2IaoM0RSzRsUD+m8wRR+5qvntpn4LU= @@ -285,10 +285,10 @@ github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcU github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/subosito/gotenv v1.4.2 h1:X1TuBLAMDFbaTAChgCBLu3DU3UPyELpnF2jjJ2cz/S8= github.com/subosito/gotenv v1.4.2/go.mod h1:ayKnFf/c6rvx/2iiLrJUk1e6plDbT3edrFNGqEflhK0= -github.com/tklauser/go-sysconf v0.3.11 h1:89WgdJhk5SNwJfu+GKyYveZ4IaJ7xAkecBo+KdJV0CM= -github.com/tklauser/go-sysconf v0.3.11/go.mod h1:GqXfhXY3kiPa0nAXPDIQIWzJbMCB7AmcWpGR8lSZfqI= -github.com/tklauser/numcpus v0.6.0 h1:kebhY2Qt+3U6RNK7UqpYNA+tJ23IBEGKkB7JQBfDYms= -github.com/tklauser/numcpus v0.6.0/go.mod h1:FEZLMke0lhOUG6w2JadTzp0a+Nl8PF/GFkQ5UVIcaL4= +github.com/tklauser/go-sysconf v0.3.12 h1:0QaGUFOdQaIVdPgfITYzaTegZvdCjmYO52cSFAEVmqU= +github.com/tklauser/go-sysconf v0.3.12/go.mod h1:Ho14jnntGE1fpdOqQEEaiKRpvIavV0hSfmBq8nJbHYI= +github.com/tklauser/numcpus v0.6.1 h1:ng9scYS7az0Bk4OZLvrNXNSAO2Pxr1XXRAPyjhIx+Fk= +github.com/tklauser/numcpus v0.6.1/go.mod h1:1XfjsgE2zo8GVw7POkMbHENHzVg3GzmoZ9fESEdAacY= github.com/trivago/grok v1.0.0 h1:oV2ljyZT63tgXkmgEHg2U0jMqiKKuL0hkn49s6aRavQ= github.com/trivago/grok v1.0.0/go.mod h1:9t59xLInhrncYq9a3J7488NgiBZi5y5yC7bss+w4NHM= github.com/trivago/tgo v1.0.7 h1:uaWH/XIy9aWYWpjm2CU3RpcqZXmX2ysQ9/Go+d9gyrM= @@ -458,8 +458,7 @@ golang.org/x/sys v0.0.0-20211025201205-69cdffdb9359/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220704084225-05e143d24a9e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.9.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.11.0 h1:eG7RXZHdqOJ1i+0lgLgCpSXAp6M3LYlAo6osgSi0xOM= golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= diff --git a/test/performance/vendor/github.com/nginx/agent/v2/src/core/pipe.go b/test/performance/vendor/github.com/nginx/agent/v2/src/core/pipe.go index 1ded89e02..657f57283 100644 --- a/test/performance/vendor/github.com/nginx/agent/v2/src/core/pipe.go +++ b/test/performance/vendor/github.com/nginx/agent/v2/src/core/pipe.go @@ -194,11 +194,11 @@ func (p *MessagePipe) GetExtensionPlugins() []ExtensionPlugin { func (p *MessagePipe) initPlugins() { for _, r := range p.plugins { - r.Init(p) + go r.Init(p) } for _, r := range p.extensionPlugins { - r.Init(p) + go r.Init(p) } } diff --git a/test/performance/vendor/github.com/nginx/agent/v2/src/plugins/nginx.go b/test/performance/vendor/github.com/nginx/agent/v2/src/plugins/nginx.go index 3c5dd16e0..bfbdad3c1 100644 --- a/test/performance/vendor/github.com/nginx/agent/v2/src/plugins/nginx.go +++ b/test/performance/vendor/github.com/nginx/agent/v2/src/plugins/nginx.go @@ -113,17 +113,17 @@ func (n *Nginx) Init(pipeline core.MessagePipeInterface) { log.Info("NginxBinary initializing") n.messagePipeline = pipeline n.nginxBinary.UpdateNginxDetailsFromProcesses(n.getNginxProccessInfo()) - nginxDetails := n.nginxBinary.GetNginxDetailsMapFromProcesses(n.getNginxProccessInfo()) - - pipeline.Process( - core.NewMessage(core.NginxPluginConfigured, n), - core.NewMessage(core.NginxInstancesFound, nginxDetails), - ) } // Process processes the messages from the messaging pipe func (n *Nginx) Process(message *core.Message) { switch message.Topic() { + case core.AgentStarted: + nginxDetails := n.nginxBinary.GetNginxDetailsMapFromProcesses(n.getNginxProccessInfo()) + n.messagePipeline.Process( + core.NewMessage(core.NginxPluginConfigured, n), + core.NewMessage(core.NginxInstancesFound, nginxDetails), + ) case core.CommNginxConfig: switch cmd := message.Data().(type) { case *proto.Command: @@ -208,6 +208,7 @@ func (n *Nginx) Subscriptions() []string { core.NginxConfigValidationPending, core.NginxConfigValidationSucceeded, core.NginxConfigValidationFailed, + core.AgentStarted, } } diff --git a/test/performance/vendor/github.com/shirou/gopsutil/v3/cpu/cpu_linux.go b/test/performance/vendor/github.com/shirou/gopsutil/v3/cpu/cpu_linux.go index 1b64241ce..b5a20e366 100644 --- a/test/performance/vendor/github.com/shirou/gopsutil/v3/cpu/cpu_linux.go +++ b/test/performance/vendor/github.com/shirou/gopsutil/v3/cpu/cpu_linux.go @@ -259,8 +259,7 @@ func InfoWithContext(ctx context.Context) ([]InfoStat, error) { } case "Model Name", "model name", "cpu": c.ModelName = value - if strings.Contains(value, "POWER8") || - strings.Contains(value, "POWER7") { + if strings.Contains(value, "POWER") { c.Model = strings.Split(value, " ")[0] c.Family = "POWER" c.VendorID = "IBM" diff --git a/test/performance/vendor/github.com/shirou/gopsutil/v3/disk/disk_linux.go b/test/performance/vendor/github.com/shirou/gopsutil/v3/disk/disk_linux.go index 2a8c50ae4..5015c34ae 100644 --- a/test/performance/vendor/github.com/shirou/gopsutil/v3/disk/disk_linux.go +++ b/test/performance/vendor/github.com/shirou/gopsutil/v3/disk/disk_linux.go @@ -474,7 +474,11 @@ func IOCountersWithContext(ctx context.Context, names ...string) (map[string]IOC } d.Name = name - d.SerialNumber, _ = SerialNumberWithContext(ctx, name) + // Names passed in can be full paths (/dev/sda) or just device names (sda). + // Since `name` here is already a basename, re-add the /dev path. + // This is not ideal, but we may break the API by changing how SerialNumberWithContext + // works. + d.SerialNumber, _ = SerialNumberWithContext(ctx, common.HostDevWithContext(ctx, name)) d.Label, _ = LabelWithContext(ctx, name) ret[name] = d diff --git a/test/performance/vendor/github.com/shirou/gopsutil/v3/disk/disk_windows.go b/test/performance/vendor/github.com/shirou/gopsutil/v3/disk/disk_windows.go index 8a1a28d69..e17db3e5b 100644 --- a/test/performance/vendor/github.com/shirou/gopsutil/v3/disk/disk_windows.go +++ b/test/performance/vendor/github.com/shirou/gopsutil/v3/disk/disk_windows.go @@ -7,7 +7,6 @@ import ( "bytes" "context" "fmt" - "sync" "syscall" "unsafe" @@ -51,6 +50,7 @@ func init() { key, err := registry.OpenKey(registry.LOCAL_MACHINE, `SYSTEM\CurrentControlSet\Services\PartMgr`, registry.SET_VALUE) if err == nil { key.SetDWordValue("EnableCounterForIoctl", 1) + key.Close() } } @@ -86,28 +86,22 @@ func PartitionsWithContext(ctx context.Context, all bool) ([]PartitionStat, erro warnings := Warnings{ Verbose: true, } - var ret []PartitionStat - retChan := make(chan []PartitionStat) - errChan := make(chan error) - lpBuffer := make([]byte, 254) - - var waitgrp sync.WaitGroup - waitgrp.Add(1) - defer waitgrp.Done() - - f := func() { - defer func() { - waitgrp.Wait() - // fires when this func and the outside func finishes. - close(errChan) - close(retChan) - }() + + var errLogicalDrives error + retChan := make(chan PartitionStat) + quitChan := make(chan struct{}) + defer close(quitChan) + + getPartitions := func() { + defer close(retChan) + + lpBuffer := make([]byte, 254) diskret, _, err := procGetLogicalDriveStringsW.Call( uintptr(len(lpBuffer)), uintptr(unsafe.Pointer(&lpBuffer[0]))) if diskret == 0 { - errChan <- err + errLogicalDrives = err return } for _, v := range lpBuffer { @@ -153,27 +147,37 @@ func PartitionsWithContext(ctx context.Context, all bool) ([]PartitionStat, erro opts = append(opts, "compress") } - d := PartitionStat{ + select { + case retChan <- PartitionStat{ Mountpoint: path, Device: path, - Fstype: string(bytes.Replace(lpFileSystemNameBuffer, []byte("\x00"), []byte(""), -1)), + Fstype: string(bytes.ReplaceAll(lpFileSystemNameBuffer, []byte("\x00"), []byte(""))), Opts: opts, + }: + case <-quitChan: + return } - ret = append(ret, d) } } } - retChan <- ret } - go f() - select { - case err := <-errChan: - return ret, err - case ret := <-retChan: - return ret, warnings.Reference() - case <-ctx.Done(): - return ret, ctx.Err() + go getPartitions() + + var ret []PartitionStat + for { + select { + case p, ok := <-retChan: + if !ok { + if errLogicalDrives != nil { + return ret, errLogicalDrives + } + return ret, warnings.Reference() + } + ret = append(ret, p) + case <-ctx.Done(): + return ret, ctx.Err() + } } } diff --git a/test/performance/vendor/github.com/shirou/gopsutil/v3/host/host_linux.go b/test/performance/vendor/github.com/shirou/gopsutil/v3/host/host_linux.go index 62a4b3ca9..e6ac63a39 100644 --- a/test/performance/vendor/github.com/shirou/gopsutil/v3/host/host_linux.go +++ b/test/performance/vendor/github.com/shirou/gopsutil/v3/host/host_linux.go @@ -138,13 +138,13 @@ func getlsbStruct(ctx context.Context) (*lsbStruct, error) { } switch field[0] { case "DISTRIB_ID": - ret.ID = field[1] + ret.ID = strings.ReplaceAll(field[1], `"`, ``) case "DISTRIB_RELEASE": - ret.Release = field[1] + ret.Release = strings.ReplaceAll(field[1], `"`, ``) case "DISTRIB_CODENAME": - ret.Codename = field[1] + ret.Codename = strings.ReplaceAll(field[1], `"`, ``) case "DISTRIB_DESCRIPTION": - ret.Description = field[1] + ret.Description = strings.ReplaceAll(field[1], `"`, ``) } } } else if common.PathExists("/usr/bin/lsb_release") { @@ -159,13 +159,13 @@ func getlsbStruct(ctx context.Context) (*lsbStruct, error) { } switch field[0] { case "Distributor ID": - ret.ID = field[1] + ret.ID = strings.ReplaceAll(field[1], `"`, ``) case "Release": - ret.Release = field[1] + ret.Release = strings.ReplaceAll(field[1], `"`, ``) case "Codename": - ret.Codename = field[1] + ret.Codename = strings.ReplaceAll(field[1], `"`, ``) case "Description": - ret.Description = field[1] + ret.Description = strings.ReplaceAll(field[1], `"`, ``) } } diff --git a/test/performance/vendor/github.com/shirou/gopsutil/v3/internal/common/common.go b/test/performance/vendor/github.com/shirou/gopsutil/v3/internal/common/common.go index 9bfece362..7a31d251b 100644 --- a/test/performance/vendor/github.com/shirou/gopsutil/v3/internal/common/common.go +++ b/test/performance/vendor/github.com/shirou/gopsutil/v3/internal/common/common.go @@ -114,6 +114,30 @@ func ReadLines(filename string) ([]string, error) { return ReadLinesOffsetN(filename, 0, -1) } +// ReadLine reads a file and returns the first occurrence of a line that is prefixed with prefix. +func ReadLine(filename string, prefix string) (string, error) { + f, err := os.Open(filename) + if err != nil { + return "", err + } + defer f.Close() + r := bufio.NewReader(f) + for { + line, err := r.ReadString('\n') + if err != nil { + if err == io.EOF { + break + } + return "", err + } + if strings.HasPrefix(line, prefix) { + return line, nil + } + } + + return "", nil +} + // ReadLinesOffsetN reads contents from file and splits them by new line. // The offset tells at which line number to start. // The count determines the number of lines to read (starting from offset): diff --git a/test/performance/vendor/github.com/shirou/gopsutil/v3/internal/common/common_linux.go b/test/performance/vendor/github.com/shirou/gopsutil/v3/internal/common/common_linux.go index b58edbeb0..a644687ba 100644 --- a/test/performance/vendor/github.com/shirou/gopsutil/v3/internal/common/common_linux.go +++ b/test/performance/vendor/github.com/shirou/gopsutil/v3/internal/common/common_linux.go @@ -62,17 +62,38 @@ func BootTimeWithContext(ctx context.Context) (uint64, error) { return 0, err } - statFile := "stat" + useStatFile := true if system == "lxc" && role == "guest" { // if lxc, /proc/uptime is used. - statFile = "uptime" + useStatFile = false } else if system == "docker" && role == "guest" { // also docker, guest - statFile = "uptime" + useStatFile = false } - filename := HostProcWithContext(ctx, statFile) + if useStatFile { + return readBootTimeStat(ctx) + } + + filename := HostProcWithContext(ctx, "uptime") lines, err := ReadLines(filename) + if err != nil { + return handleBootTimeFileReadErr(err) + } + if len(lines) != 1 { + return 0, fmt.Errorf("wrong uptime format") + } + f := strings.Fields(lines[0]) + b, err := strconv.ParseFloat(f[0], 64) + if err != nil { + return 0, err + } + currentTime := float64(time.Now().UnixNano()) / float64(time.Second) + t := currentTime - b + return uint64(t), nil +} + +func handleBootTimeFileReadErr(err error) (uint64, error) { if os.IsPermission(err) { var info syscall.Sysinfo_t err := syscall.Sysinfo(&info) @@ -84,39 +105,27 @@ func BootTimeWithContext(ctx context.Context) (uint64, error) { t := currentTime - int64(info.Uptime) return uint64(t), nil } + return 0, err +} + +func readBootTimeStat(ctx context.Context) (uint64, error) { + filename := HostProcWithContext(ctx, "stat") + line, err := ReadLine(filename, "btime") if err != nil { - return 0, err + return handleBootTimeFileReadErr(err) } - - if statFile == "stat" { - for _, line := range lines { - if strings.HasPrefix(line, "btime") { - f := strings.Fields(line) - if len(f) != 2 { - return 0, fmt.Errorf("wrong btime format") - } - b, err := strconv.ParseInt(f[1], 10, 64) - if err != nil { - return 0, err - } - t := uint64(b) - return t, nil - } - } - } else if statFile == "uptime" { - if len(lines) != 1 { - return 0, fmt.Errorf("wrong uptime format") + if strings.HasPrefix(line, "btime") { + f := strings.Fields(line) + if len(f) != 2 { + return 0, fmt.Errorf("wrong btime format") } - f := strings.Fields(lines[0]) - b, err := strconv.ParseFloat(f[0], 64) + b, err := strconv.ParseInt(f[1], 10, 64) if err != nil { return 0, err } - currentTime := float64(time.Now().UnixNano()) / float64(time.Second) - t := currentTime - b - return uint64(t), nil + t := uint64(b) + return t, nil } - return 0, fmt.Errorf("could not find btime") } diff --git a/test/performance/vendor/github.com/shirou/gopsutil/v3/mem/mem_linux.go b/test/performance/vendor/github.com/shirou/gopsutil/v3/mem/mem_linux.go index 361d06bcc..935331728 100644 --- a/test/performance/vendor/github.com/shirou/gopsutil/v3/mem/mem_linux.go +++ b/test/performance/vendor/github.com/shirou/gopsutil/v3/mem/mem_linux.go @@ -371,25 +371,25 @@ func SwapMemoryWithContext(ctx context.Context) (*SwapMemoryStat, error) { continue } ret.Sout = value * 4 * 1024 - case "pgpgIn": + case "pgpgin": value, err := strconv.ParseUint(fields[1], 10, 64) if err != nil { continue } ret.PgIn = value * 4 * 1024 - case "pgpgOut": + case "pgpgout": value, err := strconv.ParseUint(fields[1], 10, 64) if err != nil { continue } ret.PgOut = value * 4 * 1024 - case "pgFault": + case "pgfault": value, err := strconv.ParseUint(fields[1], 10, 64) if err != nil { continue } ret.PgFault = value * 4 * 1024 - case "pgMajFault": + case "pgmajfault": value, err := strconv.ParseUint(fields[1], 10, 64) if err != nil { continue diff --git a/test/performance/vendor/github.com/shirou/gopsutil/v3/process/process_darwin.go b/test/performance/vendor/github.com/shirou/gopsutil/v3/process/process_darwin.go index 55c31962a..176661cbd 100644 --- a/test/performance/vendor/github.com/shirou/gopsutil/v3/process/process_darwin.go +++ b/test/performance/vendor/github.com/shirou/gopsutil/v3/process/process_darwin.go @@ -82,8 +82,6 @@ func (p *Process) NameWithContext(ctx context.Context) (string, error) { extendedName := filepath.Base(cmdName) if strings.HasPrefix(extendedName, p.name) { name = extendedName - } else { - name = cmdName } } } diff --git a/test/performance/vendor/github.com/shirou/gopsutil/v3/process/process_freebsd.go b/test/performance/vendor/github.com/shirou/gopsutil/v3/process/process_freebsd.go index a123ccf9b..85134b7ee 100644 --- a/test/performance/vendor/github.com/shirou/gopsutil/v3/process/process_freebsd.go +++ b/test/performance/vendor/github.com/shirou/gopsutil/v3/process/process_freebsd.go @@ -55,8 +55,6 @@ func (p *Process) NameWithContext(ctx context.Context) (string, error) { extendedName := filepath.Base(cmdlineSlice[0]) if strings.HasPrefix(extendedName, p.name) { name = extendedName - } else { - name = cmdlineSlice[0] } } } diff --git a/test/performance/vendor/github.com/shirou/gopsutil/v3/process/process_linux.go b/test/performance/vendor/github.com/shirou/gopsutil/v3/process/process_linux.go index 29c447390..37cb7ca44 100644 --- a/test/performance/vendor/github.com/shirou/gopsutil/v3/process/process_linux.go +++ b/test/performance/vendor/github.com/shirou/gopsutil/v3/process/process_linux.go @@ -845,8 +845,6 @@ func (p *Process) fillFromStatusWithContext(ctx context.Context) error { extendedName := filepath.Base(cmdlineSlice[0]) if strings.HasPrefix(extendedName, p.name) { p.name = extendedName - } else { - p.name = cmdlineSlice[0] } } } diff --git a/test/performance/vendor/github.com/shirou/gopsutil/v3/process/process_openbsd.go b/test/performance/vendor/github.com/shirou/gopsutil/v3/process/process_openbsd.go index cbb1a77f6..a58c5eb11 100644 --- a/test/performance/vendor/github.com/shirou/gopsutil/v3/process/process_openbsd.go +++ b/test/performance/vendor/github.com/shirou/gopsutil/v3/process/process_openbsd.go @@ -60,8 +60,6 @@ func (p *Process) NameWithContext(ctx context.Context) (string, error) { extendedName := filepath.Base(cmdlineSlice[0]) if strings.HasPrefix(extendedName, p.name) { name = extendedName - } else { - name = cmdlineSlice[0] } } } diff --git a/test/performance/vendor/github.com/tklauser/go-sysconf/.cirrus.yml b/test/performance/vendor/github.com/tklauser/go-sysconf/.cirrus.yml index 6be2c3548..1b27f1962 100644 --- a/test/performance/vendor/github.com/tklauser/go-sysconf/.cirrus.yml +++ b/test/performance/vendor/github.com/tklauser/go-sysconf/.cirrus.yml @@ -1,6 +1,6 @@ env: CIRRUS_CLONE_DEPTH: 1 - GO_VERSION: go1.19.1 + GO_VERSION: go1.20 freebsd_12_task: freebsd_instance: diff --git a/test/performance/vendor/github.com/tklauser/go-sysconf/sysconf_darwin.go b/test/performance/vendor/github.com/tklauser/go-sysconf/sysconf_darwin.go index 4a5197b2f..3f5d83f69 100644 --- a/test/performance/vendor/github.com/tklauser/go-sysconf/sysconf_darwin.go +++ b/test/performance/vendor/github.com/tklauser/go-sysconf/sysconf_darwin.go @@ -5,6 +5,10 @@ package sysconf import ( + "strconv" + "strings" + "sync" + "golang.org/x/sys/unix" ) @@ -14,8 +18,14 @@ const ( _SYMLOOP_MAX = _MAXSYMLINKS ) -// sysconf implements sysconf(3) as in the Darwin libc, version 1244.30.3 -// (derived from the FreeBSD libc). +var uname struct { + sync.Once + macOSMajor int +} + +// sysconf implements sysconf(4) as in the Darwin libc (derived from the FreeBSD +// libc), version 1534.81.1. +// See https://github.com/apple-oss-distributions/Libc/tree/Libc-1534.81.1. func sysconf(name int) (int64, error) { switch name { case SC_AIO_LISTIO_MAX: @@ -54,12 +64,16 @@ func sysconf(name int) (int64, error) { return sysctl32("kern.ngroups"), nil case SC_OPEN_MAX, SC_STREAM_MAX: var rlim unix.Rlimit - if err := unix.Getrlimit(unix.RLIMIT_NOFILE, &rlim); err == nil { - if rlim.Cur != unix.RLIM_INFINITY { - return int64(rlim.Cur), nil - } + if err := unix.Getrlimit(unix.RLIMIT_NOFILE, &rlim); err != nil { + return -1, nil } - return -1, nil + if rlim.Cur > unix.RLIM_INFINITY { + return -1, nil + } + if rlim.Cur > _LONG_MAX { + return -1, unix.EOVERFLOW + } + return int64(rlim.Cur), nil case SC_RTSIG_MAX: return -1, nil case SC_SEM_NSEMS_MAX: @@ -126,7 +140,22 @@ func sysconf(name int) (int64, error) { } return _POSIX_SEMAPHORES, nil case SC_SPAWN: - return _POSIX_SPAWN, nil + uname.Once.Do(func() { + var u unix.Utsname + err := unix.Uname(&u) + if err != nil { + return + } + rel := unix.ByteSliceToString(u.Release[:]) + ver := strings.Split(rel, ".") + maj, _ := strconv.Atoi(ver[0]) + uname.macOSMajor = maj + }) + if uname.macOSMajor < 22 { + return -1, nil + } + // macOS 13 (Ventura) and later + return 200112, nil case SC_SPIN_LOCKS: return _POSIX_SPIN_LOCKS, nil case SC_SPORADIC_SERVER: diff --git a/test/performance/vendor/github.com/tklauser/go-sysconf/zsysconf_defs_darwin.go b/test/performance/vendor/github.com/tklauser/go-sysconf/zsysconf_defs_darwin.go index 6fa7fde8a..6fadf3db1 100644 --- a/test/performance/vendor/github.com/tklauser/go-sysconf/zsysconf_defs_darwin.go +++ b/test/performance/vendor/github.com/tklauser/go-sysconf/zsysconf_defs_darwin.go @@ -181,7 +181,6 @@ const ( _POSIX_SHARED_MEMORY_OBJECTS = -0x1 _POSIX_SHELL = 0x30db0 _POSIX_SIGQUEUE_MAX = 0x20 - _POSIX_SPAWN = -0x1 _POSIX_SPIN_LOCKS = -0x1 _POSIX_SPORADIC_SERVER = -0x1 _POSIX_SS_REPL_MAX = 0x4 @@ -248,7 +247,8 @@ const ( const ( _CHAR_BIT = 0x8 - _INT_MAX = 0x7fffffff + _INT_MAX = 0x7fffffff + _LONG_MAX = 0x7fffffffffffffff sizeofOffT = 0x8 ) diff --git a/test/performance/vendor/github.com/tklauser/numcpus/.cirrus.yml b/test/performance/vendor/github.com/tklauser/numcpus/.cirrus.yml index 53c0110b5..69c6ced5c 100644 --- a/test/performance/vendor/github.com/tklauser/numcpus/.cirrus.yml +++ b/test/performance/vendor/github.com/tklauser/numcpus/.cirrus.yml @@ -1,6 +1,6 @@ env: CIRRUS_CLONE_DEPTH: 1 - GO_VERSION: go1.19.1 + GO_VERSION: go1.20 freebsd_12_task: freebsd_instance: diff --git a/test/performance/vendor/modules.txt b/test/performance/vendor/modules.txt index f9c43eda6..db5d0da4a 100644 --- a/test/performance/vendor/modules.txt +++ b/test/performance/vendor/modules.txt @@ -237,7 +237,7 @@ github.com/shirou/gopsutil/internal/common github.com/shirou/gopsutil/mem github.com/shirou/gopsutil/net github.com/shirou/gopsutil/process -# github.com/shirou/gopsutil/v3 v3.23.6 +# github.com/shirou/gopsutil/v3 v3.23.8 ## explicit; go 1.15 github.com/shirou/gopsutil/v3/common github.com/shirou/gopsutil/v3/cpu @@ -293,10 +293,10 @@ github.com/stretchr/testify/require # github.com/subosito/gotenv v1.4.2 ## explicit; go 1.18 github.com/subosito/gotenv -# github.com/tklauser/go-sysconf v0.3.11 +# github.com/tklauser/go-sysconf v0.3.12 ## explicit; go 1.13 github.com/tklauser/go-sysconf -# github.com/tklauser/numcpus v0.6.0 +# github.com/tklauser/numcpus v0.6.1 ## explicit; go 1.13 github.com/tklauser/numcpus # github.com/trivago/grok v1.0.0 diff --git a/vendor/github.com/shirou/gopsutil/v3/cpu/cpu_linux.go b/vendor/github.com/shirou/gopsutil/v3/cpu/cpu_linux.go index 1b64241ce..b5a20e366 100644 --- a/vendor/github.com/shirou/gopsutil/v3/cpu/cpu_linux.go +++ b/vendor/github.com/shirou/gopsutil/v3/cpu/cpu_linux.go @@ -259,8 +259,7 @@ func InfoWithContext(ctx context.Context) ([]InfoStat, error) { } case "Model Name", "model name", "cpu": c.ModelName = value - if strings.Contains(value, "POWER8") || - strings.Contains(value, "POWER7") { + if strings.Contains(value, "POWER") { c.Model = strings.Split(value, " ")[0] c.Family = "POWER" c.VendorID = "IBM" diff --git a/vendor/github.com/shirou/gopsutil/v3/disk/disk_linux.go b/vendor/github.com/shirou/gopsutil/v3/disk/disk_linux.go index 2a8c50ae4..5015c34ae 100644 --- a/vendor/github.com/shirou/gopsutil/v3/disk/disk_linux.go +++ b/vendor/github.com/shirou/gopsutil/v3/disk/disk_linux.go @@ -474,7 +474,11 @@ func IOCountersWithContext(ctx context.Context, names ...string) (map[string]IOC } d.Name = name - d.SerialNumber, _ = SerialNumberWithContext(ctx, name) + // Names passed in can be full paths (/dev/sda) or just device names (sda). + // Since `name` here is already a basename, re-add the /dev path. + // This is not ideal, but we may break the API by changing how SerialNumberWithContext + // works. + d.SerialNumber, _ = SerialNumberWithContext(ctx, common.HostDevWithContext(ctx, name)) d.Label, _ = LabelWithContext(ctx, name) ret[name] = d diff --git a/vendor/github.com/shirou/gopsutil/v3/disk/disk_windows.go b/vendor/github.com/shirou/gopsutil/v3/disk/disk_windows.go index 8a1a28d69..e17db3e5b 100644 --- a/vendor/github.com/shirou/gopsutil/v3/disk/disk_windows.go +++ b/vendor/github.com/shirou/gopsutil/v3/disk/disk_windows.go @@ -7,7 +7,6 @@ import ( "bytes" "context" "fmt" - "sync" "syscall" "unsafe" @@ -51,6 +50,7 @@ func init() { key, err := registry.OpenKey(registry.LOCAL_MACHINE, `SYSTEM\CurrentControlSet\Services\PartMgr`, registry.SET_VALUE) if err == nil { key.SetDWordValue("EnableCounterForIoctl", 1) + key.Close() } } @@ -86,28 +86,22 @@ func PartitionsWithContext(ctx context.Context, all bool) ([]PartitionStat, erro warnings := Warnings{ Verbose: true, } - var ret []PartitionStat - retChan := make(chan []PartitionStat) - errChan := make(chan error) - lpBuffer := make([]byte, 254) - - var waitgrp sync.WaitGroup - waitgrp.Add(1) - defer waitgrp.Done() - - f := func() { - defer func() { - waitgrp.Wait() - // fires when this func and the outside func finishes. - close(errChan) - close(retChan) - }() + + var errLogicalDrives error + retChan := make(chan PartitionStat) + quitChan := make(chan struct{}) + defer close(quitChan) + + getPartitions := func() { + defer close(retChan) + + lpBuffer := make([]byte, 254) diskret, _, err := procGetLogicalDriveStringsW.Call( uintptr(len(lpBuffer)), uintptr(unsafe.Pointer(&lpBuffer[0]))) if diskret == 0 { - errChan <- err + errLogicalDrives = err return } for _, v := range lpBuffer { @@ -153,27 +147,37 @@ func PartitionsWithContext(ctx context.Context, all bool) ([]PartitionStat, erro opts = append(opts, "compress") } - d := PartitionStat{ + select { + case retChan <- PartitionStat{ Mountpoint: path, Device: path, - Fstype: string(bytes.Replace(lpFileSystemNameBuffer, []byte("\x00"), []byte(""), -1)), + Fstype: string(bytes.ReplaceAll(lpFileSystemNameBuffer, []byte("\x00"), []byte(""))), Opts: opts, + }: + case <-quitChan: + return } - ret = append(ret, d) } } } - retChan <- ret } - go f() - select { - case err := <-errChan: - return ret, err - case ret := <-retChan: - return ret, warnings.Reference() - case <-ctx.Done(): - return ret, ctx.Err() + go getPartitions() + + var ret []PartitionStat + for { + select { + case p, ok := <-retChan: + if !ok { + if errLogicalDrives != nil { + return ret, errLogicalDrives + } + return ret, warnings.Reference() + } + ret = append(ret, p) + case <-ctx.Done(): + return ret, ctx.Err() + } } } diff --git a/vendor/github.com/shirou/gopsutil/v3/host/host_linux.go b/vendor/github.com/shirou/gopsutil/v3/host/host_linux.go index 62a4b3ca9..e6ac63a39 100644 --- a/vendor/github.com/shirou/gopsutil/v3/host/host_linux.go +++ b/vendor/github.com/shirou/gopsutil/v3/host/host_linux.go @@ -138,13 +138,13 @@ func getlsbStruct(ctx context.Context) (*lsbStruct, error) { } switch field[0] { case "DISTRIB_ID": - ret.ID = field[1] + ret.ID = strings.ReplaceAll(field[1], `"`, ``) case "DISTRIB_RELEASE": - ret.Release = field[1] + ret.Release = strings.ReplaceAll(field[1], `"`, ``) case "DISTRIB_CODENAME": - ret.Codename = field[1] + ret.Codename = strings.ReplaceAll(field[1], `"`, ``) case "DISTRIB_DESCRIPTION": - ret.Description = field[1] + ret.Description = strings.ReplaceAll(field[1], `"`, ``) } } } else if common.PathExists("/usr/bin/lsb_release") { @@ -159,13 +159,13 @@ func getlsbStruct(ctx context.Context) (*lsbStruct, error) { } switch field[0] { case "Distributor ID": - ret.ID = field[1] + ret.ID = strings.ReplaceAll(field[1], `"`, ``) case "Release": - ret.Release = field[1] + ret.Release = strings.ReplaceAll(field[1], `"`, ``) case "Codename": - ret.Codename = field[1] + ret.Codename = strings.ReplaceAll(field[1], `"`, ``) case "Description": - ret.Description = field[1] + ret.Description = strings.ReplaceAll(field[1], `"`, ``) } } diff --git a/vendor/github.com/shirou/gopsutil/v3/internal/common/common.go b/vendor/github.com/shirou/gopsutil/v3/internal/common/common.go index 9bfece362..7a31d251b 100644 --- a/vendor/github.com/shirou/gopsutil/v3/internal/common/common.go +++ b/vendor/github.com/shirou/gopsutil/v3/internal/common/common.go @@ -114,6 +114,30 @@ func ReadLines(filename string) ([]string, error) { return ReadLinesOffsetN(filename, 0, -1) } +// ReadLine reads a file and returns the first occurrence of a line that is prefixed with prefix. +func ReadLine(filename string, prefix string) (string, error) { + f, err := os.Open(filename) + if err != nil { + return "", err + } + defer f.Close() + r := bufio.NewReader(f) + for { + line, err := r.ReadString('\n') + if err != nil { + if err == io.EOF { + break + } + return "", err + } + if strings.HasPrefix(line, prefix) { + return line, nil + } + } + + return "", nil +} + // ReadLinesOffsetN reads contents from file and splits them by new line. // The offset tells at which line number to start. // The count determines the number of lines to read (starting from offset): diff --git a/vendor/github.com/shirou/gopsutil/v3/internal/common/common_linux.go b/vendor/github.com/shirou/gopsutil/v3/internal/common/common_linux.go index b58edbeb0..a644687ba 100644 --- a/vendor/github.com/shirou/gopsutil/v3/internal/common/common_linux.go +++ b/vendor/github.com/shirou/gopsutil/v3/internal/common/common_linux.go @@ -62,17 +62,38 @@ func BootTimeWithContext(ctx context.Context) (uint64, error) { return 0, err } - statFile := "stat" + useStatFile := true if system == "lxc" && role == "guest" { // if lxc, /proc/uptime is used. - statFile = "uptime" + useStatFile = false } else if system == "docker" && role == "guest" { // also docker, guest - statFile = "uptime" + useStatFile = false } - filename := HostProcWithContext(ctx, statFile) + if useStatFile { + return readBootTimeStat(ctx) + } + + filename := HostProcWithContext(ctx, "uptime") lines, err := ReadLines(filename) + if err != nil { + return handleBootTimeFileReadErr(err) + } + if len(lines) != 1 { + return 0, fmt.Errorf("wrong uptime format") + } + f := strings.Fields(lines[0]) + b, err := strconv.ParseFloat(f[0], 64) + if err != nil { + return 0, err + } + currentTime := float64(time.Now().UnixNano()) / float64(time.Second) + t := currentTime - b + return uint64(t), nil +} + +func handleBootTimeFileReadErr(err error) (uint64, error) { if os.IsPermission(err) { var info syscall.Sysinfo_t err := syscall.Sysinfo(&info) @@ -84,39 +105,27 @@ func BootTimeWithContext(ctx context.Context) (uint64, error) { t := currentTime - int64(info.Uptime) return uint64(t), nil } + return 0, err +} + +func readBootTimeStat(ctx context.Context) (uint64, error) { + filename := HostProcWithContext(ctx, "stat") + line, err := ReadLine(filename, "btime") if err != nil { - return 0, err + return handleBootTimeFileReadErr(err) } - - if statFile == "stat" { - for _, line := range lines { - if strings.HasPrefix(line, "btime") { - f := strings.Fields(line) - if len(f) != 2 { - return 0, fmt.Errorf("wrong btime format") - } - b, err := strconv.ParseInt(f[1], 10, 64) - if err != nil { - return 0, err - } - t := uint64(b) - return t, nil - } - } - } else if statFile == "uptime" { - if len(lines) != 1 { - return 0, fmt.Errorf("wrong uptime format") + if strings.HasPrefix(line, "btime") { + f := strings.Fields(line) + if len(f) != 2 { + return 0, fmt.Errorf("wrong btime format") } - f := strings.Fields(lines[0]) - b, err := strconv.ParseFloat(f[0], 64) + b, err := strconv.ParseInt(f[1], 10, 64) if err != nil { return 0, err } - currentTime := float64(time.Now().UnixNano()) / float64(time.Second) - t := currentTime - b - return uint64(t), nil + t := uint64(b) + return t, nil } - return 0, fmt.Errorf("could not find btime") } diff --git a/vendor/github.com/shirou/gopsutil/v3/mem/mem_linux.go b/vendor/github.com/shirou/gopsutil/v3/mem/mem_linux.go index 361d06bcc..935331728 100644 --- a/vendor/github.com/shirou/gopsutil/v3/mem/mem_linux.go +++ b/vendor/github.com/shirou/gopsutil/v3/mem/mem_linux.go @@ -371,25 +371,25 @@ func SwapMemoryWithContext(ctx context.Context) (*SwapMemoryStat, error) { continue } ret.Sout = value * 4 * 1024 - case "pgpgIn": + case "pgpgin": value, err := strconv.ParseUint(fields[1], 10, 64) if err != nil { continue } ret.PgIn = value * 4 * 1024 - case "pgpgOut": + case "pgpgout": value, err := strconv.ParseUint(fields[1], 10, 64) if err != nil { continue } ret.PgOut = value * 4 * 1024 - case "pgFault": + case "pgfault": value, err := strconv.ParseUint(fields[1], 10, 64) if err != nil { continue } ret.PgFault = value * 4 * 1024 - case "pgMajFault": + case "pgmajfault": value, err := strconv.ParseUint(fields[1], 10, 64) if err != nil { continue diff --git a/vendor/github.com/shirou/gopsutil/v3/process/process_darwin.go b/vendor/github.com/shirou/gopsutil/v3/process/process_darwin.go index 55c31962a..176661cbd 100644 --- a/vendor/github.com/shirou/gopsutil/v3/process/process_darwin.go +++ b/vendor/github.com/shirou/gopsutil/v3/process/process_darwin.go @@ -82,8 +82,6 @@ func (p *Process) NameWithContext(ctx context.Context) (string, error) { extendedName := filepath.Base(cmdName) if strings.HasPrefix(extendedName, p.name) { name = extendedName - } else { - name = cmdName } } } diff --git a/vendor/github.com/shirou/gopsutil/v3/process/process_freebsd.go b/vendor/github.com/shirou/gopsutil/v3/process/process_freebsd.go index a123ccf9b..85134b7ee 100644 --- a/vendor/github.com/shirou/gopsutil/v3/process/process_freebsd.go +++ b/vendor/github.com/shirou/gopsutil/v3/process/process_freebsd.go @@ -55,8 +55,6 @@ func (p *Process) NameWithContext(ctx context.Context) (string, error) { extendedName := filepath.Base(cmdlineSlice[0]) if strings.HasPrefix(extendedName, p.name) { name = extendedName - } else { - name = cmdlineSlice[0] } } } diff --git a/vendor/github.com/shirou/gopsutil/v3/process/process_linux.go b/vendor/github.com/shirou/gopsutil/v3/process/process_linux.go index 29c447390..37cb7ca44 100644 --- a/vendor/github.com/shirou/gopsutil/v3/process/process_linux.go +++ b/vendor/github.com/shirou/gopsutil/v3/process/process_linux.go @@ -845,8 +845,6 @@ func (p *Process) fillFromStatusWithContext(ctx context.Context) error { extendedName := filepath.Base(cmdlineSlice[0]) if strings.HasPrefix(extendedName, p.name) { p.name = extendedName - } else { - p.name = cmdlineSlice[0] } } } diff --git a/vendor/github.com/shirou/gopsutil/v3/process/process_openbsd.go b/vendor/github.com/shirou/gopsutil/v3/process/process_openbsd.go index cbb1a77f6..a58c5eb11 100644 --- a/vendor/github.com/shirou/gopsutil/v3/process/process_openbsd.go +++ b/vendor/github.com/shirou/gopsutil/v3/process/process_openbsd.go @@ -60,8 +60,6 @@ func (p *Process) NameWithContext(ctx context.Context) (string, error) { extendedName := filepath.Base(cmdlineSlice[0]) if strings.HasPrefix(extendedName, p.name) { name = extendedName - } else { - name = cmdlineSlice[0] } } } diff --git a/vendor/github.com/tklauser/go-sysconf/.cirrus.yml b/vendor/github.com/tklauser/go-sysconf/.cirrus.yml index 6be2c3548..1b27f1962 100644 --- a/vendor/github.com/tklauser/go-sysconf/.cirrus.yml +++ b/vendor/github.com/tklauser/go-sysconf/.cirrus.yml @@ -1,6 +1,6 @@ env: CIRRUS_CLONE_DEPTH: 1 - GO_VERSION: go1.19.1 + GO_VERSION: go1.20 freebsd_12_task: freebsd_instance: diff --git a/vendor/github.com/tklauser/go-sysconf/sysconf_darwin.go b/vendor/github.com/tklauser/go-sysconf/sysconf_darwin.go index 4a5197b2f..3f5d83f69 100644 --- a/vendor/github.com/tklauser/go-sysconf/sysconf_darwin.go +++ b/vendor/github.com/tklauser/go-sysconf/sysconf_darwin.go @@ -5,6 +5,10 @@ package sysconf import ( + "strconv" + "strings" + "sync" + "golang.org/x/sys/unix" ) @@ -14,8 +18,14 @@ const ( _SYMLOOP_MAX = _MAXSYMLINKS ) -// sysconf implements sysconf(3) as in the Darwin libc, version 1244.30.3 -// (derived from the FreeBSD libc). +var uname struct { + sync.Once + macOSMajor int +} + +// sysconf implements sysconf(4) as in the Darwin libc (derived from the FreeBSD +// libc), version 1534.81.1. +// See https://github.com/apple-oss-distributions/Libc/tree/Libc-1534.81.1. func sysconf(name int) (int64, error) { switch name { case SC_AIO_LISTIO_MAX: @@ -54,12 +64,16 @@ func sysconf(name int) (int64, error) { return sysctl32("kern.ngroups"), nil case SC_OPEN_MAX, SC_STREAM_MAX: var rlim unix.Rlimit - if err := unix.Getrlimit(unix.RLIMIT_NOFILE, &rlim); err == nil { - if rlim.Cur != unix.RLIM_INFINITY { - return int64(rlim.Cur), nil - } + if err := unix.Getrlimit(unix.RLIMIT_NOFILE, &rlim); err != nil { + return -1, nil } - return -1, nil + if rlim.Cur > unix.RLIM_INFINITY { + return -1, nil + } + if rlim.Cur > _LONG_MAX { + return -1, unix.EOVERFLOW + } + return int64(rlim.Cur), nil case SC_RTSIG_MAX: return -1, nil case SC_SEM_NSEMS_MAX: @@ -126,7 +140,22 @@ func sysconf(name int) (int64, error) { } return _POSIX_SEMAPHORES, nil case SC_SPAWN: - return _POSIX_SPAWN, nil + uname.Once.Do(func() { + var u unix.Utsname + err := unix.Uname(&u) + if err != nil { + return + } + rel := unix.ByteSliceToString(u.Release[:]) + ver := strings.Split(rel, ".") + maj, _ := strconv.Atoi(ver[0]) + uname.macOSMajor = maj + }) + if uname.macOSMajor < 22 { + return -1, nil + } + // macOS 13 (Ventura) and later + return 200112, nil case SC_SPIN_LOCKS: return _POSIX_SPIN_LOCKS, nil case SC_SPORADIC_SERVER: diff --git a/vendor/github.com/tklauser/go-sysconf/zsysconf_defs_darwin.go b/vendor/github.com/tklauser/go-sysconf/zsysconf_defs_darwin.go index 6fa7fde8a..6fadf3db1 100644 --- a/vendor/github.com/tklauser/go-sysconf/zsysconf_defs_darwin.go +++ b/vendor/github.com/tklauser/go-sysconf/zsysconf_defs_darwin.go @@ -181,7 +181,6 @@ const ( _POSIX_SHARED_MEMORY_OBJECTS = -0x1 _POSIX_SHELL = 0x30db0 _POSIX_SIGQUEUE_MAX = 0x20 - _POSIX_SPAWN = -0x1 _POSIX_SPIN_LOCKS = -0x1 _POSIX_SPORADIC_SERVER = -0x1 _POSIX_SS_REPL_MAX = 0x4 @@ -248,7 +247,8 @@ const ( const ( _CHAR_BIT = 0x8 - _INT_MAX = 0x7fffffff + _INT_MAX = 0x7fffffff + _LONG_MAX = 0x7fffffffffffffff sizeofOffT = 0x8 ) diff --git a/vendor/github.com/tklauser/numcpus/.cirrus.yml b/vendor/github.com/tklauser/numcpus/.cirrus.yml index 53c0110b5..69c6ced5c 100644 --- a/vendor/github.com/tklauser/numcpus/.cirrus.yml +++ b/vendor/github.com/tklauser/numcpus/.cirrus.yml @@ -1,6 +1,6 @@ env: CIRRUS_CLONE_DEPTH: 1 - GO_VERSION: go1.19.1 + GO_VERSION: go1.20 freebsd_12_task: freebsd_instance: diff --git a/vendor/modules.txt b/vendor/modules.txt index 8087a1a16..f73f4696f 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -1315,7 +1315,7 @@ github.com/shirou/gopsutil/internal/common github.com/shirou/gopsutil/mem github.com/shirou/gopsutil/net github.com/shirou/gopsutil/process -# github.com/shirou/gopsutil/v3 v3.23.6 +# github.com/shirou/gopsutil/v3 v3.23.8 ## explicit; go 1.15 github.com/shirou/gopsutil/v3/common github.com/shirou/gopsutil/v3/cpu @@ -1464,10 +1464,10 @@ github.com/timonwong/loggercheck/internal/checkers/printf github.com/timonwong/loggercheck/internal/rules github.com/timonwong/loggercheck/internal/sets github.com/timonwong/loggercheck/internal/stringutil -# github.com/tklauser/go-sysconf v0.3.11 +# github.com/tklauser/go-sysconf v0.3.12 ## explicit; go 1.13 github.com/tklauser/go-sysconf -# github.com/tklauser/numcpus v0.6.0 +# github.com/tklauser/numcpus v0.6.1 ## explicit; go 1.13 github.com/tklauser/numcpus # github.com/tomarrell/wrapcheck/v2 v2.8.1