-
Notifications
You must be signed in to change notification settings - Fork 12
/
config.go
131 lines (105 loc) · 4.74 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
119
120
121
122
123
124
125
126
127
128
129
130
131
// Package config contains all the config functions that is used by the bsp-agent node
package config
import (
"flag"
)
var (
blockDivisorDefault = 3
consumerPendingTimeoutDefault = 180
logFolderDefault = "./logs/"
)
// RedisConfig contains all redis related config
type RedisConfig struct {
RedisURL string
Password string
BlockDivisor int // can be set to any divisor (decrease specimen production throughput)
ConsumerPendingTimeout int // defaults to 1 min
}
// CodecConfig contains all AVRO codec related config
type CodecConfig struct {
AvroCodecPath string
}
// StorageConfig contains all configs needed by different stores
type StorageConfig struct {
// local
BinaryFilePath string
// ipfs
IpfsPinnerServer string
}
// ProofchainConfig contains all proof-chain configs
type ProofchainConfig struct {
ProofChainAddr string
}
// ChainConfig contains config for all supported blockchains
type ChainConfig struct {
RPCURL string
PrivateKey string
KeystorePath string
KeyStorePwd string
// for elrond
WebsocketURLs string
}
// MetricsConfig contains config for collecting performance metrics
type MetricsConfig struct {
Enabled bool
HTTPServerAddr string
HTTPServerPort string
}
// AgentConfig composes all configs into a single full (env and flags) config for the bsp-agent node
type AgentConfig struct {
RedisConfig RedisConfig
CodecConfig CodecConfig
StorageConfig StorageConfig
ProofchainConfig ProofchainConfig
ChainConfig ChainConfig
MetricsConfig MetricsConfig
LogFolder string
}
// NewAgentConfig creates a new empty config
func NewAgentConfig() *AgentConfig {
return &AgentConfig{}
}
// LoadConfig gets the config from env flags and cli arguments
func (ac *AgentConfig) LoadConfig() {
envConfig, err := loadEnvConfig()
if err != nil {
panic(err)
}
ac.getConfigFromEnv(envConfig)
ac.getConfigFromFlags()
}
// SegmentLength get number of block-specimens encoded within a block-replica
func (ac *AgentConfig) SegmentLength() int {
// number of block specimen/results within a single uploaded avro encoded block-replica object
// defaults to 1 block per segment in bsp-geth/agent "live" mode
return 1
}
func (ac *AgentConfig) getConfigFromEnv(config *EnvConfig) {
ac.StorageConfig.IpfsPinnerServer = config.IpfsConfig.IpfsPinnerServer
ac.RedisConfig.Password = config.RedisConfig.Password
ac.ChainConfig.RPCURL = config.EthConfig.RPCURL
ac.ChainConfig.PrivateKey = config.EthConfig.PrivateKey
ac.ChainConfig.KeystorePath = config.EthConfig.KeystorePath
ac.ChainConfig.KeyStorePwd = config.EthConfig.KeyStorePwd
}
func (ac *AgentConfig) getConfigFromFlags() {
// redis
flag.StringVar(&ac.RedisConfig.RedisURL, "redis-url", LookupEnvOrString("RedisURL", ""), "redis consumer stream url")
flag.IntVar(&ac.RedisConfig.BlockDivisor, "block-divisor", LookupEnvOrInt("BlockDivisor", blockDivisorDefault), "integer divisor that allows for selecting only block numbers divisible by this number")
flag.IntVar(&ac.RedisConfig.ConsumerPendingTimeout, "consumer-timeout", LookupEnvOrInt("ConsumerPendingTimeout", consumerPendingTimeoutDefault), "number of seconds to wait before pending messages consumer timeout")
// avro codec
flag.StringVar(&ac.CodecConfig.AvroCodecPath, "avro-codec-path", LookupEnvOrString("CodecPath", ""), "local path to AVRO .avsc files housing the specimen/result schemas")
// proof-chain
flag.StringVar(&ac.ProofchainConfig.ProofChainAddr, "proof-chain-address", LookupEnvOrString("ProofChain", ""), "hex string address for deployed proof-chain contract")
flag.StringVar(&ac.ChainConfig.WebsocketURLs, "websocket-urls", LookupEnvOrString("WebsocketURLs", ""), "url to websockets clients separated by space")
// logs
flag.StringVar(&ac.LogFolder, "log-folder", LookupEnvOrString("LogFolder", logFolderDefault), "Location where the log files should be placed")
// storage
flag.StringVar(&ac.StorageConfig.IpfsPinnerServer, "ipfs-pinner-server", LookupEnvOrString("IpfsPinnerServer", "http://127.0.0.1:3001/"), "IPFS pinner server url for uploading data")
flag.StringVar(&ac.StorageConfig.BinaryFilePath, "binary-file-path", LookupEnvOrString("BinaryFilePath", ""), "local path to AVRO encoded binary files that contain block-replicas")
// metrics
flag.BoolVar(&ac.MetricsConfig.Enabled, "metrics", false, "enable metrics reporting and collection")
flag.StringVar(&ac.MetricsConfig.HTTPServerAddr, "metrics.addr", LookupEnvOrString("MetricsHttpServerAddr", "127.0.0.1"), "Enable stand-alone metrics HTTP server listening interface (default: \"127.0.0.1\")")
flag.StringVar(&ac.MetricsConfig.HTTPServerPort, "metrics.port", LookupEnvOrString("MetricsHttpServerPort", "6061"), "Metrics HTTP server listening port (default: 6061)")
flag.Parse()
}