-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
115 lines (96 loc) · 2.57 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/*
* Copyright (C) 2015 Alexey Gladkov <gladkov.alexey@gmail.com>
*
* This file is covered by the GNU General Public License,
* which should be included with kafka-replicator as the file COPYING.
*/
package main
import (
"github.com/Sirupsen/logrus"
"strings"
"time"
)
type CfgLogLevel struct {
logrus.Level
}
func (d *CfgLogLevel) UnmarshalText(data []byte) (err error) {
d.Level, err = logrus.ParseLevel(strings.ToLower(string(data)))
return
}
// CfgDuration is a Duration wrapper for Config.
type CfgDuration struct {
time.Duration
}
// UnmarshalText is a wrapper.
func (d *CfgDuration) UnmarshalText(data []byte) (err error) {
d.Duration, err = time.ParseDuration(string(data))
return
}
type ConfigGlobal struct {
Logfile string
Pidfile string
}
type ConfigLogging struct {
Level CfgLogLevel
DisableColors bool
DisableTimestamp bool
FullTimestamp bool
DisableSorting bool
}
type ConfigKafka struct {
Brokers []string
Topics []string
DialTimeout CfgDuration
LeaderRetryLimit int
LeaderRetryWait CfgDuration
}
type ConfigZookeeper struct {
Cluster string
SessionTimeout CfgDuration
Servers []string
}
type ConfigConsumer struct {
RequestTimeout CfgDuration
RetryLimit int
RetryWait CfgDuration
RetryErrLimit int
RetryErrWait CfgDuration
MinFetchSize int32
MaxFetchSize int32
DefaultFetchSize int32
}
type ConfigEndpoint struct {
URL string
}
// Config is a main config structure
type Config struct {
Global ConfigGlobal
Logging ConfigLogging
Kafka ConfigKafka
Zookeeper ConfigZookeeper
Endpoint ConfigEndpoint
Consumer ConfigConsumer
}
// SetDefaults applies default values to config structure.
func (c *Config) SetDefaults() {
c.Global.Logfile = "/var/log/kafka-replicator.log"
c.Global.Pidfile = "/run/kafka-replicator.pid"
c.Kafka.DialTimeout.Duration = 500 * time.Millisecond
c.Kafka.LeaderRetryLimit = 2
c.Kafka.LeaderRetryWait.Duration = 500 * time.Millisecond
c.Zookeeper.Cluster = "default"
c.Zookeeper.SessionTimeout.Duration = 1 * time.Second
c.Consumer.RequestTimeout.Duration = 50 * time.Millisecond
c.Consumer.RetryLimit = 2
c.Consumer.RetryWait.Duration = 50 * time.Millisecond
c.Consumer.RetryErrLimit = 2
c.Consumer.RetryErrWait.Duration = 50 * time.Millisecond
c.Consumer.MinFetchSize = 1
c.Consumer.MaxFetchSize = 4194304
c.Consumer.DefaultFetchSize = 524288
c.Logging.Level.Level = logrus.InfoLevel
c.Logging.DisableColors = true
c.Logging.DisableTimestamp = false
c.Logging.FullTimestamp = true
c.Logging.DisableSorting = false
}