khenaidoo | bf6e7bb | 2018-08-14 22:27:29 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018-present Open Networking Foundation |
| 3 | |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 16 | |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 17 | package config |
| 18 | |
| 19 | import ( |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 20 | "flag" |
Girish Kumar | 4d3887d | 2019-11-22 14:22:05 +0000 | [diff] [blame] | 21 | "time" |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 22 | ) |
| 23 | |
khenaidoo | 5c11af7 | 2018-07-20 17:21:05 -0400 | [diff] [blame] | 24 | // RW Core service default constants |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 25 | const ( |
khenaidoo | 5e4fca3 | 2021-05-12 16:02:23 -0400 | [diff] [blame] | 26 | EtcdStoreName = "etcd" |
| 27 | defaultGrpcAddress = ":50057" |
| 28 | defaultKafkaAdapterAddress = "127.0.0.1:9092" |
| 29 | defaultKafkaClusterAddress = "127.0.0.1:9094" |
| 30 | defaultKVStoreType = EtcdStoreName |
| 31 | defaultKVStoreTimeout = 5 * time.Second |
| 32 | defaultKVStoreAddress = "127.0.0.1:2379" // Etcd = 2379 |
| 33 | defaultKVTxnKeyDelTime = 60 |
| 34 | defaultLogLevel = "WARN" |
| 35 | defaultBanner = false |
| 36 | defaultDisplayVersionOnly = false |
| 37 | defaultCoreTopic = "rwcore" |
| 38 | defaultEventTopic = "voltha.events" |
| 39 | defaultRWCoreEndpoint = "rwcore" |
| 40 | defaultRWCoreKey = "pki/voltha.key" |
| 41 | defaultRWCoreCert = "pki/voltha.crt" |
| 42 | defaultRWCoreCA = "pki/voltha-CA.pem" |
| 43 | defaultLongRunningRequestTimeout = 2000 * time.Millisecond |
| 44 | defaultDefaultRequestTimeout = 1000 * time.Millisecond |
| 45 | defaultCoreTimeout = 1000 * time.Millisecond |
| 46 | defaultCoreBindingKey = "voltha_backend_name" |
| 47 | defaultMaxConnectionRetries = -1 // retries forever |
| 48 | defaultConnectionRetryInterval = 2 * time.Second |
| 49 | defaultLiveProbeInterval = 60 * time.Second |
| 50 | defaultNotLiveProbeInterval = 5 * time.Second // Probe more frequently when not alive |
| 51 | defaultProbeAddress = ":8080" |
| 52 | defaultTraceEnabled = false |
| 53 | defaultTraceAgentAddress = "127.0.0.1:6831" |
| 54 | defaultLogCorrelationEnabled = true |
| 55 | defaultVolthaStackID = "voltha" |
| 56 | defaultBackoffRetryInitialInterval = 500 * time.Millisecond |
| 57 | defaultBackoffRetryMaxElapsedTime = 0 |
| 58 | defaultBackoffRetryMaxInterval = 1 * time.Minute |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 59 | ) |
| 60 | |
khenaidoo | 5c11af7 | 2018-07-20 17:21:05 -0400 | [diff] [blame] | 61 | // RWCoreFlags represents the set of configurations used by the read-write core service |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 62 | type RWCoreFlags struct { |
| 63 | // Command line parameters |
khenaidoo | 5e4fca3 | 2021-05-12 16:02:23 -0400 | [diff] [blame] | 64 | RWCoreEndpoint string |
| 65 | GrpcAddress string |
| 66 | KafkaAdapterAddress string |
| 67 | KafkaClusterAddress string |
| 68 | KVStoreType string |
| 69 | KVStoreTimeout time.Duration |
| 70 | KVStoreAddress string |
| 71 | KVTxnKeyDelTime int |
| 72 | CoreTopic string |
| 73 | EventTopic string |
| 74 | LogLevel string |
| 75 | Banner bool |
| 76 | DisplayVersionOnly bool |
| 77 | RWCoreKey string |
| 78 | RWCoreCert string |
| 79 | RWCoreCA string |
| 80 | LongRunningRequestTimeout time.Duration |
| 81 | DefaultRequestTimeout time.Duration |
| 82 | DefaultCoreTimeout time.Duration |
| 83 | CoreBindingKey string |
| 84 | MaxConnectionRetries int |
| 85 | ConnectionRetryInterval time.Duration |
| 86 | LiveProbeInterval time.Duration |
| 87 | NotLiveProbeInterval time.Duration |
| 88 | ProbeAddress string |
| 89 | TraceEnabled bool |
| 90 | TraceAgentAddress string |
| 91 | LogCorrelationEnabled bool |
| 92 | VolthaStackID string |
| 93 | BackoffRetryInitialInterval time.Duration |
| 94 | BackoffRetryMaxElapsedTime time.Duration |
| 95 | BackoffRetryMaxInterval time.Duration |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 96 | } |
| 97 | |
khenaidoo | 5c11af7 | 2018-07-20 17:21:05 -0400 | [diff] [blame] | 98 | // NewRWCoreFlags returns a new RWCore config |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 99 | func NewRWCoreFlags() *RWCoreFlags { |
| 100 | var rwCoreFlag = RWCoreFlags{ // Default values |
khenaidoo | 5e4fca3 | 2021-05-12 16:02:23 -0400 | [diff] [blame] | 101 | RWCoreEndpoint: defaultRWCoreEndpoint, |
| 102 | GrpcAddress: defaultGrpcAddress, |
| 103 | KafkaAdapterAddress: defaultKafkaAdapterAddress, |
| 104 | KafkaClusterAddress: defaultKafkaClusterAddress, |
| 105 | KVStoreType: defaultKVStoreType, |
| 106 | KVStoreTimeout: defaultKVStoreTimeout, |
| 107 | KVStoreAddress: defaultKVStoreAddress, |
| 108 | KVTxnKeyDelTime: defaultKVTxnKeyDelTime, |
| 109 | CoreTopic: defaultCoreTopic, |
| 110 | EventTopic: defaultEventTopic, |
| 111 | LogLevel: defaultLogLevel, |
| 112 | Banner: defaultBanner, |
| 113 | DisplayVersionOnly: defaultDisplayVersionOnly, |
| 114 | RWCoreKey: defaultRWCoreKey, |
| 115 | RWCoreCert: defaultRWCoreCert, |
| 116 | RWCoreCA: defaultRWCoreCA, |
| 117 | DefaultRequestTimeout: defaultDefaultRequestTimeout, |
| 118 | LongRunningRequestTimeout: defaultLongRunningRequestTimeout, |
| 119 | DefaultCoreTimeout: defaultCoreTimeout, |
| 120 | CoreBindingKey: defaultCoreBindingKey, |
| 121 | MaxConnectionRetries: defaultMaxConnectionRetries, |
| 122 | ConnectionRetryInterval: defaultConnectionRetryInterval, |
| 123 | LiveProbeInterval: defaultLiveProbeInterval, |
| 124 | NotLiveProbeInterval: defaultNotLiveProbeInterval, |
| 125 | ProbeAddress: defaultProbeAddress, |
| 126 | TraceEnabled: defaultTraceEnabled, |
| 127 | TraceAgentAddress: defaultTraceAgentAddress, |
| 128 | LogCorrelationEnabled: defaultLogCorrelationEnabled, |
| 129 | VolthaStackID: defaultVolthaStackID, |
| 130 | BackoffRetryInitialInterval: defaultBackoffRetryInitialInterval, |
| 131 | BackoffRetryMaxElapsedTime: defaultBackoffRetryMaxElapsedTime, |
| 132 | BackoffRetryMaxInterval: defaultBackoffRetryMaxInterval, |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 133 | } |
| 134 | return &rwCoreFlag |
| 135 | } |
| 136 | |
khenaidoo | 5c11af7 | 2018-07-20 17:21:05 -0400 | [diff] [blame] | 137 | // ParseCommandArguments parses the arguments when running read-write core service |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 138 | func (cf *RWCoreFlags) ParseCommandArguments() { |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 139 | |
Andrey Pozolotin | 34dd63f | 2021-05-31 21:26:40 +0300 | [diff] [blame] | 140 | flag.StringVar(&(cf.RWCoreEndpoint), "vcore-endpoint", defaultRWCoreEndpoint, "RW core endpoint address") |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 141 | |
Andrey Pozolotin | 34dd63f | 2021-05-31 21:26:40 +0300 | [diff] [blame] | 142 | flag.StringVar(&(cf.GrpcAddress), "grpc_address", defaultGrpcAddress, "GRPC server - address") |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 143 | |
Andrey Pozolotin | 34dd63f | 2021-05-31 21:26:40 +0300 | [diff] [blame] | 144 | flag.StringVar(&(cf.KafkaAdapterAddress), "kafka_adapter_address", defaultKafkaAdapterAddress, "Kafka - Adapter messaging address") |
khenaidoo | 5c11af7 | 2018-07-20 17:21:05 -0400 | [diff] [blame] | 145 | |
Andrey Pozolotin | 34dd63f | 2021-05-31 21:26:40 +0300 | [diff] [blame] | 146 | flag.StringVar(&(cf.KafkaClusterAddress), "kafka_cluster_address", defaultKafkaClusterAddress, "Kafka - Cluster messaging address") |
khenaidoo | 5c11af7 | 2018-07-20 17:21:05 -0400 | [diff] [blame] | 147 | |
Andrey Pozolotin | 34dd63f | 2021-05-31 21:26:40 +0300 | [diff] [blame] | 148 | flag.StringVar(&(cf.CoreTopic), "rw_core_topic", defaultCoreTopic, "RW Core topic") |
khenaidoo | 5c11af7 | 2018-07-20 17:21:05 -0400 | [diff] [blame] | 149 | |
Andrey Pozolotin | 34dd63f | 2021-05-31 21:26:40 +0300 | [diff] [blame] | 150 | flag.StringVar(&(cf.EventTopic), "event_topic", defaultEventTopic, "RW Core Event topic") |
Himani Chawla | b4c2591 | 2020-11-12 17:16:38 +0530 | [diff] [blame] | 151 | |
David Bainbridge | 9ae1313 | 2020-06-22 17:28:01 -0700 | [diff] [blame] | 152 | flag.Bool("in_competing_mode", false, "deprecated") |
khenaidoo | 7923270 | 2018-12-04 11:00:41 -0500 | [diff] [blame] | 153 | |
Andrey Pozolotin | 34dd63f | 2021-05-31 21:26:40 +0300 | [diff] [blame] | 154 | flag.StringVar(&(cf.KVStoreType), "kv_store_type", defaultKVStoreType, "KV store type") |
khenaidoo | 5c11af7 | 2018-07-20 17:21:05 -0400 | [diff] [blame] | 155 | |
Andrey Pozolotin | 34dd63f | 2021-05-31 21:26:40 +0300 | [diff] [blame] | 156 | flag.DurationVar(&(cf.KVStoreTimeout), "kv_store_request_timeout", defaultKVStoreTimeout, "The default timeout when making a kv store request") |
khenaidoo | 5c11af7 | 2018-07-20 17:21:05 -0400 | [diff] [blame] | 157 | |
Andrey Pozolotin | 34dd63f | 2021-05-31 21:26:40 +0300 | [diff] [blame] | 158 | flag.StringVar(&(cf.KVStoreAddress), "kv_store_address", defaultKVStoreAddress, "KV store address") |
khenaidoo | 5c11af7 | 2018-07-20 17:21:05 -0400 | [diff] [blame] | 159 | |
Andrey Pozolotin | 34dd63f | 2021-05-31 21:26:40 +0300 | [diff] [blame] | 160 | flag.IntVar(&(cf.KVTxnKeyDelTime), "kv_txn_delete_time", defaultKVTxnKeyDelTime, "The time to wait before deleting a completed transaction key") |
Richard Jankowski | e4d7766 | 2018-10-17 13:53:21 -0400 | [diff] [blame] | 161 | |
Andrey Pozolotin | 34dd63f | 2021-05-31 21:26:40 +0300 | [diff] [blame] | 162 | flag.StringVar(&(cf.LogLevel), "log_level", defaultLogLevel, "Log level") |
khenaidoo | 5c11af7 | 2018-07-20 17:21:05 -0400 | [diff] [blame] | 163 | |
Andrey Pozolotin | 34dd63f | 2021-05-31 21:26:40 +0300 | [diff] [blame] | 164 | flag.DurationVar(&(cf.LongRunningRequestTimeout), "timeout_long_request", defaultLongRunningRequestTimeout, "Timeout for long running request") |
khenaidoo | b608032 | 2019-01-29 21:47:38 -0500 | [diff] [blame] | 165 | |
Andrey Pozolotin | 34dd63f | 2021-05-31 21:26:40 +0300 | [diff] [blame] | 166 | flag.DurationVar(&(cf.DefaultRequestTimeout), "timeout_request", defaultDefaultRequestTimeout, "Default timeout for regular request") |
khenaidoo | b608032 | 2019-01-29 21:47:38 -0500 | [diff] [blame] | 167 | |
Andrey Pozolotin | 34dd63f | 2021-05-31 21:26:40 +0300 | [diff] [blame] | 168 | flag.DurationVar(&(cf.DefaultCoreTimeout), "core_timeout", defaultCoreTimeout, "Default Core timeout") |
khenaidoo | 2c6a099 | 2019-04-29 13:46:56 -0400 | [diff] [blame] | 169 | |
Andrey Pozolotin | 34dd63f | 2021-05-31 21:26:40 +0300 | [diff] [blame] | 170 | flag.BoolVar(&cf.Banner, "banner", defaultBanner, "Show startup banner log lines") |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 171 | |
Andrey Pozolotin | 34dd63f | 2021-05-31 21:26:40 +0300 | [diff] [blame] | 172 | flag.BoolVar(&cf.DisplayVersionOnly, "version", defaultDisplayVersionOnly, "Show version information and exit") |
David K. Bainbridge | f430cd5 | 2019-05-28 15:00:35 -0700 | [diff] [blame] | 173 | |
Andrey Pozolotin | 34dd63f | 2021-05-31 21:26:40 +0300 | [diff] [blame] | 174 | flag.StringVar(&(cf.CoreBindingKey), "core_binding_key", defaultCoreBindingKey, "The name of the meta-key whose value is the rw-core group to which the ofagent is bound") |
Richard Jankowski | 46464e9 | 2019-03-05 11:53:55 -0500 | [diff] [blame] | 175 | |
Andrey Pozolotin | 34dd63f | 2021-05-31 21:26:40 +0300 | [diff] [blame] | 176 | flag.IntVar(&(cf.MaxConnectionRetries), "max_connection_retries", defaultMaxConnectionRetries, "The number of retries to connect to a dependent component") |
khenaidoo | b324421 | 2019-08-27 14:32:27 -0400 | [diff] [blame] | 177 | |
Andrey Pozolotin | 34dd63f | 2021-05-31 21:26:40 +0300 | [diff] [blame] | 178 | flag.DurationVar(&(cf.ConnectionRetryInterval), "connection_retry_interval", defaultConnectionRetryInterval, "The number of seconds between each connection retry attempt") |
khenaidoo | b324421 | 2019-08-27 14:32:27 -0400 | [diff] [blame] | 179 | |
Andrey Pozolotin | 34dd63f | 2021-05-31 21:26:40 +0300 | [diff] [blame] | 180 | flag.DurationVar(&(cf.LiveProbeInterval), "live_probe_interval", defaultLiveProbeInterval, "The number of seconds between liveness probes while in a live state") |
Scott Baker | ee6a087 | 2019-10-29 15:59:52 -0700 | [diff] [blame] | 181 | |
Andrey Pozolotin | 34dd63f | 2021-05-31 21:26:40 +0300 | [diff] [blame] | 182 | flag.DurationVar(&(cf.NotLiveProbeInterval), "not_live_probe_interval", defaultNotLiveProbeInterval, "The number of seconds between liveness probes while in a not live state") |
Scott Baker | ee6a087 | 2019-10-29 15:59:52 -0700 | [diff] [blame] | 183 | |
Andrey Pozolotin | 34dd63f | 2021-05-31 21:26:40 +0300 | [diff] [blame] | 184 | flag.StringVar(&(cf.ProbeAddress), "probe_address", defaultProbeAddress, "The address on which to listen to answer liveness and readiness probe queries over HTTP") |
David K. Bainbridge | b4a9ab0 | 2019-09-20 15:12:16 -0700 | [diff] [blame] | 185 | |
Andrey Pozolotin | 34dd63f | 2021-05-31 21:26:40 +0300 | [diff] [blame] | 186 | flag.BoolVar(&(cf.TraceEnabled), "trace_enabled", defaultTraceEnabled, "Whether to send logs to tracing agent?") |
Girish Kumar | 33470e8 | 2020-06-15 13:53:13 +0000 | [diff] [blame] | 187 | |
Andrey Pozolotin | 34dd63f | 2021-05-31 21:26:40 +0300 | [diff] [blame] | 188 | flag.StringVar(&(cf.TraceAgentAddress), "trace_agent_address", defaultTraceAgentAddress, "The address of tracing agent to which span info should be sent") |
Girish Kumar | 33470e8 | 2020-06-15 13:53:13 +0000 | [diff] [blame] | 189 | |
Andrey Pozolotin | 34dd63f | 2021-05-31 21:26:40 +0300 | [diff] [blame] | 190 | flag.BoolVar(&(cf.LogCorrelationEnabled), "log_correlation_enabled", defaultLogCorrelationEnabled, "Whether to enrich log statements with fields denoting operation being executed for achieving correlation?") |
Girish Kumar | 33470e8 | 2020-06-15 13:53:13 +0000 | [diff] [blame] | 191 | |
Andrey Pozolotin | 34dd63f | 2021-05-31 21:26:40 +0300 | [diff] [blame] | 192 | flag.StringVar(&cf.VolthaStackID, "stack_id", defaultVolthaStackID, "ID for the current voltha stack") |
Himani Chawla | 9cfc499 | 2021-03-22 12:43:01 +0530 | [diff] [blame] | 193 | |
Andrey Pozolotin | 34dd63f | 2021-05-31 21:26:40 +0300 | [diff] [blame] | 194 | flag.DurationVar(&(cf.BackoffRetryInitialInterval), "backoff_retry_initial_interval", defaultBackoffRetryInitialInterval, "The initial number of milliseconds an exponential backoff will wait before a retry") |
khenaidoo | 5e4fca3 | 2021-05-12 16:02:23 -0400 | [diff] [blame] | 195 | |
Andrey Pozolotin | 34dd63f | 2021-05-31 21:26:40 +0300 | [diff] [blame] | 196 | flag.DurationVar(&(cf.BackoffRetryMaxElapsedTime), "backoff_retry_max_elapsed_time", defaultBackoffRetryMaxElapsedTime, "The maximum number of milliseconds an exponential backoff can elasped") |
khenaidoo | 5e4fca3 | 2021-05-12 16:02:23 -0400 | [diff] [blame] | 197 | |
Andrey Pozolotin | 34dd63f | 2021-05-31 21:26:40 +0300 | [diff] [blame] | 198 | flag.DurationVar(&(cf.BackoffRetryMaxInterval), "backoff_retry_max_interval", defaultBackoffRetryMaxInterval, "The maximum number of milliseconds of an exponential backoff interval") |
khenaidoo | 5e4fca3 | 2021-05-12 16:02:23 -0400 | [diff] [blame] | 199 | |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 200 | flag.Parse() |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 201 | } |