github.com/m3db/m3@v1.5.1-0.20231129193456-75a402aa583b/src/cmd/services/m3aggregator/config/config.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 config 22 23 import ( 24 "github.com/m3db/m3/src/x/debug/config" 25 "github.com/m3db/m3/src/x/instrument" 26 "github.com/m3db/m3/src/x/log" 27 28 "gopkg.in/yaml.v2" 29 ) 30 31 // Configuration contains top-level configuration. 32 type Configuration struct { 33 // Logging configuration. 34 Logging *log.Configuration `yaml:"logging"` 35 36 // Metrics configuration. 37 Metrics *instrument.MetricsConfiguration `yaml:"metrics"` 38 39 // M3Msg server configuration. 40 // Optional. 41 M3Msg *M3MsgServerConfiguration `yaml:"m3msg"` 42 43 // Raw TCP server configuration. 44 // Optional. 45 RawTCP *RawTCPServerConfiguration `yaml:"rawtcp"` 46 47 // HTTP server configuration. 48 // Optional. 49 HTTP *HTTPServerConfiguration `yaml:"http"` 50 51 // Client configuration for key value store. 52 KVClient *KVClientConfiguration `yaml:"kvClient" validate:"nonzero"` 53 54 // Runtime options configuration. 55 RuntimeOptions *RuntimeOptionsConfiguration `yaml:"runtimeOptions"` 56 57 // Aggregator configuration. 58 Aggregator *AggregatorConfiguration `yaml:"aggregator"` 59 60 // Debug configuration. 61 Debug config.DebugConfiguration `yaml:"debug"` 62 } 63 64 // LoggingOrDefault returns the logging configuration or defaults. 65 func (c *Configuration) LoggingOrDefault() log.Configuration { 66 if c.Logging != nil { 67 return *c.Logging 68 } 69 70 return defaultLogging 71 } 72 73 // MetricsOrDefault returns the metrics config or default. 74 func (c *Configuration) MetricsOrDefault() instrument.MetricsConfiguration { 75 if c.Metrics != nil { 76 return *c.Metrics 77 } 78 79 return defaultMetrics 80 } 81 82 // M3MsgOrDefault returns the m3msg config or default. 83 func (c *Configuration) M3MsgOrDefault() M3MsgServerConfiguration { 84 if c.M3Msg != nil { 85 return *c.M3Msg 86 } 87 88 return defaultM3Msg 89 } 90 91 // HTTPOrDefault returns the http config or default. 92 func (c *Configuration) HTTPOrDefault() HTTPServerConfiguration { 93 if c.HTTP != nil { 94 return *c.HTTP 95 } 96 97 return defaultHTTP 98 } 99 100 // KVClientOrDefault returns the kv client or default. 101 func (c *Configuration) KVClientOrDefault() KVClientConfiguration { 102 if c.KVClient != nil { 103 return *c.KVClient 104 } 105 106 return defaultKV 107 } 108 109 // RuntimeOptionsOrDefault returns the runtime options or default. 110 func (c *Configuration) RuntimeOptionsOrDefault() RuntimeOptionsConfiguration { 111 if c.RuntimeOptions != nil { 112 return *c.RuntimeOptions 113 } 114 115 return defaultRuntimeOptions 116 } 117 118 // AggregatorOrDefault returns the aggregator config or default. 119 func (c *Configuration) AggregatorOrDefault() AggregatorConfiguration { 120 if c.Aggregator != nil { 121 return *c.Aggregator 122 } 123 124 return defaultAggregator 125 } 126 127 // DeepCopy returns a deep copy of the current configuration object. 128 func (c *Configuration) DeepCopy() (Configuration, error) { 129 rawCfg, err := yaml.Marshal(c) 130 if err != nil { 131 return Configuration{}, err 132 } 133 var dupe Configuration 134 if err := yaml.Unmarshal(rawCfg, &dupe); err != nil { 135 return Configuration{}, err 136 } 137 return dupe, nil 138 }