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 | 5e4fca3 | 2021-05-12 16:02:23 -0400 | [diff] [blame] | 33 | RWCoreEndpoint string |
| 34 | GrpcAddress string |
| 35 | KafkaAdapterAddress string |
| 36 | KafkaClusterAddress string |
| 37 | KVStoreType string |
| 38 | KVStoreTimeout time.Duration |
| 39 | KVStoreAddress string |
| 40 | KVTxnKeyDelTime int |
| 41 | CoreTopic string |
| 42 | EventTopic string |
| 43 | LogLevel string |
| 44 | Banner bool |
| 45 | DisplayVersionOnly bool |
| 46 | RWCoreKey string |
| 47 | RWCoreCert string |
| 48 | RWCoreCA string |
| 49 | LongRunningRequestTimeout time.Duration |
| 50 | DefaultRequestTimeout time.Duration |
| 51 | DefaultCoreTimeout time.Duration |
| 52 | CoreBindingKey string |
| 53 | MaxConnectionRetries int |
| 54 | ConnectionRetryInterval time.Duration |
| 55 | LiveProbeInterval time.Duration |
| 56 | NotLiveProbeInterval time.Duration |
| 57 | ProbeAddress string |
| 58 | TraceEnabled bool |
| 59 | TraceAgentAddress string |
| 60 | LogCorrelationEnabled bool |
| 61 | VolthaStackID string |
| 62 | BackoffRetryInitialInterval time.Duration |
| 63 | BackoffRetryMaxElapsedTime time.Duration |
| 64 | BackoffRetryMaxInterval time.Duration |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 65 | } |
| 66 | |
khenaidoo | 5c11af7 | 2018-07-20 17:21:05 -0400 | [diff] [blame] | 67 | // ParseCommandArguments parses the arguments when running read-write core service |
David K. Bainbridge | 6080c17 | 2021-07-24 00:22:28 +0000 | [diff] [blame^] | 68 | func (cf *RWCoreFlags) ParseCommandArguments(args []string) { |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 69 | |
David K. Bainbridge | 6080c17 | 2021-07-24 00:22:28 +0000 | [diff] [blame^] | 70 | fs := flag.NewFlagSet(os.Args[0], flag.ExitOnError) |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 71 | |
David K. Bainbridge | 6080c17 | 2021-07-24 00:22:28 +0000 | [diff] [blame^] | 72 | fs.StringVar(&cf.RWCoreEndpoint, "vcore-endpoint", |
| 73 | "rwcore", "RW core endpoint address") |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 74 | |
David K. Bainbridge | 6080c17 | 2021-07-24 00:22:28 +0000 | [diff] [blame^] | 75 | fs.StringVar(&cf.GrpcAddress, "grpc_address", |
| 76 | ":50057", "GRPC server - address") |
khenaidoo | 5c11af7 | 2018-07-20 17:21:05 -0400 | [diff] [blame] | 77 | |
David K. Bainbridge | 6080c17 | 2021-07-24 00:22:28 +0000 | [diff] [blame^] | 78 | fs.StringVar(&cf.KafkaAdapterAddress, "kafka_adapter_address", |
| 79 | "127.0.0.1:9092", "Kafka - Adapter messaging address") |
khenaidoo | 5c11af7 | 2018-07-20 17:21:05 -0400 | [diff] [blame] | 80 | |
David K. Bainbridge | 6080c17 | 2021-07-24 00:22:28 +0000 | [diff] [blame^] | 81 | fs.StringVar(&cf.KafkaClusterAddress, "kafka_cluster_address", |
| 82 | "127.0.0.1:9094", "Kafka - Cluster messaging address") |
khenaidoo | 5c11af7 | 2018-07-20 17:21:05 -0400 | [diff] [blame] | 83 | |
David K. Bainbridge | 6080c17 | 2021-07-24 00:22:28 +0000 | [diff] [blame^] | 84 | fs.StringVar(&cf.CoreTopic, "rw_core_topic", |
| 85 | "rwcore", "RW Core topic") |
Himani Chawla | b4c2591 | 2020-11-12 17:16:38 +0530 | [diff] [blame] | 86 | |
David K. Bainbridge | 6080c17 | 2021-07-24 00:22:28 +0000 | [diff] [blame^] | 87 | fs.StringVar(&cf.EventTopic, "event_topic", |
| 88 | "voltha.events", "RW Core Event topic") |
khenaidoo | 7923270 | 2018-12-04 11:00:41 -0500 | [diff] [blame] | 89 | |
David K. Bainbridge | 6080c17 | 2021-07-24 00:22:28 +0000 | [diff] [blame^] | 90 | fs.StringVar(&cf.KVStoreType, "kv_store_type", |
| 91 | EtcdStoreName, "KV store type") |
khenaidoo | 5c11af7 | 2018-07-20 17:21:05 -0400 | [diff] [blame] | 92 | |
David K. Bainbridge | 6080c17 | 2021-07-24 00:22:28 +0000 | [diff] [blame^] | 93 | fs.DurationVar(&cf.KVStoreTimeout, "kv_store_request_timeout", |
| 94 | 5*time.Second, "The default timeout when making a kv store request") |
khenaidoo | 5c11af7 | 2018-07-20 17:21:05 -0400 | [diff] [blame] | 95 | |
David K. Bainbridge | 6080c17 | 2021-07-24 00:22:28 +0000 | [diff] [blame^] | 96 | fs.StringVar(&cf.KVStoreAddress, "kv_store_address", |
| 97 | "127.0.0.1:2379", "KV store address") |
khenaidoo | 5c11af7 | 2018-07-20 17:21:05 -0400 | [diff] [blame] | 98 | |
David K. Bainbridge | 6080c17 | 2021-07-24 00:22:28 +0000 | [diff] [blame^] | 99 | fs.IntVar(&cf.KVTxnKeyDelTime, "kv_txn_delete_time", |
| 100 | 60, "The time to wait before deleting a completed transaction key") |
Richard Jankowski | e4d7766 | 2018-10-17 13:53:21 -0400 | [diff] [blame] | 101 | |
David K. Bainbridge | 6080c17 | 2021-07-24 00:22:28 +0000 | [diff] [blame^] | 102 | fs.StringVar(&cf.LogLevel, "log_level", |
| 103 | "warn", "Log level") |
khenaidoo | 5c11af7 | 2018-07-20 17:21:05 -0400 | [diff] [blame] | 104 | |
David K. Bainbridge | 6080c17 | 2021-07-24 00:22:28 +0000 | [diff] [blame^] | 105 | fs.DurationVar(&cf.LongRunningRequestTimeout, "timeout_long_request", |
| 106 | 2000*time.Millisecond, "Timeout for long running request") |
khenaidoo | b608032 | 2019-01-29 21:47:38 -0500 | [diff] [blame] | 107 | |
David K. Bainbridge | 6080c17 | 2021-07-24 00:22:28 +0000 | [diff] [blame^] | 108 | fs.DurationVar(&cf.DefaultRequestTimeout, "timeout_request", |
| 109 | 1000*time.Millisecond, "Default timeout for regular request") |
khenaidoo | b608032 | 2019-01-29 21:47:38 -0500 | [diff] [blame] | 110 | |
David K. Bainbridge | 6080c17 | 2021-07-24 00:22:28 +0000 | [diff] [blame^] | 111 | fs.DurationVar(&cf.DefaultCoreTimeout, "core_timeout", |
| 112 | 1000*time.Millisecond, "Default Core timeout") |
khenaidoo | 2c6a099 | 2019-04-29 13:46:56 -0400 | [diff] [blame] | 113 | |
David K. Bainbridge | 6080c17 | 2021-07-24 00:22:28 +0000 | [diff] [blame^] | 114 | fs.BoolVar(&cf.Banner, "banner", |
| 115 | false, "Show startup banner log lines") |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 116 | |
David K. Bainbridge | 6080c17 | 2021-07-24 00:22:28 +0000 | [diff] [blame^] | 117 | fs.BoolVar(&cf.DisplayVersionOnly, "version", |
| 118 | false, "Show version information and exit") |
David K. Bainbridge | f430cd5 | 2019-05-28 15:00:35 -0700 | [diff] [blame] | 119 | |
David K. Bainbridge | 6080c17 | 2021-07-24 00:22:28 +0000 | [diff] [blame^] | 120 | fs.StringVar(&cf.CoreBindingKey, "core_binding_key", |
| 121 | "voltha_backend_name", "The name of the meta-key whose value is the rw-core group to which the ofagent is bound") |
Richard Jankowski | 46464e9 | 2019-03-05 11:53:55 -0500 | [diff] [blame] | 122 | |
David K. Bainbridge | 6080c17 | 2021-07-24 00:22:28 +0000 | [diff] [blame^] | 123 | fs.IntVar(&cf.MaxConnectionRetries, "max_connection_retries", |
| 124 | -1, "The number of retries to connect to a dependent component") |
khenaidoo | b324421 | 2019-08-27 14:32:27 -0400 | [diff] [blame] | 125 | |
David K. Bainbridge | 6080c17 | 2021-07-24 00:22:28 +0000 | [diff] [blame^] | 126 | fs.DurationVar(&cf.ConnectionRetryInterval, "connection_retry_interval", |
| 127 | 2*time.Second, "The number of seconds between each connection retry attempt") |
khenaidoo | b324421 | 2019-08-27 14:32:27 -0400 | [diff] [blame] | 128 | |
David K. Bainbridge | 6080c17 | 2021-07-24 00:22:28 +0000 | [diff] [blame^] | 129 | fs.DurationVar(&cf.LiveProbeInterval, "live_probe_interval", |
| 130 | 60*time.Second, "The number of seconds between liveness probes while in a live state") |
Scott Baker | ee6a087 | 2019-10-29 15:59:52 -0700 | [diff] [blame] | 131 | |
David K. Bainbridge | 6080c17 | 2021-07-24 00:22:28 +0000 | [diff] [blame^] | 132 | fs.DurationVar(&cf.NotLiveProbeInterval, "not_live_probe_interval", |
| 133 | 5*time.Second, "The number of seconds between liveness probes while in a not live state") |
Scott Baker | ee6a087 | 2019-10-29 15:59:52 -0700 | [diff] [blame] | 134 | |
David K. Bainbridge | 6080c17 | 2021-07-24 00:22:28 +0000 | [diff] [blame^] | 135 | fs.StringVar(&cf.ProbeAddress, "probe_address", |
| 136 | ":8080", "The address on which to listen to answer liveness and readiness probe queries over HTTP") |
David K. Bainbridge | b4a9ab0 | 2019-09-20 15:12:16 -0700 | [diff] [blame] | 137 | |
David K. Bainbridge | 6080c17 | 2021-07-24 00:22:28 +0000 | [diff] [blame^] | 138 | fs.BoolVar(&(cf.TraceEnabled), "trace_enabled", |
| 139 | false, "Whether to send logs to tracing agent?") |
Girish Kumar | 33470e8 | 2020-06-15 13:53:13 +0000 | [diff] [blame] | 140 | |
David K. Bainbridge | 6080c17 | 2021-07-24 00:22:28 +0000 | [diff] [blame^] | 141 | fs.StringVar(&cf.TraceAgentAddress, "trace_agent_address", |
| 142 | "127.0.0.1:6831", "The address of tracing agent to which span info should be sent") |
Girish Kumar | 33470e8 | 2020-06-15 13:53:13 +0000 | [diff] [blame] | 143 | |
David K. Bainbridge | 6080c17 | 2021-07-24 00:22:28 +0000 | [diff] [blame^] | 144 | fs.BoolVar(&cf.LogCorrelationEnabled, "log_correlation_enabled", |
| 145 | true, "Whether to enrich log statements with fields denoting operation being executed for achieving correlation?") |
Girish Kumar | 33470e8 | 2020-06-15 13:53:13 +0000 | [diff] [blame] | 146 | |
David K. Bainbridge | 6080c17 | 2021-07-24 00:22:28 +0000 | [diff] [blame^] | 147 | fs.StringVar(&cf.VolthaStackID, "stack_id", |
| 148 | "voltha", "ID for the current voltha stack") |
Himani Chawla | 9cfc499 | 2021-03-22 12:43:01 +0530 | [diff] [blame] | 149 | |
David K. Bainbridge | 6080c17 | 2021-07-24 00:22:28 +0000 | [diff] [blame^] | 150 | fs.DurationVar(&cf.BackoffRetryInitialInterval, |
| 151 | "backoff_retry_initial_interval", 500*time.Millisecond, |
| 152 | "The initial number of milliseconds an exponential backoff will wait before a retry") |
khenaidoo | 5e4fca3 | 2021-05-12 16:02:23 -0400 | [diff] [blame] | 153 | |
David K. Bainbridge | 6080c17 | 2021-07-24 00:22:28 +0000 | [diff] [blame^] | 154 | fs.DurationVar(&cf.BackoffRetryMaxElapsedTime, |
| 155 | "backoff_retry_max_elapsed_time", 0*time.Second, |
| 156 | "The maximum number of milliseconds an exponential backoff can elasped") |
khenaidoo | 5e4fca3 | 2021-05-12 16:02:23 -0400 | [diff] [blame] | 157 | |
David K. Bainbridge | 6080c17 | 2021-07-24 00:22:28 +0000 | [diff] [blame^] | 158 | fs.DurationVar(&cf.BackoffRetryMaxInterval, "backoff_retry_max_interval", |
| 159 | 1*time.Minute, "The maximum number of milliseconds of an exponential backoff interval") |
khenaidoo | 5e4fca3 | 2021-05-12 16:02:23 -0400 | [diff] [blame] | 160 | |
David K. Bainbridge | 6080c17 | 2021-07-24 00:22:28 +0000 | [diff] [blame^] | 161 | _ = fs.Parse(args) |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 162 | } |