Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sidecar Flag: Random delay before upload blocks on sidecar #7239

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
1 change: 1 addition & 0 deletions cmd/thanos/config.go
Expand Up @@ -164,6 +164,7 @@ type shipperConfig struct {
allowOutOfOrderUpload bool
hashFunc string
metaFileName string
uploadJitter time.Duration
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this if not needed

}

func (sc *shipperConfig) registerFlag(cmd extkingpin.FlagClause) *shipperConfig {
Expand Down
29 changes: 29 additions & 0 deletions cmd/thanos/sidecar.go
Expand Up @@ -7,6 +7,7 @@ import (
"context"
"fmt"
"math"
"math/rand"
"net/http"
"net/url"
"sync"
Expand Down Expand Up @@ -363,6 +364,9 @@ func runSidecar(
uploadCompactedFunc, conf.shipper.allowOutOfOrderUpload, metadata.HashFunc(conf.shipper.hashFunc), conf.shipper.metaFileName)

return runutil.Repeat(30*time.Second, ctx.Done(), func() error {
// Generate random delay using upload jitter.
jitter := time.Duration(rand.Int63n(int64(conf.shipper.uploadJitter)))
time.Sleep(jitter)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of sleeping, can we do something similar to this https://github.com/cortexproject/cortex/blob/master/pkg/util/time.go#L73?

I image we will add a new function called runutil.RepeatWithJitter which takes the same parameters as runutil.Repeat but also takes variancePerc.
We can just hardcode variancePerc to a sane value like 0.05 so allows [-1.5s, 1.5s] jitter.

if uploaded, err := s.Sync(ctx); err != nil {
level.Warn(logger).Log("err", err, "uploaded", uploaded)
}
Expand Down Expand Up @@ -506,7 +510,30 @@ type sidecarConfig struct {
storeRateLimits store.SeriesSelectLimits
}

type durationValue time.Duration
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should be able to set duration via flag directly without implementing interface.

https://github.com/thanos-io/thanos/blob/main/cmd/thanos/receive.go#L968


// Set implements the Set method of the kingpin.Value interface.
func (d *durationValue) Set(value string) error {
duration, err := time.ParseDuration(value)
if err != nil {
return err
}
*d = durationValue(duration)
return nil
}

// String implements the String method of the kingpin.Value interface.
func (d *durationValue) String() string {
return time.Duration(*d).String()
}

// Register a flag with the provided duration value.
func registerDurationFlag(cmd extkingpin.FlagClause, value *time.Duration, flagName string, defaultValue string, help string) {
cmd.Flag(flagName, help).Default(defaultValue).SetValue((*durationValue)(value))
}

func (sc *sidecarConfig) registerFlag(cmd extkingpin.FlagClause) {
var uploadJitter time.Duration
sc.http.registerFlag(cmd)
sc.grpc.registerFlag(cmd)
sc.prometheus.registerFlag(cmd)
Expand All @@ -518,4 +545,6 @@ func (sc *sidecarConfig) registerFlag(cmd extkingpin.FlagClause) {
sc.storeRateLimits.RegisterFlags(cmd)
cmd.Flag("min-time", "Start of time range limit to serve. Thanos sidecar will serve only metrics, which happened later than this value. Option can be a constant time in RFC3339 format or time duration relative to current time, such as -1d or 2h45m. Valid duration units are ms, s, m, h, d, w, y.").
Default("0000-01-01T00:00:00Z").SetValue(&sc.limitMinTime)
registerDurationFlag(cmd, &uploadJitter, "upload-jitter", "0s", "Maximum random delay before uploading blocks.")
sc.shipper.uploadJitter = uploadJitter
}
1 change: 1 addition & 0 deletions docs/components/sidecar.md
Expand Up @@ -228,6 +228,7 @@ Flags:
configuration. See format details:
https://thanos.io/tip/thanos/tracing.md/#configuration
--tsdb.path="./data" Data directory of TSDB.
--upload-jitter=0s Maximum random delay before uploading blocks.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to fix docs

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also it looks like this flag is never consumed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also added nowhere

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yess will remove it

--version Show application version.

```
Expand Down