khenaidoo | bf6e7bb | 2018-08-14 22:27:29 -0400 | [diff] [blame] | 1 | /* |
| 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 | */ |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 16 | |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 17 | package config |
| 18 | |
| 19 | import ( |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 20 | "flag" |
David K. Bainbridge | 6080c17 | 2021-07-24 00:22:28 +0000 | [diff] [blame] | 21 | "os" |
Girish Kumar | 4d3887d | 2019-11-22 14:22:05 +0000 | [diff] [blame] | 22 | "time" |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 23 | ) |
| 24 | |
khenaidoo | 5c11af7 | 2018-07-20 17:21:05 -0400 | [diff] [blame] | 25 | // RW Core service default constants |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 26 | const ( |
David K. Bainbridge | 6080c17 | 2021-07-24 00:22:28 +0000 | [diff] [blame] | 27 | EtcdStoreName = "etcd" |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 28 | ) |
| 29 | |
khenaidoo | 5c11af7 | 2018-07-20 17:21:05 -0400 | [diff] [blame] | 30 | // RWCoreFlags represents the set of configurations used by the read-write core service |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 31 | type RWCoreFlags struct { |
| 32 | // Command line parameters |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 33 | GrpcNBIAddress string |
| 34 | GrpcSBIAddress string |
khenaidoo | 5e4fca3 | 2021-05-12 16:02:23 -0400 | [diff] [blame] | 35 | KafkaClusterAddress string |
| 36 | KVStoreType string |
| 37 | KVStoreTimeout time.Duration |
| 38 | KVStoreAddress string |
khenaidoo | 5e4fca3 | 2021-05-12 16:02:23 -0400 | [diff] [blame] | 39 | EventTopic string |
| 40 | LogLevel string |
| 41 | Banner bool |
| 42 | DisplayVersionOnly bool |
| 43 | RWCoreKey string |
| 44 | RWCoreCert string |
| 45 | RWCoreCA string |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 46 | InternalTimeout time.Duration |
| 47 | RPCTimeout time.Duration |
khenaidoo | 5e4fca3 | 2021-05-12 16:02:23 -0400 | [diff] [blame] | 48 | MaxConnectionRetries int |
| 49 | ConnectionRetryInterval time.Duration |
| 50 | LiveProbeInterval time.Duration |
| 51 | NotLiveProbeInterval time.Duration |
| 52 | ProbeAddress string |
| 53 | TraceEnabled bool |
| 54 | TraceAgentAddress string |
| 55 | LogCorrelationEnabled bool |
| 56 | VolthaStackID string |
| 57 | BackoffRetryInitialInterval time.Duration |
| 58 | BackoffRetryMaxElapsedTime time.Duration |
| 59 | BackoffRetryMaxInterval time.Duration |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 60 | } |
| 61 | |
khenaidoo | 5c11af7 | 2018-07-20 17:21:05 -0400 | [diff] [blame] | 62 | // ParseCommandArguments parses the arguments when running read-write core service |
David K. Bainbridge | 6080c17 | 2021-07-24 00:22:28 +0000 | [diff] [blame] | 63 | func (cf *RWCoreFlags) ParseCommandArguments(args []string) { |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 64 | |
David K. Bainbridge | 6080c17 | 2021-07-24 00:22:28 +0000 | [diff] [blame] | 65 | fs := flag.NewFlagSet(os.Args[0], flag.ExitOnError) |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 66 | |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 67 | fs.StringVar(&cf.GrpcNBIAddress, |
| 68 | "grpc_nbi_address", |
| 69 | ":50057", |
| 70 | "GRPC NBI server - address") |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 71 | |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 72 | fs.StringVar(&cf.GrpcSBIAddress, |
| 73 | "grpc_sbi_address", |
| 74 | ":50058", |
| 75 | "GRPC SBI server - address") |
khenaidoo | 5c11af7 | 2018-07-20 17:21:05 -0400 | [diff] [blame] | 76 | |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 77 | fs.StringVar(&cf.KafkaClusterAddress, |
| 78 | "kafka_cluster_address", |
| 79 | "127.0.0.1:9092", |
| 80 | "Kafka - Cluster messaging address") |
khenaidoo | 5c11af7 | 2018-07-20 17:21:05 -0400 | [diff] [blame] | 81 | |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 82 | fs.StringVar(&cf.EventTopic, |
| 83 | "event_topic", |
| 84 | "voltha.events", |
| 85 | "RW Core Event topic") |
khenaidoo | 5c11af7 | 2018-07-20 17:21:05 -0400 | [diff] [blame] | 86 | |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 87 | fs.StringVar(&cf.KVStoreType, |
| 88 | "kv_store_type", |
| 89 | EtcdStoreName, |
| 90 | "KV store type") |
Himani Chawla | b4c2591 | 2020-11-12 17:16:38 +0530 | [diff] [blame] | 91 | |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 92 | fs.DurationVar(&cf.KVStoreTimeout, |
| 93 | "kv_store_request_timeout", |
| 94 | 5*time.Second, |
| 95 | "The default timeout when making a kv store request") |
khenaidoo | 7923270 | 2018-12-04 11:00:41 -0500 | [diff] [blame] | 96 | |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 97 | fs.StringVar(&cf.KVStoreAddress, |
| 98 | "kv_store_address", |
| 99 | "127.0.0.1:2379", |
| 100 | "KV store address") |
khenaidoo | 5c11af7 | 2018-07-20 17:21:05 -0400 | [diff] [blame] | 101 | |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 102 | fs.StringVar(&cf.LogLevel, |
| 103 | "log_level", |
| 104 | "warn", |
| 105 | "Log level") |
khenaidoo | 5c11af7 | 2018-07-20 17:21:05 -0400 | [diff] [blame] | 106 | |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 107 | fs.DurationVar(&(cf.InternalTimeout), |
| 108 | "internal_timeout", |
| 109 | 5*time.Second, |
| 110 | "Core internal timeout") |
khenaidoo | 5c11af7 | 2018-07-20 17:21:05 -0400 | [diff] [blame] | 111 | |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 112 | fs.DurationVar(&(cf.RPCTimeout), |
| 113 | "rpc_timeout", |
| 114 | 5*time.Second, |
| 115 | "RPC timeout") |
Richard Jankowski | e4d7766 | 2018-10-17 13:53:21 -0400 | [diff] [blame] | 116 | |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 117 | fs.BoolVar(&cf.Banner, |
| 118 | "banner", |
| 119 | false, |
| 120 | "Show startup banner log lines") |
khenaidoo | 5c11af7 | 2018-07-20 17:21:05 -0400 | [diff] [blame] | 121 | |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 122 | fs.BoolVar(&cf.DisplayVersionOnly, |
| 123 | "version", |
| 124 | false, |
| 125 | "Show version information and exit") |
khenaidoo | b608032 | 2019-01-29 21:47:38 -0500 | [diff] [blame] | 126 | |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 127 | fs.IntVar(&cf.MaxConnectionRetries, |
| 128 | "max_connection_retries", |
| 129 | -1, |
| 130 | "The number of retries to connect to a dependent component") |
khenaidoo | b608032 | 2019-01-29 21:47:38 -0500 | [diff] [blame] | 131 | |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 132 | fs.DurationVar(&cf.ConnectionRetryInterval, |
| 133 | "connection_retry_interval", |
| 134 | 2*time.Second, |
| 135 | "The number of seconds between each connection retry attempt") |
khenaidoo | 2c6a099 | 2019-04-29 13:46:56 -0400 | [diff] [blame] | 136 | |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 137 | fs.DurationVar(&cf.LiveProbeInterval, |
| 138 | "live_probe_interval", |
| 139 | 60*time.Second, |
| 140 | "The number of seconds between liveness probes while in a live state") |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 141 | |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 142 | fs.DurationVar(&cf.NotLiveProbeInterval, |
| 143 | "not_live_probe_interval", |
| 144 | 5*time.Second, |
| 145 | "The number of seconds between liveness probes while in a not live state") |
David K. Bainbridge | f430cd5 | 2019-05-28 15:00:35 -0700 | [diff] [blame] | 146 | |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 147 | fs.StringVar(&cf.ProbeAddress, |
| 148 | "probe_address", |
| 149 | ":8080", |
| 150 | "The address on which to listen to answer liveness and readiness probe queries over HTTP") |
Richard Jankowski | 46464e9 | 2019-03-05 11:53:55 -0500 | [diff] [blame] | 151 | |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 152 | fs.BoolVar(&(cf.TraceEnabled), |
| 153 | "trace_enabled", |
| 154 | false, |
| 155 | "Whether to send logs to tracing agent?") |
khenaidoo | b324421 | 2019-08-27 14:32:27 -0400 | [diff] [blame] | 156 | |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 157 | fs.StringVar(&cf.TraceAgentAddress, |
| 158 | "trace_agent_address", |
| 159 | "127.0.0.1:6831", |
| 160 | "The address of tracing agent to which span info should be sent") |
khenaidoo | b324421 | 2019-08-27 14:32:27 -0400 | [diff] [blame] | 161 | |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 162 | fs.BoolVar(&cf.LogCorrelationEnabled, |
| 163 | "log_correlation_enabled", |
| 164 | true, |
| 165 | "Whether to enrich log statements with fields denoting operation being executed for achieving correlation?") |
Scott Baker | ee6a087 | 2019-10-29 15:59:52 -0700 | [diff] [blame] | 166 | |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 167 | fs.StringVar(&cf.VolthaStackID, |
| 168 | "stack_id", |
| 169 | "voltha", |
| 170 | "ID for the current voltha stack") |
Himani Chawla | 9cfc499 | 2021-03-22 12:43:01 +0530 | [diff] [blame] | 171 | |
David K. Bainbridge | 6080c17 | 2021-07-24 00:22:28 +0000 | [diff] [blame] | 172 | fs.DurationVar(&cf.BackoffRetryInitialInterval, |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 173 | "backoff_retry_initial_interval", |
| 174 | 500*time.Millisecond, |
David K. Bainbridge | 6080c17 | 2021-07-24 00:22:28 +0000 | [diff] [blame] | 175 | "The initial number of milliseconds an exponential backoff will wait before a retry") |
khenaidoo | 5e4fca3 | 2021-05-12 16:02:23 -0400 | [diff] [blame] | 176 | |
David K. Bainbridge | 6080c17 | 2021-07-24 00:22:28 +0000 | [diff] [blame] | 177 | fs.DurationVar(&cf.BackoffRetryMaxElapsedTime, |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 178 | "backoff_retry_max_elapsed_time", |
| 179 | 0*time.Second, |
David K. Bainbridge | 6080c17 | 2021-07-24 00:22:28 +0000 | [diff] [blame] | 180 | "The maximum number of milliseconds an exponential backoff can elasped") |
khenaidoo | 5e4fca3 | 2021-05-12 16:02:23 -0400 | [diff] [blame] | 181 | |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 182 | fs.DurationVar(&cf.BackoffRetryMaxInterval, |
| 183 | "backoff_retry_max_interval", |
| 184 | 1*time.Minute, |
| 185 | "The maximum number of milliseconds of an exponential backoff interval") |
khenaidoo | 5e4fca3 | 2021-05-12 16:02:23 -0400 | [diff] [blame] | 186 | |
David K. Bainbridge | 6080c17 | 2021-07-24 00:22:28 +0000 | [diff] [blame] | 187 | _ = fs.Parse(args) |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 188 | } |