Skip to content

Commit 30404d3

Browse files
committed
Updated step-3 with nit improvements
Signed-off-by: soniasingla <[email protected]> Updated step-4 with nit improvements Signed-off-by: soniasingla <[email protected]> cached, loaded Signed-off-by: soniasingla <[email protected]> updated sh file Signed-off-by: soniasingla <[email protected]> updated sh file Signed-off-by: soniasingla <[email protected]> updated sh file Signed-off-by: soniasingla <[email protected]> nit improvements Signed-off-by: soniasingla <[email protected]> nit improvements Signed-off-by: soniasingla <[email protected]> nit improvements Signed-off-by: soniasingla <[email protected]> Update tutorials/katacoda/thanos/2-lts/intro.md Co-authored-by: Bartlomiej Plotka <[email protected]> Signed-off-by: soniasingla <[email protected]> Update tutorials/katacoda/thanos/2-lts/step1.md Co-authored-by: Bartlomiej Plotka <[email protected]> Signed-off-by: soniasingla <[email protected]> Update tutorials/katacoda/thanos/2-lts/step1.md Co-authored-by: Bartlomiej Plotka <[email protected]> Signed-off-by: soniasingla <[email protected]> Update tutorials/katacoda/thanos/2-lts/step1.md Co-authored-by: Bartlomiej Plotka <[email protected]> Signed-off-by: soniasingla <[email protected]> Update tutorials/katacoda/thanos/2-lts/step1.md Co-authored-by: Bartlomiej Plotka <[email protected]> Signed-off-by: soniasingla <[email protected]> refactored states Signed-off-by: soniasingla <[email protected]> Revert "Replace sync/atomic with uber-go/atomic (thanos-io#2935)" This reverts commit 20a82b9. Signed-off-by: soniasingla <[email protected]> Revert "cleanup shipper NewWithCompacted function (thanos-io#2940)" This reverts commit 2a54885. Signed-off-by: soniasingla <[email protected]> running querier Signed-off-by: soniasingla <[email protected]> Adding updated thanos version Signed-off-by: soniasingla <[email protected]> tutorials/katacoda/thanos/2-lts/index.json ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~users querying data Signed-off-by: soniasingla <[email protected]>
1 parent 7fe647a commit 30404d3

29 files changed

+196
-93
lines changed

Makefile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,8 +266,7 @@ github.com/prometheus/prometheus/pkg/testutils=github.com/thanos-io/thanos/pkg/t
266266
github.com/prometheus/client_golang/prometheus.{DefaultGatherer,DefBuckets,NewUntypedFunc,UntypedFunc},\
267267
github.com/prometheus/client_golang/prometheus.{NewCounter,NewCounterVec,NewCounterVec,NewGauge,NewGaugeVec,NewGaugeFunc,\
268268
NewHistorgram,NewHistogramVec,NewSummary,NewSummaryVec}=github.com/prometheus/client_golang/prometheus/promauto.{NewCounter,\
269-
NewCounterVec,NewCounterVec,NewGauge,NewGaugeVec,NewGaugeFunc,NewHistorgram,NewHistogramVec,NewSummary,NewSummaryVec},\
270-
sync/atomic=go.uber.org/atomic" ./...
269+
NewCounterVec,NewCounterVec,NewGauge,NewGaugeVec,NewGaugeFunc,NewHistorgram,NewHistogramVec,NewSummary,NewSummaryVec}" ./...
271270
@$(FAILLINT) -paths "fmt.{Print,Println,Sprint}" -ignore-tests ./...
272271
@echo ">> linting all of the Go files GOGC=${GOGC}"
273272
@$(GOLANGCI_LINT) run

cmd/thanos/rule.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,7 @@ func runRule(
626626
}
627627
}()
628628

629-
s := shipper.New(logger, reg, dataDir, bkt, func() labels.Labels { return lset }, metadata.RulerSource, false, allowOutOfOrderUpload)
629+
s := shipper.New(logger, reg, dataDir, bkt, func() labels.Labels { return lset }, metadata.RulerSource, allowOutOfOrderUpload)
630630

631631
ctx, cancel := context.WithCancel(context.Background())
632632

cmd/thanos/sidecar.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,8 +273,12 @@ func runSidecar(
273273
return errors.Wrapf(err, "aborting as no external labels found after waiting %s", promReadyTimeout)
274274
}
275275

