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