Skip to content

Commit

Permalink
Wrap object store Prometheus registry (thanos-io#6152)
Browse files Browse the repository at this point in the history
* Wrap object store Prometheus registery

In preparation for the work being done at thanos-io/objstore#26.

Signed-off-by: Douglas Camata <[email protected]>

* Update objstore to the latest version

This version removes the `thanos_` prefix from metrics, which is the
reason for wrapping the objstore's metrics registry in the first place.

Signed-off-by: Douglas Camata <[email protected]>

* Fix modules

Signed-off-by: Douglas Camata <[email protected]>

* Rerun CI

Signed-off-by: Douglas Camata <[email protected]>

* Wrap metrics registerer for objstore bucket

Signed-off-by: Douglas Camata <[email protected]>

* Remove prefix from Thanos Store metrics

Signed-off-by: Douglas Camata <[email protected]>

* Fix goimports

Signed-off-by: Douglas Camata <[email protected]>

* Rerun CI

Signed-off-by: Douglas Camata <[email protected]>

* Rerun CI

Signed-off-by: Douglas Camata <[email protected]>

* Put back upgraded objstore dep

Signed-off-by: Douglas Camata <[email protected]>

* Rerun CI

Signed-off-by: Douglas Camata <[email protected]>

* Rerun CI

Signed-off-by: Douglas Camata <[email protected]>

* Move to more recent ref of thanos/objstore

Signed-off-by: Douglas Camata <[email protected]>

* Ignore OBS in objstore tests

Signed-off-by: Douglas Camata <[email protected]>

* Fix linting error on main test after objstore upgrade

Signed-off-by: Douglas Camata <[email protected]>

* Skip OCS objstore test in circle ci

Signed-off-by: Douglas Camata <[email protected]>

* Fix echo in makefile

Signed-off-by: Douglas Camata <[email protected]>

* Fix typo

Signed-off-by: Douglas Camata <[email protected]>

---------

Signed-off-by: Douglas Camata <[email protected]>
Signed-off-by: Giedrius Statkevičius <[email protected]>
  • Loading branch information
douglascamata authored and GiedriusS committed Jul 27, 2023
1 parent 43ea481 commit c2709a4
Show file tree
Hide file tree
Showing 14 changed files with 34 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
- run:
name: "Run unit tests."
environment:
THANOS_TEST_OBJSTORE_SKIP: GCS,S3,AZURE,COS,ALIYUNOSS,BOS,OCI
THANOS_TEST_OBJSTORE_SKIP: GCS,S3,AZURE,COS,ALIYUNOSS,BOS,OCI,OBS
# Variables for Swift testing.
OS_AUTH_URL: http://127.0.0.1:5000/v2.0
OS_PASSWORD: s3cr3t
Expand Down
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -307,12 +307,12 @@ test: export THANOS_TEST_PROMETHEUS_PATHS= $(PROMETHEUS)
test: export THANOS_TEST_ALERTMANAGER_PATH= $(ALERTMANAGER)
test: check-git install-tool-deps
@echo ">> install thanos GOOPTS=${GOOPTS}"
@echo ">> running unit tests (without /test/e2e). Do export THANOS_TEST_OBJSTORE_SKIP=GCS,S3,AZURE,SWIFT,COS,ALIYUNOSS,BOS,OCI if you want to skip e2e tests against all real store buckets. Current value: ${THANOS_TEST_OBJSTORE_SKIP}"
@echo ">> running unit tests (without /test/e2e). Do export THANOS_TEST_OBJSTORE_SKIP=GCS,S3,AZURE,SWIFT,COS,ALIYUNOSS,BOS,OCI,OBS if you want to skip e2e tests against all real store buckets. Current value: ${THANOS_TEST_OBJSTORE_SKIP}"
@go test -timeout 15m $(shell go list ./... | grep -v /vendor/ | grep -v /test/e2e);

.PHONY: test-local
test-local: ## Runs test excluding tests for ALL object storage integrations.
test-local: export THANOS_TEST_OBJSTORE_SKIP=GCS,S3,AZURE,SWIFT,COS,ALIYUNOSS,BOS,OCI
test-local: export THANOS_TEST_OBJSTORE_SKIP=GCS,S3,AZURE,SWIFT,COS,ALIYUNOSS,BOS,OCI,OBS
test-local:
$(MAKE) test

Expand All @@ -333,7 +333,7 @@ test-e2e: docker $(GOTESPLIT)

.PHONY: test-e2e-local
test-e2e-local: ## Runs all thanos e2e tests locally.
test-e2e-local: export THANOS_TEST_OBJSTORE_SKIP=GCS,S3,AZURE,SWIFT,COS,ALIYUNOSS,BOS,OCI
test-e2e-local: export THANOS_TEST_OBJSTORE_SKIP=GCS,S3,AZURE,SWIFT,COS,ALIYUNOSS,BOS,OCI,OBS
test-e2e-local:
$(MAKE) test-e2e

Expand Down
2 changes: 1 addition & 1 deletion cmd/thanos/compact.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ func runCompact(
return err
}

bkt, err := client.NewBucket(logger, confContentYaml, reg, component.String())
bkt, err := client.NewBucket(logger, confContentYaml, extprom.WrapRegistererWithPrefix("thanos_", reg), component.String())
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/thanos/downsample.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func RunDownsample(
return err
}

bkt, err := client.NewBucket(logger, confContentYaml, reg, component.Downsample.String())
bkt, err := client.NewBucket(logger, confContentYaml, extprom.WrapRegistererWithPrefix("thanos_", reg), component.Downsample.String())
if err != nil {
return err
}
Expand Down
4 changes: 4 additions & 0 deletions cmd/thanos/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ type erroringBucket struct {
bkt objstore.InstrumentedBucket
}

func (b *erroringBucket) IsCustomerManagedKeyError(err error) bool {
return b.bkt.IsCustomerManagedKeyError(err)
}

func (b *erroringBucket) Close() error {
return b.bkt.Close()
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/thanos/receive.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ func runReceive(
}
// The background shipper continuously scans the data directory and uploads
// new blocks to object storage service.
bkt, err = client.NewBucket(logger, confContentYaml, reg, comp.String())
bkt, err = client.NewBucket(logger, confContentYaml, extprom.WrapRegistererWithPrefix("thanos_", reg), comp.String())
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/thanos/rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,7 @@ func runRule(
if len(confContentYaml) > 0 {
// The background shipper continuously scans the data directory and uploads
// new blocks to Google Cloud Storage or an S3-compatible storage service.
bkt, err := client.NewBucket(logger, confContentYaml, reg, component.Rule.String())
bkt, err := client.NewBucket(logger, confContentYaml, extprom.WrapRegistererWithPrefix("thanos_", reg), component.Rule.String())
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/thanos/sidecar.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ func runSidecar(
if uploads {
// The background shipper continuously scans the data directory and uploads
// new blocks to Google Cloud Storage or an S3-compatible storage service.
bkt, err := client.NewBucket(logger, confContentYaml, reg, component.Sidecar.String())
bkt, err := client.NewBucket(logger, confContentYaml, extprom.WrapRegistererWithPrefix("thanos_", reg), component.Sidecar.String())
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/thanos/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ func runStore(
return err
}

bkt, err := client.NewBucket(logger, confContentYaml, reg, conf.component.String())
bkt, err := client.NewBucket(logger, confContentYaml, extprom.WrapRegistererWithPrefix("thanos_", reg), conf.component.String())
if err != nil {
return errors.Wrap(err, "create bucket client")
}
Expand Down
16 changes: 8 additions & 8 deletions cmd/thanos/tools_bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ func registerBucketVerify(app extkingpin.AppClause, objStoreConfig *extflag.Path
return err
}

bkt, err := client.NewBucket(logger, confContentYaml, reg, component.Bucket.String())
bkt, err := client.NewBucket(logger, confContentYaml, extprom.WrapRegistererWithPrefix("thanos_", reg), component.Bucket.String())
if err != nil {
return err
}
Expand Down Expand Up @@ -380,7 +380,7 @@ func registerBucketLs(app extkingpin.AppClause, objStoreConfig *extflag.PathOrCo
return err
}

bkt, err := client.NewBucket(logger, confContentYaml, reg, component.Bucket.String())
bkt, err := client.NewBucket(logger, confContentYaml, extprom.WrapRegistererWithPrefix("thanos_", reg), component.Bucket.String())
if err != nil {
return err
}
Expand Down Expand Up @@ -486,7 +486,7 @@ func registerBucketInspect(app extkingpin.AppClause, objStoreConfig *extflag.Pat
return err
}

bkt, err := client.NewBucket(logger, confContentYaml, reg, component.Bucket.String())
bkt, err := client.NewBucket(logger, confContentYaml, extprom.WrapRegistererWithPrefix("thanos_", reg), component.Bucket.String())
if err != nil {
return err
}
Expand Down Expand Up @@ -594,7 +594,7 @@ func registerBucketWeb(app extkingpin.AppClause, objStoreConfig *extflag.PathOrC
return err
}

bkt, err := client.NewBucket(logger, confContentYaml, reg, component.Bucket.String())
bkt, err := client.NewBucket(logger, confContentYaml, extprom.WrapRegistererWithPrefix("thanos_", reg), component.Bucket.String())
if err != nil {
return errors.Wrap(err, "bucket client")
}
Expand Down Expand Up @@ -779,7 +779,7 @@ func registerBucketCleanup(app extkingpin.AppClause, objStoreConfig *extflag.Pat
return err
}

bkt, err := client.NewBucket(logger, confContentYaml, reg, component.Cleanup.String())
bkt, err := client.NewBucket(logger, confContentYaml, extprom.WrapRegistererWithPrefix("thanos_", reg), component.Cleanup.String())
if err != nil {
return err
}
Expand Down Expand Up @@ -1034,7 +1034,7 @@ func registerBucketMarkBlock(app extkingpin.AppClause, objStoreConfig *extflag.P
return err
}

bkt, err := client.NewBucket(logger, confContentYaml, reg, component.Mark.String())
bkt, err := client.NewBucket(logger, confContentYaml, extprom.WrapRegistererWithPrefix("thanos_", reg), component.Mark.String())
if err != nil {
return err
}
Expand Down Expand Up @@ -1113,7 +1113,7 @@ func registerBucketRewrite(app extkingpin.AppClause, objStoreConfig *extflag.Pat
return err
}

bkt, err := client.NewBucket(logger, confContentYaml, reg, component.Rewrite.String())
bkt, err := client.NewBucket(logger, confContentYaml, extprom.WrapRegistererWithPrefix("thanos_", reg), component.Rewrite.String())
if err != nil {
return err
}
Expand Down Expand Up @@ -1320,7 +1320,7 @@ func registerBucketRetention(app extkingpin.AppClause, objStoreConfig *extflag.P
return err
}

bkt, err := client.NewBucket(logger, confContentYaml, reg, component.Retention.String())
bkt, err := client.NewBucket(logger, confContentYaml, extprom.WrapRegistererWithPrefix("thanos_", reg), component.Retention.String())
if err != nil {
return err
}
Expand Down
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ require (
github.com/prometheus/prometheus v0.44.1-0.20230524110021-37e5249e33e4
github.com/sony/gobreaker v0.5.0
github.com/stretchr/testify v1.8.2
github.com/thanos-io/objstore v0.0.0-20230201072718-11ffbc490204
github.com/thanos-io/objstore v0.0.0-20230710163637-47c0118da0ca
github.com/thanos-io/promql-engine v0.0.0-20230524050847-9a1a33217cf2
github.com/uber/jaeger-client-go v2.30.0+incompatible
github.com/uber/jaeger-lib v2.4.1+incompatible // indirect
Expand Down Expand Up @@ -124,6 +124,7 @@ require (
)

require (
github.com/huaweicloud/huaweicloud-sdk-go-obs v3.23.3+incompatible // indirect
github.com/onsi/ginkgo v1.16.5 // indirect
go4.org/unsafe/assume-no-moving-gc v0.0.0-20230209150437-ee73d164e760 // indirect
)
Expand Down
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,8 @@ github.com/hashicorp/serf v0.8.2/go.mod h1:6hOLApaqBFA1NXqRQAsxw9QxuDEvNxSQRwA/J
github.com/hashicorp/serf v0.10.1 h1:Z1H2J60yRKvfDYAOZLd2MU0ND4AH/WDz7xYHDWQsIPY=
github.com/hetznercloud/hcloud-go v1.45.1 h1:nl0OOklFfQT5J6AaNIOhl5Ruh3fhmGmhvZEqHbibVuk=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/huaweicloud/huaweicloud-sdk-go-obs v3.23.3+incompatible h1:tKTaPHNVwikS3I1rdyf1INNvgJXWSf/+TzqsiGbrgnQ=
github.com/huaweicloud/huaweicloud-sdk-go-obs v3.23.3+incompatible/go.mod h1:l7VUhRbTKCzdOacdT4oWCwATKyvZqUOlOqr0Ous3k4s=
github.com/hudl/fargo v1.3.0/go.mod h1:y3CKSmjA+wD2gak7sUSXTAoopbhU08POFhmITJgmKTg=
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
Expand Down Expand Up @@ -896,8 +898,8 @@ github.com/tencentyun/cos-go-sdk-v5 v0.7.40 h1:W6vDGKCHe4wBACI1d2UgE6+50sJFhRWU4
github.com/tencentyun/cos-go-sdk-v5 v0.7.40/go.mod h1:4dCEtLHGh8QPxHEkgq+nFaky7yZxQuYwgSJM87icDaw=
github.com/thanos-community/galaxycache v0.0.0-20211122094458-3a32041a1f1e h1:f1Zsv7OAU9iQhZwigp50Yl38W10g/vd5NC8Rdk1Jzng=
github.com/thanos-community/galaxycache v0.0.0-20211122094458-3a32041a1f1e/go.mod h1:jXcofnrSln/cLI6/dhlBxPQZEEQHVPCcFaH75M+nSzM=
github.com/thanos-io/objstore v0.0.0-20230201072718-11ffbc490204 h1:W4w5Iph7j32Sf1QFWLJDCqvO0WgZS0jHGID+qnq3wV0=
github.com/thanos-io/objstore v0.0.0-20230201072718-11ffbc490204/go.mod h1:STSgpY8M6EKF2G/raUFdbIMf2U9GgYlEjAEHJxjvpAo=
github.com/thanos-io/objstore v0.0.0-20230710163637-47c0118da0ca h1:JRF7i58HovirZQVJGwCClQsMK6CCmK2fvialXjeoSpI=
github.com/thanos-io/objstore v0.0.0-20230710163637-47c0118da0ca/go.mod h1:5V7lzXuaxwt6XFQoA/zJrhdnQrxq1+r0bwQ1iYOq3gM=
github.com/themihai/gomemcache v0.0.0-20180902122335-24332e2d58ab h1:7ZR3hmisBWw77ZpO1/o86g+JV3VKlk3d48jopJxzTjU=
github.com/themihai/gomemcache v0.0.0-20180902122335-24332e2d58ab/go.mod h1:eheTFp954zcWZXCU8d0AT76ftsQOTo4DTqkN/h3k1MY=
github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
Expand Down
4 changes: 3 additions & 1 deletion pkg/block/block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import (
"testing"
"time"

"github.com/thanos-io/thanos/pkg/extprom"

"github.com/go-kit/log"
"github.com/oklog/ulid"
"github.com/pkg/errors"
Expand Down Expand Up @@ -449,7 +451,7 @@ func TestHashDownload(t *testing.T) {

bkt := objstore.NewInMemBucket()
r := prometheus.NewRegistry()
instrumentedBkt := objstore.BucketWithMetrics("test", bkt, r)
instrumentedBkt := objstore.BucketWithMetrics("test", bkt, extprom.WrapRegistererWithPrefix("thanos_", r))

b1, err := e2eutil.CreateBlockWithTombstone(ctx, tmpDir, []labels.Labels{
{{Name: "a", Value: "1"}},
Expand Down
4 changes: 3 additions & 1 deletion pkg/shipper/shipper_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import (
"testing"
"time"

"github.com/thanos-io/thanos/pkg/extprom"

"github.com/go-kit/log"
"github.com/oklog/ulid"
"github.com/prometheus/client_golang/prometheus"
Expand All @@ -37,7 +39,7 @@ func TestShipper_SyncBlocks_e2e(t *testing.T) {
objtesting.ForeachStore(t, func(t *testing.T, bkt objstore.Bucket) {
// TODO(GiedriusS): consider switching to BucketWithMetrics() everywhere?
metrics := prometheus.NewRegistry()
metricsBucket := objstore.BucketWithMetrics("test", bkt, metrics)
metricsBucket := objstore.BucketWithMetrics("test", bkt, extprom.WrapRegistererWithPrefix("thanos_", metrics))

dir := t.TempDir()

Expand Down

0 comments on commit c2709a4

Please sign in to comment.