Files
kopia/cli/command_repository_throttle_set.go
Jarek Kowalski 99eeb3c063 feat(cli): added CLI for controlling throttler (#1956)
Supported are:

```
$ kopia throttle set \
    --download-bytes-per-second=N | unlimited
    --upload-bytes-per-second=N | unlimited
    --read-requests-per-second=N | unlimited
    --write-requests-per-second=N | unlimited
    --list-requests-per-second=N | unlimited
    --concurrent-reads=N | unlimited
    --concurrent-writes=N | unlimited
```

To change parameters of a running server use:

```
$ kopia server throttle set \
    --address=<server-url> \
    --server-control-password=<password> \
    --download-bytes-per-second=N | unlimited
    --upload-bytes-per-second=N | unlimited
    --read-requests-per-second=N | unlimited
    --write-requests-per-second=N | unlimited
    --list-requests-per-second=N | unlimited
    --concurrent-reads=N | unlimited
    --concurrent-writes=N | unlimited
```
2022-05-18 01:27:06 -07:00

39 lines
815 B
Go

package cli
import (
"context"
"github.com/pkg/errors"
"github.com/kopia/kopia/repo"
)
type commandRepositoryThrottleSet struct {
cts commonThrottleSet
}
func (c *commandRepositoryThrottleSet) setup(svc appServices, parent commandParent) {
cmd := parent.Command("set", "Set throttling parameters for a repository")
c.cts.setup(cmd)
cmd.Action(svc.directRepositoryWriteAction(c.run))
}
func (c *commandRepositoryThrottleSet) run(ctx context.Context, rep repo.DirectRepositoryWriter) error {
thr := rep.Throttler()
limits := thr.Limits()
var changeCount int
if err := c.cts.apply(ctx, &limits, &changeCount); err != nil {
return err
}
if changeCount == 0 {
log(ctx).Infof("No changes made.")
return nil
}
return errors.Wrap(rep.Throttler().SetLimits(limits), "error setting limits")
}