Skip to content

Commit

Permalink
worker: don't record host scan on 'successfull failure'
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisSchinnerl committed Jul 29, 2024
1 parent f90040a commit 660ea3d
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 28 deletions.
16 changes: 7 additions & 9 deletions worker/interactions.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
package worker

func isSuccessfulInteraction(err error) bool {
// No error always means success.
if err == nil {
return true
}
// List of errors that are considered successful interactions.
func shouldRecordPriceTable(err error) bool {
// List of errors that are considered 'successful' failures. Meaning that
// the host was reachable but we were unable to obtain a price table due to
// reasons out of the host's control.
if isInsufficientFunds(err) {
return true
return false
}
if isBalanceInsufficient(err) {
return true
return false
}
return false
return true
}
22 changes: 12 additions & 10 deletions worker/pricetables.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,16 +174,18 @@ func (p *priceTable) fetch(ctx context.Context, rev *types.FileContractRevision)
hpt, err = h.FetchPriceTable(ctx, rev)

// record it in the background
go func(hpt api.HostPriceTable, success bool) {
p.hs.RecordPriceTables(context.Background(), []api.HostPriceTableUpdate{
{
HostKey: p.hk,
Success: success,
Timestamp: time.Now(),
PriceTable: hpt,
},
})
}(hpt, isSuccessfulInteraction(err))
if shouldRecordPriceTable(err) {
go func(hpt api.HostPriceTable, success bool) {
p.hs.RecordPriceTables(context.Background(), []api.HostPriceTableUpdate{
{
HostKey: p.hk,
Success: success,
Timestamp: time.Now(),
PriceTable: hpt,
},
})
}(hpt, err == nil)
}

// handle error after recording
if err != nil {
Expand Down
21 changes: 12 additions & 9 deletions worker/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,14 +354,16 @@ func (w *worker) rhpPriceTableHandler(jc jape.Context) {
var err error
var hpt api.HostPriceTable
defer func() {
w.bus.RecordPriceTables(jc.Request.Context(), []api.HostPriceTableUpdate{
{
HostKey: rptr.HostKey,
Success: isSuccessfulInteraction(err),
Timestamp: time.Now(),
PriceTable: hpt,
},
})
if shouldRecordPriceTable(err) {
w.bus.RecordPriceTables(jc.Request.Context(), []api.HostPriceTableUpdate{
{
HostKey: rptr.HostKey,
Success: err == nil,
Timestamp: time.Now(),
PriceTable: hpt,
},
})
}
}()

// apply timeout
Expand Down Expand Up @@ -1487,14 +1489,15 @@ func (w *worker) scanHost(ctx context.Context, timeout time.Duration, hostKey ty
HostKey: hostKey,
PriceTable: pt,
Subnets: subnets,
Success: isSuccessfulInteraction(err),
Success: err == nil,
Settings: settings,
Timestamp: time.Now(),
},
})
if scanErr != nil {
logger.Errorw("failed to record host scan", zap.Error(scanErr))
}
logger.With(zap.Error(err)).Debugw("scanned host", "success", err == nil)
return settings, pt, duration, err
}

Expand Down

0 comments on commit 660ea3d

Please sign in to comment.