blob: 1fe1940f9864eddbefe60e58a9f69345d0949842 [file] [log] [blame]
khenaidoobf6e7bb2018-08-14 22:27:29 -04001/*
Joey Armstrong5f51f2e2023-01-17 17:06:26 -05002 * Copyright 2018-2023 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 (
David K. Bainbridge6080c172021-07-24 00:22:28 +000027 EtcdStoreName = "etcd"
khenaidoocfee5f42018-07-19 22:47:38 -040028)
29
khenaidoo5c11af72018-07-20 17:21:05 -040030// RWCoreFlags represents the set of configurations used by the read-write core service
khenaidoocfee5f42018-07-19 22:47:38 -040031type RWCoreFlags struct {
32 // Command line parameters
khenaidood948f772021-08-11 17:49:24 -040033 GrpcNBIAddress string
34 GrpcSBIAddress string
khenaidoo5e4fca32021-05-12 16:02:23 -040035 KafkaClusterAddress string
36 KVStoreType string
37 KVStoreTimeout time.Duration
38 KVStoreAddress string
khenaidoo5e4fca32021-05-12 16:02:23 -040039 EventTopic string
kesavand92fac102022-03-16 12:33:06 +053040 EventTopicPartitions int
41 EventTopicReplicas int
khenaidoo5e4fca32021-05-12 16:02:23 -040042 LogLevel string
43 Banner bool
44 DisplayVersionOnly bool
45 RWCoreKey string
46 RWCoreCert string
47 RWCoreCA string
khenaidood948f772021-08-11 17:49:24 -040048 InternalTimeout time.Duration
49 RPCTimeout time.Duration
Himani Chawla4b4bd252021-11-08 15:59:40 +053050 FlowTimeout time.Duration
khenaidoo5e4fca32021-05-12 16:02:23 -040051 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
nikesh.krishnan0ded28d2023-06-28 12:36:32 +053063 PerRPCRetryTimeout time.Duration
64 MaxRetries uint
khenaidoocfee5f42018-07-19 22:47:38 -040065}
66
khenaidoo5c11af72018-07-20 17:21:05 -040067// ParseCommandArguments parses the arguments when running read-write core service
David K. Bainbridge6080c172021-07-24 00:22:28 +000068func (cf *RWCoreFlags) ParseCommandArguments(args []string) {
khenaidoocfee5f42018-07-19 22:47:38 -040069
David K. Bainbridge6080c172021-07-24 00:22:28 +000070 fs := flag.NewFlagSet(os.Args[0], flag.ExitOnError)
khenaidoocfee5f42018-07-19 22:47:38 -040071
khenaidood948f772021-08-11 17:49:24 -040072 fs.StringVar(&cf.GrpcNBIAddress,
73 "grpc_nbi_address",
74 ":50057",
75 "GRPC NBI server - address")
khenaidoocfee5f42018-07-19 22:47:38 -040076
khenaidood948f772021-08-11 17:49:24 -040077 fs.StringVar(&cf.GrpcSBIAddress,
78 "grpc_sbi_address",
79 ":50058",
80 "GRPC SBI server - address")
khenaidoo5c11af72018-07-20 17:21:05 -040081
khenaidood948f772021-08-11 17:49:24 -040082 fs.StringVar(&cf.KafkaClusterAddress,
83 "kafka_cluster_address",
84 "127.0.0.1:9092",
85 "Kafka - Cluster messaging address")
khenaidoo5c11af72018-07-20 17:21:05 -040086
khenaidood948f772021-08-11 17:49:24 -040087 fs.StringVar(&cf.EventTopic,
88 "event_topic",
89 "voltha.events",
90 "RW Core Event topic")
khenaidoo5c11af72018-07-20 17:21:05 -040091
kesavand92fac102022-03-16 12:33:06 +053092 fs.IntVar(&cf.EventTopicPartitions,
93 "EventTopicPartitions",
kesavand26b6a552022-04-13 16:57:19 +053094 1,
kesavand92fac102022-03-16 12:33:06 +053095 "RW Core Event topic partitions")
96
97 fs.IntVar(&cf.EventTopicReplicas,
98 "EventTopicReplicas",
99 1,
100 "RW Core Event topic replicas")
101
khenaidood948f772021-08-11 17:49:24 -0400102 fs.StringVar(&cf.KVStoreType,
103 "kv_store_type",
104 EtcdStoreName,
105 "KV store type")
Himani Chawlab4c25912020-11-12 17:16:38 +0530106
khenaidood948f772021-08-11 17:49:24 -0400107 fs.DurationVar(&cf.KVStoreTimeout,
108 "kv_store_request_timeout",
109 5*time.Second,
110 "The default timeout when making a kv store request")
khenaidoo79232702018-12-04 11:00:41 -0500111
khenaidood948f772021-08-11 17:49:24 -0400112 fs.StringVar(&cf.KVStoreAddress,
113 "kv_store_address",
114 "127.0.0.1:2379",
115 "KV store address")
khenaidoo5c11af72018-07-20 17:21:05 -0400116
khenaidood948f772021-08-11 17:49:24 -0400117 fs.StringVar(&cf.LogLevel,
118 "log_level",
119 "warn",
120 "Log level")
khenaidoo5c11af72018-07-20 17:21:05 -0400121
khenaidood948f772021-08-11 17:49:24 -0400122 fs.DurationVar(&(cf.InternalTimeout),
123 "internal_timeout",
124 5*time.Second,
125 "Core internal timeout")
khenaidoo5c11af72018-07-20 17:21:05 -0400126
khenaidood948f772021-08-11 17:49:24 -0400127 fs.DurationVar(&(cf.RPCTimeout),
128 "rpc_timeout",
129 5*time.Second,
130 "RPC timeout")
Richard Jankowskie4d77662018-10-17 13:53:21 -0400131
Himani Chawla4b4bd252021-11-08 15:59:40 +0530132 fs.DurationVar(&(cf.FlowTimeout), //Note flow time out will be considered for flows related rpc's not rpc timeout
133 "flow_timeout",
134 30*time.Second,
135 "Flow timeout")
136
khenaidood948f772021-08-11 17:49:24 -0400137 fs.BoolVar(&cf.Banner,
138 "banner",
139 false,
140 "Show startup banner log lines")
khenaidoo5c11af72018-07-20 17:21:05 -0400141
khenaidood948f772021-08-11 17:49:24 -0400142 fs.BoolVar(&cf.DisplayVersionOnly,
143 "version",
144 false,
145 "Show version information and exit")
khenaidoob6080322019-01-29 21:47:38 -0500146
khenaidood948f772021-08-11 17:49:24 -0400147 fs.IntVar(&cf.MaxConnectionRetries,
148 "max_connection_retries",
149 -1,
150 "The number of retries to connect to a dependent component")
khenaidoob6080322019-01-29 21:47:38 -0500151
khenaidood948f772021-08-11 17:49:24 -0400152 fs.DurationVar(&cf.ConnectionRetryInterval,
153 "connection_retry_interval",
154 2*time.Second,
155 "The number of seconds between each connection retry attempt")
khenaidoo2c6a0992019-04-29 13:46:56 -0400156
khenaidood948f772021-08-11 17:49:24 -0400157 fs.DurationVar(&cf.LiveProbeInterval,
158 "live_probe_interval",
159 60*time.Second,
160 "The number of seconds between liveness probes while in a live state")
khenaidoocfee5f42018-07-19 22:47:38 -0400161
khenaidood948f772021-08-11 17:49:24 -0400162 fs.DurationVar(&cf.NotLiveProbeInterval,
163 "not_live_probe_interval",
164 5*time.Second,
165 "The number of seconds between liveness probes while in a not live state")
David K. Bainbridgef430cd52019-05-28 15:00:35 -0700166
khenaidood948f772021-08-11 17:49:24 -0400167 fs.StringVar(&cf.ProbeAddress,
168 "probe_address",
169 ":8080",
170 "The address on which to listen to answer liveness and readiness probe queries over HTTP")
Richard Jankowski46464e92019-03-05 11:53:55 -0500171
khenaidood948f772021-08-11 17:49:24 -0400172 fs.BoolVar(&(cf.TraceEnabled),
173 "trace_enabled",
174 false,
175 "Whether to send logs to tracing agent?")
khenaidoob3244212019-08-27 14:32:27 -0400176
khenaidood948f772021-08-11 17:49:24 -0400177 fs.StringVar(&cf.TraceAgentAddress,
178 "trace_agent_address",
179 "127.0.0.1:6831",
180 "The address of tracing agent to which span info should be sent")
khenaidoob3244212019-08-27 14:32:27 -0400181
khenaidood948f772021-08-11 17:49:24 -0400182 fs.BoolVar(&cf.LogCorrelationEnabled,
183 "log_correlation_enabled",
184 true,
185 "Whether to enrich log statements with fields denoting operation being executed for achieving correlation?")
Scott Bakeree6a0872019-10-29 15:59:52 -0700186
khenaidood948f772021-08-11 17:49:24 -0400187 fs.StringVar(&cf.VolthaStackID,
188 "stack_id",
189 "voltha",
190 "ID for the current voltha stack")
Himani Chawla9cfc4992021-03-22 12:43:01 +0530191
David K. Bainbridge6080c172021-07-24 00:22:28 +0000192 fs.DurationVar(&cf.BackoffRetryInitialInterval,
khenaidood948f772021-08-11 17:49:24 -0400193 "backoff_retry_initial_interval",
194 500*time.Millisecond,
David K. Bainbridge6080c172021-07-24 00:22:28 +0000195 "The initial number of milliseconds an exponential backoff will wait before a retry")
khenaidoo5e4fca32021-05-12 16:02:23 -0400196
David K. Bainbridge6080c172021-07-24 00:22:28 +0000197 fs.DurationVar(&cf.BackoffRetryMaxElapsedTime,
khenaidood948f772021-08-11 17:49:24 -0400198 "backoff_retry_max_elapsed_time",
199 0*time.Second,
David K. Bainbridge6080c172021-07-24 00:22:28 +0000200 "The maximum number of milliseconds an exponential backoff can elasped")
khenaidoo5e4fca32021-05-12 16:02:23 -0400201
khenaidood948f772021-08-11 17:49:24 -0400202 fs.DurationVar(&cf.BackoffRetryMaxInterval,
203 "backoff_retry_max_interval",
204 1*time.Minute,
205 "The maximum number of milliseconds of an exponential backoff interval")
nikesh.krishnan0ded28d2023-06-28 12:36:32 +0530206 fs.DurationVar(&cf.PerRPCRetryTimeout,
207 "per_rpc_retry_timeout",
208 0*time.Second,
209 "The default timeout per RPC retry")
210 fs.UintVar(&cf.MaxRetries,
211 "max_grpc_client_retry",
212 0,
213 "The maximum number of times olt adaptor will retry in case grpc request timeouts")
David K. Bainbridge6080c172021-07-24 00:22:28 +0000214 _ = fs.Parse(args)
khenaidoocfee5f42018-07-19 22:47:38 -0400215}