github.com/m3db/m3@v1.5.1-0.20231129193456-75a402aa583b/src/aggregator/client/m3msg_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 client 22 23 import ( 24 "errors" 25 26 "github.com/m3db/m3/src/msg/producer" 27 "github.com/m3db/m3/src/x/instrument" 28 ) 29 30 var ( 31 errM3MsgOptionsNoProducer = errors.New("no producer set") 32 33 // defaultM3MsgTimerOptions by defaults ensures to use 34 // low overhead timers for M3Msg clients (can't do this 35 // for legacy clients since people depend on those stats being 36 // non-histograms). 37 defaultM3MsgTimerOptions = instrument.TimerOptions{ 38 Type: instrument.HistogramTimerType, 39 HistogramBuckets: instrument.DefaultHistogramTimerHistogramBuckets(), 40 } 41 ) 42 43 // M3MsgOptions is a set of M3Msg client options. 44 type M3MsgOptions interface { 45 // Validate validates the M3Msg client options. 46 Validate() error 47 48 // SetProducer sets the producer. 49 SetProducer(value producer.Producer) M3MsgOptions 50 51 // Producer gets the producer. 52 Producer() producer.Producer 53 54 // SetTimerOptions sets the instrument timer options. 55 SetTimerOptions(value instrument.TimerOptions) M3MsgOptions 56 57 // TimerOptions gets the instrument timer options. 58 TimerOptions() instrument.TimerOptions 59 } 60 61 type m3msgOptions struct { 62 producer producer.Producer 63 timerOptions instrument.TimerOptions 64 } 65 66 // NewM3MsgOptions returns a new set of M3Msg options. 67 func NewM3MsgOptions() M3MsgOptions { 68 return &m3msgOptions{ 69 timerOptions: defaultM3MsgTimerOptions, 70 } 71 } 72 73 func (o *m3msgOptions) Validate() error { 74 if o.producer == nil { 75 return errM3MsgOptionsNoProducer 76 } 77 return nil 78 } 79 80 func (o *m3msgOptions) SetProducer(value producer.Producer) M3MsgOptions { 81 opts := *o 82 opts.producer = value 83 return &opts 84 } 85 86 func (o *m3msgOptions) Producer() producer.Producer { 87 return o.producer 88 } 89 90 func (o *m3msgOptions) SetTimerOptions(value instrument.TimerOptions) M3MsgOptions { 91 opts := *o 92 opts.timerOptions = value 93 return &opts 94 } 95 96 func (o *m3msgOptions) TimerOptions() instrument.TimerOptions { 97 return o.timerOptions 98 }