blob: 4356f1f1a7a8fd663f84cc61713bbce3abde6909 [file] [log] [blame]
khenaidoobf6e7bb2018-08-14 22:27:29 -04001/*
Joey Armstrong7a9af442024-01-03 19:26:36 -05002 * Copyright 2018-2024 Open Networking Foundation (ONF) and the ONF Contributors
khenaidoobf6e7bb2018-08-14 22:27:29 -04003
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 */
npujar1d86a522019-11-14 17:11:16 +053016
khenaidoocfee5f42018-07-19 22:47:38 -040017package config
18
19import (
khenaidoocfee5f42018-07-19 22:47:38 -040020 "flag"
David K. Bainbridge6080c172021-07-24 00:22:28 +000021 "os"
Girish Kumar4d3887d2019-11-22 14:22:05 +000022 "time"
khenaidoocfee5f42018-07-19 22:47:38 -040023)
24
khenaidoo5c11af72018-07-20 17:21:05 -040025// RW Core service default constants
khenaidoocfee5f42018-07-19 22:47:38 -040026const (
akashreddykc199cd12025-09-16 16:52:07 +053027 KVStoreName = "etcd"
28 defaultProducerRetryMax = 10
29 defaultMetadataRetryMax = 15
khenaidoocfee5f42018-07-19 22:47:38 -040030)
31
khenaidoo5c11af72018-07-20 17:21:05 -040032// RWCoreFlags represents the set of configurations used by the read-write core service
khenaidoocfee5f42018-07-19 22:47:38 -040033type RWCoreFlags struct {
34 // Command line parameters
khenaidood948f772021-08-11 17:49:24 -040035 GrpcNBIAddress string
36 GrpcSBIAddress string
khenaidoo5e4fca32021-05-12 16:02:23 -040037 KafkaClusterAddress string
38 KVStoreType string
khenaidoo5e4fca32021-05-12 16:02:23 -040039 KVStoreAddress string
khenaidoo5e4fca32021-05-12 16:02:23 -040040 EventTopic string
41 LogLevel string
khenaidoo5e4fca32021-05-12 16:02:23 -040042 RWCoreKey string
43 RWCoreCert string
44 RWCoreCA string
Akash Reddy Kankanala929cc002025-04-08 15:05:21 +053045 ProbeAddress string
46 TraceAgentAddress string
47 VolthaStackID string
48 KVStoreTimeout time.Duration
49 EventTopicPartitions int
50 EventTopicReplicas int
khenaidood948f772021-08-11 17:49:24 -040051 InternalTimeout time.Duration
52 RPCTimeout time.Duration
Himani Chawla4b4bd252021-11-08 15:59:40 +053053 FlowTimeout time.Duration
khenaidoo5e4fca32021-05-12 16:02:23 -040054 MaxConnectionRetries int
55 ConnectionRetryInterval time.Duration
56 LiveProbeInterval time.Duration
57 NotLiveProbeInterval time.Duration
khenaidoo5e4fca32021-05-12 16:02:23 -040058 BackoffRetryInitialInterval time.Duration
59 BackoffRetryMaxElapsedTime time.Duration
60 BackoffRetryMaxInterval time.Duration
nikesh.krishnan0ded28d2023-06-28 12:36:32 +053061 PerRPCRetryTimeout time.Duration
62 MaxRetries uint
Akash Reddy Kankanala929cc002025-04-08 15:05:21 +053063 Banner bool
64 DisplayVersionOnly bool
65 TraceEnabled bool
66 LogCorrelationEnabled bool
akashreddykc199cd12025-09-16 16:52:07 +053067 ProducerRetryMax int
68 MetadataRetryMax int
khenaidoocfee5f42018-07-19 22:47:38 -040069}
70
khenaidoo5c11af72018-07-20 17:21:05 -040071// ParseCommandArguments parses the arguments when running read-write core service
David K. Bainbridge6080c172021-07-24 00:22:28 +000072func (cf *RWCoreFlags) ParseCommandArguments(args []string) {
khenaidoocfee5f42018-07-19 22:47:38 -040073
David K. Bainbridge6080c172021-07-24 00:22:28 +000074 fs := flag.NewFlagSet(os.Args[0], flag.ExitOnError)
khenaidoocfee5f42018-07-19 22:47:38 -040075
khenaidood948f772021-08-11 17:49:24 -040076 fs.StringVar(&cf.GrpcNBIAddress,
77 "grpc_nbi_address",
78 ":50057",
79 "GRPC NBI server - address")
khenaidoocfee5f42018-07-19 22:47:38 -040080
khenaidood948f772021-08-11 17:49:24 -040081 fs.StringVar(&cf.GrpcSBIAddress,
82 "grpc_sbi_address",
83 ":50058",
84 "GRPC SBI server - address")
khenaidoo5c11af72018-07-20 17:21:05 -040085
khenaidood948f772021-08-11 17:49:24 -040086 fs.StringVar(&cf.KafkaClusterAddress,
87 "kafka_cluster_address",
88 "127.0.0.1:9092",
89 "Kafka - Cluster messaging address")
khenaidoo5c11af72018-07-20 17:21:05 -040090
khenaidood948f772021-08-11 17:49:24 -040091 fs.StringVar(&cf.EventTopic,
92 "event_topic",
93 "voltha.events",
94 "RW Core Event topic")
khenaidoo5c11af72018-07-20 17:21:05 -040095
kesavand92fac102022-03-16 12:33:06 +053096 fs.IntVar(&cf.EventTopicPartitions,
97 "EventTopicPartitions",
kesavand26b6a552022-04-13 16:57:19 +053098 1,
kesavand92fac102022-03-16 12:33:06 +053099 "RW Core Event topic partitions")
100
101 fs.IntVar(&cf.EventTopicReplicas,
102 "EventTopicReplicas",
103 1,
104 "RW Core Event topic replicas")
105
khenaidood948f772021-08-11 17:49:24 -0400106 fs.StringVar(&cf.KVStoreType,
107 "kv_store_type",
Abhay Kumar4e0f37b2024-07-12 09:33:01 +0530108 KVStoreName,
khenaidood948f772021-08-11 17:49:24 -0400109 "KV store type")
Himani Chawlab4c25912020-11-12 17:16:38 +0530110
khenaidood948f772021-08-11 17:49:24 -0400111 fs.DurationVar(&cf.KVStoreTimeout,
112 "kv_store_request_timeout",
113 5*time.Second,
114 "The default timeout when making a kv store request")
khenaidoo79232702018-12-04 11:00:41 -0500115
khenaidood948f772021-08-11 17:49:24 -0400116 fs.StringVar(&cf.KVStoreAddress,
117 "kv_store_address",
118 "127.0.0.1:2379",
119 "KV store address")
khenaidoo5c11af72018-07-20 17:21:05 -0400120
khenaidood948f772021-08-11 17:49:24 -0400121 fs.StringVar(&cf.LogLevel,
122 "log_level",
123 "warn",
124 "Log level")
khenaidoo5c11af72018-07-20 17:21:05 -0400125
khenaidood948f772021-08-11 17:49:24 -0400126 fs.DurationVar(&(cf.InternalTimeout),
127 "internal_timeout",
128 5*time.Second,
129 "Core internal timeout")
khenaidoo5c11af72018-07-20 17:21:05 -0400130
khenaidood948f772021-08-11 17:49:24 -0400131 fs.DurationVar(&(cf.RPCTimeout),
132 "rpc_timeout",
133 5*time.Second,
134 "RPC timeout")
Richard Jankowskie4d77662018-10-17 13:53:21 -0400135
Akash Reddy Kankanala929cc002025-04-08 15:05:21 +0530136 fs.DurationVar(&(cf.FlowTimeout), // Note flow time out will be considered for flows related rpc's not rpc timeout
Himani Chawla4b4bd252021-11-08 15:59:40 +0530137 "flow_timeout",
138 30*time.Second,
139 "Flow timeout")
140
khenaidood948f772021-08-11 17:49:24 -0400141 fs.BoolVar(&cf.Banner,
142 "banner",
143 false,
144 "Show startup banner log lines")
khenaidoo5c11af72018-07-20 17:21:05 -0400145
khenaidood948f772021-08-11 17:49:24 -0400146 fs.BoolVar(&cf.DisplayVersionOnly,
147 "version",
148 false,
149 "Show version information and exit")
khenaidoob6080322019-01-29 21:47:38 -0500150
khenaidood948f772021-08-11 17:49:24 -0400151 fs.IntVar(&cf.MaxConnectionRetries,
152 "max_connection_retries",
153 -1,
154 "The number of retries to connect to a dependent component")
khenaidoob6080322019-01-29 21:47:38 -0500155
khenaidood948f772021-08-11 17:49:24 -0400156 fs.DurationVar(&cf.ConnectionRetryInterval,
157 "connection_retry_interval",
158 2*time.Second,
159 "The number of seconds between each connection retry attempt")
khenaidoo2c6a0992019-04-29 13:46:56 -0400160
khenaidood948f772021-08-11 17:49:24 -0400161 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")
khenaidoocfee5f42018-07-19 22:47:38 -0400165
khenaidood948f772021-08-11 17:49:24 -0400166 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. Bainbridgef430cd52019-05-28 15:00:35 -0700170
khenaidood948f772021-08-11 17:49:24 -0400171 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 Jankowski46464e92019-03-05 11:53:55 -0500175
khenaidood948f772021-08-11 17:49:24 -0400176 fs.BoolVar(&(cf.TraceEnabled),
177 "trace_enabled",
178 false,
179 "Whether to send logs to tracing agent?")
khenaidoob3244212019-08-27 14:32:27 -0400180
khenaidood948f772021-08-11 17:49:24 -0400181 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")
khenaidoob3244212019-08-27 14:32:27 -0400185
khenaidood948f772021-08-11 17:49:24 -0400186 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 Bakeree6a0872019-10-29 15:59:52 -0700190
khenaidood948f772021-08-11 17:49:24 -0400191 fs.StringVar(&cf.VolthaStackID,
192 "stack_id",
193 "voltha",
194 "ID for the current voltha stack")
Himani Chawla9cfc4992021-03-22 12:43:01 +0530195
David K. Bainbridge6080c172021-07-24 00:22:28 +0000196 fs.DurationVar(&cf.BackoffRetryInitialInterval,
khenaidood948f772021-08-11 17:49:24 -0400197 "backoff_retry_initial_interval",
198 500*time.Millisecond,
David K. Bainbridge6080c172021-07-24 00:22:28 +0000199 "The initial number of milliseconds an exponential backoff will wait before a retry")
khenaidoo5e4fca32021-05-12 16:02:23 -0400200
David K. Bainbridge6080c172021-07-24 00:22:28 +0000201 fs.DurationVar(&cf.BackoffRetryMaxElapsedTime,
khenaidood948f772021-08-11 17:49:24 -0400202 "backoff_retry_max_elapsed_time",
203 0*time.Second,
Akash Reddy Kankanala929cc002025-04-08 15:05:21 +0530204 "The maximum number of milliseconds an exponential backoff can elapsed")
khenaidoo5e4fca32021-05-12 16:02:23 -0400205
khenaidood948f772021-08-11 17:49:24 -0400206 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.krishnan0ded28d2023-06-28 12:36:32 +0530210 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")
akashreddykc199cd12025-09-16 16:52:07 +0530218 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. Bainbridge6080c172021-07-24 00:22:28 +0000226 _ = fs.Parse(args)
khenaidoocfee5f42018-07-19 22:47:38 -0400227}