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 3 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 @@ -9,6 +9,7 @@
* [CHANGE] Change default value of `-server.grpc.keepalive.min-time-between-pings` to `10s` and `-server.grpc.keepalive.ping-without-stream-allowed` to `true`. #4168
* [FEATURE] Querier: Added new `-querier.max-fetched-series-per-query` flag. When Cortex is running with blocks storage, the max series per query limit is enforced in the querier and applies to unique series received from ingesters and store-gateway (long-term storage). #4179
* [FEATURE] Alertmanager: Added rate-limits to notifiers. Rate limits used by all integrations can be configured using `-alertmanager.notification-rate-limit`, while per-integration rate limits can be specified via `-alertmanager.notification-rate-limit-per-integration` parameter. Both shared and per-integration limits can be overwritten using overrides mechanism. These limits are applied on individual (per-tenant) alertmanagers. Rate-limited notifications are failed notifications. It is possible to monitor rate-limited notifications via new `cortex_alertmanager_notification_rate_limited_total` metric. #4135 #4163
* [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 @@ -1991,6 +1995,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 @@ -2981,6 +2989,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