-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
118 lines (109 loc) · 3.5 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
package common
import (
"fmt"
log "github.com/Sirupsen/logrus"
"gopkg.in/gcfg.v1"
)
// configuration for the logging
type LoggingConfig struct {
// whether or not log outputs in JSON
UseJSON bool
Level string
}
// server configuration
type ServerConfig struct {
// if true, listens on 0.0.0.0
Global bool
// Client Interface
Port int
// the public-facing address of the broker
Host string
// A unique key for this Broker
BrokerID UUID
// the name of the coordinator server
CoordinatorHost string
// the port of the coordinator server
CoordinatorPort int
// if true, then the broker evaluates metadata locally
// (distribution option #2). If false, then it forwards
// queries to the coordinator (distribution option #1).
// Note that if running in single-node mode, without
// a coordinator, this must be TRUE.
LocalEvaluation bool
}
// Coordinator configuration
type CoordinatorConfig struct {
Port int
Global bool
HeartbeatInterval int // seconds
CoordinatorCount int // number of coordinators total
EtcdAddresses string // comma-separated list
GCFreq int // how often (number of events) to GC etcd
EnableContinuousCheckpointing bool // true to continuously checkpoint
DisableSendLog bool // true to not log sent messages
UseAWSIPSwitcher bool // true to use the AWP IP Switcher; doesn't switch IPs otherwise
UseEtcd bool // true if events should be stored in Etcd; CoordinatorCount must be 1
InstanceId string // AWS instance id, e.g. i-1a2b3c4d
Region string // AWS region name, e.g. us-west-1
ElasticIP string // the elastic IP to fight over
}
// MongoDB configuration
type MongoConfig struct {
Port int
Host string
Database string
}
// Debugging configuration
type DebugConfig struct {
Enable bool
ProfileType string
ProfileLength int
}
type BenchmarkConfig struct {
BrokerURL string
BrokerPort int
StepSpacing int // How long between increasing client/publisher counts (seconds)
ConfigurationName string // Named bundle of query/metadata
}
type Config struct {
Logging LoggingConfig
Server ServerConfig
Mongo MongoConfig
Coordinator CoordinatorConfig
Debug DebugConfig
Benchmark BenchmarkConfig
}
// Don't want to log anything since this is called before SetupLogging;
// return the desired log message to be logged later if desired
// TODO this makes it so that default_config.ini overwrites config.ini...
func LoadConfig(filename string) (config *Config, logmsg string) {
config = new(Config)
err := gcfg.ReadFileInto(config, filename)
if err == nil {
logmsg = fmt.Sprintf("Using local config at %v", filename)
return
}
err = gcfg.ReadFileInto(config, "./config.ini")
if err == nil {
return
}
err = gcfg.ReadFileInto(config, "./default_config.ini")
if err == nil {
logmsg = "Using default configuration found at ./default_config.ini. "
} else {
logmsg = fmt.Sprintf("Unable to find any configuration file at ./default_config.ini, ./config.ini, or %v", filename)
}
return
}
func SetupLogging(config *Config) {
if config.Logging.UseJSON {
log.SetFormatter(&log.JSONFormatter{})
}
loglevel, err := log.ParseLevel(config.Logging.Level)
log.Infof("Using log level %v", loglevel)
if err != nil {
log.Error(err)
loglevel = log.InfoLevel // default to Info
}
log.SetLevel(loglevel)
}