-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' of github.com:SiaFoundation/renterd into pj/mock-bus
- Loading branch information
Showing
17 changed files
with
256 additions
and
152 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package autopilot | ||
|
||
import ( | ||
"time" | ||
|
||
"go.sia.tech/core/types" | ||
"go.sia.tech/renterd/alerts" | ||
) | ||
|
||
type ( | ||
accumulatedChurn struct { | ||
additions map[types.FileContractID]contractSetAdditions | ||
removals map[types.FileContractID]contractSetRemovals | ||
} | ||
) | ||
|
||
func newAccumulatedChurn() *accumulatedChurn { | ||
return &accumulatedChurn{ | ||
additions: make(map[types.FileContractID]contractSetAdditions), | ||
removals: make(map[types.FileContractID]contractSetRemovals), | ||
} | ||
} | ||
|
||
func (c *accumulatedChurn) Alert(name string) alerts.Alert { | ||
var hint string | ||
if len(c.removals) > 0 { | ||
hint = "A high churn rate can lead to a lot of unnecessary migrations, it might be necessary to tweak your configuration depending on the reason hosts are being discarded from the set." | ||
} | ||
|
||
return alerts.Alert{ | ||
ID: alertChurnID, | ||
Severity: alerts.SeverityInfo, | ||
Message: "Contract set changed", | ||
Data: map[string]any{ | ||
"name": name, | ||
"set_additions": c.additions, | ||
"set_removals": c.removals, | ||
"hint": hint, | ||
}, | ||
Timestamp: time.Now(), | ||
} | ||
} | ||
|
||
func (c *accumulatedChurn) Apply(additions map[types.FileContractID]contractSetAdditions, removals map[types.FileContractID]contractSetRemovals) { | ||
for fcid, a := range additions { | ||
if _, exists := c.additions[fcid]; !exists { | ||
c.additions[fcid] = a | ||
} else { | ||
additions := c.additions[fcid] | ||
additions.Additions = append(additions.Additions, a.Additions...) | ||
c.additions[fcid] = additions | ||
} | ||
} | ||
for fcid, r := range removals { | ||
if _, exists := c.removals[fcid]; !exists { | ||
c.removals[fcid] = r | ||
} else { | ||
removals := c.removals[fcid] | ||
removals.Removals = append(removals.Removals, r.Removals...) | ||
c.removals[fcid] = removals | ||
} | ||
} | ||
} | ||
|
||
func (c *accumulatedChurn) Reset() { | ||
c.additions = make(map[types.FileContractID]contractSetAdditions) | ||
c.removals = make(map[types.FileContractID]contractSetRemovals) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.