Documentation ¶
Index ¶
- Constants
- Variables
- func AcceptanceTest(t *testing.T, bkt Bucket)
- func CreateTemporaryTestBucketName(t testing.TB) string
- func DownloadDir(ctx context.Context, logger log.Logger, bkt BucketReader, ...) error
- func DownloadFile(ctx context.Context, logger log.Logger, bkt BucketReader, src, dst string) (err error)
- func EmptyBucket(t testing.TB, ctx context.Context, bkt Bucket)
- func NewTLSConfig(cfg *TLSConfig) (*tls.Config, error)
- func NopCloserWithSize(r io.Reader) io.ReadCloser
- func TryToGetSize(r io.Reader) (int64, error)
- func UploadDir(ctx context.Context, logger log.Logger, bkt Bucket, srcdir, dstdir string, ...) error
- func UploadFile(ctx context.Context, logger log.Logger, bkt Bucket, src, dst string) error
- func ValidateIterOptions(supportedOptions []IterOptionType, options ...IterOption) error
- func WrapWith(b Bucket, metrics *Metrics) *metricBucket
- func WrapWithMetrics(b Bucket, reg prometheus.Registerer, name string) *metricBucket
- type Bucket
- type BucketReader
- type DownloadOption
- type InMemBucket
- func (b *InMemBucket) Attributes(_ context.Context, name string) (ObjectAttributes, error)
- func (b *InMemBucket) Close() error
- func (b *InMemBucket) Delete(_ context.Context, name string) error
- func (b *InMemBucket) Exists(_ context.Context, name string) (bool, error)
- func (b *InMemBucket) Get(_ context.Context, name string) (io.ReadCloser, error)
- func (b *InMemBucket) GetRange(_ context.Context, name string, off, length int64) (io.ReadCloser, error)
- func (b *InMemBucket) IsAccessDeniedErr(err error) bool
- func (b *InMemBucket) IsObjNotFoundErr(err error) bool
- func (b *InMemBucket) Iter(_ context.Context, dir string, f func(string) error, options ...IterOption) error
- func (b *InMemBucket) IterWithAttributes(ctx context.Context, dir string, f func(attrs IterObjectAttributes) error, ...) error
- func (b *InMemBucket) Name() string
- func (b *InMemBucket) Objects() map[string][]byte
- func (b *InMemBucket) Provider() ObjProvider
- func (i *InMemBucket) SupportedIterOptions() []IterOptionType
- func (b *InMemBucket) Upload(_ context.Context, name string, r io.Reader) error
- type InstrumentedBucket
- type InstrumentedBucketReader
- type IsOpFailureExpectedFunc
- type IterObjectAttributes
- type IterOption
- type IterOptionType
- type IterParams
- type Metrics
- type ObjProvider
- type ObjectAttributes
- type ObjectSizer
- type ObjectSizerReadCloser
- type PrefixedBucket
- func (p *PrefixedBucket) Attributes(ctx context.Context, name string) (ObjectAttributes, error)
- func (p *PrefixedBucket) Close() error
- func (p *PrefixedBucket) Delete(ctx context.Context, name string) error
- func (p *PrefixedBucket) Exists(ctx context.Context, name string) (bool, error)
- func (p *PrefixedBucket) Get(ctx context.Context, name string) (io.ReadCloser, error)
- func (p *PrefixedBucket) GetRange(ctx context.Context, name string, off int64, length int64) (io.ReadCloser, error)
- func (p *PrefixedBucket) IsAccessDeniedErr(err error) bool
- func (p *PrefixedBucket) IsObjNotFoundErr(err error) bool
- func (p *PrefixedBucket) Iter(ctx context.Context, dir string, f func(string) error, options ...IterOption) error
- func (p *PrefixedBucket) IterWithAttributes(ctx context.Context, dir string, f func(IterObjectAttributes) error, ...) error
- func (p *PrefixedBucket) Name() string
- func (p *PrefixedBucket) Provider() ObjProvider
- func (p *PrefixedBucket) SupportedIterOptions() []IterOptionType
- func (p *PrefixedBucket) Upload(ctx context.Context, name string, r io.Reader) error
- type TLSConfig
- type UploadOption
Constants ¶
const ( OpIter = "iter" OpGet = "get" OpGetRange = "get_range" OpExists = "exists" OpUpload = "upload" OpDelete = "delete" OpAttributes = "attributes" )
const DirDelim = "/"
DirDelim is the delimiter used to model a directory structure in an object store bucket.
Variables ¶
var ErrOptionNotSupported = errors.New("iter option is not supported")
Functions ¶
func AcceptanceTest ¶
func DownloadDir ¶
func DownloadDir(ctx context.Context, logger log.Logger, bkt BucketReader, originalSrc, src, dst string, options ...DownloadOption) error
DownloadDir downloads all object found in the directory into the local directory.
func DownloadFile ¶
func DownloadFile(ctx context.Context, logger log.Logger, bkt BucketReader, src, dst string) (err error)
DownloadFile downloads the src file from the bucket to dst. If dst is an existing directory, a file with the same name as the source is created in dst. If destination file is already existing, download file will overwrite it.
func EmptyBucket ¶
EmptyBucket deletes all objects from bucket. This operation is required to properly delete bucket as a whole. It is used for testing only. TODO(bplotka): Add retries.
func NewTLSConfig ¶
NewTLSConfig creates a new tls.Config from the given TLSConfig.
func NopCloserWithSize ¶
func NopCloserWithSize(r io.Reader) io.ReadCloser
NopCloserWithSize returns a ReadCloser with a no-op Close method wrapping the provided Reader r. Returned ReadCloser also implements Size method.
func TryToGetSize ¶
TryToGetSize tries to get upfront size from reader. Some implementations may return only size of unread data in the reader, so it's best to call this method before doing any reading.
TODO(https://github.com/thanos-io/thanos/issues/678): Remove guessing length when minio provider will support multipart upload without this.
func UploadDir ¶
func UploadDir(ctx context.Context, logger log.Logger, bkt Bucket, srcdir, dstdir string, options ...UploadOption) error
UploadDir uploads all files in srcdir to the bucket with into a top-level directory named dstdir. It is a caller responsibility to clean partial upload in case of failure.
func UploadFile ¶
UploadFile uploads the file with the given name to the bucket. It is a caller responsibility to clean partial upload in case of failure.
func ValidateIterOptions ¶
func ValidateIterOptions(supportedOptions []IterOptionType, options ...IterOption) error
func WrapWith ¶
WrapWith takes a `bucket` and `metrics` that returns instrumented bucket. Similar to WrapWithMetrics, but `metrics` can be passed separately as an argument.
func WrapWithMetrics ¶
func WrapWithMetrics(b Bucket, reg prometheus.Registerer, name string) *metricBucket
WrapWithMetrics takes a bucket and registers metrics with the given registry for operations run against the bucket.
Types ¶
type Bucket ¶
type Bucket interface { io.Closer BucketReader Provider() ObjProvider // Upload the contents of the reader as an object into the bucket. // Upload should be idempotent. Upload(ctx context.Context, name string, r io.Reader) error // Delete removes the object with the given name. // If object does not exist in the moment of deletion, Delete should throw error. Delete(ctx context.Context, name string) error // Name returns the bucket name for the provider. Name() string }
Bucket provides read and write access to an object storage bucket. NOTE: We assume strong consistency for write-read flow.
func NewPrefixedBucket ¶
type BucketReader ¶
type BucketReader interface { // Entries are passed to function in sorted order. Iter(ctx context.Context, dir string, f func(name string) error, options ...IterOption) error // IterWithAttributes calls f for each entry in the given directory similar to Iter. // In addition to Name, it also includes requested object attributes in the argument to f. // // Attributes can be requested using IterOption. // Not all IterOptions are supported by all providers, requesting for an unsupported option will fail with ErrOptionNotSupported. IterWithAttributes(ctx context.Context, dir string, f func(attrs IterObjectAttributes) error, options ...IterOption) error // SupportedIterOptions returns a list of supported IterOptions by the underlying provider. SupportedIterOptions() []IterOptionType // Get returns a reader for the given object name. Get(ctx context.Context, name string) (io.ReadCloser, error) // GetRange returns a new range reader for the given object name and range. GetRange(ctx context.Context, name string, off, length int64) (io.ReadCloser, error) // Exists checks if the given object exists in the bucket. Exists(ctx context.Context, name string) (bool, error) // IsObjNotFoundErr returns true if error means that object is not found. Relevant to Get operations. IsObjNotFoundErr(err error) bool // IsAccessDeniedErr returns true if access to object is denied. IsAccessDeniedErr(err error) bool // Attributes returns information about the specified object. Attributes(ctx context.Context, name string) (ObjectAttributes, error) }
BucketReader provides read access to an object storage bucket.
type DownloadOption ¶
type DownloadOption func(params *downloadParams)
DownloadOption configures the provided params.
func WithDownloadIgnoredPaths ¶
func WithDownloadIgnoredPaths(ignoredPaths ...string) DownloadOption
WithDownloadIgnoredPaths is an option to set the paths to not be downloaded.
func WithFetchConcurrency ¶
func WithFetchConcurrency(concurrency int) DownloadOption
WithFetchConcurrency is an option to set the concurrency of the download operation.
type InMemBucket ¶
type InMemBucket struct {
// contains filtered or unexported fields
}
InMemBucket implements the objstore.Bucket interfaces against local memory. Methods from Bucket interface are thread-safe. Objects are assumed to be immutable.
func NewInMemBucket ¶
func NewInMemBucket() *InMemBucket
NewInMemBucket returns a new in memory Bucket. NOTE: Returned bucket is just a naive in memory bucket implementation. For test use cases only.
func (*InMemBucket) Attributes ¶
func (b *InMemBucket) Attributes(_ context.Context, name string) (ObjectAttributes, error)
Attributes returns information about the specified object.
func (*InMemBucket) Close ¶
func (b *InMemBucket) Close() error
func (*InMemBucket) Delete ¶
func (b *InMemBucket) Delete(_ context.Context, name string) error
Delete removes all data prefixed with the dir.
func (*InMemBucket) Get ¶
func (b *InMemBucket) Get(_ context.Context, name string) (io.ReadCloser, error)
Get returns a reader for the given object name.
func (*InMemBucket) GetRange ¶
func (b *InMemBucket) GetRange(_ context.Context, name string, off, length int64) (io.ReadCloser, error)
GetRange returns a new range reader for the given object name and range.
func (*InMemBucket) IsAccessDeniedErr ¶
func (b *InMemBucket) IsAccessDeniedErr(err error) bool
IsAccessDeniedErr returns true if access to object is denied.
func (*InMemBucket) IsObjNotFoundErr ¶
func (b *InMemBucket) IsObjNotFoundErr(err error) bool
IsObjNotFoundErr returns true if error means that object is not found. Relevant to Get operations.
func (*InMemBucket) Iter ¶
func (b *InMemBucket) Iter(_ context.Context, dir string, f func(string) error, options ...IterOption) error
Iter calls f for each entry in the given directory. The argument to f is the full object name including the prefix of the inspected directory.
func (*InMemBucket) IterWithAttributes ¶
func (b *InMemBucket) IterWithAttributes(ctx context.Context, dir string, f func(attrs IterObjectAttributes) error, options ...IterOption) error
func (*InMemBucket) Objects ¶
func (b *InMemBucket) Objects() map[string][]byte
Objects returns a copy of the internally stored objects. NOTE: For assert purposes.
func (*InMemBucket) Provider ¶
func (b *InMemBucket) Provider() ObjProvider
func (*InMemBucket) SupportedIterOptions ¶
func (i *InMemBucket) SupportedIterOptions() []IterOptionType
type InstrumentedBucket ¶
type InstrumentedBucket interface { Bucket // WithExpectedErrs allows to specify a filter that marks certain errors as expected, so it will not increment // objstore_bucket_operation_failures_total metric. WithExpectedErrs(IsOpFailureExpectedFunc) Bucket // ReaderWithExpectedErrs allows to specify a filter that marks certain errors as expected, so it will not increment // objstore_bucket_operation_failures_total metric. // TODO(bwplotka): Remove this when moved to Go 1.14 and replace with InstrumentedBucketReader. ReaderWithExpectedErrs(IsOpFailureExpectedFunc) BucketReader }
InstrumentedBucket is a Bucket with optional instrumentation control on reader.
func WithNoopInstr ¶
func WithNoopInstr(bkt Bucket) InstrumentedBucket
type InstrumentedBucketReader ¶
type InstrumentedBucketReader interface { BucketReader // ReaderWithExpectedErrs allows to specify a filter that marks certain errors as expected, so it will not increment // objstore_bucket_operation_failures_total metric. ReaderWithExpectedErrs(IsOpFailureExpectedFunc) BucketReader }
InstrumentedBucketReader is a BucketReader with optional instrumentation control.
type IsOpFailureExpectedFunc ¶
IsOpFailureExpectedFunc allows to mark certain errors as expected, so they will not increment objstore_bucket_operation_failures_total metric.
type IterObjectAttributes ¶
type IterObjectAttributes struct { Name string // contains filtered or unexported fields }
func (*IterObjectAttributes) LastModified ¶
func (i *IterObjectAttributes) LastModified() (time.Time, bool)
LastModified returns the timestamp the object was last modified. Returns false if the timestamp is not available.
func (*IterObjectAttributes) SetLastModified ¶
func (i *IterObjectAttributes) SetLastModified(t time.Time)
type IterOption ¶
type IterOption struct { Type IterOptionType Apply func(params *IterParams) }
IterOption configures the provided params.
func WithRecursiveIter ¶
func WithRecursiveIter() IterOption
WithRecursiveIter is an option that can be applied to Iter() to recursively list objects in the bucket.
func WithUpdatedAt ¶
func WithUpdatedAt() IterOption
WithUpdatedAt is an option that can be applied to Iter() to include the last modified time in the attributes. NB: Prefixes may not report last modified time. This option is currently supported for the azure, s3, bos, gcs and filesystem providers.
type IterOptionType ¶
type IterOptionType int
IterOptionType is used for type-safe option support checking.
const ( Recursive IterOptionType = iota UpdatedAt )
type IterParams ¶
IterParams holds the Iter() parameters and is used by objstore clients implementations.
func ApplyIterOptions ¶
func ApplyIterOptions(options ...IterOption) IterParams
type Metrics ¶
type Metrics struct {
// contains filtered or unexported fields
}
func BucketMetrics ¶
func BucketMetrics(reg prometheus.Registerer, name string) *Metrics
type ObjProvider ¶
type ObjProvider string
const ( MEMORY ObjProvider = "MEMORY" FILESYSTEM ObjProvider = "FILESYSTEM" GCS ObjProvider = "GCS" S3 ObjProvider = "S3" AZURE ObjProvider = "AZURE" SWIFT ObjProvider = "SWIFT" COS ObjProvider = "COS" ALIYUNOSS ObjProvider = "ALIYUNOSS" BOS ObjProvider = "BOS" OCI ObjProvider = "OCI" OBS ObjProvider = "OBS" )
type ObjectAttributes ¶
type ObjectSizer ¶
type ObjectSizer interface { // ObjectSize returns the size of the object in bytes, or error if it is not available. ObjectSize() (int64, error) }
ObjectSizer can return size of object.
type ObjectSizerReadCloser ¶
type ObjectSizerReadCloser struct { io.ReadCloser Size func() (int64, error) }
func (ObjectSizerReadCloser) ObjectSize ¶
func (o ObjectSizerReadCloser) ObjectSize() (int64, error)
ObjectSize implement ObjectSizer.
type PrefixedBucket ¶
type PrefixedBucket struct {
// contains filtered or unexported fields
}
func (*PrefixedBucket) Attributes ¶
func (p *PrefixedBucket) Attributes(ctx context.Context, name string) (ObjectAttributes, error)
Attributes returns information about the specified object.
func (*PrefixedBucket) Close ¶
func (p *PrefixedBucket) Close() error
func (*PrefixedBucket) Delete ¶
func (p *PrefixedBucket) Delete(ctx context.Context, name string) error
Delete removes the object with the given name. If object does not exists in the moment of deletion, Delete should throw error.
func (*PrefixedBucket) Get ¶
func (p *PrefixedBucket) Get(ctx context.Context, name string) (io.ReadCloser, error)
Get returns a reader for the given object name.
func (*PrefixedBucket) GetRange ¶
func (p *PrefixedBucket) GetRange(ctx context.Context, name string, off int64, length int64) (io.ReadCloser, error)
GetRange returns a new range reader for the given object name and range.
func (*PrefixedBucket) IsAccessDeniedErr ¶
func (p *PrefixedBucket) IsAccessDeniedErr(err error) bool
IsAccessDeniedErr returns true if access to object is denied.
func (*PrefixedBucket) IsObjNotFoundErr ¶
func (p *PrefixedBucket) IsObjNotFoundErr(err error) bool
IsObjNotFoundErr returns true if error means that object is not found. Relevant to Get operations.
func (*PrefixedBucket) Iter ¶
func (p *PrefixedBucket) Iter(ctx context.Context, dir string, f func(string) error, options ...IterOption) error
Iter calls f for each entry in the given directory (not recursive.). The argument to f is the full object name including the prefix of the inspected directory. Entries are passed to function in sorted order.
func (*PrefixedBucket) IterWithAttributes ¶
func (p *PrefixedBucket) IterWithAttributes(ctx context.Context, dir string, f func(IterObjectAttributes) error, options ...IterOption) error
func (*PrefixedBucket) Name ¶
func (p *PrefixedBucket) Name() string
Name returns the bucket name for the provider.
func (*PrefixedBucket) Provider ¶
func (p *PrefixedBucket) Provider() ObjProvider
func (*PrefixedBucket) SupportedIterOptions ¶
func (p *PrefixedBucket) SupportedIterOptions() []IterOptionType
type TLSConfig ¶
type TLSConfig struct { // The CA cert to use for the targets. CAFile string `yaml:"ca_file"` // The client cert file for the targets. CertFile string `yaml:"cert_file"` // The client key file for the targets. KeyFile string `yaml:"key_file"` // Used to verify the hostname for the targets. ServerName string `yaml:"server_name"` // Disable target certificate validation. InsecureSkipVerify bool `yaml:"insecure_skip_verify"` }
TLSConfig configures the options for TLS connections.
type UploadOption ¶
type UploadOption func(params *uploadParams)
UploadOption configures the provided params.
func WithUploadConcurrency ¶
func WithUploadConcurrency(concurrency int) UploadOption
WithUploadConcurrency is an option to set the concurrency of the upload operation.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
providers
|
|
gcs
Package gcs implements common object storage abstractions against Google Cloud Storage.
|
Package gcs implements common object storage abstractions against Google Cloud Storage. |
s3
Package s3 implements common object storage abstractions against s3-compatible APIs.
|
Package s3 implements common object storage abstractions against s3-compatible APIs. |
swift
Package swift implements common object storage abstractions against OpenStack swift APIs.
|
Package swift implements common object storage abstractions against OpenStack swift APIs. |
scripts
|
|
test
|
|