Skip to content

Feature/169366221 flux monitor heartbeat#2233

Merged
thodges-gh merged 7 commits into
developfrom
feature/169366221-flux-monitor-heartbeat
Feb 18, 2020
Merged

Feature/169366221 flux monitor heartbeat#2233
thodges-gh merged 7 commits into
developfrom
feature/169366221-flux-monitor-heartbeat

Conversation

@felder-cl

@felder-cl felder-cl commented Jan 30, 2020

Copy link
Copy Markdown
Contributor

Allow chainlink operators to configure the Flux Monitor to trigger a Job Run if it has exceeded a specified 'idle time'. The 'idle time' is the time for which no Job Run has been started.

The behavior is disabled if no idle time is defined.

https://www.pivotaltracker.com/story/show/169366221

@felder-cl
felder-cl force-pushed the feature/169366221-flux-monitor-heartbeat branch 2 times, most recently from 0a8a2ac to 57c7472 Compare February 5, 2020 15:29
@felder-cl
felder-cl requested a review from thodges-gh February 5, 2020 15:29
@felder-cl
felder-cl force-pushed the feature/169366221-flux-monitor-heartbeat branch 6 times, most recently from e41ce80 to 69a1ae6 Compare February 7, 2020 12:07
Comment thread core/services/flux_monitor.go Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason for this choice of default? Seems arbitrary.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, I've updated it to be greater than or equal to the pollingInterval

@felder-cl
felder-cl force-pushed the feature/169366221-flux-monitor-heartbeat branch 2 times, most recently from 9f6bfb3 to f340be9 Compare February 7, 2020 14:46
@felder-cl
felder-cl marked this pull request as ready for review February 7, 2020 14:58
@felder-cl
felder-cl requested a review from samsondav February 7, 2020 16:16
@felder-cl
felder-cl marked this pull request as ready for review February 7, 2020 16:16
Comment thread core/services/flux_monitor_helpers_test.go
Comment thread core/web/job_specs_controller_test.go Outdated
Comment thread core/services/flux_monitor.go Outdated
cancel context.CancelFunc
newRounds chan eth.Log

stopC chan struct{}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the significance of C in stopC? Is it indicating Checker or Channel?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its for channel, would you prefer another name or have any suggestions?

@rupurt rupurt Feb 12, 2020

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the change to waitOnStop as we can lookup that it's channel from the type. Captures the intent well.

Comment thread core/services/flux_monitor_helpers_test.go
{"inside deviation", decimal.NewFromInt(100), decimal.NewFromInt(101), 2, false},
{"equal to deviation", decimal.NewFromInt(100), decimal.NewFromInt(102), 2, true},
{"outside deviation", decimal.NewFromInt(100), decimal.NewFromInt(103), 2, true},
{"outside deviation zero", decimal.NewFromInt(100), decimal.NewFromInt(0), 2, true},

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is perhaps outside the scope of this PR...

But how do you feel about adding test coverage for when threshold is negative?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The difference between current price and next price is computed as an absolute value... But if curPrice could go negative, OutsideDeviation would not trigger. I don't know whether there's a check elsewhere in the code that the price is non-negative. Decimals can be negative.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i feel validation and these constraints are outside the scope for sure. It probably deserves its own story and we are waiting to hear back re: the audit.

@coventry coventry left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall, this looks good, but there are some aspects to it I don't follow, and I think it would probably be helpful to other readers if you could clarify them in the code.

