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" |
David K. Bainbridge | 6080c17 | 2021-07-24 00:22:28 +0000 | [diff] [blame] | 21 | "os" |
Girish Kumar | 4d3887d | 2019-11-22 14:22:05 +0000 | [diff] [blame] | 22 | "time" |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 23 | ) |
| 24 | |
khenaidoo | 5c11af7 | 2018-07-20 17:21:05 -0400 | [diff] [blame] | 25 | // RW Core service default constants |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 26 | const ( |
David K. Bainbridge | 6080c17 | 2021-07-24 00:22:28 +0000 | [diff] [blame] | 27 | EtcdStoreName = "etcd" |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 28 | ) |
| 29 | |
khenaidoo | 5c11af7 | 2018-07-20 17:21:05 -0400 | [diff] [blame] | 30 | // RWCoreFlags represents the set of configurations used by the read-write core service |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 31 | type RWCoreFlags struct { |
| 32 | // Command line parameters |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 33 | GrpcNBIAddress string |
| 34 | GrpcSBIAddress string |
khenaidoo | 5e4fca3 | 2021-05-12 16:02:23 -0400 | [diff] [blame] | 35 | KafkaClusterAddress string |
| 36 | KVStoreType string |
| 37 | KVStoreTimeout time.Duration |
| 38 | KVStoreAddress string |
khenaidoo | 5e4fca3 | 2021-05-12 16:02:23 -0400 | [diff] [blame] | 39 | EventTopic string |
kesavand | 92fac10 | 2022-03-16 12:33:06 +0530 | [diff] [blame] | 40 | EventTopicPartitions int |
| 41 | EventTopicReplicas int |
khenaidoo | 5e4fca3 | 2021-05-12 16:02:23 -0400 | [diff] [blame] | 42 | LogLevel string |
| 43 | Banner bool |
| 44 | DisplayVersionOnly bool |
| 45 | RWCoreKey string |
| 46 | RWCoreCert string |
| 47 | RWCoreCA string |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 48 | InternalTimeout time.Duration |
| 49 | RPCTimeout time.Duration |
Himani Chawla | 4b4bd25 | 2021-11-08 15:59:40 +0530 | [diff] [blame] | 50 | FlowTimeout time.Duration |
khenaidoo | 5e4fca3 | 2021-05-12 16:02:23 -0400 | [diff] [blame] | 51 | MaxConnectionRetries int |
| 52 | ConnectionRetryInterval time.Duration |
| 53 | LiveProbeInterval time.Duration |
| 54 | NotLiveProbeInterval time.Duration |
| 55 | ProbeAddress string |
| 56 | TraceEnabled bool |
| 57 | TraceAgentAddress string |
| 58 | LogCorrelationEnabled bool |
| 59 | VolthaStackID string |
| 60 | BackoffRetryInitialInterval time.Duration |
| 61 | BackoffRetryMaxElapsedTime time.Duration |
| 62 | BackoffRetryMaxInterval time.Duration |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 63 | } |
| 64 | |
khenaidoo | 5c11af7 | 2018-07-20 17:21:05 -0400 | [diff] [blame] | 65 | // ParseCommandArguments parses the arguments when running read-write core service |
David K. Bainbridge | 6080c17 | 2021-07-24 00:22:28 +0000 | [diff] [blame] | 66 | func (cf *RWCoreFlags) ParseCommandArguments(args []string) { |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 67 | |
David K. Bainbridge | 6080c17 | 2021-07-24 00:22:28 +0000 | [diff] [blame] | 68 | fs := flag.NewFlagSet(os.Args[0], flag.ExitOnError) |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 69 | |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 70 | fs.StringVar(&cf.GrpcNBIAddress, |
| 71 | "grpc_nbi_address", |
| 72 | ":50057", |
| 73 | "GRPC NBI server - address") |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 74 | |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 75 | fs.StringVar(&cf.GrpcSBIAddress, |
| 76 | "grpc_sbi_address", |
| 77 | ":50058", |
| 78 | "GRPC SBI server - address") |
khenaidoo | 5c11af7 | 2018-07-20 17:21:05 -0400 | [diff] [blame] | 79 | |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 80 | fs.StringVar(&cf.KafkaClusterAddress, |
| 81 | "kafka_cluster_address", |
| 82 | "127.0.0.1:9092", |
| 83 | "Kafka - Cluster messaging address") |
khenaidoo | 5c11af7 | 2018-07-20 17:21:05 -0400 | [diff] [blame] | 84 | |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 85 | fs.StringVar(&cf.EventTopic, |
| 86 | "event_topic", |
| 87 | "voltha.events", |
| 88 | "RW Core Event topic") |
khenaidoo | 5c11af7 | 2018-07-20 17:21:05 -0400 | [diff] [blame] | 89 | |
kesavand | 92fac10 | 2022-03-16 12:33:06 +0530 | [diff] [blame] | 90 | fs.IntVar(&cf.EventTopicPartitions, |
| 91 | "EventTopicPartitions", |
kesavand | 26b6a55 | 2022-04-13 16:57:19 +0530 | [diff] [blame^] | 92 | 1, |
kesavand | 92fac10 | 2022-03-16 12:33:06 +0530 | [diff] [blame] | 93 | "RW Core Event topic partitions") |
| 94 | |
| 95 | fs.IntVar(&cf.EventTopicReplicas, |
| 96 | "EventTopicReplicas", |
| 97 | 1, |
| 98 | "RW Core Event topic replicas") |
| 99 | |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 100 | fs.StringVar(&cf.KVStoreType, |
| 101 | "kv_store_type", |
| 102 | EtcdStoreName, |
| 103 | "KV store type") |
Himani Chawla | b4c2591 | 2020-11-12 17:16:38 +0530 | [diff] [blame] | 104 | |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 105 | fs.DurationVar(&cf.KVStoreTimeout, |
| 106 | "kv_store_request_timeout", |
| 107 | 5*time.Second, |
| 108 | "The default timeout when making a kv store request") |
khenaidoo | 7923270 | 2018-12-04 11:00:41 -0500 | [diff] [blame] | 109 | |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 110 | fs.StringVar(&cf.KVStoreAddress, |
| 111 | "kv_store_address", |
| 112 | "127.0.0.1:2379", |
| 113 | "KV store address") |
khenaidoo | 5c11af7 | 2018-07-20 17:21:05 -0400 | [diff] [blame] | 114 | |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 115 | fs.StringVar(&cf.LogLevel, |
| 116 | "log_level", |
| 117 | "warn", |
| 118 | "Log level") |
khenaidoo | 5c11af7 | 2018-07-20 17:21:05 -0400 | [diff] [blame] | 119 | |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 120 | fs.DurationVar(&(cf.InternalTimeout), |
| 121 | "internal_timeout", |
| 122 | 5*time.Second, |
| 123 | "Core internal timeout") |
khenaidoo | 5c11af7 | 2018-07-20 17:21:05 -0400 | [diff] [blame] | 124 | |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 125 | fs.DurationVar(&(cf.RPCTimeout), |
| 126 | "rpc_timeout", |
| 127 | 5*time.Second, |
| 128 | "RPC timeout") |
Richard Jankowski | e4d7766 | 2018-10-17 13:53:21 -0400 | [diff] [blame] | 129 | |
Himani Chawla | 4b4bd25 | 2021-11-08 15:59:40 +0530 | [diff] [blame] | 130 | fs.DurationVar(&(cf.FlowTimeout), //Note flow time out will be considered for flows related rpc's not rpc timeout |
| 131 | "flow_timeout", |
| 132 | 30*time.Second, |
| 133 | "Flow timeout") |
| 134 | |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 135 | fs.BoolVar(&cf.Banner, |
| 136 | "banner", |
| 137 | false, |
| 138 | "Show startup banner log lines") |
khenaidoo | 5c11af7 | 2018-07-20 17:21:05 -0400 | [diff] [blame] | 139 | |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 140 | fs.BoolVar(&cf.DisplayVersionOnly, |
| 141 | "version", |
| 142 | false, |
| 143 | "Show version information and exit") |
khenaidoo | b608032 | 2019-01-29 21:47:38 -0500 | [diff] [blame] | 144 | |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 145 | fs.IntVar(&cf.MaxConnectionRetries, |
| 146 | "max_connection_retries", |
| 147 | -1, |
| 148 | "The number of retries to connect to a dependent component") |
khenaidoo | b608032 | 2019-01-29 21:47:38 -0500 | [diff] [blame] | 149 | |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 150 | fs.DurationVar(&cf.ConnectionRetryInterval, |
| 151 | "connection_retry_interval", |
| 152 | 2*time.Second, |
| 153 | "The number of seconds between each connection retry attempt") |
khenaidoo | 2c6a099 | 2019-04-29 13:46:56 -0400 | [diff] [blame] | 154 | |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 155 | fs.DurationVar(&cf.LiveProbeInterval, |
| 156 | "live_probe_interval", |
| 157 | 60*time.Second, |
| 158 | "The number of seconds between liveness probes while in a live state") |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 159 | |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 160 | fs.DurationVar(&cf.NotLiveProbeInterval, |
| 161 | "not_live_probe_interval", |
| 162 | 5*time.Second, |
| 163 | "The number of seconds between liveness probes while in a not live state") |
David K. Bainbridge | f430cd5 | 2019-05-28 15:00:35 -0700 | [diff] [blame] | 164 | |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 165 | fs.StringVar(&cf.ProbeAddress, |
| 166 | "probe_address", |
| 167 | ":8080", |
| 168 | "The address on which to listen to answer liveness and readiness probe queries over HTTP") |
Richard Jankowski | 46464e9 | 2019-03-05 11:53:55 -0500 | [diff] [blame] | 169 | |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 170 | fs.BoolVar(&(cf.TraceEnabled), |
| 171 | "trace_enabled", |
| 172 | false, |
| 173 | "Whether to send logs to tracing agent?") |
khenaidoo | b324421 | 2019-08-27 14:32:27 -0400 | [diff] [blame] | 174 | |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 175 | fs.StringVar(&cf.TraceAgentAddress, |
| 176 | "trace_agent_address", |
| 177 | "127.0.0.1:6831", |
| 178 | "The address of tracing agent to which span info should be sent") |
khenaidoo | b324421 | 2019-08-27 14:32:27 -0400 | [diff] [blame] | 179 | |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 180 | fs.BoolVar(&cf.LogCorrelationEnabled, |
| 181 | "log_correlation_enabled", |
| 182 | true, |
| 183 | "Whether to enrich log statements with fields denoting operation being executed for achieving correlation?") |
Scott Baker | ee6a087 | 2019-10-29 15:59:52 -0700 | [diff] [blame] | 184 | |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 185 | fs.StringVar(&cf.VolthaStackID, |
| 186 | "stack_id", |
| 187 | "voltha", |
| 188 | "ID for the current voltha stack") |
Himani Chawla | 9cfc499 | 2021-03-22 12:43:01 +0530 | [diff] [blame] | 189 | |
David K. Bainbridge | 6080c17 | 2021-07-24 00:22:28 +0000 | [diff] [blame] | 190 | fs.DurationVar(&cf.BackoffRetryInitialInterval, |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 191 | "backoff_retry_initial_interval", |
| 192 | 500*time.Millisecond, |
David K. Bainbridge | 6080c17 | 2021-07-24 00:22:28 +0000 | [diff] [blame] | 193 | "The initial number of milliseconds an exponential backoff will wait before a retry") |
khenaidoo | 5e4fca3 | 2021-05-12 16:02:23 -0400 | [diff] [blame] | 194 | |
David K. Bainbridge | 6080c17 | 2021-07-24 00:22:28 +0000 | [diff] [blame] | 195 | fs.DurationVar(&cf.BackoffRetryMaxElapsedTime, |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 196 | "backoff_retry_max_elapsed_time", |
| 197 | 0*time.Second, |
David K. Bainbridge | 6080c17 | 2021-07-24 00:22:28 +0000 | [diff] [blame] | 198 | "The maximum number of milliseconds an exponential backoff can elasped") |
khenaidoo | 5e4fca3 | 2021-05-12 16:02:23 -0400 | [diff] [blame] | 199 | |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 200 | fs.DurationVar(&cf.BackoffRetryMaxInterval, |
| 201 | "backoff_retry_max_interval", |
| 202 | 1*time.Minute, |
| 203 | "The maximum number of milliseconds of an exponential backoff interval") |
khenaidoo | 5e4fca3 | 2021-05-12 16:02:23 -0400 | [diff] [blame] | 204 | |
David K. Bainbridge | 6080c17 | 2021-07-24 00:22:28 +0000 | [diff] [blame] | 205 | _ = fs.Parse(args) |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 206 | } |