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 the ability to disable OpenCensus within GCS client. #4219

Merged
merged 4 commits into from
May 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
* [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
* [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
* [FEATURE] Added flag `-debug.block-profile-rate` to enable goroutine blocking events profiling. #4217
* [ENHANCEMENT] Storage: Added the ability to disable Open Census within GCS client (e.g `-gcs.enable-opencensus=false`). #4219
* [ENHANCEMENT] Alertmanager: introduced new metrics to monitor operation when using `-alertmanager.sharding-enabled`: #4149
* `cortex_alertmanager_state_fetch_replica_state_total`
* `cortex_alertmanager_state_fetch_replica_state_failed_total`
Expand Down
12 changes: 12 additions & 0 deletions docs/configuration/config-file-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -1297,6 +1297,10 @@ storage:
# CLI flag: -ruler.storage.gcs.request-timeout
[request_timeout: <duration> | default = 0s]

# Enabled OpenCensus (OC) instrumentation for all requests.
# CLI flag: -ruler.storage.gcs.enable-opencensus
[enable_opencensus: <boolean> | default = true]

s3:
# S3 endpoint URL with escaped Key and Secret encoded. If only region is
# specified as a host, proper endpoint will be deduced. Use
Expand Down Expand Up @@ -2001,6 +2005,10 @@ storage:
# CLI flag: -alertmanager.storage.gcs.request-timeout
[request_timeout: <duration> | default = 0s]

# Enabled OpenCensus (OC) instrumentation for all requests.
# CLI flag: -alertmanager.storage.gcs.enable-opencensus
[enable_opencensus: <boolean> | default = true]

s3:
# S3 endpoint URL with escaped Key and Secret encoded. If only region is
# specified as a host, proper endpoint will be deduced. Use
Expand Down Expand Up @@ -2991,6 +2999,10 @@ gcs:
# CLI flag: -gcs.request-timeout
[request_timeout: <duration> | default = 0s]

# Enabled OpenCensus (OC) instrumentation for all requests.
# CLI flag: -gcs.enable-opencensus
[enable_opencensus: <boolean> | default = true]

cassandra:
# Comma-separated hostnames or IPs of Cassandra instances.
# CLI flag: -cassandra.addresses
Expand Down
20 changes: 13 additions & 7 deletions pkg/chunk/gcp/gcs_object_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"cloud.google.com/go/storage"
"google.golang.org/api/iterator"
"google.golang.org/api/option"

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

// GCSConfig is config for the GCS Chunk Client.
type GCSConfig struct {
BucketName string `yaml:"bucket_name"`
ChunkBufferSize int `yaml:"chunk_buffer_size"`
RequestTimeout time.Duration `yaml:"request_timeout"`
BucketName string `yaml:"bucket_name"`
ChunkBufferSize int `yaml:"chunk_buffer_size"`
RequestTimeout time.Duration `yaml:"request_timeout"`
EnableOpenCensus bool `yaml:"enable_opencensus"`
}

// RegisterFlags registers flags.
Expand All @@ -36,16 +38,22 @@ func (cfg *GCSConfig) RegisterFlagsWithPrefix(prefix string, f *flag.FlagSet) {
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.")
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.")
f.DurationVar(&cfg.RequestTimeout, prefix+"gcs.request-timeout", 0, "The duration after which the requests to GCS should be timed out.")
f.BoolVar(&cfg.EnableOpenCensus, prefix+"gcs.enable-opencensus", true, "Enabled OpenCensus (OC) instrumentation for all requests.")
}

// NewGCSObjectClient makes a new chunk.Client that writes chunks to GCS.
func NewGCSObjectClient(ctx context.Context, cfg GCSConfig) (*GCSObjectClient, error) {
option, err := gcsInstrumentation(ctx, storage.ScopeReadWrite)
var opts []option.ClientOption
instrumentation, err := gcsInstrumentation(ctx, storage.ScopeReadWrite)
if err != nil {
return nil, err
}
opts = append(opts, instrumentation)
if !cfg.EnableOpenCensus {
opts = append(opts, option.WithTelemetryDisabled())
}

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

func (s *GCSObjectClient) getObject(ctx context.Context, objectKey string) (rc io.ReadCloser, err error) {
reader, err := s.bucket.Object(objectKey).NewReader(ctx)

if err != nil {
if err == storage.ErrObjectNotExist {
return nil, chunk.ErrStorageObjectNotFound
Expand Down Expand Up @@ -165,7 +172,6 @@ func (s *GCSObjectClient) List(ctx context.Context, prefix, delimiter string) ([
// key does not exist a generic chunk.ErrStorageObjectNotFound error is returned.
func (s *GCSObjectClient) DeleteObject(ctx context.Context, objectKey string) error {
err := s.bucket.Object(objectKey).Delete(ctx)

if err != nil {
if err == storage.ErrObjectNotExist {
return chunk.ErrStorageObjectNotFound
Expand Down