github.com/m3db/m3@v1.5.1-0.20231129193456-75a402aa583b/src/aggregator/runtime/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 runtime 22 23 import "time" 24 25 const ( 26 // A default rate limit value of 0 means rate limiting is disabled. 27 defaultWriteValuesPerMetricLimitPerSecond = 0 28 29 // A default rate limit value of 0 means rate limiting is disabled. 30 defaultWriteNewMetricLimitPerShardPerSecond = 0 31 32 // A default warmup duration of 0 means there is no warmup. 33 defaultWriteNewMetricNoLimitWarmupDuration = 0 34 ) 35 36 // Options provide a set of options that are configurable at runtime. 37 type Options interface { 38 // SetWriteValuesPerMetricLimitPerSecond sets the rate limit used 39 // to cap the maximum number of values allowed to be written per second. 40 SetWriteValuesPerMetricLimitPerSecond(value int64) Options 41 42 // WriteValuesPerMetricLimitPerSecond returns the rate limit used 43 // to cap the maximum number of values allowed to be written per second. 44 WriteValuesPerMetricLimitPerSecond() int64 45 46 // SetWriteNewMetricLimitPerShardPerSecond sets the rate limit used 47 // to cap the maximum number of new metrics allowed to be written per shard per second. 48 SetWriteNewMetricLimitPerShardPerSecond(value int64) Options 49 50 // WriteNewMetricLimitPerShardPerSecond returns the rate limit used 51 // to cap the maximum number of new metrics allowed to be written per shard per second. 52 WriteNewMetricLimitPerShardPerSecond() int64 53 54 // SetWriteNewMetricNoLimitWarmupDuration sets the warmup duration during which 55 // rate limiting is not applied for writing new metric series for the purpose 56 // of not aggresively limiting new series insertion rate when an instance just 57 // comes online and is ingesting a large number of new series during startup. 58 // The warmup duration is in effect starting from the time when the first entry 59 // is insert into the shard. 60 SetWriteNewMetricNoLimitWarmupDuration(value time.Duration) Options 61 62 // WriteNewMetricNoLimitWarmupDuration returns the warmup duration during which 63 // rate limiting is not applied for writing new metric series for the purpose 64 // of not aggresively limiting new series insertion rate when an instance just 65 // comes online and is ingesting a large number of new series during startup. 66 // The warmup duration is in effect starting from the time when the first entry 67 // is insert into the shard. 68 WriteNewMetricNoLimitWarmupDuration() time.Duration 69 } 70 71 type options struct { 72 writeValuesPerMetricLimitPerSecond int64 73 writeNewMetricLimitPerShardPerSecond int64 74 writeNewMetricNoLimitWarmupDuration time.Duration 75 } 76 77 // NewOptions creates a new set of runtime options. 78 func NewOptions() Options { 79 return &options{ 80 writeValuesPerMetricLimitPerSecond: defaultWriteValuesPerMetricLimitPerSecond, 81 writeNewMetricLimitPerShardPerSecond: defaultWriteNewMetricLimitPerShardPerSecond, 82 writeNewMetricNoLimitWarmupDuration: defaultWriteNewMetricNoLimitWarmupDuration, 83 } 84 } 85 86 func (o *options) SetWriteValuesPerMetricLimitPerSecond(value int64) Options { 87 opts := *o 88 opts.writeValuesPerMetricLimitPerSecond = value 89 return &opts 90 } 91 92 func (o *options) WriteValuesPerMetricLimitPerSecond() int64 { 93 return o.writeValuesPerMetricLimitPerSecond 94 } 95 96 func (o *options) SetWriteNewMetricLimitPerShardPerSecond(value int64) Options { 97 opts := *o 98 opts.writeNewMetricLimitPerShardPerSecond = value 99 return &opts 100 } 101 102 func (o *options) WriteNewMetricLimitPerShardPerSecond() int64 { 103 return o.writeNewMetricLimitPerShardPerSecond 104 } 105 106 func (o *options) SetWriteNewMetricNoLimitWarmupDuration(value time.Duration) Options { 107 opts := *o 108 opts.writeNewMetricNoLimitWarmupDuration = value 109 return &opts 110 } 111 112 func (o *options) WriteNewMetricNoLimitWarmupDuration() time.Duration { 113 return o.writeNewMetricNoLimitWarmupDuration 114 }