Skip to content

Commit 93010bf

Browse files
committed
update more defaults, logs
1 parent b3f84f5 commit 93010bf

File tree

6 files changed

+48
-24
lines changed

6 files changed

+48
-24
lines changed

fog.conf

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,19 @@ log_file_mb = 0
1919
# FW_LOG_FILES: How many logs files to keep around.
2020
log_files = 0
2121
# FW_BUFFER_UDP: This is the UDP socket buffer in bytes.
22-
buffer_udp = 1048576
22+
buffer_udp = 4194304 # 4MB
2323
# FW_BUFFER_PACKET: This is the size of the read buffer per packet.
24-
buffer_packet = 8192
24+
buffer_packet = 262144 # 256KB
2525
# FW_BUFFER_CHAN: This is the channel buffer between the listeners and processors.
26-
buffer_chan = 10240
26+
buffer_chan = 32768 # 32 thousand
2727
# FW_LISTENERS: How many UDP socket listener threads to start.
2828
listeners = 1
2929
# FW_PROCESSORS: How many packet processor threads to start.
3030
processors = 1
3131
# FW_WRITERS: How many file system operations may happen in parallel. 2-5 is fine with fast disks.
3232
writers = 1
3333
# FW_BUFFER_FILE_SYS: How many file pointers can be buffered into the file system writer.
34-
buffer_file_sys = 10240
34+
buffer_file_sys = 32768 # 32 thousand
3535
# FW_DEBUG: Prints 1 line per packet when enabled.
3636
debug = false
3737

pkg/fog/logger.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,22 @@ func (c *Config) Errorf(msg string, v ...any) {
6464
// printConfig logs the current configuration information.
6565
func (c *Config) printConfig() {
6666
c.Printf("=> Fog Willow Starting, pid: %d", os.Getpid())
67-
c.Printf("=> Listen Address / Password: %s / %v", c.ListenAddr, c.Password != "")
67+
c.Printf("=> UDP Listen Address / Password: %s / %v", c.ListenAddr, c.Password != "")
68+
69+
if c.HTTPServer.TLSCertPath != "" && c.HTTPServer.TLSKeyPath != "" {
70+
c.Printf("=> HTTPS Listen Address: %s (Cert=%s, Key=%s)", c.HTTPServer.ListenAddr, c.HTTPServer.TLSCertPath, c.HTTPServer.TLSKeyPath)
71+
} else {
72+
c.Printf("=> HTTP Listen Address: %s", c.HTTPServer.ListenAddr)
73+
}
74+
75+
c.Printf("=> HTTP Server; Read/Header/Write/Idle: %s/%s/%s/%s, Max Header Bytes: %d",
76+
c.HTTPServer.ReadTimeout, c.HTTPServer.ReadHeaderTimeout, c.HTTPServer.WriteTimeout,
77+
c.HTTPServer.IdleTimeout, c.HTTPServer.MaxHeaderBytes)
78+
6879
c.Printf("=> Output Path: %s", c.OutputPath)
6980
c.Printf("=> Intervals; Flush/Group: %s/%s", c.FlushInterval, c.GroupInterval)
7081
c.Printf("=> Buffers; UDP/Packet/Chan/FS: %d/%d/%d/%d", c.BufferUDP, c.BufferPacket, c.BufferChan, c.BufferFileSys)
82+
c.Printf("=> Buffer Pool (File Buffers): %v", c.BufferPool)
7183
c.Printf("=> Threads; Listen/Process/Writer: %d/%d/%d", c.Listeners, c.Processors, c.Writers)
7284

7385
if c.LogFile != "" {

pkg/fog/start.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ type Config struct {
5757
func LoadConfigFile(path string) (*Config, error) {
5858
config := &Config{
5959
OutputPath: DefaultOutputPath,
60-
HTTPServer: &httpserver.Config{ListenAddr: httpserver.DefaultListenAddr},
60+
HTTPServer: httpserver.DefaultConfig(),
6161
BufferUDP: DefaultUDPBuffer,
6262
BufferPacket: DefaultPacketBuffer,
6363
BufferChan: DefaultChanBuffer,
@@ -136,17 +136,23 @@ func (c *Config) setup() {
136136
c.Logger = c
137137
c.Metrics = c.metrics
138138
c.willow = willow.NeWillow(c.Config)
139+
140+
if c.HTTPServer == nil {
141+
c.HTTPServer = httpserver.DefaultConfig()
142+
}
143+
144+
c.HTTPServer.Setup()
139145
}
140146

141147
func (c *Config) setupSocket() error {
142-
addr, err := net.ResolveUDPAddr("udp", c.HTTPServer.ListenAddr)
148+
addr, err := net.ResolveUDPAddr("udp", c.ListenAddr)
143149
if err != nil {
144-
return fmt.Errorf("invalid listen_addr provided: %w", err)
150+
return fmt.Errorf("invalid udp listen_addr: %w", err)
145151
}
146152

147153
c.sock, err = net.ListenUDP("udp", addr)
148154
if err != nil {
149-
return fmt.Errorf("unable to use provided listen_addr: %w", err)
155+
return fmt.Errorf("unable to use udp listen_addr: %w", err)
150156
}
151157

152158
err = c.sock.SetReadBuffer(int(c.BufferUDP)) //nolint:gosec

pkg/httpserver/config.go

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ type Config struct {
2424
TLSKeyPath string `toml:"tls_key_path" xml:"tls_key_path"`
2525
}
2626

27-
func defaultConfig() *Config {
27+
// DefaultConfig returns the default configuration for the HTTP server.
28+
func DefaultConfig() *Config {
2829
return &Config{
2930
ListenAddr: DefaultListenAddr,
3031
ReadTimeout: DefaultReadTimeout,
@@ -35,24 +36,29 @@ func defaultConfig() *Config {
3536
}
3637
}
3738

38-
func validateConfig(config *Config) {
39-
if config.ReadTimeout <= 0 {
40-
config.ReadTimeout = DefaultReadTimeout
39+
// Setup fills empty listen address and any zero timeouts or limits so logs and runtime match.
40+
func (c *Config) Setup() {
41+
if c.ListenAddr == "" {
42+
c.ListenAddr = DefaultListenAddr
4143
}
4244

43-
if config.ReadHeaderTimeout <= 0 {
44-
config.ReadHeaderTimeout = DefaultReadHeaderTimeout
45+
if c.ReadTimeout <= 0 {
46+
c.ReadTimeout = DefaultReadTimeout
4547
}
4648

47-
if config.WriteTimeout <= 0 {
48-
config.WriteTimeout = DefaultWriteTimeout
49+
if c.ReadHeaderTimeout <= 0 {
50+
c.ReadHeaderTimeout = DefaultReadHeaderTimeout
4951
}
5052

51-
if config.IdleTimeout <= 0 {
52-
config.IdleTimeout = DefaultIdleTimeout
53+
if c.WriteTimeout <= 0 {
54+
c.WriteTimeout = DefaultWriteTimeout
5355
}
5456

55-
if config.MaxHeaderBytes <= 0 {
56-
config.MaxHeaderBytes = DefaultMaxHeaderBytes
57+
if c.IdleTimeout <= 0 {
58+
c.IdleTimeout = DefaultIdleTimeout
59+
}
60+
61+
if c.MaxHeaderBytes <= 0 {
62+
c.MaxHeaderBytes = DefaultMaxHeaderBytes
5763
}
5864
}

pkg/httpserver/server.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ type Server struct {
2323
// to the same mux (e.g. mux.Handle("/api/", apiHandler)). /metrics is always registered.
2424
func New(config *Config, register func(mux *http.ServeMux)) *Server {
2525
if config == nil {
26-
config = defaultConfig()
26+
config = DefaultConfig()
2727
}
2828

29-
validateConfig(config)
29+
config.Setup()
3030

3131
mux := http.NewServeMux()
3232
mux.Handle("/metrics", promhttp.Handler())

pkg/willow/willow.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212

1313
// Defaults for the module.
1414
const (
15-
DefaultFileSysBuffer = 1024 * 10
15+
DefaultFileSysBuffer = 1 << 15 // 32 thousand
1616
DefaultFlushInterval = 16 * time.Second
1717
)
1818

0 commit comments

Comments
 (0)