blob: 5c092d697f5c01bcabee4b06ca59ad89a3d3bd8f [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"
Girish Kumar4d3887d2019-11-22 14:22:05 +000021 "time"
khenaidoocfee5f42018-07-19 22:47:38 -040022)
23
khenaidoo5c11af72018-07-20 17:21:05 -040024// RW Core service default constants
khenaidoocfee5f42018-07-19 22:47:38 -040025const (
khenaidoo5e4fca32021-05-12 16:02:23 -040026 EtcdStoreName = "etcd"
27 defaultGrpcAddress = ":50057"
28 defaultKafkaAdapterAddress = "127.0.0.1:9092"
29 defaultKafkaClusterAddress = "127.0.0.1:9094"
30 defaultKVStoreType = EtcdStoreName
31 defaultKVStoreTimeout = 5 * time.Second
32 defaultKVStoreAddress = "127.0.0.1:2379" // Etcd = 2379
33 defaultKVTxnKeyDelTime = 60
34 defaultLogLevel = "WARN"
35 defaultBanner = false
36 defaultDisplayVersionOnly = false
37 defaultCoreTopic = "rwcore"
38 defaultEventTopic = "voltha.events"
39 defaultRWCoreEndpoint = "rwcore"
40 defaultRWCoreKey = "pki/voltha.key"
41 defaultRWCoreCert = "pki/voltha.crt"
42 defaultRWCoreCA = "pki/voltha-CA.pem"
43 defaultLongRunningRequestTimeout = 2000 * time.Millisecond
44 defaultDefaultRequestTimeout = 1000 * time.Millisecond
45 defaultCoreTimeout = 1000 * time.Millisecond
46 defaultCoreBindingKey = "voltha_backend_name"
47 defaultMaxConnectionRetries = -1 // retries forever
48 defaultConnectionRetryInterval = 2 * time.Second
49 defaultLiveProbeInterval = 60 * time.Second
50 defaultNotLiveProbeInterval = 5 * time.Second // Probe more frequently when not alive
51 defaultProbeAddress = ":8080"
52 defaultTraceEnabled = false
53 defaultTraceAgentAddress = "127.0.0.1:6831"
54 defaultLogCorrelationEnabled = true
55 defaultVolthaStackID = "voltha"
56 defaultBackoffRetryInitialInterval = 500 * time.Millisecond
57 defaultBackoffRetryMaxElapsedTime = 0
58 defaultBackoffRetryMaxInterval = 1 * time.Minute
khenaidoocfee5f42018-07-19 22:47:38 -040059)
60
khenaidoo5c11af72018-07-20 17:21:05 -040061// RWCoreFlags represents the set of configurations used by the read-write core service
khenaidoocfee5f42018-07-19 22:47:38 -040062type RWCoreFlags struct {
63 // Command line parameters
khenaidoo5e4fca32021-05-12 16:02:23 -040064 RWCoreEndpoint string
65 GrpcAddress string
66 KafkaAdapterAddress string
67 KafkaClusterAddress string
68 KVStoreType string
69 KVStoreTimeout time.Duration
70 KVStoreAddress string
71 KVTxnKeyDelTime int
72 CoreTopic string
73 EventTopic string
74 LogLevel string
75 Banner bool
76 DisplayVersionOnly bool
77 RWCoreKey string
78 RWCoreCert string
79 RWCoreCA string
80 LongRunningRequestTimeout time.Duration
81 DefaultRequestTimeout time.Duration
82 DefaultCoreTimeout time.Duration
83 CoreBindingKey string
84 MaxConnectionRetries int
85 ConnectionRetryInterval time.Duration
86 LiveProbeInterval time.Duration
87 NotLiveProbeInterval time.Duration
88 ProbeAddress string
89 TraceEnabled bool
90 TraceAgentAddress string
91 LogCorrelationEnabled bool
92 VolthaStackID string
93 BackoffRetryInitialInterval time.Duration
94 BackoffRetryMaxElapsedTime time.Duration
95 BackoffRetryMaxInterval time.Duration
khenaidoocfee5f42018-07-19 22:47:38 -040096}
97
khenaidoo5c11af72018-07-20 17:21:05 -040098// NewRWCoreFlags returns a new RWCore config
khenaidoocfee5f42018-07-19 22:47:38 -040099func NewRWCoreFlags() *RWCoreFlags {
100 var rwCoreFlag = RWCoreFlags{ // Default values
khenaidoo5e4fca32021-05-12 16:02:23 -0400101 RWCoreEndpoint: defaultRWCoreEndpoint,
102 GrpcAddress: defaultGrpcAddress,
103 KafkaAdapterAddress: defaultKafkaAdapterAddress,
104 KafkaClusterAddress: defaultKafkaClusterAddress,
105 KVStoreType: defaultKVStoreType,
106 KVStoreTimeout: defaultKVStoreTimeout,
107 KVStoreAddress: defaultKVStoreAddress,
108 KVTxnKeyDelTime: defaultKVTxnKeyDelTime,
109 CoreTopic: defaultCoreTopic,
110 EventTopic: defaultEventTopic,
111 LogLevel: defaultLogLevel,
112 Banner: defaultBanner,
113 DisplayVersionOnly: defaultDisplayVersionOnly,
114 RWCoreKey: defaultRWCoreKey,
115 RWCoreCert: defaultRWCoreCert,
116 RWCoreCA: defaultRWCoreCA,
117 DefaultRequestTimeout: defaultDefaultRequestTimeout,
118 LongRunningRequestTimeout: defaultLongRunningRequestTimeout,
119 DefaultCoreTimeout: defaultCoreTimeout,
120 CoreBindingKey: defaultCoreBindingKey,
121 MaxConnectionRetries: defaultMaxConnectionRetries,
122 ConnectionRetryInterval: defaultConnectionRetryInterval,
123 LiveProbeInterval: defaultLiveProbeInterval,
124 NotLiveProbeInterval: defaultNotLiveProbeInterval,
125 ProbeAddress: defaultProbeAddress,
126 TraceEnabled: defaultTraceEnabled,
127 TraceAgentAddress: defaultTraceAgentAddress,
128 LogCorrelationEnabled: defaultLogCorrelationEnabled,
129 VolthaStackID: defaultVolthaStackID,
130 BackoffRetryInitialInterval: defaultBackoffRetryInitialInterval,
131 BackoffRetryMaxElapsedTime: defaultBackoffRetryMaxElapsedTime,
132 BackoffRetryMaxInterval: defaultBackoffRetryMaxInterval,
khenaidoocfee5f42018-07-19 22:47:38 -0400133 }
134 return &rwCoreFlag
135}
136
khenaidoo5c11af72018-07-20 17:21:05 -0400137// ParseCommandArguments parses the arguments when running read-write core service
khenaidoocfee5f42018-07-19 22:47:38 -0400138func (cf *RWCoreFlags) ParseCommandArguments() {
khenaidoocfee5f42018-07-19 22:47:38 -0400139
Andrey Pozolotin34dd63f2021-05-31 21:26:40 +0300140 flag.StringVar(&(cf.RWCoreEndpoint), "vcore-endpoint", defaultRWCoreEndpoint, "RW core endpoint address")
khenaidoocfee5f42018-07-19 22:47:38 -0400141
Andrey Pozolotin34dd63f2021-05-31 21:26:40 +0300142 flag.StringVar(&(cf.GrpcAddress), "grpc_address", defaultGrpcAddress, "GRPC server - address")
khenaidoocfee5f42018-07-19 22:47:38 -0400143
Andrey Pozolotin34dd63f2021-05-31 21:26:40 +0300144 flag.StringVar(&(cf.KafkaAdapterAddress), "kafka_adapter_address", defaultKafkaAdapterAddress, "Kafka - Adapter messaging address")
khenaidoo5c11af72018-07-20 17:21:05 -0400145
Andrey Pozolotin34dd63f2021-05-31 21:26:40 +0300146 flag.StringVar(&(cf.KafkaClusterAddress), "kafka_cluster_address", defaultKafkaClusterAddress, "Kafka - Cluster messaging address")
khenaidoo5c11af72018-07-20 17:21:05 -0400147
Andrey Pozolotin34dd63f2021-05-31 21:26:40 +0300148 flag.StringVar(&(cf.CoreTopic), "rw_core_topic", defaultCoreTopic, "RW Core topic")
khenaidoo5c11af72018-07-20 17:21:05 -0400149
Andrey Pozolotin34dd63f2021-05-31 21:26:40 +0300150 flag.StringVar(&(cf.EventTopic), "event_topic", defaultEventTopic, "RW Core Event topic")
Himani Chawlab4c25912020-11-12 17:16:38 +0530151
David Bainbridge9ae13132020-06-22 17:28:01 -0700152 flag.Bool("in_competing_mode", false, "deprecated")
khenaidoo79232702018-12-04 11:00:41 -0500153
Andrey Pozolotin34dd63f2021-05-31 21:26:40 +0300154 flag.StringVar(&(cf.KVStoreType), "kv_store_type", defaultKVStoreType, "KV store type")
khenaidoo5c11af72018-07-20 17:21:05 -0400155
Andrey Pozolotin34dd63f2021-05-31 21:26:40 +0300156 flag.DurationVar(&(cf.KVStoreTimeout), "kv_store_request_timeout", defaultKVStoreTimeout, "The default timeout when making a kv store request")
khenaidoo5c11af72018-07-20 17:21:05 -0400157
Andrey Pozolotin34dd63f2021-05-31 21:26:40 +0300158 flag.StringVar(&(cf.KVStoreAddress), "kv_store_address", defaultKVStoreAddress, "KV store address")
khenaidoo5c11af72018-07-20 17:21:05 -0400159
Andrey Pozolotin34dd63f2021-05-31 21:26:40 +0300160 flag.IntVar(&(cf.KVTxnKeyDelTime), "kv_txn_delete_time", defaultKVTxnKeyDelTime, "The time to wait before deleting a completed transaction key")
Richard Jankowskie4d77662018-10-17 13:53:21 -0400161
Andrey Pozolotin34dd63f2021-05-31 21:26:40 +0300162 flag.StringVar(&(cf.LogLevel), "log_level", defaultLogLevel, "Log level")
khenaidoo5c11af72018-07-20 17:21:05 -0400163
Andrey Pozolotin34dd63f2021-05-31 21:26:40 +0300164 flag.DurationVar(&(cf.LongRunningRequestTimeout), "timeout_long_request", defaultLongRunningRequestTimeout, "Timeout for long running request")
khenaidoob6080322019-01-29 21:47:38 -0500165
Andrey Pozolotin34dd63f2021-05-31 21:26:40 +0300166 flag.DurationVar(&(cf.DefaultRequestTimeout), "timeout_request", defaultDefaultRequestTimeout, "Default timeout for regular request")
khenaidoob6080322019-01-29 21:47:38 -0500167
Andrey Pozolotin34dd63f2021-05-31 21:26:40 +0300168 flag.DurationVar(&(cf.DefaultCoreTimeout), "core_timeout", defaultCoreTimeout, "Default Core timeout")
khenaidoo2c6a0992019-04-29 13:46:56 -0400169
Andrey Pozolotin34dd63f2021-05-31 21:26:40 +0300170 flag.BoolVar(&cf.Banner, "banner", defaultBanner, "Show startup banner log lines")
khenaidoocfee5f42018-07-19 22:47:38 -0400171
Andrey Pozolotin34dd63f2021-05-31 21:26:40 +0300172 flag.BoolVar(&cf.DisplayVersionOnly, "version", defaultDisplayVersionOnly, "Show version information and exit")
David K. Bainbridgef430cd52019-05-28 15:00:35 -0700173
Andrey Pozolotin34dd63f2021-05-31 21:26:40 +0300174 flag.StringVar(&(cf.CoreBindingKey), "core_binding_key", defaultCoreBindingKey, "The name of the meta-key whose value is the rw-core group to which the ofagent is bound")
Richard Jankowski46464e92019-03-05 11:53:55 -0500175
Andrey Pozolotin34dd63f2021-05-31 21:26:40 +0300176 flag.IntVar(&(cf.MaxConnectionRetries), "max_connection_retries", defaultMaxConnectionRetries, "The number of retries to connect to a dependent component")
khenaidoob3244212019-08-27 14:32:27 -0400177
Andrey Pozolotin34dd63f2021-05-31 21:26:40 +0300178 flag.DurationVar(&(cf.ConnectionRetryInterval), "connection_retry_interval", defaultConnectionRetryInterval, "The number of seconds between each connection retry attempt")
khenaidoob3244212019-08-27 14:32:27 -0400179
Andrey Pozolotin34dd63f2021-05-31 21:26:40 +0300180 flag.DurationVar(&(cf.LiveProbeInterval), "live_probe_interval", defaultLiveProbeInterval, "The number of seconds between liveness probes while in a live state")
Scott Bakeree6a0872019-10-29 15:59:52 -0700181
Andrey Pozolotin34dd63f2021-05-31 21:26:40 +0300182 flag.DurationVar(&(cf.NotLiveProbeInterval), "not_live_probe_interval", defaultNotLiveProbeInterval, "The number of seconds between liveness probes while in a not live state")
Scott Bakeree6a0872019-10-29 15:59:52 -0700183
Andrey Pozolotin34dd63f2021-05-31 21:26:40 +0300184 flag.StringVar(&(cf.ProbeAddress), "probe_address", defaultProbeAddress, "The address on which to listen to answer liveness and readiness probe queries over HTTP")
David K. Bainbridgeb4a9ab02019-09-20 15:12:16 -0700185
Andrey Pozolotin34dd63f2021-05-31 21:26:40 +0300186 flag.BoolVar(&(cf.TraceEnabled), "trace_enabled", defaultTraceEnabled, "Whether to send logs to tracing agent?")
Girish Kumar33470e82020-06-15 13:53:13 +0000187
Andrey Pozolotin34dd63f2021-05-31 21:26:40 +0300188 flag.StringVar(&(cf.TraceAgentAddress), "trace_agent_address", defaultTraceAgentAddress, "The address of tracing agent to which span info should be sent")
Girish Kumar33470e82020-06-15 13:53:13 +0000189
Andrey Pozolotin34dd63f2021-05-31 21:26:40 +0300190 flag.BoolVar(&(cf.LogCorrelationEnabled), "log_correlation_enabled", defaultLogCorrelationEnabled, "Whether to enrich log statements with fields denoting operation being executed for achieving correlation?")
Girish Kumar33470e82020-06-15 13:53:13 +0000191
Andrey Pozolotin34dd63f2021-05-31 21:26:40 +0300192 flag.StringVar(&cf.VolthaStackID, "stack_id", defaultVolthaStackID, "ID for the current voltha stack")
Himani Chawla9cfc4992021-03-22 12:43:01 +0530193
Andrey Pozolotin34dd63f2021-05-31 21:26:40 +0300194 flag.DurationVar(&(cf.BackoffRetryInitialInterval), "backoff_retry_initial_interval", defaultBackoffRetryInitialInterval, "The initial number of milliseconds an exponential backoff will wait before a retry")
khenaidoo5e4fca32021-05-12 16:02:23 -0400195
Andrey Pozolotin34dd63f2021-05-31 21:26:40 +0300196 flag.DurationVar(&(cf.BackoffRetryMaxElapsedTime), "backoff_retry_max_elapsed_time", defaultBackoffRetryMaxElapsedTime, "The maximum number of milliseconds an exponential backoff can elasped")
khenaidoo5e4fca32021-05-12 16:02:23 -0400197
Andrey Pozolotin34dd63f2021-05-31 21:26:40 +0300198 flag.DurationVar(&(cf.BackoffRetryMaxInterval), "backoff_retry_max_interval", defaultBackoffRetryMaxInterval, "The maximum number of milliseconds of an exponential backoff interval")
khenaidoo5e4fca32021-05-12 16:02:23 -0400199
khenaidoocfee5f42018-07-19 22:47:38 -0400200 flag.Parse()
khenaidoocfee5f42018-07-19 22:47:38 -0400201}