github.com/vseinstrumentiru/lego@v1.0.2/internal/lego/monitor/exporter/config.go (about) 1 package exporter 2 3 import ( 4 "contrib.go.opencensus.io/exporter/ocagent" 5 "emperror.dev/errors" 6 "github.com/spf13/pflag" 7 "github.com/spf13/viper" 8 lego2 "github.com/vseinstrumentiru/lego/internal/lego" 9 "time" 10 ) 11 12 type Config struct { 13 Jaeger struct { 14 lego2.WithSwitch `mapstructure:",squash"` 15 Addr string 16 } 17 18 Opencensus struct { 19 lego2.WithSwitch `mapstructure:",squash"` 20 21 Addr string 22 Insecure bool 23 ReconnectPeriod time.Duration 24 } 25 26 NewRelic struct { 27 lego2.WithSwitch `mapstructure:",squash"` 28 Key string 29 AppName string 30 } 31 32 Prometheus struct { 33 lego2.WithSwitch `mapstructure:",squash"` 34 } 35 } 36 37 func (c Config) SetDefaults(env *viper.Viper, flag *pflag.FlagSet) { 38 env.SetDefault("srv.monitor.exporter.prometheus.enabled", true) 39 } 40 41 func (c Config) Validate() (err error) { 42 if c.Jaeger.Enabled && c.Jaeger.Addr == "" { 43 err = errors.Append(err, errors.New("srv.monitor.exporter.jaeger.addr is required")) 44 } 45 46 if c.Opencensus.Enabled { 47 if c.Opencensus.Addr == "" { 48 err = errors.Append(err, errors.New("srv.monitor.exporter.opencensus.addr is required")) 49 } 50 } 51 52 if c.NewRelic.Enabled { 53 if c.NewRelic.Key == "" { 54 err = errors.Append(err, errors.New("srv.monitor.exporter.newrelic.key is required")) 55 } 56 } 57 58 return 59 } 60 61 func (c Config) OpencensusOptions() []ocagent.ExporterOption { 62 options := []ocagent.ExporterOption{ 63 ocagent.WithAddress(c.Opencensus.Addr), 64 ocagent.WithReconnectionPeriod(c.Opencensus.ReconnectPeriod), 65 } 66 67 if c.Opencensus.Insecure { 68 options = append(options, ocagent.WithInsecure()) 69 } 70 71 return options 72 }