github.com/m3db/m3@v1.5.0/src/metrics/rules/validator/namespace/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/cluster/kv" 27 "github.com/m3db/m3/src/x/instrument" 28 ) 29 30 const ( 31 defaultInitWatchTimeout = 10 * time.Second 32 ) 33 34 // NamespaceValidatorOptions provide a set of options for the KV-backed namespace validator. 35 type NamespaceValidatorOptions interface { 36 // SetInstrumentOptions sets the instrument options. 37 SetInstrumentOptions(value instrument.Options) NamespaceValidatorOptions 38 39 // InstrumentOptions returns the instrument options. 40 InstrumentOptions() instrument.Options 41 42 // SetKVStore sets the KV store for namespace validation. 43 SetKVStore(value kv.Store) NamespaceValidatorOptions 44 45 // KVStore returns the KV store for namespace validation. 46 KVStore() kv.Store 47 48 // SetInitWatchTimeout sets the initial watch timeout. 49 SetInitWatchTimeout(value time.Duration) NamespaceValidatorOptions 50 51 // InitWatchTimeout returns the initial watch timeout. 52 InitWatchTimeout() time.Duration 53 54 // SetValidNamespacesKey sets the KV key associated with valid namespaces. 55 SetValidNamespacesKey(value string) NamespaceValidatorOptions 56 57 // ValidNamespacesKey returns the KV key associated with valid namespaces. 58 ValidNamespacesKey() string 59 60 // SetDefaultValidNamespaces sets the default list of valid namespaces. 61 SetDefaultValidNamespaces(value []string) NamespaceValidatorOptions 62 63 // DefaultValidNamespaces returns the default list of valid namespaces. 64 DefaultValidNamespaces() []string 65 } 66 67 type namespaceValidatorOptions struct { 68 instrumentOpts instrument.Options 69 kvStore kv.Store 70 initWatchTimeout time.Duration 71 validNamespacesKey string 72 defaultValidNamespaces []string 73 } 74 75 // NewNamespaceValidatorOptions create a new set of namespace validator options. 76 func NewNamespaceValidatorOptions() NamespaceValidatorOptions { 77 return &namespaceValidatorOptions{ 78 instrumentOpts: instrument.NewOptions(), 79 initWatchTimeout: defaultInitWatchTimeout, 80 } 81 } 82 83 func (o *namespaceValidatorOptions) SetInstrumentOptions(value instrument.Options) NamespaceValidatorOptions { 84 opts := *o 85 opts.instrumentOpts = value 86 return &opts 87 } 88 89 func (o *namespaceValidatorOptions) InstrumentOptions() instrument.Options { 90 return o.instrumentOpts 91 } 92 93 func (o *namespaceValidatorOptions) SetKVStore(value kv.Store) NamespaceValidatorOptions { 94 opts := *o 95 opts.kvStore = value 96 return &opts 97 } 98 99 func (o *namespaceValidatorOptions) KVStore() kv.Store { 100 return o.kvStore 101 } 102 103 func (o *namespaceValidatorOptions) SetInitWatchTimeout(value time.Duration) NamespaceValidatorOptions { 104 opts := *o 105 opts.initWatchTimeout = value 106 return &opts 107 } 108 109 func (o *namespaceValidatorOptions) InitWatchTimeout() time.Duration { 110 return o.initWatchTimeout 111 } 112 113 func (o *namespaceValidatorOptions) SetValidNamespacesKey(value string) NamespaceValidatorOptions { 114 opts := *o 115 opts.validNamespacesKey = value 116 return &opts 117 } 118 119 func (o *namespaceValidatorOptions) ValidNamespacesKey() string { 120 return o.validNamespacesKey 121 } 122 123 func (o *namespaceValidatorOptions) SetDefaultValidNamespaces(value []string) NamespaceValidatorOptions { 124 cloned := make([]string, len(value)) 125 copy(cloned, value) 126 opts := *o 127 opts.defaultValidNamespaces = cloned 128 return &opts 129 } 130 131 func (o *namespaceValidatorOptions) DefaultValidNamespaces() []string { 132 return o.defaultValidNamespaces 133 }