276-
s := shipper.New(logger, reg, conf.tsdb.path, bkt, m.Labels, metadata.SidecarSource,
277-
conf.shipper.uploadCompacted, conf.shipper.allowOutOfOrderUpload)
276+
var s *shipper.Shipper
277+
if conf.shipper.uploadCompacted {
278+
s = shipper.NewWithCompacted(logger, reg, conf.tsdb.path, bkt, m.Labels, metadata.SidecarSource, conf.shipper.allowOutOfOrderUpload)
279+
} else {
280+
s = shipper.New(logger, reg, conf.tsdb.path, bkt, m.Labels, metadata.SidecarSource, conf.shipper.allowOutOfOrderUpload)
281+
}
278282

279283
return runutil.Repeat(30*time.Second, ctx.Done(), func() error {
280284
if uploaded, err := s.Sync(ctx); err != nil {

docs/components/sidecar.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ Prometheus servers connected to the Thanos cluster via the sidecar are subject t
3232
If you choose to use the sidecar to also upload data to object storage:
3333

3434
* Must specify object storage (`--objstore.*` flags)
35-
* It only uploads uncompacted Prometheus blocks. For compacted blocks, see [Upload compacted blocks](./sidecar.md/#upload-compacted-blocks).
35+
* It only uploads uncompacted Prometheus blocks. For compacted blocks, see [Upload compacted blocks](./sidecar.md/#upload-compacted-blocks-experimental).
3636
* The `--storage.tsdb.min-block-duration` and `--storage.tsdb.max-block-duration` must be set to equal values to disable local compaction on order to use Thanos sidecar upload, otherwise leave local compaction on if sidecar just exposes StoreAPI and your retention is normal. The default of `2h` is recommended.
3737
Mentioned parameters set to equal values disable the internal Prometheus compaction, which is needed to avoid the uploaded data corruption when Thanos compactor does its job, this is critical for data consistency and should not be ignored if you plan to use Thanos compactor. Even though you set mentioned parameters equal, you might observe Prometheus internal metric `prometheus_tsdb_compactions_total` being incremented, don't be confused by that: Prometheus writes initial head block to filesytem via its internal compaction mechanism, but if you have followed recommendations - data won't be modified by Prometheus before the sidecar uploads it. Thanos sidecar will also check sanity of the flags set to Prometheus on the startup and log errors or warning if they have been configured improperly (#838).
3838
* The retention is recommended to not be lower than three times the min block duration, so 6 hours. This achieves resilience in the face of connectivity issues to the object storage since all local data will remain available within the Thanos cluster. If connectivity gets restored the backlog of blocks gets uploaded to the object storage.
@@ -70,7 +70,7 @@ config:
7070
bucket: example-bucket
7171
```
7272
73-
## Upload compacted blocks
73+
## Upload compacted blocks (EXPERIMENTAL)
7474
7575
If you want to migrate from a pure Prometheus setup to Thanos and have to keep the historical data, you can use the flag `--shipper.upload-compacted`. This will also upload blocks that were compacted by Prometheus. Values greater than 1 in the `compaction.level` field of a Prometheus block’s `meta.json` file indicate level of compaction.
7676

go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ require (
5454
github.com/uber/jaeger-lib v2.2.0+incompatible
5555
go.elastic.co/apm v1.5.0
5656
go.elastic.co/apm/module/apmot v1.5.0
57-
go.uber.org/atomic v1.6.0
5857
go.uber.org/automaxprocs v1.2.0
5958
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9
6059
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d

pkg/alert/alert.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"net/url"
1515
"path"
1616
"sync"
17+
"sync/atomic"
1718
"time"
1819

1920
"github.com/go-kit/kit/log"
@@ -24,7 +25,6 @@ import (
2425
"github.com/prometheus/client_golang/prometheus"
2526
"github.com/prometheus/client_golang/prometheus/promauto"
2627
"github.com/prometheus/prometheus/pkg/labels"
27-
"go.uber.org/atomic"
2828

2929
"github.com/thanos-io/thanos/pkg/runutil"
3030
"github.com/thanos-io/thanos/pkg/tracing"
@@ -370,7 +370,7 @@ func (s *Sender) Send(ctx context.Context, alerts []*Alert) {
370370

371371
var (
372372
wg sync.WaitGroup
373-
numSuccess atomic.Uint64
373+
numSuccess uint64
374374
)
375375
for _, am := range s.alertmanagers {
376376
for _, u := range am.dispatcher.Endpoints() {
@@ -396,14 +396,14 @@ func (s *Sender) Send(ctx context.Context, alerts []*Alert) {
396396
s.latency.WithLabelValues(u.Host).Observe(time.Since(start).Seconds())
397397
s.sent.WithLabelValues(u.Host).Add(float64(len(alerts)))
398398

399-
numSuccess.Inc()
399+
atomic.AddUint64(&numSuccess, 1)
400400
})
401401
}(am, *u)
402402
}
403403
}
404404
wg.Wait()
405405

406-
if numSuccess.Load() > 0 {
406+
if numSuccess > 0 {
407407
return
408408
}
409409

pkg/prober/http.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,18 @@ package prober
66
import (
77
"io"
88
"net/http"
9+
"sync/atomic"
910

1011
"github.com/go-kit/kit/log"
1112
"github.com/go-kit/kit/log/level"
12-
"go.uber.org/atomic"
1313
)
1414

1515
type check func() bool
1616

1717
// HTTPProbe represents health and readiness status of given component, and provides HTTP integration.
1818
type HTTPProbe struct {
19-
ready atomic.Uint32
20-
healthy atomic.Uint32
19+
ready uint32
20+
healthy uint32
2121
}
2222

2323
// NewHTTP returns HTTPProbe representing readiness and healthiness of given component.
@@ -49,33 +49,34 @@ func (p *HTTPProbe) handler(logger log.Logger, c check) http.HandlerFunc {
4949

5050
// isReady returns true if component is ready.
5151
func (p *HTTPProbe) isReady() bool {
52-
ready := p.ready.Load()
52+
ready := atomic.LoadUint32(&p.ready)
5353
return ready > 0
5454
}
5555

5656
// isHealthy returns true if component is healthy.
5757
func (p *HTTPProbe) isHealthy() bool {
58-
healthy := p.healthy.Load()
58+
healthy := atomic.LoadUint32(&p.healthy)
5959
return healthy > 0
6060
}
6161

6262
// Ready sets components status to ready.
6363
func (p *HTTPProbe) Ready() {
64-
p.ready.Swap(1)
64+
atomic.SwapUint32(&p.ready, 1)
6565
}
6666

6767
// NotReady sets components status to not ready with given error as a cause.
6868
func (p *HTTPProbe) NotReady(err error) {
69-
p.ready.Swap(0)
69+
atomic.SwapUint32(&p.ready, 0)
7070

7171
}
7272

7373
// Healthy sets components status to healthy.
7474
func (p *HTTPProbe) Healthy() {
75-
p.healthy.Swap(1)
75+
atomic.SwapUint32(&p.healthy, 1)
76+
7677
}
7778

7879
// NotHealthy sets components status to not healthy with given error as a cause.
7980
func (p *HTTPProbe) NotHealthy(err error) {
80-
p.healthy.Swap(0)
81+
atomic.SwapUint32(&p.healthy, 0)
8182
}

pkg/receive/multitsdb.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,6 @@ func (t *MultiTSDB) startTSDB(logger log.Logger, tenantID string, tenant *tenant
282282
t.bucket,
283283
func() labels.Labels { return lbls },
284284
metadata.ReceiveSource,
285-
false,
286285
t.allowOutOfOrderUpload,
287286
)
288287
}

pkg/reloader/reloader.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ func (r *Reloader) apply(ctx context.Context) error {
288288
return err
289289
}
290290

291-
// filepath.Walk uses Lstat to retrieve os.FileInfo. Lstat does not
291+
// filepath.Walk uses Lstat to retriev os.FileInfo. Lstat does not
292292
// follow symlinks. Make sure to follow a symlink before checking
293293
// if it is a directory.
294294
targetFile, err := os.Stat(path)

pkg/reloader/reloader_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ import (
1515
"path/filepath"
1616
"strings"
1717
"sync"
18+
"sync/atomic"
1819
"testing"
1920
"time"
2021

2122
"github.com/fortytw2/leaktest"
2223
"github.com/thanos-io/thanos/pkg/testutil"
23-
"go.uber.org/atomic"
2424
)
2525

2626
func TestReloader_ConfigApply(t *testing.T) {

pkg/shipper/shipper.go

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,17 +83,15 @@ type Shipper struct {
8383
allowOutOfOrderUploads bool
8484
}
8585

86-
// New creates a new shipper that detects new TSDB blocks in dir and uploads them to
87-
// remote if necessary. It attaches the Thanos metadata section in each meta JSON file.
88-
// If uploadCompacted is enabled, it also uploads compacted blocks which are already in filesystem.
86+
// New creates a new shipper that detects new TSDB blocks in dir and uploads them
87+
// to remote if necessary. It attaches the Thanos metadata section in each meta JSON file.
8988
func New(
9089
logger log.Logger,
9190
r prometheus.Registerer,
9291
dir string,
9392
bucket objstore.Bucket,
9493
lbls func() labels.Labels,
9594
source metadata.SourceType,
96-
uploadCompacted bool,
9795
allowOutOfOrderUploads bool,
9896
) *Shipper {
9997
if logger == nil {
@@ -108,10 +106,40 @@ func New(
108106
dir: dir,
109107
bucket: bucket,
110108
labels: lbls,
111-
metrics: newMetrics(r, uploadCompacted),
109+
metrics: newMetrics(r, false),
112110
source: source,
113111
allowOutOfOrderUploads: allowOutOfOrderUploads,
114-
uploadCompacted: uploadCompacted,
112+
}
113+
}
114+
115+
// NewWithCompacted creates a new shipper that detects new TSDB blocks in dir and uploads them
116+
// to remote if necessary, including compacted blocks which are already in filesystem.
117+
// It attaches the Thanos metadata section in each meta JSON file.
118+
func NewWithCompacted(
119+
logger log.Logger,
120+
r prometheus.Registerer,
121+
dir string,
122+
bucket objstore.Bucket,
123+
lbls func() labels.Labels,
124+
source metadata.SourceType,
125+
allowOutOfOrderUploads bool,
126+
) *Shipper {
127+
if logger == nil {
128+
logger = log.NewNopLogger()
129+
}
130+
if lbls == nil {
131+
lbls = func() labels.Labels { return nil }
132+
}
133+
134+
return &Shipper{
135+
logger: logger,
136+
dir: dir,
137+
bucket: bucket,
138+
labels: lbls,
139+
metrics: newMetrics(r, true),
140+
source: source,
141+
uploadCompacted: true,
142+
allowOutOfOrderUploads: allowOutOfOrderUploads,
115143
}
116144
}
117145

pkg/shipper/shipper_e2e_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func TestShipper_SyncBlocks_e2e(t *testing.T) {
4545
}()
4646

4747
extLset := labels.FromStrings("prometheus", "prom-1")
48-
shipper := New(log.NewLogfmtLogger(os.Stderr), nil, dir, metricsBucket, func() labels.Labels { return extLset }, metadata.TestSource, false, false)
48+
shipper := New(log.NewLogfmtLogger(os.Stderr), nil, dir, metricsBucket, func() labels.Labels { return extLset }, metadata.TestSource, false)
4949

5050
ctx, cancel := context.WithCancel(context.Background())
5151
defer cancel()
@@ -219,7 +219,7 @@ func TestShipper_SyncBlocksWithMigrating_e2e(t *testing.T) {
219219
defer upcancel2()
220220
testutil.Ok(t, p.WaitPrometheusUp(upctx2))
221221

222-
shipper := New(log.NewLogfmtLogger(os.Stderr), nil, dir, bkt, func() labels.Labels { return extLset }, metadata.TestSource, true, false)
222+
shipper := NewWithCompacted(log.NewLogfmtLogger(os.Stderr), nil, dir, bkt, func() labels.Labels { return extLset }, metadata.TestSource, false)
223223

224224
// Create 10 new blocks. 9 of them (non compacted) should be actually uploaded.
225225
var (

pkg/shipper/shipper_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func TestShipperTimestamps(t *testing.T) {
2626
testutil.Ok(t, os.RemoveAll(dir))
2727
}()
2828

29-
s := New(nil, nil, dir, nil, nil, metadata.TestSource, false, false)
29+
s := New(nil, nil, dir, nil, nil, metadata.TestSource, false)
3030

3131
// Missing thanos meta file.
3232
_, _, err = s.Timestamps()
@@ -123,7 +123,7 @@ func TestIterBlockMetas(t *testing.T) {
123123
},
124124
}))
125125

126-
shipper := New(nil, nil, dir, nil, nil, metadata.TestSource, false, false)
126+
shipper := New(nil, nil, dir, nil, nil, metadata.TestSource, false)
127127
metas, err := shipper.blockMetasFromOldest()
128128
testutil.Ok(t, err)
129129
testutil.Equals(t, sort.SliceIsSorted(metas, func(i, j int) bool {
@@ -162,7 +162,7 @@ func BenchmarkIterBlockMetas(b *testing.B) {
162162
})
163163
b.ResetTimer()
164164

165-
shipper := New(nil, nil, dir, nil, nil, metadata.TestSource, false, false)
165+
shipper := New(nil, nil, dir, nil, nil, metadata.TestSource, false)
166166

167167
_, err = shipper.blockMetasFromOldest()
168168
testutil.Ok(b, err)

pkg/store/bucket_test.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"sort"
2020
"strconv"
2121
"sync"
22+
"sync/atomic"
2223
"testing"
2324
"time"
2425

@@ -51,7 +52,6 @@ import (
5152
storetestutil "github.com/thanos-io/thanos/pkg/store/storepb/testutil"
5253
"github.com/thanos-io/thanos/pkg/testutil"
5354
"github.com/thanos-io/thanos/pkg/testutil/e2eutil"
54-
"go.uber.org/atomic"
5555
)
5656

5757
var emptyRelabelConfig = make([]*relabel.Config, 0)
@@ -1281,10 +1281,10 @@ func benchBucketSeries(t testutil.TB, samplesPerSeries, totalSeries int, request
12811281

12821282
if !t.IsBenchmark() {
12831283
// Make sure the pool is correctly used. This is expected for 200k numbers.
1284-
testutil.Equals(t, numOfBlocks, int(chunkPool.(*mockedPool).gets.Load()))
1284+
testutil.Equals(t, numOfBlocks, int(chunkPool.(*mockedPool).gets))
12851285
// TODO(bwplotka): This is wrong negative for large number of samples (1mln). Investigate.
1286-
testutil.Equals(t, 0, int(chunkPool.(*mockedPool).balance.Load()))
1287-
chunkPool.(*mockedPool).gets.Store(0)
1286+
testutil.Equals(t, 0, int(chunkPool.(*mockedPool).balance))
1287+
chunkPool.(*mockedPool).gets = 0
12881288

12891289
for _, b := range blocks {
12901290
// NOTE(bwplotka): It is 4 x 1.0 for 100mln samples. Kind of make sense: long series.
@@ -1306,22 +1306,22 @@ func (m fakePool) Put(_ *[]byte) {}
13061306

13071307
type mockedPool struct {
13081308
parent pool.BytesPool
1309-
balance atomic.Uint64
1310-
gets atomic.Uint64
1309+
balance uint64
1310+
gets uint64
13111311
}
13121312

13131313
func (m *mockedPool) Get(sz int) (*[]byte, error) {
13141314
b, err := m.parent.Get(sz)
13151315
if err != nil {
13161316
return nil, err
13171317
}
1318-
m.balance.Add(uint64(cap(*b)))
1319-
m.gets.Add(uint64(1))
1318+
atomic.AddUint64(&m.balance, uint64(cap(*b)))
1319+
atomic.AddUint64(&m.gets, uint64(1))
13201320
return b, nil
13211321
}
13221322

13231323
func (m *mockedPool) Put(b *[]byte) {
1324-
m.balance.Sub(uint64(cap(*b)))
1324+
atomic.AddUint64(&m.balance, ^uint64(cap(*b)-1))
13251325
m.parent.Put(b)
13261326
}
13271327

pkg/store/limiter.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ package store
55

66
import (
77
"sync"
8+
"sync/atomic"
89

910
"github.com/pkg/errors"
1011
"github.com/prometheus/client_golang/prometheus"
11-
"go.uber.org/atomic"
1212
)
1313

1414
type ChunksLimiter interface {
@@ -25,7 +25,7 @@ type ChunksLimiterFactory func(failedCounter prometheus.Counter) ChunksLimiter
2525
// Limiter is a simple mechanism for checking if something has passed a certain threshold.
2626
type Limiter struct {
2727
limit uint64
28-
reserved atomic.Uint64
28+
reserved uint64
2929

3030
// Counter metric which we will increase if limit is exceeded.
3131
failedCounter prometheus.Counter
@@ -42,7 +42,7 @@ func (l *Limiter) Reserve(num uint64) error {
4242
if l.limit == 0 {
4343
return nil
4444
}
45-
if reserved := l.reserved.Add(num); reserved > l.limit {
45+
if reserved := atomic.AddUint64(&l.reserved, num); reserved > l.limit {
4646
// We need to protect from the counter being incremented twice due to concurrency
4747
// while calling Reserve().
4848
l.failedOnce.Do(l.failedCounter.Inc)

tutorials/katacoda/thanos/2-lts/courseBase.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22

33
docker pull dockerenginesonia/thanosbench:v7
44
docker pull quay.io/prometheus/prometheus:v2.19.0
5-
docker pull quay.io/thanos/thanos:v0.13.0
5+
docker pull quay.io/thanos/thanos:v0.15.0
66
docker pull minio/minio:RELEASE.2019-01-31T00-31-19Z

0 commit comments

Comments
 (0)