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

Add support to specify metric name for stress #43

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
54 changes: 34 additions & 20 deletions cmd/thanosbench/stress.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,34 @@ var (
maxTime = timestamp.FromTime(time.Unix(math.MaxInt64/1000-62135596801, 999999999))
)

func getMetricsFromStore(ctx context.Context, timeout *time.Duration, c storepb.StoreClient) ([]string, error) {
lblvlsCtx, lblvlsCancel := context.WithTimeout(ctx, *timeout)
defer lblvlsCancel()

labelvaluesResp, err := c.LabelValues(lblvlsCtx, &storepb.LabelValuesRequest{
Label: labels.MetricName,
Start: minTime,
End: maxTime,
})
if err != nil {
return nil, err
}
if len(labelvaluesResp.Warnings) > 0 {
return nil, errors.New(fmt.Sprintf("got %#v warnings from LabelValues() call", labelvaluesResp.Warnings))
}
labelvalues := labelvaluesResp.Values
if len(labelvalues) == 0 {
return nil, errors.New("the StoreAPI responded with zero metric names")
}
return labelvalues, nil
}

func registerStress(m map[string]setupFunc, app *kingpin.Application) {
cmd := app.Command("stress", "Stress tests a remote StoreAPI.")
workers := cmd.Flag("workers", "Number of go routines for stress testing.").Required().Int()
timeout := cmd.Flag("timeout", "Timeout of each operation").Default("60s").Duration()
lookback := cmd.Flag("query.look-back", "How much time into the past at max we should look back").Default("300h").Duration()
userSpecifiedMetrics := cmd.Flag("metric-name", "Metric to query for").Strings()
target := cmd.Arg("target", "IP:PORT pair of the target to stress.").Required().TCP()

// TODO(GiedriusS): send other requests like Info() as well.
Expand All @@ -43,28 +66,19 @@ func registerStress(m map[string]setupFunc, app *kingpin.Application) {
return err
}
defer conn.Close()
c := storepb.NewStoreClient(conn)

lblvlsCtx, lblvlsCancel := context.WithTimeout(mainCtx, *timeout)
defer lblvlsCancel()
c := storepb.NewStoreClient(conn)
errg, errCtx := errgroup.WithContext(mainCtx)

labelvaluesResp, err := c.LabelValues(lblvlsCtx, &storepb.LabelValuesRequest{
Label: labels.MetricName,
Start: minTime,
End: maxTime,
})
if err != nil {
return err
}
if len(labelvaluesResp.Warnings) > 0 {
return errors.New(fmt.Sprintf("got %#v warnings from LabelValues() call", labelvaluesResp.Warnings))
var metrics []string
if *userSpecifiedMetrics != nil && len(*userSpecifiedMetrics) != 0 {
metrics = *userSpecifiedMetrics
} else {
metrics, err = getMetricsFromStore(mainCtx, timeout, c)
if err != nil {
return err
}
}
labelvalues := labelvaluesResp.Values
if len(labelvalues) == 0 {
return errors.New("the StoreAPI responded with zero metric names")
}

errg, errCtx := errgroup.WithContext(mainCtx)

for i := 0; i < *workers; i++ {
errg.Go(func() error {
Expand All @@ -78,7 +92,7 @@ func registerStress(m map[string]setupFunc, app *kingpin.Application) {
opCtx, cancel := context.WithTimeout(errCtx, *timeout)
defer cancel()

randomMetric := labelvalues[rand.Intn(len(labelvalues))]
randomMetric := metrics[rand.Intn(len(metrics))]
max := time.Now().Unix()
min := time.Now().Unix() - rand.Int63n(int64(lookback.Seconds()))

Expand Down