blob: 327302f46df13f9641c7777631e79c849b34f77a [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
khenaidoo5e4fca32021-05-12 16:02:23 -040033 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
khenaidoocfee5f42018-07-19 22:47:38 -040065}
66
khenaidoo5c11af72018-07-20 17:21:05 -040067// ParseCommandArguments parses the arguments when running read-write core service
David K. Bainbridge6080c172021-07-24 00:22:28 +000068func (cf *RWCoreFlags) ParseCommandArguments(args []string) {
khenaidoocfee5f42018-07-19 22:47:38 -040069
David K. Bainbridge6080c172021-07-24 00:22:28 +000070 fs := flag.NewFlagSet(os.Args[0], flag.ExitOnError)
khenaidoocfee5f42018-07-19 22:47:38 -040071
David K. Bainbridge6080c172021-07-24 00:22:28 +000072 fs.StringVar(&cf.RWCoreEndpoint, "vcore-endpoint",
73 "rwcore", "RW core endpoint address")
khenaidoocfee5f42018-07-19 22:47:38 -040074
David K. Bainbridge6080c172021-07-24 00:22:28 +000075 fs.StringVar(&cf.GrpcAddress, "grpc_address",
76 ":50057", "GRPC server - address")
khenaidoo5c11af72018-07-20 17:21:05 -040077
David K. Bainbridge6080c172021-07-24 00:22:28 +000078 fs.StringVar(&cf.KafkaAdapterAddress, "kafka_adapter_address",
79 "127.0.0.1:9092", "Kafka - Adapter messaging address")
khenaidoo5c11af72018-07-20 17:21:05 -040080
David K. Bainbridge6080c172021-07-24 00:22:28 +000081 fs.StringVar(&cf.KafkaClusterAddress, "kafka_cluster_address",
82 "127.0.0.1:9094", "Kafka - Cluster messaging address")
khenaidoo5c11af72018-07-20 17:21:05 -040083
David K. Bainbridge6080c172021-07-24 00:22:28 +000084 fs.StringVar(&cf.CoreTopic, "rw_core_topic",
85 "rwcore", "RW Core topic")
Himani Chawlab4c25912020-11-12 17:16:38 +053086
David K. Bainbridge6080c172021-07-24 00:22:28 +000087 fs.StringVar(&cf.EventTopic, "event_topic",
88 "voltha.events", "RW Core Event topic")
khenaidoo79232702018-12-04 11:00:41 -050089
David K. Bainbridge6080c172021-07-24 00:22:28 +000090 fs.StringVar(&cf.KVStoreType, "kv_store_type",
91 EtcdStoreName, "KV store type")
khenaidoo5c11af72018-07-20 17:21:05 -040092
David K. Bainbridge6080c172021-07-24 00:22:28 +000093 fs.DurationVar(&cf.KVStoreTimeout, "kv_store_request_timeout",
94 5*time.Second, "The default timeout when making a kv store request")
khenaidoo5c11af72018-07-20 17:21:05 -040095
David K. Bainbridge6080c172021-07-24 00:22:28 +000096 fs.StringVar(&cf.KVStoreAddress, "kv_store_address",
97 "127.0.0.1:2379", "KV store address")
khenaidoo5c11af72018-07-20 17:21:05 -040098
David K. Bainbridge6080c172021-07-24 00:22:28 +000099 fs.IntVar(&cf.KVTxnKeyDelTime, "kv_txn_delete_time",
100 60, "The time to wait before deleting a completed transaction key")
Richard Jankowskie4d77662018-10-17 13:53:21 -0400101
David K. Bainbridge6080c172021-07-24 00:22:28 +0000102 fs.StringVar(&cf.LogLevel, "log_level",
103 "warn", "Log level")
khenaidoo5c11af72018-07-20 17:21:05 -0400104
David K. Bainbridge6080c172021-07-24 00:22:28 +0000105 fs.DurationVar(&cf.LongRunningRequestTimeout, "timeout_long_request",
106 2000*time.Millisecond, "Timeout for long running request")
khenaidoob6080322019-01-29 21:47:38 -0500107
David K. Bainbridge6080c172021-07-24 00:22:28 +0000108 fs.DurationVar(&cf.DefaultRequestTimeout, "timeout_request",
109 1000*time.Millisecond, "Default timeout for regular request")
khenaidoob6080322019-01-29 21:47:38 -0500110
David K. Bainbridge6080c172021-07-24 00:22:28 +0000111 fs.DurationVar(&cf.DefaultCoreTimeout, "core_timeout",
112 1000*time.Millisecond, "Default Core timeout")
khenaidoo2c6a0992019-04-29 13:46:56 -0400113
David K. Bainbridge6080c172021-07-24 00:22:28 +0000114 fs.BoolVar(&cf.Banner, "banner",
115 false, "Show startup banner log lines")
khenaidoocfee5f42018-07-19 22:47:38 -0400116
David K. Bainbridge6080c172021-07-24 00:22:28 +0000117 fs.BoolVar(&cf.DisplayVersionOnly, "version",
118 false, "Show version information and exit")
David K. Bainbridgef430cd52019-05-28 15:00:35 -0700119
David K. Bainbridge6080c172021-07-24 00:22:28 +0000120 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 Jankowski46464e92019-03-05 11:53:55 -0500122
David K. Bainbridge6080c172021-07-24 00:22:28 +0000123 fs.IntVar(&cf.MaxConnectionRetries, "max_connection_retries",
124 -1, "The number of retries to connect to a dependent component")
khenaidoob3244212019-08-27 14:32:27 -0400125
David K. Bainbridge6080c172021-07-24 00:22:28 +0000126 fs.DurationVar(&cf.ConnectionRetryInterval, "connection_retry_interval",
127 2*time.Second, "The number of seconds between each connection retry attempt")
khenaidoob3244212019-08-27 14:32:27 -0400128
David K. Bainbridge6080c172021-07-24 00:22:28 +0000129 fs.DurationVar(&cf.LiveProbeInterval, "live_probe_interval",
130 60*time.Second, "The number of seconds between liveness probes while in a live state")
Scott Bakeree6a0872019-10-29 15:59:52 -0700131
David K. Bainbridge6080c172021-07-24 00:22:28 +0000132 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 Bakeree6a0872019-10-29 15:59:52 -0700134
David K. Bainbridge6080c172021-07-24 00:22:28 +0000135 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. Bainbridgeb4a9ab02019-09-20 15:12:16 -0700137
David K. Bainbridge6080c172021-07-24 00:22:28 +0000138 fs.BoolVar(&(cf.TraceEnabled), "trace_enabled",
139 false, "Whether to send logs to tracing agent?")
Girish Kumar33470e82020-06-15 13:53:13 +0000140
David K. Bainbridge6080c172021-07-24 00:22:28 +0000141 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 Kumar33470e82020-06-15 13:53:13 +0000143
David K. Bainbridge6080c172021-07-24 00:22:28 +0000144 fs.BoolVar(&cf.LogCorrelationEnabled, "log_correlation_enabled",
145 true, "Whether to enrich log statements with fields denoting operation being executed for achieving correlation?")
Girish Kumar33470e82020-06-15 13:53:13 +0000146
David K. Bainbridge6080c172021-07-24 00:22:28 +0000147 fs.StringVar(&cf.VolthaStackID, "stack_id",
148 "voltha", "ID for the current voltha stack")
Himani Chawla9cfc4992021-03-22 12:43:01 +0530149
David K. Bainbridge6080c172021-07-24 00:22:28 +0000150 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")
khenaidoo5e4fca32021-05-12 16:02:23 -0400153
David K. Bainbridge6080c172021-07-24 00:22:28 +0000154 fs.DurationVar(&cf.BackoffRetryMaxElapsedTime,
155 "backoff_retry_max_elapsed_time", 0*time.Second,
156 "The maximum number of milliseconds an exponential backoff can elasped")
khenaidoo5e4fca32021-05-12 16:02:23 -0400157
David K. Bainbridge6080c172021-07-24 00:22:28 +0000158 fs.DurationVar(&cf.BackoffRetryMaxInterval, "backoff_retry_max_interval",
159 1*time.Minute, "The maximum number of milliseconds of an exponential backoff interval")
khenaidoo5e4fca32021-05-12 16:02:23 -0400160
David K. Bainbridge6080c172021-07-24 00:22:28 +0000161 _ = fs.Parse(args)
khenaidoocfee5f42018-07-19 22:47:38 -0400162}