Skip to content
This repository has been archived by the owner on Jul 27, 2023. It is now read-only.

Commit

Permalink
Merge pull request #198 from adrienkohlbecker/ak/fix-arm
Browse files Browse the repository at this point in the history
Support running on 32bit ARM platform
  • Loading branch information
sunhay authored Oct 16, 2018
2 parents 371fd62 + 8044402 commit 2da91c5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
14 changes: 7 additions & 7 deletions cmd/agent/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ type Collector struct {
cfg *config.AgentConfig
httpClient http.Client
groupID int32
runCounter int64
runCounter int32
enabledChecks []checks.Check

// Controls the real-time interval, can change live.
realTimeInterval time.Duration
// Set to 1 if enabled 0 is not. We're using an integer
// so we can use the sync/atomic for thread-safe access.
realTimeEnabled int64
realTimeEnabled int32
}

// NewCollector creates a new Collector
Expand Down Expand Up @@ -71,7 +71,7 @@ func NewCollector(cfg *config.AgentConfig) (Collector, error) {
}

func (l *Collector) runCheck(c checks.Check) {
runCounter := atomic.AddInt64(&l.runCounter, 1)
runCounter := atomic.AddInt32(&l.runCounter, 1)
s := time.Now()
// update the last collected timestamp for info
updateLastCollectTime(time.Now())
Expand Down Expand Up @@ -139,7 +139,7 @@ func (l *Collector) run(exit chan bool) {
for {
select {
case <-ticker.C:
realTimeEnabled := atomic.LoadInt64(&l.realTimeEnabled) == 1
realTimeEnabled := atomic.LoadInt32(&l.realTimeEnabled) == 1
if !c.RealTime() || realTimeEnabled {
l.runCheck(c)
}
Expand Down Expand Up @@ -212,7 +212,7 @@ func (l *Collector) postMessage(checkPath string, m model.MessageBody) {
}

func (l *Collector) updateStatus(statuses []*model.CollectorStatus) {
curEnabled := atomic.LoadInt64(&l.realTimeEnabled) == 1
curEnabled := atomic.LoadInt32(&l.realTimeEnabled) == 1

// If any of the endpoints wants real-time we'll do that.
// We will pick the maximum interval given since generally this is
Expand All @@ -229,10 +229,10 @@ func (l *Collector) updateStatus(statuses []*model.CollectorStatus) {

if curEnabled && !shouldEnableRT {
log.Info("Detected 0 clients, disabling real-time mode")
atomic.StoreInt64(&l.realTimeEnabled, 0)
atomic.StoreInt32(&l.realTimeEnabled, 0)
} else if !curEnabled && shouldEnableRT {
log.Info("Detected active clients, enabling real-time mode")
atomic.StoreInt64(&l.realTimeEnabled, 1)
atomic.StoreInt32(&l.realTimeEnabled, 1)
}

if maxInterval != l.realTimeInterval {
Expand Down
8 changes: 4 additions & 4 deletions cmd/agent/collector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func TestUpdateRTStatus(t *testing.T) {
{ActiveClients: 0, Interval: 2},
}
c.updateStatus(statuses)
assert.Equal(int64(1), atomic.LoadInt64(&c.realTimeEnabled))
assert.Equal(int32(1), atomic.LoadInt32(&c.realTimeEnabled))

// Validate that we stay that way
statuses = []*model.CollectorStatus{
Expand All @@ -34,7 +34,7 @@ func TestUpdateRTStatus(t *testing.T) {
{ActiveClients: 0, Interval: 2},
}
c.updateStatus(statuses)
assert.Equal(int64(1), atomic.LoadInt64(&c.realTimeEnabled))
assert.Equal(int32(1), atomic.LoadInt32(&c.realTimeEnabled))

// And that it can turn back off
statuses = []*model.CollectorStatus{
Expand All @@ -43,7 +43,7 @@ func TestUpdateRTStatus(t *testing.T) {
{ActiveClients: 0, Interval: 2},
}
c.updateStatus(statuses)
assert.Equal(int64(0), atomic.LoadInt64(&c.realTimeEnabled))
assert.Equal(int32(0), atomic.LoadInt32(&c.realTimeEnabled))
}

func TestUpdateRTInterval(t *testing.T) {
Expand All @@ -61,6 +61,6 @@ func TestUpdateRTInterval(t *testing.T) {
{ActiveClients: 0, Interval: 10},
}
c.updateStatus(statuses)
assert.Equal(int64(1), atomic.LoadInt64(&c.realTimeEnabled))
assert.Equal(int32(1), atomic.LoadInt32(&c.realTimeEnabled))
assert.Equal(10*time.Second, c.realTimeInterval)
}

0 comments on commit 2da91c5

Please sign in to comment.