blob: c928a841b44b74bd70f5fb1b108cc08bd3f65aef [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
khenaidoocfee5f42018-07-19 22:47:38 -040063}
64
khenaidoo5c11af72018-07-20 17:21:05 -040065// ParseCommandArguments parses the arguments when running read-write core service
David K. Bainbridge6080c172021-07-24 00:22:28 +000066func (cf *RWCoreFlags) ParseCommandArguments(args []string) {
khenaidoocfee5f42018-07-19 22:47:38 -040067
David K. Bainbridge6080c172021-07-24 00:22:28 +000068 fs := flag.NewFlagSet(os.Args[0], flag.ExitOnError)
khenaidoocfee5f42018-07-19 22:47:38 -040069
khenaidood948f772021-08-11 17:49:24 -040070 fs.StringVar(&cf.GrpcNBIAddress,
71 "grpc_nbi_address",
72 ":50057",
73 "GRPC NBI server - address")
khenaidoocfee5f42018-07-19 22:47:38 -040074
khenaidood948f772021-08-11 17:49:24 -040075 fs.StringVar(&cf.GrpcSBIAddress,
76 "grpc_sbi_address",
77 ":50058",
78 "GRPC SBI server - address")
khenaidoo5c11af72018-07-20 17:21:05 -040079
khenaidood948f772021-08-11 17:49:24 -040080 fs.StringVar(&cf.KafkaClusterAddress,
81 "kafka_cluster_address",
82 "127.0.0.1:9092",
83 "Kafka - Cluster messaging address")
khenaidoo5c11af72018-07-20 17:21:05 -040084
khenaidood948f772021-08-11 17:49:24 -040085 fs.StringVar(&cf.EventTopic,
86 "event_topic",
87 "voltha.events",
88 "RW Core Event topic")
khenaidoo5c11af72018-07-20 17:21:05 -040089
kesavand92fac102022-03-16 12:33:06 +053090 fs.IntVar(&cf.EventTopicPartitions,
91 "EventTopicPartitions",
kesavand26b6a552022-04-13 16:57:19 +053092 1,
kesavand92fac102022-03-16 12:33:06 +053093 "RW Core Event topic partitions")
94
95 fs.IntVar(&cf.EventTopicReplicas,
96 "EventTopicReplicas",
97 1,
98 "RW Core Event topic replicas")
99
khenaidood948f772021-08-11 17:49:24 -0400100 fs.StringVar(&cf.KVStoreType,
101 "kv_store_type",
102 EtcdStoreName,
103 "KV store type")
Himani Chawlab4c25912020-11-12 17:16:38 +0530104
khenaidood948f772021-08-11 17:49:24 -0400105 fs.DurationVar(&cf.KVStoreTimeout,
106 "kv_store_request_timeout",
107 5*time.Second,
108 "The default timeout when making a kv store request")
khenaidoo79232702018-12-04 11:00:41 -0500109
khenaidood948f772021-08-11 17:49:24 -0400110 fs.StringVar(&cf.KVStoreAddress,
111 "kv_store_address",
112 "127.0.0.1:2379",
113 "KV store address")
khenaidoo5c11af72018-07-20 17:21:05 -0400114
khenaidood948f772021-08-11 17:49:24 -0400115 fs.StringVar(&cf.LogLevel,
116 "log_level",
117 "warn",
118 "Log level")
khenaidoo5c11af72018-07-20 17:21:05 -0400119
khenaidood948f772021-08-11 17:49:24 -0400120 fs.DurationVar(&(cf.InternalTimeout),
121 "internal_timeout",
122 5*time.Second,
123 "Core internal timeout")
khenaidoo5c11af72018-07-20 17:21:05 -0400124
khenaidood948f772021-08-11 17:49:24 -0400125 fs.DurationVar(&(cf.RPCTimeout),
126 "rpc_timeout",
127 5*time.Second,
128 "RPC timeout")
Richard Jankowskie4d77662018-10-17 13:53:21 -0400129
Himani Chawla4b4bd252021-11-08 15:59:40 +0530130 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
khenaidood948f772021-08-11 17:49:24 -0400135 fs.BoolVar(&cf.Banner,
136 "banner",
137 false,
138 "Show startup banner log lines")
khenaidoo5c11af72018-07-20 17:21:05 -0400139
khenaidood948f772021-08-11 17:49:24 -0400140 fs.BoolVar(&cf.DisplayVersionOnly,
141 "version",
142 false,
143 "Show version information and exit")
khenaidoob6080322019-01-29 21:47:38 -0500144
khenaidood948f772021-08-11 17:49:24 -0400145 fs.IntVar(&cf.MaxConnectionRetries,
146 "max_connection_retries",
147 -1,
148 "The number of retries to connect to a dependent component")
khenaidoob6080322019-01-29 21:47:38 -0500149
khenaidood948f772021-08-11 17:49:24 -0400150 fs.DurationVar(&cf.ConnectionRetryInterval,
151 "connection_retry_interval",
152 2*time.Second,
153 "The number of seconds between each connection retry attempt")
khenaidoo2c6a0992019-04-29 13:46:56 -0400154
khenaidood948f772021-08-11 17:49:24 -0400155 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")
khenaidoocfee5f42018-07-19 22:47:38 -0400159
khenaidood948f772021-08-11 17:49:24 -0400160 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. Bainbridgef430cd52019-05-28 15:00:35 -0700164
khenaidood948f772021-08-11 17:49:24 -0400165 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 Jankowski46464e92019-03-05 11:53:55 -0500169
khenaidood948f772021-08-11 17:49:24 -0400170 fs.BoolVar(&(cf.TraceEnabled),
171 "trace_enabled",
172 false,
173 "Whether to send logs to tracing agent?")
khenaidoob3244212019-08-27 14:32:27 -0400174
khenaidood948f772021-08-11 17:49:24 -0400175 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")
khenaidoob3244212019-08-27 14:32:27 -0400179
khenaidood948f772021-08-11 17:49:24 -0400180 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 Bakeree6a0872019-10-29 15:59:52 -0700184
khenaidood948f772021-08-11 17:49:24 -0400185 fs.StringVar(&cf.VolthaStackID,
186 "stack_id",
187 "voltha",
188 "ID for the current voltha stack")
Himani Chawla9cfc4992021-03-22 12:43:01 +0530189
David K. Bainbridge6080c172021-07-24 00:22:28 +0000190 fs.DurationVar(&cf.BackoffRetryInitialInterval,
khenaidood948f772021-08-11 17:49:24 -0400191 "backoff_retry_initial_interval",
192 500*time.Millisecond,
David K. Bainbridge6080c172021-07-24 00:22:28 +0000193 "The initial number of milliseconds an exponential backoff will wait before a retry")
khenaidoo5e4fca32021-05-12 16:02:23 -0400194
David K. Bainbridge6080c172021-07-24 00:22:28 +0000195 fs.DurationVar(&cf.BackoffRetryMaxElapsedTime,
khenaidood948f772021-08-11 17:49:24 -0400196 "backoff_retry_max_elapsed_time",
197 0*time.Second,
David K. Bainbridge6080c172021-07-24 00:22:28 +0000198 "The maximum number of milliseconds an exponential backoff can elasped")
khenaidoo5e4fca32021-05-12 16:02:23 -0400199
khenaidood948f772021-08-11 17:49:24 -0400200 fs.DurationVar(&cf.BackoffRetryMaxInterval,
201 "backoff_retry_max_interval",
202 1*time.Minute,
203 "The maximum number of milliseconds of an exponential backoff interval")
khenaidoo5e4fca32021-05-12 16:02:23 -0400204
David K. Bainbridge6080c172021-07-24 00:22:28 +0000205 _ = fs.Parse(args)
khenaidoocfee5f42018-07-19 22:47:38 -0400206}