blob: 13cfabcbb191008c4d7584edbd076d3b6a080d1b [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
Abhay Kumar0b343192025-12-09 08:33:36 +000046 PrometheusAddress string
Akash Reddy Kankanala929cc002025-04-08 15:05:21 +053047 TraceAgentAddress string
48 VolthaStackID string
49 KVStoreTimeout time.Duration
50 EventTopicPartitions int
51 EventTopicReplicas int
khenaidood948f772021-08-11 17:49:24 -040052 InternalTimeout time.Duration
53 RPCTimeout time.Duration
Himani Chawla4b4bd252021-11-08 15:59:40 +053054 FlowTimeout time.Duration
khenaidoo5e4fca32021-05-12 16:02:23 -040055 MaxConnectionRetries int
56 ConnectionRetryInterval time.Duration
57 LiveProbeInterval time.Duration
58 NotLiveProbeInterval time.Duration
khenaidoo5e4fca32021-05-12 16:02:23 -040059 BackoffRetryInitialInterval time.Duration
60 BackoffRetryMaxElapsedTime time.Duration
61 BackoffRetryMaxInterval time.Duration
nikesh.krishnan0ded28d2023-06-28 12:36:32 +053062 PerRPCRetryTimeout time.Duration
63 MaxRetries uint
Akash Reddy Kankanala929cc002025-04-08 15:05:21 +053064 Banner bool
65 DisplayVersionOnly bool
66 TraceEnabled bool
67 LogCorrelationEnabled bool
akashreddykc199cd12025-09-16 16:52:07 +053068 ProducerRetryMax int
69 MetadataRetryMax int
khenaidoocfee5f42018-07-19 22:47:38 -040070}
71
khenaidoo5c11af72018-07-20 17:21:05 -040072// ParseCommandArguments parses the arguments when running read-write core service
David K. Bainbridge6080c172021-07-24 00:22:28 +000073func (cf *RWCoreFlags) ParseCommandArguments(args []string) {
khenaidoocfee5f42018-07-19 22:47:38 -040074
David K. Bainbridge6080c172021-07-24 00:22:28 +000075 fs := flag.NewFlagSet(os.Args[0], flag.ExitOnError)
khenaidoocfee5f42018-07-19 22:47:38 -040076
khenaidood948f772021-08-11 17:49:24 -040077 fs.StringVar(&cf.GrpcNBIAddress,
78 "grpc_nbi_address",
79 ":50057",
80 "GRPC NBI server - address")
khenaidoocfee5f42018-07-19 22:47:38 -040081
khenaidood948f772021-08-11 17:49:24 -040082 fs.StringVar(&cf.GrpcSBIAddress,
83 "grpc_sbi_address",
84 ":50058",
85 "GRPC SBI server - address")
khenaidoo5c11af72018-07-20 17:21:05 -040086
khenaidood948f772021-08-11 17:49:24 -040087 fs.StringVar(&cf.KafkaClusterAddress,
88 "kafka_cluster_address",
89 "127.0.0.1:9092",
90 "Kafka - Cluster messaging address")
khenaidoo5c11af72018-07-20 17:21:05 -040091
khenaidood948f772021-08-11 17:49:24 -040092 fs.StringVar(&cf.EventTopic,
93 "event_topic",
94 "voltha.events",
95 "RW Core Event topic")
khenaidoo5c11af72018-07-20 17:21:05 -040096
kesavand92fac102022-03-16 12:33:06 +053097 fs.IntVar(&cf.EventTopicPartitions,
98 "EventTopicPartitions",
kesavand26b6a552022-04-13 16:57:19 +053099 1,
kesavand92fac102022-03-16 12:33:06 +0530100 "RW Core Event topic partitions")
101
102 fs.IntVar(&cf.EventTopicReplicas,
103 "EventTopicReplicas",
104 1,
105 "RW Core Event topic replicas")
106
khenaidood948f772021-08-11 17:49:24 -0400107 fs.StringVar(&cf.KVStoreType,
108 "kv_store_type",
Abhay Kumar4e0f37b2024-07-12 09:33:01 +0530109 KVStoreName,
khenaidood948f772021-08-11 17:49:24 -0400110 "KV store type")
Himani Chawlab4c25912020-11-12 17:16:38 +0530111
khenaidood948f772021-08-11 17:49:24 -0400112 fs.DurationVar(&cf.KVStoreTimeout,
113 "kv_store_request_timeout",
114 5*time.Second,
115 "The default timeout when making a kv store request")
khenaidoo79232702018-12-04 11:00:41 -0500116
khenaidood948f772021-08-11 17:49:24 -0400117 fs.StringVar(&cf.KVStoreAddress,
118 "kv_store_address",
119 "127.0.0.1:2379",
120 "KV store address")
khenaidoo5c11af72018-07-20 17:21:05 -0400121
khenaidood948f772021-08-11 17:49:24 -0400122 fs.StringVar(&cf.LogLevel,
123 "log_level",
124 "warn",
125 "Log level")
khenaidoo5c11af72018-07-20 17:21:05 -0400126
khenaidood948f772021-08-11 17:49:24 -0400127 fs.DurationVar(&(cf.InternalTimeout),
128 "internal_timeout",
129 5*time.Second,
130 "Core internal timeout")
khenaidoo5c11af72018-07-20 17:21:05 -0400131
khenaidood948f772021-08-11 17:49:24 -0400132 fs.DurationVar(&(cf.RPCTimeout),
133 "rpc_timeout",
134 5*time.Second,
135 "RPC timeout")
Richard Jankowskie4d77662018-10-17 13:53:21 -0400136
Akash Reddy Kankanala929cc002025-04-08 15:05:21 +0530137 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 +0530138 "flow_timeout",
139 30*time.Second,
140 "Flow timeout")
141
khenaidood948f772021-08-11 17:49:24 -0400142 fs.BoolVar(&cf.Banner,
143 "banner",
144 false,
145 "Show startup banner log lines")
khenaidoo5c11af72018-07-20 17:21:05 -0400146
khenaidood948f772021-08-11 17:49:24 -0400147 fs.BoolVar(&cf.DisplayVersionOnly,
148 "version",
149 false,
150 "Show version information and exit")
khenaidoob6080322019-01-29 21:47:38 -0500151
khenaidood948f772021-08-11 17:49:24 -0400152 fs.IntVar(&cf.MaxConnectionRetries,
153 "max_connection_retries",
154 -1,
155 "The number of retries to connect to a dependent component")
khenaidoob6080322019-01-29 21:47:38 -0500156
khenaidood948f772021-08-11 17:49:24 -0400157 fs.DurationVar(&cf.ConnectionRetryInterval,
158 "connection_retry_interval",
159 2*time.Second,
160 "The number of seconds between each connection retry attempt")
khenaidoo2c6a0992019-04-29 13:46:56 -0400161
khenaidood948f772021-08-11 17:49:24 -0400162 fs.DurationVar(&cf.LiveProbeInterval,
163 "live_probe_interval",
164 60*time.Second,
165 "The number of seconds between liveness probes while in a live state")
khenaidoocfee5f42018-07-19 22:47:38 -0400166
khenaidood948f772021-08-11 17:49:24 -0400167 fs.DurationVar(&cf.NotLiveProbeInterval,
168 "not_live_probe_interval",
169 5*time.Second,
170 "The number of seconds between liveness probes while in a not live state")
David K. Bainbridgef430cd52019-05-28 15:00:35 -0700171
khenaidood948f772021-08-11 17:49:24 -0400172 fs.StringVar(&cf.ProbeAddress,
173 "probe_address",
174 ":8080",
175 "The address on which to listen to answer liveness and readiness probe queries over HTTP")
Richard Jankowski46464e92019-03-05 11:53:55 -0500176
Abhay Kumar0b343192025-12-09 08:33:36 +0000177 fs.StringVar(&cf.PrometheusAddress,
178 "prometheus_address",
179 ":8081",
180 "Used for exposing the metrics to prometheus")
181
khenaidood948f772021-08-11 17:49:24 -0400182 fs.BoolVar(&(cf.TraceEnabled),
183 "trace_enabled",
184 false,
185 "Whether to send logs to tracing agent?")
khenaidoob3244212019-08-27 14:32:27 -0400186
khenaidood948f772021-08-11 17:49:24 -0400187 fs.StringVar(&cf.TraceAgentAddress,
188 "trace_agent_address",
189 "127.0.0.1:6831",
190 "The address of tracing agent to which span info should be sent")
khenaidoob3244212019-08-27 14:32:27 -0400191
khenaidood948f772021-08-11 17:49:24 -0400192 fs.BoolVar(&cf.LogCorrelationEnabled,
193 "log_correlation_enabled",
194 true,
195 "Whether to enrich log statements with fields denoting operation being executed for achieving correlation?")
Scott Bakeree6a0872019-10-29 15:59:52 -0700196
khenaidood948f772021-08-11 17:49:24 -0400197 fs.StringVar(&cf.VolthaStackID,
198 "stack_id",
199 "voltha",
200 "ID for the current voltha stack")
Himani Chawla9cfc4992021-03-22 12:43:01 +0530201
David K. Bainbridge6080c172021-07-24 00:22:28 +0000202 fs.DurationVar(&cf.BackoffRetryInitialInterval,
khenaidood948f772021-08-11 17:49:24 -0400203 "backoff_retry_initial_interval",
204 500*time.Millisecond,
David K. Bainbridge6080c172021-07-24 00:22:28 +0000205 "The initial number of milliseconds an exponential backoff will wait before a retry")
khenaidoo5e4fca32021-05-12 16:02:23 -0400206
David K. Bainbridge6080c172021-07-24 00:22:28 +0000207 fs.DurationVar(&cf.BackoffRetryMaxElapsedTime,
khenaidood948f772021-08-11 17:49:24 -0400208 "backoff_retry_max_elapsed_time",
209 0*time.Second,
Akash Reddy Kankanala929cc002025-04-08 15:05:21 +0530210 "The maximum number of milliseconds an exponential backoff can elapsed")
khenaidoo5e4fca32021-05-12 16:02:23 -0400211
khenaidood948f772021-08-11 17:49:24 -0400212 fs.DurationVar(&cf.BackoffRetryMaxInterval,
213 "backoff_retry_max_interval",
214 1*time.Minute,
215 "The maximum number of milliseconds of an exponential backoff interval")
nikesh.krishnan0ded28d2023-06-28 12:36:32 +0530216 fs.DurationVar(&cf.PerRPCRetryTimeout,
217 "per_rpc_retry_timeout",
218 0*time.Second,
219 "The default timeout per RPC retry")
220 fs.UintVar(&cf.MaxRetries,
221 "max_grpc_client_retry",
222 0,
223 "The maximum number of times olt adaptor will retry in case grpc request timeouts")
akashreddykc199cd12025-09-16 16:52:07 +0530224 fs.IntVar(&cf.ProducerRetryMax,
225 "producer_retry_max",
226 defaultProducerRetryMax,
227 "This option specifies the maximum number of times the producer will retry sending messages before giving up")
228 fs.IntVar(&cf.MetadataRetryMax,
229 "metadata_retry_max",
230 defaultMetadataRetryMax,
231 "This option specifies the maximum number of times retry to receive messages before giving up")
David K. Bainbridge6080c172021-07-24 00:22:28 +0000232 _ = fs.Parse(args)
khenaidoocfee5f42018-07-19 22:47:38 -0400233}