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

Configurable s3 storage class #4300

Merged
merged 82 commits into from
Apr 6, 2023

Conversation

inbarpatashnik
Copy link
Contributor

@inbarpatashnik inbarpatashnik commented Feb 25, 2023

What this PR does

Added support in configurable s3 storage class.

Which issue(s) this PR fixes or relates to

Fixes #3438

Checklist

  • Tests updated
  • Documentation added
  • CHANGELOG.md updated - the order of entries should be [CHANGE], [FEATURE], [ENHANCEMENT], [BUGFIX]

@inbarpatashnik inbarpatashnik requested a review from a team as a code owner February 25, 2023 18:50
@CLAassistant
Copy link

CLAassistant commented Feb 25, 2023

CLA assistant check
All committers have signed the CLA.

@inbarpatashnik
Copy link
Contributor Author

I haven't tried to run it against a real s3.
So I would really appreciate if you could also check it after reviewing :)

@inbarpatashnik inbarpatashnik requested a review from a team as a code owner March 4, 2023 21:15
Copy link
Contributor

@charleskorn charleskorn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR @inbarpatashnik!

CHANGELOG.md Outdated Show resolved Hide resolved
CHANGELOG.md Outdated Show resolved Hide resolved
pkg/storage/bucket/s3/bucket_client.go Outdated Show resolved Hide resolved
pkg/storage/bucket/s3/config.go Outdated Show resolved Hide resolved
pkg/storage/bucket/s3/config.go Outdated Show resolved Hide resolved
AccessKey: cfg.AccessKeyID,
SecretKey: cfg.SecretAccessKey.String(),
Insecure: cfg.Insecure,
PutUserMetadata: map[string]string{awsStorageClassHeader: cfg.StorageClass},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be being overly cautious here: it's probably safest for the default value of cfg.StorageClass to be an empty string, and to not set PutUserMetadata at all if StorageClass is not set - some S3-compatible storage services may not support STANDARD.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi! thank you so much for the review!
It sounds like a very good point - Ive tried to edit so the default value of the storage class in the config.go will be an empty string, but it seemed to fail some tests because the object storage class "" doesn't exist.
Maybe I should edit it in this file to be an empty string?
I fixed the pr according to all the comments, but I still think how to fix so solve this one.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And also I'm thinking - maybe its better if it will have an actual default value that will be supported by default (If it exists?)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than setting it to an empty string, I would simply not set it at all (which is what we were doing before).

@pstibrany
Copy link
Member

The CHANGELOG has just been cut to prepare for the next Mimir release. Please rebase main and eventually move the CHANGELOG entry added / updated in this PR to the top of the CHANGELOG document. Thanks!

Copy link
Contributor

@charleskorn charleskorn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

34a746f went too far 😄

This comment was a suggestion to only set the X-Amz-Storage-Class value if cfg.StorageClass was not an empty string.

So, I'm imagining something like this:

func newS3Config(cfg Config) (s3.Config, error) {
	sseCfg, err := cfg.SSE.BuildThanosConfig()
	if err != nil {
		return s3.Config{}, err
	}

	putUserMetadata := map[string]string{}

	if cfg.StorageClass != "" {
		putUserMetadata[awsStorageClassHeader] = cfg.StorageClass
	}

	return s3.Config{
		Bucket:          cfg.BucketName,
		Endpoint:        cfg.Endpoint,
		Region:          cfg.Region,
		AccessKey:       cfg.AccessKeyID,
		SecretKey:       cfg.SecretAccessKey.String(),
		Insecure:        cfg.Insecure,
		PutUserMetadata: putUserMetadata,
		SSEConfig:       sseCfg,
		HTTPConfig: s3.HTTPConfig{
			IdleConnTimeout:       model.Duration(cfg.HTTP.IdleConnTimeout),
			ResponseHeaderTimeout: model.Duration(cfg.HTTP.ResponseHeaderTimeout),
			InsecureSkipVerify:    cfg.HTTP.InsecureSkipVerify,
			TLSHandshakeTimeout:   model.Duration(cfg.HTTP.TLSHandshakeTimeout),
			ExpectContinueTimeout: model.Duration(cfg.HTTP.ExpectContinueTimeout),
			MaxIdleConns:          cfg.HTTP.MaxIdleConns,
			MaxIdleConnsPerHost:   cfg.HTTP.MaxIdleConnsPerHost,
			MaxConnsPerHost:       cfg.HTTP.MaxConnsPerHost,
			Transport:             cfg.HTTP.Transport,
		},
		// Enforce signature version 2 if CLI flag is set
		SignatureV2: cfg.SignatureVersion == SignatureVersionV2,
	}, nil
}

