Skip to content

Commit

Permalink
feat: add config options to enable / disable push or pull monitoring …
Browse files Browse the repository at this point in the history
…individually (#174)
  • Loading branch information
dirkmc authored Mar 24, 2021
1 parent b1a43bd commit 60ff921
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
10 changes: 10 additions & 0 deletions channelmonitor/channelmonitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ type Monitor struct {
}

type Config struct {
// Indicates whether push channel monitoring is enabled
MonitorPushChannels bool
// Indicates whether pull channel monitoring is enabled
MonitorPullChannels bool
// Max time to wait for other side to accept open channel request before attempting restart
AcceptTimeout time.Duration
// Interval between checks of transfer rate
Expand Down Expand Up @@ -111,6 +115,12 @@ func (m *Monitor) addChannel(chid datatransfer.ChannelID, isPush bool) monitored
if !m.enabled() {
return nil
}
if isPush && !m.cfg.MonitorPushChannels {
return nil
}
if !isPush && !m.cfg.MonitorPullChannels {
return nil
}

m.lk.Lock()
defer m.lk.Unlock()
Expand Down
10 changes: 9 additions & 1 deletion channelmonitor/channelmonitor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ func TestPushChannelMonitorAutoRestart(t *testing.T) {
mockAPI := newMockMonitorAPI(ch, tc.errOnRestart)

m := NewMonitor(mockAPI, &Config{
MonitorPushChannels: true,
AcceptTimeout: time.Hour,
Interval: 10 * time.Millisecond,
ChecksPerInterval: 10,
Expand Down Expand Up @@ -144,6 +145,7 @@ func TestPullChannelMonitorAutoRestart(t *testing.T) {
mockAPI := newMockMonitorAPI(ch, tc.errOnRestart)

m := NewMonitor(mockAPI, &Config{
MonitorPullChannels: true,
AcceptTimeout: time.Hour,
Interval: 10 * time.Millisecond,
ChecksPerInterval: 10,
Expand Down Expand Up @@ -306,6 +308,7 @@ func TestPushChannelMonitorDataRate(t *testing.T) {

checksPerInterval := uint32(1)
m := NewMonitor(mockAPI, &Config{
MonitorPushChannels: true,
AcceptTimeout: time.Hour,
Interval: time.Hour,
ChecksPerInterval: checksPerInterval,
Expand Down Expand Up @@ -374,6 +377,7 @@ func TestPullChannelMonitorDataRate(t *testing.T) {

checksPerInterval := uint32(1)
m := NewMonitor(mockAPI, &Config{
MonitorPullChannels: true,
AcceptTimeout: time.Hour,
Interval: time.Hour,
ChecksPerInterval: checksPerInterval,
Expand Down Expand Up @@ -418,6 +422,8 @@ func TestChannelMonitorMaxConsecutiveRestarts(t *testing.T) {

maxConsecutiveRestarts := 3
m := NewMonitor(mockAPI, &Config{
MonitorPushChannels: isPush,
MonitorPullChannels: !isPush,
AcceptTimeout: time.Hour,
Interval: time.Hour,
ChecksPerInterval: 1,
Expand Down Expand Up @@ -536,6 +542,8 @@ func TestChannelMonitorTimeouts(t *testing.T) {
acceptTimeout := 10 * time.Millisecond
completeTimeout := 10 * time.Millisecond
m := NewMonitor(mockAPI, &Config{
MonitorPushChannels: isPush,
MonitorPullChannels: !isPush,
AcceptTimeout: acceptTimeout,
Interval: time.Hour,
ChecksPerInterval: 1,
Expand All @@ -550,7 +558,7 @@ func TestChannelMonitorTimeouts(t *testing.T) {
mch := m.AddPushChannel(ch1).(*monitoredPushChannel)
chCtx = mch.ctx
} else {
mch := m.AddPushChannel(ch1).(*monitoredPushChannel)
mch := m.AddPullChannel(ch1).(*monitoredPullChannel)
chCtx = mch.ctx
}

Expand Down
2 changes: 2 additions & 0 deletions impl/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,8 @@ func TestAutoRestart(t *testing.T) {

// Set up
restartConf := ChannelRestartConfig(channelmonitor.Config{
MonitorPushChannels: true,
MonitorPullChannels: true,
AcceptTimeout: 100 * time.Millisecond,
Interval: 100 * time.Millisecond,
MinBytesTransferred: 1,
Expand Down

0 comments on commit 60ff921

Please sign in to comment.