Skip to content

Commit

Permalink
config file: log_max_entries
Browse files Browse the repository at this point in the history
  • Loading branch information
metachris committed Nov 20, 2024
1 parent 347544f commit 3150ef3
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 7 deletions.
3 changes: 3 additions & 0 deletions systemapi-config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ pprof = true
log_json = false
log_debug = true

# Maximum number of entries in the log
log_max_entries = 1000

# HTTP Basic Auth
basic_auth_secret_path = "basic-auth-secret.txt" # basic auth is supported if a path is provided
basic_auth_secret_salt = "D;%yL9TS:5PalS/d" # use a random string for the salt
Expand Down
17 changes: 12 additions & 5 deletions systemapi/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ import (
)

type systemAPIConfigGeneral struct {
ListenAddr string `toml:"listen_addr"`
PipeFile string `toml:"pipe_file"`
LogJSON bool `toml:"log_json"`
LogDebug bool `toml:"log_debug"`
EnablePprof bool `toml:"pprof"` // Enables pprof endpoints
ListenAddr string `toml:"listen_addr"`
PipeFile string `toml:"pipe_file"`
LogJSON bool `toml:"log_json"`
LogDebug bool `toml:"log_debug"`
EnablePprof bool `toml:"pprof"` // Enables pprof endpoints
LogMaxEntries int `toml:"log_max_entries"` // Maximum number of log entries

BasicAuthSecretPath string `toml:"basic_auth_secret_path"`
BasicAuthSecretSalt string `toml:"basic_auth_secret_salt"`
Expand Down Expand Up @@ -41,6 +42,12 @@ func LoadConfig(content []byte) (*SystemAPIConfig, error) {
if err != nil {
return nil, err
}

// Apply default
if cfg.General.LogMaxEntries == 0 {
cfg.General.LogMaxEntries = DefaultLogMaxEntries
}

return cfg, nil
}

Expand Down
7 changes: 7 additions & 0 deletions systemapi/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,10 @@ func TestLoadConfig(t *testing.T) {
require.NotEmpty(t, cfg.Actions)
require.Equal(t, "echo test", cfg.Actions["echo_test"])
}

func TestEmptyConfig(t *testing.T) {
cfg, err := LoadConfig([]byte{})
require.NoError(t, err)
require.NotNil(t, cfg)
require.Equal(t, DefaultLogMaxEntries, cfg.General.LogMaxEntries)
}
2 changes: 1 addition & 1 deletion systemapi/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ func (s *Server) addEvent(event Event) {
// Add event to the list and prune if necessary
s.eventsLock.Lock()
s.events = append(s.events, event)
if len(s.events) > MaxEvents {
if len(s.events) > s.cfg.General.LogMaxEntries {
s.events = s.events[1:]
}
s.eventsLock.Unlock()
Expand Down
2 changes: 1 addition & 1 deletion systemapi/vars.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ package systemapi

import "github.com/flashbots/system-api/common"

var MaxEvents = common.GetEnvInt("MAX_EVENTS", 1000)
var DefaultLogMaxEntries = common.GetEnvInt("MAX_EVENTS", 1000)

0 comments on commit 3150ef3

Please sign in to comment.