github.com/m3db/m3@v1.5.1-0.20231129193456-75a402aa583b/src/dbnode/storage/limits/options.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 limits
    22  
    23  import (
    24  	"errors"
    25  	"fmt"
    26  
    27  	"github.com/m3db/m3/src/x/instrument"
    28  )
    29  
    30  type limitOpts struct {
    31  	iOpts                      instrument.Options
    32  	docsLimitOpts              LookbackLimitOptions
    33  	bytesReadLimitOpts         LookbackLimitOptions
    34  	diskSeriesReadLimitOpts    LookbackLimitOptions
    35  	diskAggregateDocsLimitOpts LookbackLimitOptions
    36  	sourceLoggerBuilder        SourceLoggerBuilder
    37  }
    38  
    39  // NewOptions creates limit options with default values.
    40  func NewOptions() Options {
    41  	return &limitOpts{
    42  		sourceLoggerBuilder: &sourceLoggerBuilder{},
    43  	}
    44  }
    45  
    46  // Validate validates the options.
    47  func (o *limitOpts) Validate() error {
    48  	if o.iOpts == nil {
    49  		return errors.New("limit options invalid: no instrument options")
    50  	}
    51  
    52  	if err := o.docsLimitOpts.validate(); err != nil {
    53  		return fmt.Errorf("doc limit options invalid: %w", err)
    54  	}
    55  
    56  	if err := o.bytesReadLimitOpts.validate(); err != nil {
    57  		return fmt.Errorf("bytes limit options invalid: %w", err)
    58  	}
    59  
    60  	return nil
    61  }
    62  
    63  // SetInstrumentOptions sets the instrument options.
    64  func (o *limitOpts) SetInstrumentOptions(value instrument.Options) Options {
    65  	opts := *o
    66  	opts.iOpts = value
    67  	return &opts
    68  }
    69  
    70  // InstrumentOptions returns the instrument options.
    71  func (o *limitOpts) InstrumentOptions() instrument.Options {
    72  	return o.iOpts
    73  }
    74  
    75  // SetDocsLimitOpts sets the doc limit options.
    76  func (o *limitOpts) SetDocsLimitOpts(value LookbackLimitOptions) Options {
    77  	opts := *o
    78  	opts.docsLimitOpts = value
    79  	return &opts
    80  }
    81  
    82  // DocsLimitOpts returns the doc limit options.
    83  func (o *limitOpts) DocsLimitOpts() LookbackLimitOptions {
    84  	return o.docsLimitOpts
    85  }
    86  
    87  // SetBytesReadLimitOpts sets the byte read limit options.
    88  func (o *limitOpts) SetBytesReadLimitOpts(value LookbackLimitOptions) Options {
    89  	opts := *o
    90  	opts.bytesReadLimitOpts = value
    91  	return &opts
    92  }
    93  
    94  // BytesReadLimitOpts returns the byte read limit options.
    95  func (o *limitOpts) BytesReadLimitOpts() LookbackLimitOptions {
    96  	return o.bytesReadLimitOpts
    97  }
    98  
    99  // SetDiskSeriesReadLimitOpts sets the disk ts read limit options.
   100  func (o *limitOpts) SetDiskSeriesReadLimitOpts(value LookbackLimitOptions) Options {
   101  	opts := *o
   102  	opts.diskSeriesReadLimitOpts = value
   103  	return &opts
   104  }
   105  
   106  // DiskSeriesReadLimitOpts returns the disk ts read limit options.
   107  func (o *limitOpts) DiskSeriesReadLimitOpts() LookbackLimitOptions {
   108  	return o.diskSeriesReadLimitOpts
   109  }
   110  
   111  // SetDiskSeriesReadLimitOpts sets the disk ts read limit options.
   112  func (o *limitOpts) SetAggregateDocsLimitOpts(value LookbackLimitOptions) Options {
   113  	opts := *o
   114  	opts.diskAggregateDocsLimitOpts = value
   115  	return &opts
   116  }
   117  
   118  // DiskSeriesReadLimitOpts returns the disk ts read limit options.
   119  func (o *limitOpts) AggregateDocsLimitOpts() LookbackLimitOptions {
   120  	return o.diskAggregateDocsLimitOpts
   121  }
   122  
   123  // SetSourceLoggerBuilder sets the source logger.
   124  func (o *limitOpts) SetSourceLoggerBuilder(value SourceLoggerBuilder) Options {
   125  	opts := *o
   126  	opts.sourceLoggerBuilder = value
   127  	return &opts
   128  }
   129  
   130  // SourceLoggerBuilder sets the source logger.
   131  func (o *limitOpts) SourceLoggerBuilder() SourceLoggerBuilder {
   132  	return o.sourceLoggerBuilder
   133  }