Skip to content

Commit

Permalink
feat: upload check
Browse files Browse the repository at this point in the history
  • Loading branch information
acha-bill committed Jul 31, 2023
1 parent 537b05a commit 146a3e8
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 13 deletions.
2 changes: 2 additions & 0 deletions config/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,8 @@ checks:
mode: default
upload-count: 1
pin: false
postage-amount: 1000000
postage-depth: 17

# simulations defines simulations Beekeeper can execute against the cluster
# type filed allows defining same simulation with different names and options
Expand Down
2 changes: 2 additions & 0 deletions config/local.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -390,3 +390,5 @@ checks:
mode: default
count: 1
pin: false
postage-amount: 100000
postage-depth: 17
36 changes: 26 additions & 10 deletions pkg/check/upload/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,18 @@ import (
var _ beekeeper.Action = (*Check)(nil)

type Options struct {
Mode string
UploadCount int
Pin bool
Mode string
UploadCount int
PostageAmount int64
PostageDepth uint64
Pin bool
}

func NewDefaultOptions() Options {
return Options{
UploadCount: 1,
UploadCount: 1,
PostageAmount: 1000000,
PostageDepth: 20,
}
}

Expand Down Expand Up @@ -77,7 +81,7 @@ func (c Check) directUploadCheck(ctx context.Context, cluster orchestration.Clus
}

nodeNames := cluster.NodeNames()
uploadClient, downloadClient := clients[nodeNames[0]], clients[nodeNames[1]]
uploadClient, downloadClient := clients[nodeNames[1]], clients[nodeNames[2]]

for i := 0; i < opts.UploadCount; i++ {
payload := make([]byte, bee.MaxChunkSize)
Expand All @@ -86,8 +90,14 @@ func (c Check) directUploadCheck(ctx context.Context, cluster orchestration.Clus
return fmt.Errorf("rand: %w", err)
}

batchID, err := uploadClient.GetOrCreateBatch(ctx, opts.PostageAmount, opts.PostageDepth, "", "upload-check")
if err != nil {
return fmt.Errorf("create batch: %w", err)
}

addr, err := uploadClient.UploadBytes(ctx, payload, api.UploadOptions{
Direct: true,
Direct: true,
BatchID: batchID,
})
if err != nil {
return fmt.Errorf("upload: %w", err)
Expand All @@ -101,7 +111,7 @@ func (c Check) directUploadCheck(ctx context.Context, cluster orchestration.Clus
if !bytes.Equal(payload, download) {
return fmt.Errorf("expected payload and download to be equal")
}
c.logger.Infof("payload and download successful between node %s and %s", nodeNames[0], nodeNames[1])
c.logger.Infof("payload and download successful between node %s and %s", nodeNames[1], nodeNames[2])
}

return nil
Expand Down Expand Up @@ -134,10 +144,16 @@ func (c Check) deferredUploadCheck(ctx context.Context, cluster orchestration.Cl
}
tags[i] = tag

batchID, err := uploadClient.GetOrCreateBatch(ctx, opts.PostageAmount, opts.PostageDepth, "", "upload-check")
if err != nil {
return fmt.Errorf("create batch: %w", err)
}

_, err = uploadClient.UploadBytes(ctx, payload, api.UploadOptions{
Tag: tag.Uid,
Direct: false,
Pin: opts.Pin,
Tag: tag.Uid,
Direct: false,
Pin: opts.Pin,
BatchID: batchID,
})
if err != nil {
return fmt.Errorf("upload: %w", err)
Expand Down
8 changes: 5 additions & 3 deletions pkg/config/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -495,9 +495,11 @@ var Checks = map[string]CheckType{
NewAction: upload.NewCheck,
NewOptions: func(checkGlobalConfig CheckGlobalConfig, check Check) (interface{}, error) {
checkOpts := new(struct {
Mode *string `yaml:"node"`
UploadCount *int `yaml:"upload-count"`
Pin *bool `yaml:"pin"`
Mode *string `yaml:"node"`
UploadCount *int `yaml:"upload-count"`
Pin *bool `yaml:"pin"`
PostageAmount *int64 `yaml:"postage-amount"`
PostageDepth *uint64 `yaml:"postage-depth"`
})
if err := check.Options.Decode(checkOpts); err != nil {
return nil, fmt.Errorf("decoding check %s options: %w", check.Type, err)
Expand Down

0 comments on commit 146a3e8

Please sign in to comment.