github.com/m3db/m3@v1.5.0/src/cmd/services/m3em_agent/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 agentmain 22 23 import ( 24 "io/ioutil" 25 26 xgrpc "github.com/m3db/m3/src/m3em/x/grpc" 27 28 tallym3 "github.com/uber-go/tally/m3" 29 "google.golang.org/grpc/credentials" 30 ) 31 32 // Configuration is a collection of knobs to configure m3em_agent processes 33 type Configuration struct { 34 Server ServerConfiguration `yaml:"server"` 35 Metrics MetricsConfiguration `yaml:"metrics"` 36 Agent AgentConfiguration `yaml:"agent"` 37 } 38 39 // AgentConfiguration is a collection of knobs to configure agents 40 type AgentConfiguration struct { 41 WorkingDir string `yaml:"workingDir" validate:"nonzero"` 42 StartupCmds []ExecCommand `yaml:"startupCmds"` 43 ReleaseCmds []ExecCommand `yaml:"releaseCmds"` 44 TestEnvVars map[string]string `yaml:"testEnvVars"` 45 } 46 47 // ExecCommand is an executable command 48 type ExecCommand struct { 49 Path string `yaml:"path" validate:"nonzero"` 50 Args []string `yaml:"args"` 51 } 52 53 // MetricsConfiguration is a collection of knobs to configure metrics collection 54 type MetricsConfiguration struct { 55 Prefix string `yaml:"prefix"` 56 SampleRate float64 `yaml:"sampleRate" validate:"min=0.01,max=1.0"` 57 M3 tallym3.Configuration `yaml:"m3" validate:"nonzero"` 58 } 59 60 // ServerConfiguration is a collection of knobs to control grpc server configuration 61 type ServerConfiguration struct { 62 ListenAddress string `yaml:"listenAddress" validate:"nonzero"` 63 DebugAddress string `yaml:"debugAddress" validate:"nonzero"` 64 TLS *TLSConfiguration `yaml:"tls"` 65 } 66 67 // TLSConfiguration are the resources required for TLS Communication 68 type TLSConfiguration struct { 69 CACrtPath string `yaml:"caCrt" validate:"nonzero"` 70 ServerCrtPath string `yaml:"serverCrt" validate:"nonzero"` 71 ServerKeyPath string `yaml:"serverKey" validate:"nonzero"` 72 } 73 74 // Credentials returns the TransportCredentials corresponding to the provided struct 75 func (t TLSConfiguration) Credentials() (credentials.TransportCredentials, error) { 76 caCrt, err := ioutil.ReadFile(t.CACrtPath) 77 if err != nil { 78 return nil, err 79 } 80 81 serverCrt, err := ioutil.ReadFile(t.ServerCrtPath) 82 if err != nil { 83 return nil, err 84 } 85 86 serverKey, err := ioutil.ReadFile(t.ServerKeyPath) 87 if err != nil { 88 return nil, err 89 } 90 91 return xgrpc.NewServerCredentials(caCrt, serverCrt, serverKey) 92 }