github.com/m3db/m3@v1.5.0/src/ctl/service/r2/store/kv/options.go (about)

     1  // Copyright (c) 2017 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 kv
    22  
    23  import (
    24  	"time"
    25  
    26  	"github.com/m3db/m3/src/metrics/rules"
    27  	"github.com/m3db/m3/src/x/clock"
    28  	"github.com/m3db/m3/src/x/instrument"
    29  )
    30  
    31  const (
    32  	defaultRuleUpdatePropagationDelay = time.Minute
    33  )
    34  
    35  // StoreOptions is a set of options for a kv backed store.
    36  type StoreOptions interface {
    37  	// SetClockOptions sets the clock options.
    38  	SetClockOptions(value clock.Options) StoreOptions
    39  
    40  	// ClockOptions returns the clock options
    41  	ClockOptions() clock.Options
    42  
    43  	// SetInstrumentOptions sets the instrument options.
    44  	SetInstrumentOptions(value instrument.Options) StoreOptions
    45  
    46  	// InstrumentOptions returns the instrument options.
    47  	InstrumentOptions() instrument.Options
    48  
    49  	// SetRuleUpdatePropagationDelay sets the propagation delay for rule updates.
    50  	SetRuleUpdatePropagationDelay(value time.Duration) StoreOptions
    51  
    52  	// RuleUpdatePropagationDelay returns the propagation delay for rule updates.
    53  	RuleUpdatePropagationDelay() time.Duration
    54  
    55  	// SetStoreValidator sets the validator for the store.
    56  	SetValidator(value rules.Validator) StoreOptions
    57  
    58  	// ValidatprOptions returns the validator for the store.
    59  	Validator() rules.Validator
    60  }
    61  
    62  type storeOptions struct {
    63  	clockOpts                  clock.Options
    64  	instrumentOpts             instrument.Options
    65  	ruleUpdatePropagationDelay time.Duration
    66  	validator                  rules.Validator
    67  }
    68  
    69  // NewStoreOptions creates a new set of store options.
    70  func NewStoreOptions() StoreOptions {
    71  	return &storeOptions{
    72  		clockOpts:                  clock.NewOptions(),
    73  		instrumentOpts:             instrument.NewOptions(),
    74  		ruleUpdatePropagationDelay: defaultRuleUpdatePropagationDelay,
    75  	}
    76  }
    77  
    78  func (o *storeOptions) SetClockOptions(value clock.Options) StoreOptions {
    79  	opts := *o
    80  	opts.clockOpts = value
    81  	return &opts
    82  }
    83  
    84  func (o *storeOptions) ClockOptions() clock.Options {
    85  	return o.clockOpts
    86  }
    87  
    88  func (o *storeOptions) SetInstrumentOptions(value instrument.Options) StoreOptions {
    89  	opts := *o
    90  	opts.instrumentOpts = value
    91  	return &opts
    92  }
    93  
    94  func (o *storeOptions) InstrumentOptions() instrument.Options {
    95  	return o.instrumentOpts
    96  }
    97  
    98  func (o *storeOptions) SetRuleUpdatePropagationDelay(value time.Duration) StoreOptions {
    99  	opts := *o
   100  	opts.ruleUpdatePropagationDelay = value
   101  	return &opts
   102  }
   103  
   104  func (o *storeOptions) RuleUpdatePropagationDelay() time.Duration {
   105  	return o.ruleUpdatePropagationDelay
   106  }
   107  
   108  func (o *storeOptions) SetValidator(value rules.Validator) StoreOptions {
   109  	opts := *o
   110  	opts.validator = value
   111  	return &opts
   112  }
   113  
   114  func (o *storeOptions) Validator() rules.Validator {
   115  	return o.validator
   116  }