Comment thread core/services/flux_monitor.go Outdated
func stopTimer(arg *time.Timer) {
if !arg.Stop() && len(arg.C) > 0 {
// timer's channel may have backlog
// refer to: https://developpaper.com/detailed-explanation-of-the-trap-of-timer-in-golang/

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a more authoritative reference for this? The writing on that site is a bit difficult to follow.

The point is to drain the potential backlog? What could go wrong if you didn't?

@felder-cl felder-cl Feb 12, 2020

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Authoritative yes, better explained, no. This was the best article I could find on the subject.

I've updated the comment, but I've assumed the reader has an understanding of the operation of the timer entity. Therefor I've left out what could go wrong.

a201e38

Comment thread core/internal/cltest/factories.go
Comment thread core/services/flux_monitor.go
Comment thread core/services/flux_monitor.go Outdated
Comment thread core/services/flux_monitor.go Outdated
func (p *PollingDeviationChecker) Stop() {
if p.cancel != nil {
p.cancel()
<-p.stopC

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm unsure about the purpose of this. Is it to hang until the channel is closed in the consumer loop?

I think an explanatory comment is helpful, when this kind of action at a distance is going on.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've renamed it to waitOnStop

Comment thread core/services/flux_monitor_test.go Outdated
err = deviationChecker.Start(context.Background(), ethClient)
require.NoError(t, err)

<-fetchCalled // Called on start

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will hang on failure, which is a bit inconvenient. Would it be straightforward to wrap this in a timeout shorter than 10 minutes?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for pointing this out

@felder-cl felder-cl Feb 12, 2020

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've improved the test a bit and fixed this problem in 8d49a90cc551dca77da8f13358ba71076a15482a

{"inside deviation", decimal.NewFromInt(100), decimal.NewFromInt(101), 2, false},
{"equal to deviation", decimal.NewFromInt(100), decimal.NewFromInt(102), 2, true},
{"outside deviation", decimal.NewFromInt(100), decimal.NewFromInt(103), 2, true},
{"outside deviation zero", decimal.NewFromInt(100), decimal.NewFromInt(0), 2, true},

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The difference between current price and next price is computed as an absolute value... But if curPrice could go negative, OutsideDeviation would not trigger. I don't know whether there's a check elsewhere in the code that the price is non-negative. Decimals can be negative.

Comment thread core/web/job_specs_controller_test.go Outdated
@felder-cl
felder-cl force-pushed the feature/169366221-flux-monitor-heartbeat branch 3 times, most recently from 8d49a90 to 34f4e1c Compare February 12, 2020 15:17
samsondav
samsondav previously approved these changes Feb 12, 2020
@felder-cl
felder-cl dismissed stale reviews from thodges-gh and samsondav via a8c55ae February 14, 2020 12:43
@felder-cl
felder-cl force-pushed the feature/169366221-flux-monitor-heartbeat branch from 34f4e1c to a8c55ae Compare February 14, 2020 12:43
@thodges-gh

Copy link
Copy Markdown
Contributor

It doesn't seem like this new "idleThreshold" is actually working.

@felder-cl
felder-cl force-pushed the feature/169366221-flux-monitor-heartbeat branch from a8c55ae to 9107e42 Compare February 17, 2020 13:49
@smartcontractkit smartcontractkit deleted a comment Feb 17, 2020
@felder-cl
felder-cl force-pushed the feature/169366221-flux-monitor-heartbeat branch 7 times, most recently from 9f92b04 to 0057e68 Compare February 18, 2020 15:32
@felder-cl

Copy link
Copy Markdown
Contributor Author

It doesn't seem like this new "idleThreshold" is actually working.

There was a logic error where the idleThreshold was linked to the last time the price was polled, not updated. This is fixed in cdbdca3.

Thanks for spotting this.

@felder-cl
felder-cl force-pushed the feature/169366221-flux-monitor-heartbeat branch 2 times, most recently from 660de6f to 804dd45 Compare February 18, 2020 17:36
thodges-gh
thodges-gh previously approved these changes Feb 18, 2020
Allow chainlink operators to configure the Flux Monitor to trigger a Job
Run if it has exceeded a specified 'idle time'.  The 'idle time' is the
time for which no Job Run has been started.

The behavior is disabled if no IdleTime is defined.

https://www.pivotaltracker.com/story/show/169366221

To make testing easier, ensure the DeviationChecker has stopped
completely before returning.
Fix a logic error the implementation of the Idle Threshold by making the
timeout occur since the last Job Run.

The IdleThreshold is mistakenly linked to the last pollingInterval check.
@felder-cl
felder-cl force-pushed the feature/169366221-flux-monitor-heartbeat branch from 804dd45 to 7709d56 Compare February 18, 2020 18:25
@thodges-gh
thodges-gh merged commit ba9b253 into develop Feb 18, 2020
@j16r
j16r deleted the feature/169366221-flux-monitor-heartbeat branch March 3, 2020 20:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants