Rename config.yaml to example and add config.yaml to gitignore, make Metrics optional and configurable
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -3,3 +3,5 @@
|
||||
bin/
|
||||
data.json
|
||||
*.json
|
||||
config.yaml
|
||||
|
||||
|
||||
@@ -61,11 +61,11 @@ func main() {
|
||||
var wg sync.WaitGroup
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
<-sigs
|
||||
log.Info().Msg("Stopping server")
|
||||
server.Shutdown(context.Background())
|
||||
pipeline.Stop()
|
||||
wg.Done()
|
||||
}()
|
||||
|
||||
if config.Server.Ssl.Enabled {
|
||||
@@ -127,8 +127,14 @@ func configureMiddleware(config *domainrouter.Config) *middleware.Pipeline {
|
||||
pipeline.AddMiddleware(&middleware.RequestLogger{})
|
||||
}
|
||||
|
||||
metrics := middleware.NewMetrics(512, 1*time.Minute, "tmp_metrics.json")
|
||||
if config.Metrics.Enabled {
|
||||
flushInterval, err := time.ParseDuration(config.Metrics.FlushInterval)
|
||||
if err != nil {
|
||||
log.Fatal().Err(err).Str("flush_interval", config.Metrics.FlushInterval).Msg("Could not parse FlushInterval")
|
||||
}
|
||||
metrics := middleware.NewMetrics(config.Metrics.BufferSize, flushInterval, config.Metrics.File)
|
||||
pipeline.AddMiddleware(metrics)
|
||||
}
|
||||
|
||||
return pipeline
|
||||
}
|
||||
|
||||
@@ -43,4 +43,10 @@ type Config struct {
|
||||
MaxBackups int `yamls:"maxBackups"`
|
||||
} `yaml:"file"`
|
||||
} `yaml:"logging"`
|
||||
Metrics struct {
|
||||
Enabled bool `yaml:"enabled"`
|
||||
File string `yaml:"file"`
|
||||
BufferSize int `yaml:"bufferSize"`
|
||||
FlushInterval string `yaml:"flushInterval"`
|
||||
} `yaml:"metrics"`
|
||||
}
|
||||
|
||||
@@ -1,21 +1,20 @@
|
||||
server:
|
||||
port: 443
|
||||
port: 80
|
||||
ssl:
|
||||
enabled: true
|
||||
enabled: false
|
||||
certFile: server.crt
|
||||
keyFile: server.key
|
||||
acme:
|
||||
enabled: false
|
||||
email: me@pablu.de
|
||||
email: user@host.dev
|
||||
keyFile: userKey.key
|
||||
caDirUrl: https://192.168.2.154:14000/dir
|
||||
caDirUrl: https://localhost:14000/dir
|
||||
tlsAlpn01Port: 5001
|
||||
http01Port: 5002
|
||||
renewTime: 30s
|
||||
|
||||
|
||||
logging:
|
||||
level: trace
|
||||
level: info
|
||||
# Pretty print for human consumption otherwise json
|
||||
pretty: true
|
||||
# Log incoming requests
|
||||
@@ -27,7 +26,6 @@ logging:
|
||||
maxBackups: 10
|
||||
path: ~/logs/router
|
||||
|
||||
|
||||
rateLimit:
|
||||
enabled: false
|
||||
# How many requests per ip adress are allowed
|
||||
@@ -39,35 +37,25 @@ rateLimit:
|
||||
# How often Ip Addresses get cleaned up (only ip addresses with max allowed requests are cleaned up)
|
||||
cleanupTime: 45s
|
||||
|
||||
# Experimental
|
||||
metrics:
|
||||
enabled: false
|
||||
flushInterval: 1h
|
||||
bufferSize: 512
|
||||
file: ~/metrics.json
|
||||
|
||||
hosts:
|
||||
# Remote address to request
|
||||
- remotes:
|
||||
- localhost
|
||||
# Port on which to request
|
||||
port: 8181
|
||||
# Domains which get redirected to host
|
||||
- 127.0.0.1
|
||||
port: 3000
|
||||
domains:
|
||||
- localhost
|
||||
- test.localhost
|
||||
|
||||
- remotes:
|
||||
- localhost
|
||||
port: 8080
|
||||
domains:
|
||||
- api.hitstar.localhost
|
||||
|
||||
- remotes:
|
||||
- localhost
|
||||
port: 5173
|
||||
domains:
|
||||
- hitstar.localhost
|
||||
- hipstar.localhost
|
||||
rewrite:
|
||||
"/api": api.hitstar.localhost
|
||||
- api.hitstar.xyz
|
||||
|
||||
- remotes:
|
||||
- 127.0.0.1
|
||||
port: 46009
|
||||
port: 5173
|
||||
domains:
|
||||
- chat.localhost
|
||||
- localhost
|
||||
- hitstar.xyz
|
||||
rewrite:
|
||||
"/api": api.hitstar.xyz
|
||||
@@ -130,7 +130,7 @@ func (m *Metrics) Flush() {
|
||||
return
|
||||
}
|
||||
|
||||
log.Info().Str("file", m.file).Int("count", len(a)).Msg("Completed Metrics flush")
|
||||
log.Debug().Str("file", m.file).Int("count", len(a)).Msg("Completed Metrics flush")
|
||||
}
|
||||
|
||||
func (m *Metrics) Stop() {
|
||||
|
||||
Reference in New Issue
Block a user