github.com/m3db/m3@v1.5.0/src/cmd/services/m3coordinator/server/m3msg/config.go (about) 1 // Copyright (c) 2018 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 m3msg 22 23 import ( 24 "github.com/m3db/m3/src/metrics/policy" 25 "github.com/m3db/m3/src/msg/consumer" 26 "github.com/m3db/m3/src/x/instrument" 27 xio "github.com/m3db/m3/src/x/io" 28 "github.com/m3db/m3/src/x/pool" 29 "github.com/m3db/m3/src/x/server" 30 ) 31 32 // Configuration configs the m3msg server. 33 type Configuration struct { 34 // Server configs the server. 35 Server server.Configuration `yaml:"server"` 36 37 // Handler configs the handler. 38 Handler handlerConfiguration `yaml:"handler"` 39 40 // Consumer configs the consumer. 41 Consumer consumer.Configuration `yaml:"consumer"` 42 } 43 44 // NewServer creates a new server. 45 func (c Configuration) NewServer( 46 writeFn WriteFn, 47 rwOpts xio.Options, 48 iOpts instrument.Options, 49 ) (server.Server, error) { 50 scope := iOpts.MetricsScope().Tagged(map[string]string{"server": "m3msg"}) 51 cOpts := c.Consumer.NewOptions( 52 iOpts.SetMetricsScope(scope.Tagged(map[string]string{ 53 "component": "consumer", 54 })), 55 ) 56 57 cOpts = cOpts.SetDecoderOptions(cOpts.DecoderOptions().SetRWOptions(rwOpts)) 58 h, err := c.Handler.newHandler(writeFn, cOpts, iOpts.SetMetricsScope(scope)) 59 if err != nil { 60 return nil, err 61 } 62 return c.Server.NewServer( 63 h, 64 iOpts.SetMetricsScope(scope), 65 ), nil 66 } 67 68 type handlerConfiguration struct { 69 // ProtobufDecoderPool configs the protobuf decoder pool. 70 ProtobufDecoderPool pool.ObjectPoolConfiguration `yaml:"protobufDecoderPool"` 71 BlackholePolicies []policy.StoragePolicy `yaml:"blackholePolicies"` 72 } 73 74 func (c handlerConfiguration) newHandler( 75 writeFn WriteFn, 76 cOpts consumer.Options, 77 iOpts instrument.Options, 78 ) (server.Handler, error) { 79 p := newProtobufProcessor(Options{ 80 WriteFn: writeFn, 81 InstrumentOptions: iOpts.SetMetricsScope( 82 iOpts.MetricsScope().Tagged(map[string]string{ 83 "handler": "protobuf", 84 }), 85 ), 86 ProtobufDecoderPoolOptions: c.ProtobufDecoderPool.NewObjectPoolOptions(iOpts), 87 BlockholePolicies: c.BlackholePolicies, 88 }) 89 return consumer.NewMessageHandler(consumer.SingletonMessageProcessor(p), cOpts), nil 90 } 91 92 // NewOptions creates handler options. 93 func (c handlerConfiguration) NewOptions( 94 writeFn WriteFn, 95 iOpts instrument.Options, 96 ) Options { 97 return Options{ 98 WriteFn: writeFn, 99 InstrumentOptions: iOpts, 100 ProtobufDecoderPoolOptions: c.ProtobufDecoderPool.NewObjectPoolOptions(iOpts), 101 } 102 }