mirror of
https://github.com/kemko/nomad.git
synced 2026-01-05 01:45:44 +03:00
Adds new package that can be used by client and server RPC endpoints to facilitate monitoring based off of a logger clean up old code small comment about write rm old comment about minsize rename to Monitor Removes connection logic from monitor command Keep connection logic in endpoints, use a channel to send results from monitoring use new multisink logger and interfaces small test for dropped messages update go-hclogger and update sink/intercept logger interfaces
63 lines
1.0 KiB
Go
63 lines
1.0 KiB
Go
package monitor
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
log "github.com/hashicorp/go-hclog"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestMonitor_Start(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
logger := log.NewInterceptLogger(&log.LoggerOptions{
|
|
Level: log.Error,
|
|
})
|
|
|
|
m := New(512, logger, &log.LoggerOptions{
|
|
Level: log.Debug,
|
|
})
|
|
|
|
closeCh := make(chan struct{})
|
|
defer close(closeCh)
|
|
|
|
logCh := m.Start(closeCh)
|
|
go func() {
|
|
for {
|
|
select {
|
|
case log := <-logCh:
|
|
require.Contains(t, string(log), "[DEBUG] test log")
|
|
case <-time.After(1 * time.Second):
|
|
t.Fatal("Expected to receive from log channel")
|
|
}
|
|
}
|
|
}()
|
|
logger.Debug("test log")
|
|
}
|
|
|
|
func TestMonitor_DroppedMessages(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
logger := log.NewInterceptLogger(&log.LoggerOptions{
|
|
Level: log.Warn,
|
|
})
|
|
|
|
m := New(5, logger, &log.LoggerOptions{
|
|
Level: log.Debug,
|
|
})
|
|
|
|
doneCh := make(chan struct{})
|
|
defer close(doneCh)
|
|
|
|
m.Start(doneCh)
|
|
|
|
for i := 0; i <= 6; i++ {
|
|
logger.Debug("test message")
|
|
}
|
|
|
|
assert.Equal(t, 1, m.droppedCount)
|
|
}
|