@inbarpatashnik
Copy link
Contributor Author

34a746f went too far 😄

This comment was a suggestion to only set the X-Amz-Storage-Class value if cfg.StorageClass was not an empty string.

So, I'm imagining something like this:

func newS3Config(cfg Config) (s3.Config, error) {
	sseCfg, err := cfg.SSE.BuildThanosConfig()
	if err != nil {
		return s3.Config{}, err
	}

	putUserMetadata := map[string]string{}

	if cfg.StorageClass != "" {
		putUserMetadata[awsStorageClassHeader] = cfg.StorageClass
	}

	return s3.Config{
		Bucket:          cfg.BucketName,
		Endpoint:        cfg.Endpoint,
		Region:          cfg.Region,
		AccessKey:       cfg.AccessKeyID,
		SecretKey:       cfg.SecretAccessKey.String(),
		Insecure:        cfg.Insecure,
		PutUserMetadata: putUserMetadata,
		SSEConfig:       sseCfg,
		HTTPConfig: s3.HTTPConfig{
			IdleConnTimeout:       model.Duration(cfg.HTTP.IdleConnTimeout),
			ResponseHeaderTimeout: model.Duration(cfg.HTTP.ResponseHeaderTimeout),
			InsecureSkipVerify:    cfg.HTTP.InsecureSkipVerify,
			TLSHandshakeTimeout:   model.Duration(cfg.HTTP.TLSHandshakeTimeout),
			ExpectContinueTimeout: model.Duration(cfg.HTTP.ExpectContinueTimeout),
			MaxIdleConns:          cfg.HTTP.MaxIdleConns,
			MaxIdleConnsPerHost:   cfg.HTTP.MaxIdleConnsPerHost,
			MaxConnsPerHost:       cfg.HTTP.MaxConnsPerHost,
			Transport:             cfg.HTTP.Transport,
		},
		// Enforce signature version 2 if CLI flag is set
		SignatureV2: cfg.SignatureVersion == SignatureVersionV2,
	}, nil
}

ohh, yes. Makes more sense🤭 @charleskorn
When changing I didn't understand how It would be saved in the config when removing it.
thanks :)

CHANGELOG.md Outdated Show resolved Hide resolved
Copy link
Contributor

@charleskorn charleskorn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks again @inbarpatashnik!

@inbarpatashnik
Copy link
Contributor Author

Thanks again @inbarpatashnik!

Thank you!!🤗

Copy link
Contributor

@56quarters 56quarters left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with some minor tweaks. Thanks!

pkg/storage/bucket/s3/config.go Outdated Show resolved Hide resolved
"github.com/grafana/dskit/flagext"
"github.com/minio/minio-go/v7/pkg/encrypt"
"github.com/pkg/errors"
"github.com/thanos-io/objstore/providers/s3"

"net/http"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you group this with the other stdlib imports?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@56quarters i tried to reorganize them, but it seems to fail in the lint :(

"github.com/grafana/dskit/flagext"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"net/http"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you move these with the other stdlib imports?

pkg/storage/bucket/s3/config.go Outdated Show resolved Hide resolved
CHANGELOG.md Outdated Show resolved Hide resolved
@inbarpatashnik inbarpatashnik deleted the fixture/conflicts branch April 5, 2023 21:11
@inbarpatashnik inbarpatashnik restored the fixture/conflicts branch April 5, 2023 21:13
@inbarpatashnik inbarpatashnik reopened this Apr 5, 2023
Signed-off-by: Nick Pillitteri <[email protected]>
@56quarters 56quarters merged commit 157021f into grafana:main Apr 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add S3 storage class configuration
5 participants