github.com/m3db/m3@v1.5.1-0.20231129193456-75a402aa583b/src/query/storage/remote/storage.go (about)

     1  // Copyright (c) 2018 Uber Technologies, Inc.
     2  //
     3  // Permission is hereby granted, free of charge, to any person obtaining a copy
     4  // of this software and associated documentation files (the "Software"), to deal
     5  // in the Software without restriction, including without limitation the rights
     6  // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
     7  // copies of the Software, and to permit persons to whom the Software is
     8  // furnished to do so, subject to the following conditions:
     9  //
    10  // The above copyright notice and this permission notice shall be included in
    11  // all copies or substantial portions of the Software.
    12  //
    13  // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    14  // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    15  // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    16  // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    17  // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    18  // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    19  // THE SOFTWARE.
    20  
    21  package remote
    22  
    23  import (
    24  	"context"
    25  	"fmt"
    26  	"time"
    27  
    28  	"github.com/m3db/m3/src/query/block"
    29  	"github.com/m3db/m3/src/query/errors"
    30  	"github.com/m3db/m3/src/query/remote"
    31  	"github.com/m3db/m3/src/query/storage"
    32  	"github.com/m3db/m3/src/query/storage/m3/consolidators"
    33  	"github.com/m3db/m3/src/query/storage/m3/storagemetadata"
    34  )
    35  
    36  // Options contains options for remote clients.
    37  type Options struct {
    38  	// ErrorBehavior determines the error behavior for this remote storage.
    39  	ErrorBehavior storage.ErrorBehavior
    40  	// Name is this storage's name.
    41  	Name string
    42  }
    43  
    44  type remoteStorage struct {
    45  	client remote.Client
    46  	opts   Options
    47  }
    48  
    49  // NewStorage creates a new remote Storage instance.
    50  func NewStorage(c remote.Client, opts Options) storage.Storage {
    51  	return &remoteStorage{client: c, opts: opts}
    52  }
    53  
    54  func (s *remoteStorage) QueryStorageMetadataAttributes(
    55  	ctx context.Context,
    56  	queryStart, queryEnd time.Time,
    57  	opts *storage.FetchOptions,
    58  ) ([]storagemetadata.Attributes, error) {
    59  	return s.client.QueryStorageMetadataAttributes(ctx, queryStart, queryEnd, opts)
    60  }
    61  
    62  func (s *remoteStorage) FetchProm(
    63  	ctx context.Context,
    64  	query *storage.FetchQuery,
    65  	options *storage.FetchOptions,
    66  ) (storage.PromResult, error) {
    67  	return s.client.FetchProm(ctx, query, options)
    68  }
    69  
    70  func (s *remoteStorage) FetchCompressed(
    71  	ctx context.Context,
    72  	query *storage.FetchQuery,
    73  	options *storage.FetchOptions,
    74  ) (consolidators.MultiFetchResult, error) {
    75  	return s.client.FetchCompressed(ctx, query, options)
    76  }
    77  
    78  func (s *remoteStorage) FetchBlocks(
    79  	ctx context.Context,
    80  	query *storage.FetchQuery,
    81  	options *storage.FetchOptions,
    82  ) (block.Result, error) {
    83  	return s.client.FetchBlocks(ctx, query, options)
    84  }
    85  
    86  func (s *remoteStorage) SearchSeries(
    87  	ctx context.Context,
    88  	query *storage.FetchQuery,
    89  	options *storage.FetchOptions,
    90  ) (*storage.SearchResults, error) {
    91  	return s.client.SearchSeries(ctx, query, options)
    92  }
    93  
    94  func (s *remoteStorage) CompleteTags(
    95  	ctx context.Context,
    96  	query *storage.CompleteTagsQuery,
    97  	options *storage.FetchOptions,
    98  ) (*consolidators.CompleteTagsResult, error) {
    99  	return s.client.CompleteTags(ctx, query, options)
   100  }
   101  
   102  func (s *remoteStorage) Write(ctx context.Context, query *storage.WriteQuery) error {
   103  	return errors.ErrRemoteWriteQuery
   104  }
   105  
   106  func (s *remoteStorage) ErrorBehavior() storage.ErrorBehavior {
   107  	return s.opts.ErrorBehavior
   108  }
   109  
   110  func (s *remoteStorage) Type() storage.Type {
   111  	return storage.TypeRemoteDC
   112  }
   113  
   114  func (s *remoteStorage) Name() string {
   115  	return fmt.Sprintf("remote_store_%s", s.opts.Name)
   116  }
   117  
   118  func (s *remoteStorage) Close() error {
   119  	return nil
   120  }