Skip to content

Commit ebe2a13

Browse files
authored
fix label values query in stress; bump dependencies (#30)
Signed-off-by: Ben Ye <[email protected]>
1 parent d9cd7f7 commit ebe2a13

File tree

8 files changed

+581
-40
lines changed

8 files changed

+581
-40
lines changed

cmd/thanosbench/stress.go

+12-2
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,18 @@ import (
1414
"github.com/oklog/run"
1515
"github.com/pkg/errors"
1616
"github.com/prometheus/prometheus/pkg/labels"
17+
"github.com/prometheus/prometheus/pkg/timestamp"
1718
"github.com/thanos-io/thanos/pkg/store/storepb"
1819
"golang.org/x/sync/errgroup"
1920
"google.golang.org/grpc"
2021
"gopkg.in/alecthomas/kingpin.v2"
2122
)
2223

24+
var (
25+
minTime = timestamp.FromTime(time.Unix(math.MinInt64/1000+62135596801, 0))
26+
maxTime = timestamp.FromTime(time.Unix(math.MaxInt64/1000-62135596801, 999999999))
27+
)
28+
2329
func registerStress(m map[string]setupFunc, app *kingpin.Application) {
2430
cmd := app.Command("stress", "Stress tests a remote StoreAPI.")
2531
workers := cmd.Flag("workers", "Number of go routines for stress testing.").Required().Int()
@@ -42,7 +48,11 @@ func registerStress(m map[string]setupFunc, app *kingpin.Application) {
4248
lblvlsCtx, lblvlsCancel := context.WithTimeout(mainCtx, *timeout)
4349
defer lblvlsCancel()
4450

45-
labelvaluesResp, err := c.LabelValues(lblvlsCtx, &storepb.LabelValuesRequest{Label: labels.MetricName})
51+
labelvaluesResp, err := c.LabelValues(lblvlsCtx, &storepb.LabelValuesRequest{
52+
Label: labels.MetricName,
53+
Start: minTime,
54+
End: maxTime,
55+
})
4656
if err != nil {
4757
return err
4858
}
@@ -76,7 +86,7 @@ func registerStress(m map[string]setupFunc, app *kingpin.Application) {
7686
MinTime: min * 1000,
7787
MaxTime: max * 1000,
7888
Matchers: []storepb.LabelMatcher{
79-
storepb.LabelMatcher{
89+
{
8090
Type: storepb.LabelMatcher_EQ,
8191
Name: labels.MetricName,
8292
Value: randomMetric,

go.mod

+11-11
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,21 @@ module github.com/thanos-io/thanosbench
33
require (
44
github.com/bwplotka/mimic v0.0.0-20190730202618-06ab9976e8ef
55
github.com/fatih/structtag v1.1.0
6-
github.com/go-kit/kit v0.9.0
7-
github.com/go-openapi/swag v0.19.5
8-
github.com/oklog/run v1.0.0
6+
github.com/go-kit/kit v0.10.0
7+
github.com/go-openapi/swag v0.19.9
8+
github.com/oklog/run v1.1.0
99
github.com/oklog/ulid v1.3.1
1010
github.com/pkg/errors v0.9.1
11-
github.com/prometheus/common v0.9.1
12-
github.com/prometheus/prometheus v1.8.2-0.20200213233353-b90be6f32a33
13-
github.com/thanos-io/thanos v0.12.2
11+
github.com/prometheus/common v0.11.1
12+
github.com/prometheus/prometheus v1.8.2-0.20200811193703-869f1bc587e6
13+
github.com/thanos-io/thanos v0.15.0
1414
go.uber.org/automaxprocs v1.2.0
15-
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e
16-
google.golang.org/grpc v1.25.1
15+
golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208
16+
google.golang.org/grpc v1.30.0
1717
gopkg.in/alecthomas/kingpin.v2 v2.2.6
18-
gopkg.in/yaml.v2 v2.2.7
19-
k8s.io/api v0.0.0-20191115095533-47f6de673b26
20-
k8s.io/apimachinery v0.0.0-20191115015347-3c7067801da2
18+
gopkg.in/yaml.v2 v2.3.0
19+
k8s.io/api v0.18.6
20+
k8s.io/apimachinery v0.18.6
2121
)
2222

2323
// We want to replace the client-go version with a specific commit hash,

go.sum

+543
Large diffs are not rendered by default.

pkg/blockgen/blockgen.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ import (
1212
"github.com/go-kit/kit/log"
1313
"github.com/oklog/ulid"
1414
"github.com/prometheus/prometheus/pkg/labels"
15-
"github.com/prometheus/prometheus/tsdb"
15+
"github.com/prometheus/prometheus/storage"
1616
"github.com/thanos-io/thanos/pkg/block/metadata"
1717
"github.com/thanos-io/thanosbench/pkg/seriesgen"
1818
)
1919

2020
// Writer is interface to write time series into Prometheus blocks.
2121
type Writer interface {
22-
tsdb.Appendable
22+
storage.Appendable
2323

2424
// Flush writes current block to disk.
2525
// The block will contain values accumulated by `Write`.

pkg/blockgen/writer.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"github.com/go-kit/kit/log/level"
1313
"github.com/pkg/errors"
1414
"github.com/prometheus/prometheus/pkg/timestamp"
15+
"github.com/prometheus/prometheus/storage"
1516
"github.com/prometheus/prometheus/tsdb"
1617
"github.com/prometheus/prometheus/tsdb/chunkenc"
1718
)
@@ -65,8 +66,8 @@ func NewTSDBBlockWriter(logger log.Logger, dir string) (*BlockWriter, error) {
6566
}
6667

6768
// Appender is not thread-safe. Returned Appender is thread-save however..
68-
func (w *BlockWriter) Appender() tsdb.Appender {
69-
return w.head.Appender()
69+
func (w *BlockWriter) Appender(ctx context.Context) storage.Appender {
70+
return w.head.Appender(ctx)
7071
}
7172

7273
// Flush implements Writer interface. This is where actual block writing
@@ -96,7 +97,7 @@ func (w *BlockWriter) initHeadAndAppender() error {
9697
// var w *wal.WAL = nil
9798
// Put huge chunkRange; It has to be equal then expected block size.
9899
// Since we don't have info about block size here, set it to large number.
99-
h, err := tsdb.NewHead(nil, logger, nil, durToMilis(9999*time.Hour), tsdb.DefaultStripeSize)
100+
h, err := tsdb.NewHead(nil, logger, nil, durToMilis(9999*time.Hour), "", nil, tsdb.DefaultStripeSize, nil)
100101
if err != nil {
101102
return errors.Wrap(err, "tsdb.NewHead")
102103
}
@@ -108,7 +109,7 @@ func (w *BlockWriter) initHeadAndAppender() error {
108109

109110
// writeHeadToDisk commits the appender and writes the head to disk.
110111
func (w *BlockWriter) writeHeadToDisk() (ulid.ULID, error) {
111-
if err := w.Appender().Commit(); err != nil {
112+
if err := w.Appender(context.TODO()).Commit(); err != nil {
112113
return ulid.ULID{}, errors.Wrap(err, "appender.Commit")
113114
}
114115

pkg/seriesgen/append.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,16 @@ import (
44
"context"
55

66
"github.com/pkg/errors"
7-
8-
"github.com/prometheus/prometheus/tsdb"
7+
"github.com/prometheus/prometheus/storage"
98
"golang.org/x/sync/errgroup"
109
)
1110

12-
func Append(ctx context.Context, goroutines int, appendable tsdb.Appendable, series SeriesSet) error {
11+
func Append(ctx context.Context, goroutines int, appendable storage.Appendable, series SeriesSet) error {
1312
g, gctx := errgroup.WithContext(ctx)
1413

1514
workBuffer := make(chan Series)
1615
for i := 0; i < goroutines; i++ {
17-
app := appendable.Appender()
16+
app := appendable.Appender(gctx)
1817
g.Go(func() error {
1918
var (
2019
s Series

pkg/seriesgen/append_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111

1212
"github.com/prometheus/prometheus/pkg/labels"
1313
"github.com/prometheus/prometheus/pkg/timestamp"
14-
"github.com/prometheus/prometheus/tsdb"
14+
"github.com/prometheus/prometheus/storage"
1515
"github.com/thanos-io/thanos/pkg/testutil"
1616
)
1717

@@ -71,7 +71,7 @@ func (a *testAppendable) Rollback() error {
7171
return nil
7272
}
7373

74-
func (a *testAppendable) Appender() tsdb.Appender {
74+
func (a *testAppendable) Appender(_ context.Context) storage.Appender {
7575
return a
7676
}
7777

pkg/walgen/walgen.go

+3-15
Original file line numberDiff line numberDiff line change
@@ -48,25 +48,13 @@ func GenerateTSDBWAL(logger log.Logger, dir string, config Config) error {
4848
config.ScrapeInterval = 15 * time.Second
4949
}
5050

51-
// Same code as Prometheus for compaction levels and max block.
52-
rngs := tsdb.ExponentialBlockRanges(int64(2*time.Hour.Seconds()*1000), 10, 3)
5351
maxBlockDuration := config.Retention / 10
54-
for i, v := range rngs {
55-
if v > int64(maxBlockDuration.Seconds()*1000) {
56-
rngs = rngs[:i]
57-
break
58-
}
59-
}
60-
61-
if len(rngs) == 0 {
62-
rngs = append(rngs, int64(2*time.Hour.Seconds()*1000))
63-
}
64-
6552
// TODO(bwplotka): Moved to something like https://github.com/thanos-io/thanos/blob/master/pkg/testutil/prometheus.go#L289
6653
// to actually generate blocks! It will be fine for TSDB use cases as well.
6754
db, err := tsdb.Open(dir, nil, nil, &tsdb.Options{
68-
BlockRanges: rngs,
69-
RetentionDuration: uint64(config.Retention.Seconds() * 1000),
55+
MinBlockDuration: int64(2 * time.Hour / time.Millisecond),
56+
MaxBlockDuration: maxBlockDuration.Milliseconds(),
57+
RetentionDuration: config.Retention.Milliseconds(),
7058
NoLockfile: true,
7159
})
7260
if err != nil {

0 commit comments

Comments
 (0)