Skip to content

Commit

Permalink
Remove agentinfo (#947)
Browse files Browse the repository at this point in the history
  • Loading branch information
jefchien authored Nov 7, 2023
1 parent 593160e commit 996d191
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 667 deletions.
15 changes: 6 additions & 9 deletions extension/agenthealth/handler/stats/provider/interval_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,10 @@ func TestIntervalStats(t *testing.T) {
s.stats.Store(agent.Stats{
ThreadCount: aws.Int32(2),
})
got := s.Stats("")
assert.NotNil(t, got.ThreadCount)
got = s.Stats("")
assert.Nil(t, got.ThreadCount)
time.Sleep(2 * time.Millisecond)
got = s.Stats("")
assert.NotNil(t, got.ThreadCount)
got = s.Stats("")
assert.Nil(t, got.ThreadCount)
assert.NotNil(t, s.Stats("").ThreadCount)
assert.Nil(t, s.Stats("").ThreadCount)
time.Sleep(time.Millisecond)
assert.Eventually(t, func() bool {
return s.Stats("").ThreadCount != nil
}, 5*time.Millisecond, time.Millisecond)
}
32 changes: 22 additions & 10 deletions extension/agenthealth/handler/stats/provider/process_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,41 +5,53 @@ package provider

import (
"errors"
"sync"
"testing"
"time"

"github.com/shirou/gopsutil/v3/process"
"github.com/stretchr/testify/assert"

"github.com/aws/amazon-cloudwatch-agent/extension/agenthealth/handler/stats/agent"
)

type mockProcessMetrics struct {
mu sync.RWMutex
err error
}

var _ processMetrics = (*mockProcessMetrics)(nil)

func (m mockProcessMetrics) CPUPercent() (float64, error) {
func (m *mockProcessMetrics) CPUPercent() (float64, error) {
m.mu.RLock()
defer m.mu.RUnlock()
if m.err != nil {
return -1, m.err
}
return 1, nil
}

func (m mockProcessMetrics) MemoryInfo() (*process.MemoryInfoStat, error) {
func (m *mockProcessMetrics) MemoryInfo() (*process.MemoryInfoStat, error) {
m.mu.RLock()
defer m.mu.RUnlock()
if m.err != nil {
return nil, m.err
}
return &process.MemoryInfoStat{RSS: uint64(2)}, nil
}

func (m mockProcessMetrics) NumFDs() (int32, error) {
func (m *mockProcessMetrics) NumFDs() (int32, error) {
m.mu.RLock()
defer m.mu.RUnlock()
if m.err != nil {
return -1, m.err
}
return 3, nil
}

func (m mockProcessMetrics) NumThreads() (int32, error) {
func (m *mockProcessMetrics) NumThreads() (int32, error) {
m.mu.RLock()
defer m.mu.RUnlock()
if m.err != nil {
return -1, m.err
}
Expand All @@ -59,11 +71,11 @@ func TestProcessStats(t *testing.T) {
assert.EqualValues(t, 2, *got.MemoryBytes)
assert.EqualValues(t, 3, *got.FileDescriptorCount)
assert.EqualValues(t, 4, *got.ThreadCount)
mock.mu.Lock()
mock.err = testErr
time.Sleep(2 * time.Millisecond)
got = provider.getStats()
assert.Nil(t, got.CpuPercent)
assert.Nil(t, got.MemoryBytes)
assert.Nil(t, got.FileDescriptorCount)
assert.Nil(t, got.ThreadCount)
mock.mu.Unlock()
provider.refresh()
assert.Eventually(t, func() bool {
return provider.getStats() == agent.Stats{}
}, 5*time.Millisecond, time.Millisecond)
}
Loading

0 comments on commit 996d191

Please sign in to comment.