github.com/m3db/m3@v1.5.1-0.20231129193456-75a402aa583b/src/query/storage/noop_storage.go (about) 1 // Copyright (c) 2020 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 storage 22 23 import ( 24 "context" 25 "errors" 26 "time" 27 28 "github.com/m3db/m3/src/query/block" 29 "github.com/m3db/m3/src/query/storage/m3/consolidators" 30 "github.com/m3db/m3/src/query/storage/m3/storagemetadata" 31 ) 32 33 var errNoopClient = errors.New("operation not valid for noop client") 34 35 // NewNoopStorage returns a fake implementation of Storage that rejects all 36 // writes and returns errors for all queries. 37 func NewNoopStorage() Storage { 38 return noopStorage{} 39 } 40 41 type noopStorage struct{} 42 43 func (noopStorage) QueryStorageMetadataAttributes( 44 ctx context.Context, 45 queryStart, queryEnd time.Time, 46 opts *FetchOptions, 47 ) ([]storagemetadata.Attributes, error) { 48 return nil, errNoopClient 49 } 50 51 func (noopStorage) Fetch(ctx context.Context, query *FetchQuery, options *FetchOptions) (*FetchResult, error) { 52 return nil, errNoopClient 53 } 54 55 func (noopStorage) FetchProm(ctx context.Context, query *FetchQuery, options *FetchOptions) (PromResult, error) { 56 return PromResult{}, errNoopClient 57 } 58 59 // FetchBlocks fetches timeseries as blocks based on a query. 60 func (noopStorage) FetchBlocks(ctx context.Context, query *FetchQuery, options *FetchOptions) (block.Result, error) { 61 return block.Result{}, errNoopClient 62 } 63 64 func (noopStorage) FetchCompressed( 65 ctx context.Context, 66 query *FetchQuery, 67 options *FetchOptions, 68 ) (consolidators.MultiFetchResult, error) { 69 return nil, errNoopClient 70 } 71 72 // SearchSeries returns series IDs matching the current query. 73 func (noopStorage) SearchSeries(ctx context.Context, query *FetchQuery, options *FetchOptions) (*SearchResults, error) { 74 return nil, errNoopClient 75 } 76 77 // CompleteTags returns autocompleted tag results. 78 func (noopStorage) CompleteTags(ctx context.Context, query *CompleteTagsQuery, options *FetchOptions) (*consolidators.CompleteTagsResult, error) { 79 return nil, errNoopClient 80 } 81 82 // Write writes a batched set of datapoints to storage based on the provided 83 // query. 84 func (noopStorage) Write(ctx context.Context, query *WriteQuery) error { 85 return errNoopClient 86 } 87 88 // Type identifies the type of the underlying 89 func (noopStorage) Type() Type { 90 return TypeLocalDC 91 } 92 93 // Close is used to close the underlying storage and free up resources. 94 func (noopStorage) Close() error { 95 return errNoopClient 96 } 97 98 // ErrorBehavior dictates what fanout storage should do when this storage 99 // encounters an error. 100 func (noopStorage) ErrorBehavior() ErrorBehavior { 101 return BehaviorWarn 102 } 103 104 // Name gives the plaintext name for this storage, used for logging purposes. 105 func (noopStorage) Name() string { 106 return "noopStorage" 107 }