Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions cmd/beekeeper/cmd/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,8 @@ func newMetricsPusher(pusherAddress, job string, logger logging.Logger) (*push.P
killC := make(chan struct{})
var wg sync.WaitGroup

wg.Add(1)

// start period flusher
go func() {
defer wg.Done()
wg.Go(func() {
for {
select {
case <-killC:
Expand All @@ -32,7 +29,7 @@ func newMetricsPusher(pusherAddress, job string, logger logging.Logger) (*push.P
}
}
}
}()
})
cleanupFn := func() {
close(killC)
wg.Wait()
Expand Down
8 changes: 4 additions & 4 deletions pkg/bee/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func newClient(apiURL *url.URL, httpClient *http.Client) (c *Client) {
// body, creates an HTTP request with provided method on a path with required
// headers and decodes request body if the v argument is not nil and content type is
// application/json.
func (c *Client) requestJSON(ctx context.Context, method, path string, body, v interface{}) (err error) {
func (c *Client) requestJSON(ctx context.Context, method, path string, body, v any) (err error) {
var bodyBuffer io.ReadWriter
if body != nil {
bodyBuffer = new(bytes.Buffer)
Expand All @@ -136,7 +136,7 @@ func (c *Client) getFullURL(path string) (string, error) {
}

// request handles the HTTP request response cycle.
func (c *Client) request(ctx context.Context, method, path string, body io.Reader, v interface{}) (err error) {
func (c *Client) request(ctx context.Context, method, path string, body io.Reader, v any) (err error) {
fullURL, err := c.getFullURL(path)
if err != nil {
return err
Expand Down Expand Up @@ -171,7 +171,7 @@ func (c *Client) request(ctx context.Context, method, path string, body io.Reade

// encodeJSON writes a JSON-encoded v object to the provided writer with
// SetEscapeHTML set to false.
func encodeJSON(w io.Writer, v interface{}) (err error) {
func encodeJSON(w io.Writer, v any) (err error) {
enc := json.NewEncoder(w)
enc.SetEscapeHTML(false)
return enc.Encode(v)
Expand Down Expand Up @@ -238,7 +238,7 @@ func (c *Client) requestDataGetHeader(ctx context.Context, method, path string,
}

// requestWithHeader handles the HTTP request response cycle.
func (c *Client) requestWithHeader(ctx context.Context, method, path string, header http.Header, body io.Reader, v interface{}, headerParser ...func(http.Header)) (err error) {
func (c *Client) requestWithHeader(ctx context.Context, method, path string, header http.Header, body io.Reader, v any, headerParser ...func(http.Header)) (err error) {
fullURL, err := c.getFullURL(path)
if err != nil {
return err
Expand Down
6 changes: 3 additions & 3 deletions pkg/bee/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ func (c *Client) CreatePostageBatch(ctx context.Context, amount int64, depth uin
exists := false
usable := false
// wait for the stamp to become usable
for i := 0; i < 900; i++ {
for range 900 {
time.Sleep(1 * time.Second)
state, err := c.api.Postage.PostageStamp(ctx, id)
if err != nil {
Expand Down Expand Up @@ -558,7 +558,7 @@ func (c *Client) TopUpPostageBatch(ctx context.Context, batchID string, amount i
return err
}

for i := 0; i < 60; i++ {
for range 60 {
time.Sleep(time.Second)

b, err := c.PostageStamp(ctx, batchID)
Expand Down Expand Up @@ -587,7 +587,7 @@ func (c *Client) DilutePostageBatch(ctx context.Context, batchID string, depth u
return err
}

for i := 0; i < 60; i++ {
for range 60 {
time.Sleep(time.Second)

b, err := c.api.Postage.PostageStamp(ctx, batchID)
Expand Down
2 changes: 1 addition & 1 deletion pkg/beekeeper/beekeeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ import (
// needs to expose metrics should implement the metrics.Reporter
// interface.
type Action interface {
Run(ctx context.Context, cluster orchestration.Cluster, o interface{}) (err error)
Run(ctx context.Context, cluster orchestration.Cluster, o any) (err error)
}
2 changes: 1 addition & 1 deletion pkg/beekeeper/tracing.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func NewActionMiddleware(tracer opentracing.Tracer, action Action, actionName st
}

// Run implements beekeeper.Action
func (am *actionMiddleware) Run(ctx context.Context, cluster orchestration.Cluster, o interface{}) (err error) {
func (am *actionMiddleware) Run(ctx context.Context, cluster orchestration.Cluster, o any) (err error) {
span := createSpan(ctx, am.tracer, am.actionName)
defer span.Finish()
ctx = opentracing.ContextWithSpan(ctx, span)
Expand Down
2 changes: 1 addition & 1 deletion pkg/check/act/act.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func NewCheck(logger logging.Logger) beekeeper.Action {
}

// Run executes act check
func (c *Check) Run(ctx context.Context, cluster orchestration.Cluster, opts interface{}) (err error) {
func (c *Check) Run(ctx context.Context, cluster orchestration.Cluster, opts any) (err error) {
o, ok := opts.(Options)
if !ok {
return fmt.Errorf("invalid options type")
Expand Down
9 changes: 4 additions & 5 deletions pkg/check/balances/balances.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package balances
import (
"context"
"fmt"
"maps"
"time"

"github.com/ethersphere/beekeeper/pkg/beekeeper"
Expand Down Expand Up @@ -56,7 +57,7 @@ func NewCheck(log logging.Logger) beekeeper.Action {
}
}

func (c *Check) Run(ctx context.Context, cluster orchestration.Cluster, opts interface{}) (err error) {
func (c *Check) Run(ctx context.Context, cluster orchestration.Cluster, opts any) (err error) {
o, ok := opts.(Options)
if !ok {
return fmt.Errorf("invalid options type")
Expand Down Expand Up @@ -151,7 +152,7 @@ func dryRun(ctx context.Context, cluster orchestration.Cluster, log logging.Logg
}

func expectBalancesHaveChanged(balances, newBalances orchestration.NodeGroupBalances, log logging.Logger) error {
for t := 0; t < 5; t++ {
for t := range 5 {
sleepTime := 2 * time.Duration(t) * time.Second
log.Infof("Waiting %s before checking balances", sleepTime)
time.Sleep(sleepTime)
Expand Down Expand Up @@ -212,9 +213,7 @@ func balancesHaveChanged(current, previous orchestration.NodeGroupBalances, log
func flattenBalances(b orchestration.ClusterBalances) map[string]map[string]int64 {
res := make(map[string]map[string]int64)
for _, ngb := range b {
for n, balances := range ngb {
res[n] = balances
}
maps.Copy(res, ngb)
}
return res
}
4 changes: 2 additions & 2 deletions pkg/check/cashout/cashout.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ type CashoutAction struct {
}

// Check executes settlements check
func (c *Check) Run(ctx context.Context, cluster orchestration.Cluster, opts interface{}) (err error) {
func (c *Check) Run(ctx context.Context, cluster orchestration.Cluster, opts any) (err error) {
o, ok := opts.(Options)
if !ok {
return fmt.Errorf("invalid options type")
Expand Down Expand Up @@ -111,7 +111,7 @@ func (c *Check) Run(ctx context.Context, cluster orchestration.Cluster, opts int
}

LOOP:
for i := 0; i < 10; i++ {
for range 10 {
time.Sleep(5 * time.Second)

for _, action := range actions {
Expand Down
4 changes: 2 additions & 2 deletions pkg/check/datadurability/datadurability.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func NewCheck(logger logging.Logger) beekeeper.Action {

// Run runs the check
// It downloads a file that contains a list of chunks and then attempts to download each chunk in the file.
func (c *Check) Run(ctx context.Context, cluster orchestration.Cluster, o interface{}) error {
func (c *Check) Run(ctx context.Context, cluster orchestration.Cluster, o any) error {
opts, ok := o.(Options)
if !ok {
return fmt.Errorf("invalid options type")
Expand Down Expand Up @@ -140,7 +140,7 @@ func fetchFile(ctx context.Context, logger logging.Logger, ref swarm.Address, cl
nodes = append(nodes, node)
}

for i := 0; i < maxAttempts; i++ {
for i := range maxAttempts {
node := nodes[i%len(nodes)]
d, err := node.Client().DownloadFileBytes(ctx, ref, nil)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/check/feed/feed.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func NewCheck(logger logging.Logger) beekeeper.Action {
}
}

func (c *Check) Run(ctx context.Context, cluster orchestration.Cluster, opts interface{}) (err error) {
func (c *Check) Run(ctx context.Context, cluster orchestration.Cluster, opts any) (err error) {
o, ok := opts.(Options)
if !ok {
return fmt.Errorf("invalid options type")
Expand Down
2 changes: 1 addition & 1 deletion pkg/check/fileretrieval/fileretrieval.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func NewCheck(logger logging.Logger) beekeeper.Action {
}
}

func (c *Check) Run(ctx context.Context, cluster orchestration.Cluster, opts interface{}) (err error) {
func (c *Check) Run(ctx context.Context, cluster orchestration.Cluster, opts any) (err error) {
o, ok := opts.(Options)
if !ok {
return fmt.Errorf("invalid options type")
Expand Down
2 changes: 1 addition & 1 deletion pkg/check/fullconnectivity/fullconnectivity.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func NewDefaultOptions() Options {

var errFullConnectivity = errors.New("full connectivity")

func (c *Check) Run(ctx context.Context, cluster orchestration.Cluster, opts interface{}) (err error) {
func (c *Check) Run(ctx context.Context, cluster orchestration.Cluster, opts any) (err error) {
lightNodes := opts.(Options).LightNodeNames
bootNodes := opts.(Options).BootNodeNames
if err := c.checkFullNodesConnectivity(ctx, cluster, lightNodes, bootNodes); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/check/gc/reserve.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ A little bit about how the numbers make sense:
checks on the pinning API.
*/

func (c *Check) Run(ctx context.Context, cluster orchestration.Cluster, opts interface{}) (err error) {
func (c *Check) Run(ctx context.Context, cluster orchestration.Cluster, opts any) (err error) {
o, ok := opts.(Options)
if !ok {
return fmt.Errorf("invalid options type")
Expand Down
4 changes: 2 additions & 2 deletions pkg/check/gsoc/gsoc.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func NewCheck(logger logging.Logger) beekeeper.Action {
}
}

func (c *Check) Run(ctx context.Context, cluster orchestration.Cluster, opts interface{}) (err error) {
func (c *Check) Run(ctx context.Context, cluster orchestration.Cluster, opts any) (err error) {
o, ok := opts.(Options)
if !ok {
return fmt.Errorf("invalid options type")
Expand Down Expand Up @@ -178,7 +178,7 @@ func run(ctx context.Context, uploadClient *bee.Client, listenClient *bee.Client

receivedMtx.Lock()
defer receivedMtx.Unlock()
for i := 0; i < numChunks; i++ {
for i := range numChunks {
want := fmt.Sprintf("data %d", i)
if !received[want] {
return fmt.Errorf("message '%s' not received", want)
Expand Down
2 changes: 1 addition & 1 deletion pkg/check/kademlia/kademlia.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func NewCheck(logger logging.Logger) beekeeper.Action {
}
}

func (c *Check) Run(ctx context.Context, cluster orchestration.Cluster, opts interface{}) (err error) {
func (c *Check) Run(ctx context.Context, cluster orchestration.Cluster, opts any) (err error) {
o, ok := opts.(Options)
if !ok {
return fmt.Errorf("invalid options type")
Expand Down
2 changes: 1 addition & 1 deletion pkg/check/load/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func NewCheck(log logging.Logger) beekeeper.Action {
}
}

func (c *Check) Run(ctx context.Context, cluster orchestration.Cluster, opts interface{}) error {
func (c *Check) Run(ctx context.Context, cluster orchestration.Cluster, opts any) error {
o, ok := opts.(Options)
if !ok {
return errors.New("invalid options type")
Expand Down
2 changes: 1 addition & 1 deletion pkg/check/longavailability/longavailability.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func NewCheck(logger logging.Logger) beekeeper.Action {
}
}

func (c *Check) Run(ctx context.Context, cluster orchestration.Cluster, o interface{}) error {
func (c *Check) Run(ctx context.Context, cluster orchestration.Cluster, o any) error {
opts, ok := o.(Options)
if !ok {
return fmt.Errorf("invalid options type")
Expand Down
4 changes: 2 additions & 2 deletions pkg/check/manifest/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func NewCheck(logger logging.Logger) beekeeper.Action {
}
}

func (c *Check) Run(ctx context.Context, cluster orchestration.Cluster, opts interface{}) (err error) {
func (c *Check) Run(ctx context.Context, cluster orchestration.Cluster, opts any) (err error) {
o, ok := opts.(Options)
if !ok {
return fmt.Errorf("invalid options type")
Expand Down Expand Up @@ -258,7 +258,7 @@ func (c *Check) downloadAndVerify(ctx context.Context, client *bee.Client, addre
}
c.logger.Infof("downloading file: %s/%s", address, fName)

for i := 0; i < 10; i++ {
for range 10 {
select {
case <-time.After(5 * time.Second):
_, hash, err := client.DownloadManifestFile(ctx, address, fName)
Expand Down
4 changes: 2 additions & 2 deletions pkg/check/networkavailability/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func NewCheck(logger logging.Logger) beekeeper.Action {
}

// Run creates file of specified size that is uploaded and downloaded.
func (c *Check) Run(ctx context.Context, cluster orchestration.Cluster, opts interface{}) error {
func (c *Check) Run(ctx context.Context, cluster orchestration.Cluster, opts any) error {
o, ok := opts.(Options)
if !ok {
return fmt.Errorf("invalid options type")
Expand Down Expand Up @@ -162,7 +162,7 @@ func neighborhoods(bits int) []swarm.Address {

ret := make([]swarm.Address, 0, max)

for i := 0; i < max; i++ {
for i := range max {
buf := make([]byte, 4)
binary.LittleEndian.PutUint32(buf, uint32(i))

Expand Down
2 changes: 1 addition & 1 deletion pkg/check/peercount/peercount.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func NewCheck(logger logging.Logger) beekeeper.Action {
}
}

func (c *Check) Run(ctx context.Context, cluster orchestration.Cluster, opts interface{}) (err error) {
func (c *Check) Run(ctx context.Context, cluster orchestration.Cluster, opts any) (err error) {
overlays, err := cluster.Overlays(ctx)
if err != nil {
return err
Expand Down
4 changes: 2 additions & 2 deletions pkg/check/pingpong/pingpong.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func NewCheck(logger logging.Logger) beekeeper.Action {
}

// Run executes ping check
func (c *Check) Run(ctx context.Context, cluster orchestration.Cluster, _ interface{}) (err error) {
func (c *Check) Run(ctx context.Context, cluster orchestration.Cluster, _ any) (err error) {
nodeGroups := cluster.NodeGroups()
for _, ng := range nodeGroups {
nodesClients, err := ng.NodesClients(ctx)
Expand All @@ -48,7 +48,7 @@ func (c *Check) Run(ctx context.Context, cluster orchestration.Cluster, _ interf
}

for n := range nodeStream(ctx, nodesClients) { // TODO: confirm use case for nodeStream(ctx, ng.NodesClientsAll(ctx))
for t := 0; t < 5; t++ {
for t := range 5 {
time.Sleep(2 * time.Duration(t) * time.Second)

if n.Error != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/check/postage/postage.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func NewCheck(logger logging.Logger) beekeeper.Action {
}
}

func (c *Check) Run(ctx context.Context, cluster orchestration.Cluster, opts interface{}) (err error) {
func (c *Check) Run(ctx context.Context, cluster orchestration.Cluster, opts any) (err error) {
o, ok := opts.(Options)
if !ok {
return fmt.Errorf("invalid options type")
Expand Down
2 changes: 1 addition & 1 deletion pkg/check/pss/pss.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func NewCheck(logger logging.Logger) beekeeper.Action {
}
}

func (c *Check) Run(ctx context.Context, cluster orchestration.Cluster, opts interface{}) (err error) {
func (c *Check) Run(ctx context.Context, cluster orchestration.Cluster, opts any) (err error) {
o, ok := opts.(Options)
if !ok {
return fmt.Errorf("invalid options type")
Expand Down
2 changes: 1 addition & 1 deletion pkg/check/pullsync/pullsync.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func NewCheck(logger logging.Logger) beekeeper.Action {

var errPullSync = errors.New("pull sync")

func (c *Check) Run(ctx context.Context, cluster orchestration.Cluster, opts interface{}) (err error) {
func (c *Check) Run(ctx context.Context, cluster orchestration.Cluster, opts any) (err error) {
o, ok := opts.(Options)
if !ok {
return fmt.Errorf("invalid options type")
Expand Down
6 changes: 3 additions & 3 deletions pkg/check/pushsync/check_lightnode.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func checkLightChunks(ctx context.Context, cluster orchestration.Cluster, o Opti
lightNodes := cluster.LightNodeNames()

// prepare postage batches
for i := 0; i < len(lightNodes); i++ {
for i := range lightNodes {
nodeName := lightNodes[i]
batchID, err := clients[nodeName].GetOrCreateMutableBatch(ctx, o.PostageTTL, o.PostageDepth, o.PostageLabel)
if err != nil {
Expand Down Expand Up @@ -61,7 +61,7 @@ func checkLightChunks(ctx context.Context, cluster orchestration.Cluster, o Opti

var ref swarm.Address

for i := 0; i < 3; i++ {
for range 3 {
ref, err = uploader.UploadChunk(ctx, chunk.Data(), api.UploadOptions{BatchID: batchID})
if err == nil {
break
Expand All @@ -83,7 +83,7 @@ func checkLightChunks(ctx context.Context, cluster orchestration.Cluster, o Opti
l.Infof("closest node %s overlay %s", closestName, closestAddress)

var synced bool
for i := 0; i < 3; i++ {
for range 3 {
synced, _ = clients[closestName].HasChunk(ctx, ref)
if synced {
break
Expand Down
2 changes: 1 addition & 1 deletion pkg/check/pushsync/pushsync.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func NewCheck(logger logging.Logger) beekeeper.Action {
}
}

func (c *Check) Run(ctx context.Context, cluster orchestration.Cluster, opts interface{}) (err error) {
func (c *Check) Run(ctx context.Context, cluster orchestration.Cluster, opts any) (err error) {
o, ok := opts.(Options)
if !ok {
return fmt.Errorf("invalid options type")
Expand Down
2 changes: 1 addition & 1 deletion pkg/check/redundancy/redundancy.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func NewCheck(logger logging.Logger) beekeeper.Action {
}
}

func (c *Check) Run(ctx context.Context, cluster orchestration.Cluster, o interface{}) (err error) {
func (c *Check) Run(ctx context.Context, cluster orchestration.Cluster, o any) (err error) {
opts, ok := o.(Options)
if !ok {
return fmt.Errorf("invalid options type")
Expand Down
Loading