blob: 4375b9b556693ae09f627774c2cf3189f6733410 [file] [log] [blame]
khenaidoobf6e7bb2018-08-14 22:27:29 -04001/*
2 * Copyright 2018-present Open Networking Foundation
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 */
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
40 LogLevel string
41 Banner bool
42 DisplayVersionOnly bool
43 RWCoreKey string
44 RWCoreCert string
45 RWCoreCA string
khenaidood948f772021-08-11 17:49:24 -040046 InternalTimeout time.Duration
47 RPCTimeout time.Duration
Himani Chawla4b4bd252021-11-08 15:59:40 +053048 FlowTimeout time.Duration
khenaidoo5e4fca32021-05-12 16:02:23 -040049 MaxConnectionRetries int
50 ConnectionRetryInterval time.Duration
51 LiveProbeInterval time.Duration
52 NotLiveProbeInterval time.Duration
53 ProbeAddress string
54 TraceEnabled bool
55 TraceAgentAddress string
56 LogCorrelationEnabled bool
57 VolthaStackID string
58 BackoffRetryInitialInterval time.Duration
59 BackoffRetryMaxElapsedTime time.Duration
60 BackoffRetryMaxInterval time.Duration
khenaidoocfee5f42018-07-19 22:47:38 -040061}
62
khenaidoo5c11af72018-07-20 17:21:05 -040063// ParseCommandArguments parses the arguments when running read-write core service
David K. Bainbridge6080c172021-07-24 00:22:28 +000064func (cf *RWCoreFlags) ParseCommandArguments(args []string) {
khenaidoocfee5f42018-07-19 22:47:38 -040065
David K. Bainbridge6080c172021-07-24 00:22:28 +000066 fs := flag.NewFlagSet(os.Args[0], flag.ExitOnError)
khenaidoocfee5f42018-07-19 22:47:38 -040067
khenaidood948f772021-08-11 17:49:24 -040068 fs.StringVar(&cf.GrpcNBIAddress,
69 "grpc_nbi_address",
70 ":50057",
71 "GRPC NBI server - address")
khenaidoocfee5f42018-07-19 22:47:38 -040072
khenaidood948f772021-08-11 17:49:24 -040073 fs.StringVar(&cf.GrpcSBIAddress,
74 "grpc_sbi_address",
75 ":50058",
76 "GRPC SBI server - address")
khenaidoo5c11af72018-07-20 17:21:05 -040077
khenaidood948f772021-08-11 17:49:24 -040078 fs.StringVar(&cf.KafkaClusterAddress,
79 "kafka_cluster_address",
80 "127.0.0.1:9092",
81 "Kafka - Cluster messaging address")
khenaidoo5c11af72018-07-20 17:21:05 -040082
khenaidood948f772021-08-11 17:49:24 -040083 fs.StringVar(&cf.EventTopic,
84 "event_topic",
85 "voltha.events",
86 "RW Core Event topic")
khenaidoo5c11af72018-07-20 17:21:05 -040087
khenaidood948f772021-08-11 17:49:24 -040088 fs.StringVar(&cf.KVStoreType,
89 "kv_store_type",
90 EtcdStoreName,
91 "KV store type")
Himani Chawlab4c25912020-11-12 17:16:38 +053092
khenaidood948f772021-08-11 17:49:24 -040093 fs.DurationVar(&cf.KVStoreTimeout,
94 "kv_store_request_timeout",
95 5*time.Second,
96 "The default timeout when making a kv store request")
khenaidoo79232702018-12-04 11:00:41 -050097
khenaidood948f772021-08-11 17:49:24 -040098 fs.StringVar(&cf.KVStoreAddress,
99 "kv_store_address",
100 "127.0.0.1:2379",
101 "KV store address")
khenaidoo5c11af72018-07-20 17:21:05 -0400102
khenaidood948f772021-08-11 17:49:24 -0400103 fs.StringVar(&cf.LogLevel,
104 "log_level",
105 "warn",
106 "Log level")
khenaidoo5c11af72018-07-20 17:21:05 -0400107
khenaidood948f772021-08-11 17:49:24 -0400108 fs.DurationVar(&(cf.InternalTimeout),
109 "internal_timeout",
110 5*time.Second,
111 "Core internal timeout")
khenaidoo5c11af72018-07-20 17:21:05 -0400112
khenaidood948f772021-08-11 17:49:24 -0400113 fs.DurationVar(&(cf.RPCTimeout),
114 "rpc_timeout",
115 5*time.Second,
116 "RPC timeout")
Richard Jankowskie4d77662018-10-17 13:53:21 -0400117
Himani Chawla4b4bd252021-11-08 15:59:40 +0530118 fs.DurationVar(&(cf.FlowTimeout), //Note flow time out will be considered for flows related rpc's not rpc timeout
119 "flow_timeout",
120 30*time.Second,
121 "Flow timeout")
122
khenaidood948f772021-08-11 17:49:24 -0400123 fs.BoolVar(&cf.Banner,
124 "banner",
125 false,
126 "Show startup banner log lines")
khenaidoo5c11af72018-07-20 17:21:05 -0400127
khenaidood948f772021-08-11 17:49:24 -0400128 fs.BoolVar(&cf.DisplayVersionOnly,
129 "version",
130 false,
131 "Show version information and exit")
khenaidoob6080322019-01-29 21:47:38 -0500132
khenaidood948f772021-08-11 17:49:24 -0400133 fs.IntVar(&cf.MaxConnectionRetries,
134 "max_connection_retries",
135 -1,
136 "The number of retries to connect to a dependent component")
khenaidoob6080322019-01-29 21:47:38 -0500137
khenaidood948f772021-08-11 17:49:24 -0400138 fs.DurationVar(&cf.ConnectionRetryInterval,
139 "connection_retry_interval",
140 2*time.Second,
141 "The number of seconds between each connection retry attempt")
khenaidoo2c6a0992019-04-29 13:46:56 -0400142
khenaidood948f772021-08-11 17:49:24 -0400143 fs.DurationVar(&cf.LiveProbeInterval,
144 "live_probe_interval",
145 60*time.Second,
146 "The number of seconds between liveness probes while in a live state")
khenaidoocfee5f42018-07-19 22:47:38 -0400147
khenaidood948f772021-08-11 17:49:24 -0400148 fs.DurationVar(&cf.NotLiveProbeInterval,
149 "not_live_probe_interval",
150 5*time.Second,
151 "The number of seconds between liveness probes while in a not live state")
David K. Bainbridgef430cd52019-05-28 15:00:35 -0700152
khenaidood948f772021-08-11 17:49:24 -0400153 fs.StringVar(&cf.ProbeAddress,
154 "probe_address",
155 ":8080",
156 "The address on which to listen to answer liveness and readiness probe queries over HTTP")
Richard Jankowski46464e92019-03-05 11:53:55 -0500157
khenaidood948f772021-08-11 17:49:24 -0400158 fs.BoolVar(&(cf.TraceEnabled),
159 "trace_enabled",
160 false,
161 "Whether to send logs to tracing agent?")
khenaidoob3244212019-08-27 14:32:27 -0400162
khenaidood948f772021-08-11 17:49:24 -0400163 fs.StringVar(&cf.TraceAgentAddress,
164 "trace_agent_address",
165 "127.0.0.1:6831",
166 "The address of tracing agent to which span info should be sent")
khenaidoob3244212019-08-27 14:32:27 -0400167
khenaidood948f772021-08-11 17:49:24 -0400168 fs.BoolVar(&cf.LogCorrelationEnabled,
169 "log_correlation_enabled",
170 true,
171 "Whether to enrich log statements with fields denoting operation being executed for achieving correlation?")
Scott Bakeree6a0872019-10-29 15:59:52 -0700172
khenaidood948f772021-08-11 17:49:24 -0400173 fs.StringVar(&cf.VolthaStackID,
174 "stack_id",
175 "voltha",
176 "ID for the current voltha stack")
Himani Chawla9cfc4992021-03-22 12:43:01 +0530177
David K. Bainbridge6080c172021-07-24 00:22:28 +0000178 fs.DurationVar(&cf.BackoffRetryInitialInterval,
khenaidood948f772021-08-11 17:49:24 -0400179 "backoff_retry_initial_interval",
180 500*time.Millisecond,
David K. Bainbridge6080c172021-07-24 00:22:28 +0000181 "The initial number of milliseconds an exponential backoff will wait before a retry")
khenaidoo5e4fca32021-05-12 16:02:23 -0400182
David K. Bainbridge6080c172021-07-24 00:22:28 +0000183 fs.DurationVar(&cf.BackoffRetryMaxElapsedTime,
khenaidood948f772021-08-11 17:49:24 -0400184 "backoff_retry_max_elapsed_time",
185 0*time.Second,
David K. Bainbridge6080c172021-07-24 00:22:28 +0000186 "The maximum number of milliseconds an exponential backoff can elasped")
khenaidoo5e4fca32021-05-12 16:02:23 -0400187
khenaidood948f772021-08-11 17:49:24 -0400188 fs.DurationVar(&cf.BackoffRetryMaxInterval,
189 "backoff_retry_max_interval",
190 1*time.Minute,
191 "The maximum number of milliseconds of an exponential backoff interval")
khenaidoo5e4fca32021-05-12 16:02:23 -0400192
David K. Bainbridge6080c172021-07-24 00:22:28 +0000193 _ = fs.Parse(args)
khenaidoocfee5f42018-07-19 22:47:38 -0400194}