-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.go
More file actions
124 lines (108 loc) · 3.02 KB
/
config.go
File metadata and controls
124 lines (108 loc) · 3.02 KB
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
116
117
118
119
120
121
122
123
124
package sentry_transport
import (
"time"
)
// Config represents the plugin configuration
type Config struct {
// Sentry DSN
DSN string `mapstructure:"dsn"`
// HTTP transport settings
Transport TransportConfig `mapstructure:"transport"`
// Retry configuration
Retry RetryConfig `mapstructure:"retry"`
// Queue configuration
Queue QueueConfig `mapstructure:"queue"`
}
// TransportConfig contains HTTP transport settings
type TransportConfig struct {
// Request timeout
Timeout time.Duration `mapstructure:"timeout"`
// Connection timeout
ConnectTimeout time.Duration `mapstructure:"connect_timeout"`
// Enable gzip compression
Compression bool `mapstructure:"compression"`
// SSL verification
SSLVerify bool `mapstructure:"ssl_verify"`
// Proxy settings
Proxy string `mapstructure:"proxy"`
ProxyAuth string `mapstructure:"proxy_auth"`
}
// RetryConfig contains retry mechanism settings
type RetryConfig struct {
// Maximum retry attempts
MaxAttempts int `mapstructure:"max_attempts"`
// Initial backoff duration
InitialBackoff time.Duration `mapstructure:"initial_backoff"`
// Backoff multiplier
BackoffMultiplier float64 `mapstructure:"backoff_multiplier"`
// Maximum backoff duration
MaxBackoff time.Duration `mapstructure:"max_backoff"`
// Enable dead letter queue
DeadLetterQueue bool `mapstructure:"dead_letter_queue"`
}
// QueueConfig contains queue settings
type QueueConfig struct {
// Buffer size for the event queue
BufferSize int `mapstructure:"buffer_size"`
// Number of worker goroutines
Workers int `mapstructure:"workers"`
// Batch size for processing events
BatchSize int `mapstructure:"batch_size"`
// Batch timeout
BatchTimeout time.Duration `mapstructure:"batch_timeout"`
}
// InitDefaults initializes default configuration values
func (cfg *Config) InitDefaults() {
if cfg.Transport.Timeout == 0 {
cfg.Transport.Timeout = 30 * time.Second
}
if cfg.Transport.ConnectTimeout == 0 {
cfg.Transport.ConnectTimeout = 10 * time.Second
}
if cfg.Transport.Compression == false {
cfg.Transport.Compression = true
}
if cfg.Transport.SSLVerify == false {
cfg.Transport.SSLVerify = true
}
if cfg.Retry.MaxAttempts == 0 {
cfg.Retry.MaxAttempts = 3
}
if cfg.Retry.InitialBackoff == 0 {
cfg.Retry.InitialBackoff = 1 * time.Second
}
if cfg.Retry.BackoffMultiplier == 0 {
cfg.Retry.BackoffMultiplier = 2.0
}
if cfg.Retry.MaxBackoff == 0 {
cfg.Retry.MaxBackoff = 300 * time.Second
}
if cfg.Queue.BufferSize == 0 {
cfg.Queue.BufferSize = 1000
}
if cfg.Queue.Workers == 0 {
cfg.Queue.Workers = 1
}
if cfg.Queue.BatchSize == 0 {
cfg.Queue.BatchSize = 10
}
if cfg.Queue.BatchTimeout == 0 {
cfg.Queue.BatchTimeout = 5 * time.Second
}
}
// Validate validates the configuration
func (cfg *Config) Validate() error {
if cfg.DSN == "" {
return nil // DSN can be empty to disable transmission
}
if cfg.Queue.BufferSize <= 0 {
cfg.Queue.BufferSize = 1000
}
if cfg.Queue.Workers <= 0 {
cfg.Queue.Workers = 1
}
if cfg.Retry.MaxAttempts < 0 {
cfg.Retry.MaxAttempts = 0
}
return nil
}