Skip to content

Commit 09fe17c

Browse files
Add the ability to disable OpenCensus within GCS client. (#4219)
* Adds the ability to remove OpenCensus instrumentation on GCS. Signed-off-by: Cyril Tovena <[email protected]> * Add the ability to disable OpenCensus within GCS client. The rationale is that we're pretty biaised about Prometheus instrumentation here and it should be possible to disable this if we don't want it at all. Signed-off-by: Cyril Tovena <[email protected]> * Adds changelog entry. Signed-off-by: Cyril Tovena <[email protected]> Co-authored-by: Marco Pracucci <[email protected]>
1 parent 4888a1c commit 09fe17c

File tree

3 files changed

+26
-7
lines changed

3 files changed

+26
-7
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
* [FEATURE] Alertmanager: Added `-alertmanager.max-config-size-bytes` limit to control size of configuration files that Cortex users can upload to Alertmanager via API. This limit is configurable per-tenant. #4201
1313
* [FEATURE] Alertmanager: Added `-alertmanager.max-templates-count` and `-alertmanager.max-template-size-bytes` options to control number and size of templates uploaded to Alertmanager via API. These limits are configurable per-tenant. #4223
1414
* [FEATURE] Added flag `-debug.block-profile-rate` to enable goroutine blocking events profiling. #4217
15+
* [ENHANCEMENT] Storage: Added the ability to disable Open Census within GCS client (e.g `-gcs.enable-opencensus=false`). #4219
1516
* [ENHANCEMENT] Alertmanager: introduced new metrics to monitor operation when using `-alertmanager.sharding-enabled`: #4149
1617
* `cortex_alertmanager_state_fetch_replica_state_total`
1718
* `cortex_alertmanager_state_fetch_replica_state_failed_total`

docs/configuration/config-file-reference.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1297,6 +1297,10 @@ storage:
12971297
# CLI flag: -ruler.storage.gcs.request-timeout
12981298
[request_timeout: <duration> | default = 0s]
12991299
1300+
# Enabled OpenCensus (OC) instrumentation for all requests.
1301+
# CLI flag: -ruler.storage.gcs.enable-opencensus
1302+
[enable_opencensus: <boolean> | default = true]
1303+
13001304
s3:
13011305
# S3 endpoint URL with escaped Key and Secret encoded. If only region is
13021306
# specified as a host, proper endpoint will be deduced. Use
@@ -2001,6 +2005,10 @@ storage:
20012005
# CLI flag: -alertmanager.storage.gcs.request-timeout
20022006
[request_timeout: <duration> | default = 0s]
20032007
2008+
# Enabled OpenCensus (OC) instrumentation for all requests.
2009+
# CLI flag: -alertmanager.storage.gcs.enable-opencensus
2010+
[enable_opencensus: <boolean> | default = true]
2011+
20042012
s3:
20052013
# S3 endpoint URL with escaped Key and Secret encoded. If only region is
20062014
# specified as a host, proper endpoint will be deduced. Use
@@ -2991,6 +2999,10 @@ gcs:
29912999
# CLI flag: -gcs.request-timeout
29923000
[request_timeout: <duration> | default = 0s]
29933001

3002+
# Enabled OpenCensus (OC) instrumentation for all requests.
3003+
# CLI flag: -gcs.enable-opencensus
3004+
[enable_opencensus: <boolean> | default = true]
3005+
29943006
cassandra:
29953007
# Comma-separated hostnames or IPs of Cassandra instances.
29963008
# CLI flag: -cassandra.addresses

pkg/chunk/gcp/gcs_object_client.go

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88

99
"cloud.google.com/go/storage"
1010
"google.golang.org/api/iterator"
11+
"google.golang.org/api/option"
1112

1213
"github.com/cortexproject/cortex/pkg/chunk"
1314
"github.com/cortexproject/cortex/pkg/chunk/util"
@@ -21,9 +22,10 @@ type GCSObjectClient struct {
2122

2223
// GCSConfig is config for the GCS Chunk Client.
2324
type GCSConfig struct {
24-
BucketName string `yaml:"bucket_name"`
25-
ChunkBufferSize int `yaml:"chunk_buffer_size"`
26-
RequestTimeout time.Duration `yaml:"request_timeout"`
25+
BucketName string `yaml:"bucket_name"`
26+
ChunkBufferSize int `yaml:"chunk_buffer_size"`
27+
RequestTimeout time.Duration `yaml:"request_timeout"`
28+
EnableOpenCensus bool `yaml:"enable_opencensus"`
2729
}
2830

2931
// RegisterFlags registers flags.
@@ -36,16 +38,22 @@ func (cfg *GCSConfig) RegisterFlagsWithPrefix(prefix string, f *flag.FlagSet) {
3638
f.StringVar(&cfg.BucketName, prefix+"gcs.bucketname", "", "Name of GCS bucket. Please refer to https://cloud.google.com/docs/authentication/production for more information about how to configure authentication.")
3739
f.IntVar(&cfg.ChunkBufferSize, prefix+"gcs.chunk-buffer-size", 0, "The size of the buffer that GCS client for each PUT request. 0 to disable buffering.")
3840
f.DurationVar(&cfg.RequestTimeout, prefix+"gcs.request-timeout", 0, "The duration after which the requests to GCS should be timed out.")
41+
f.BoolVar(&cfg.EnableOpenCensus, prefix+"gcs.enable-opencensus", true, "Enabled OpenCensus (OC) instrumentation for all requests.")
3942
}
4043

4144
// NewGCSObjectClient makes a new chunk.Client that writes chunks to GCS.
4245
func NewGCSObjectClient(ctx context.Context, cfg GCSConfig) (*GCSObjectClient, error) {
43-
option, err := gcsInstrumentation(ctx, storage.ScopeReadWrite)
46+
var opts []option.ClientOption
47+
instrumentation, err := gcsInstrumentation(ctx, storage.ScopeReadWrite)
4448
if err != nil {
4549
return nil, err
4650
}
51+
opts = append(opts, instrumentation)
52+
if !cfg.EnableOpenCensus {
53+
opts = append(opts, option.WithTelemetryDisabled())
54+
}
4755

48-
client, err := storage.NewClient(ctx, option)
56+
client, err := storage.NewClient(ctx, opts...)
4957
if err != nil {
5058
return nil, err
5159
}
@@ -85,7 +93,6 @@ func (s *GCSObjectClient) GetObject(ctx context.Context, objectKey string) (io.R
8593

8694
func (s *GCSObjectClient) getObject(ctx context.Context, objectKey string) (rc io.ReadCloser, err error) {
8795
reader, err := s.bucket.Object(objectKey).NewReader(ctx)
88-
8996
if err != nil {
9097
if err == storage.ErrObjectNotExist {
9198
return nil, chunk.ErrStorageObjectNotFound
@@ -165,7 +172,6 @@ func (s *GCSObjectClient) List(ctx context.Context, prefix, delimiter string) ([
165172
// key does not exist a generic chunk.ErrStorageObjectNotFound error is returned.
166173
func (s *GCSObjectClient) DeleteObject(ctx context.Context, objectKey string) error {
167174
err := s.bucket.Object(objectKey).Delete(ctx)
168-
169175
if err != nil {
170176
if err == storage.ErrObjectNotExist {
171177
return chunk.ErrStorageObjectNotFound

0 commit comments

Comments
 (0)