diff --git a/command/agent/agent.go b/command/agent/agent.go index ca4df6672..bfecfec7d 100644 --- a/command/agent/agent.go +++ b/command/agent/agent.go @@ -165,6 +165,20 @@ func convertServerConfig(agentConfig *Config, logOutput io.Writer) (*nomad.Confi } conf.NodeGCThreshold = dur } + if gcThreshold := agentConfig.Server.JobGCThreshold; gcThreshold != "" { + dur, err := time.ParseDuration(gcThreshold) + if err != nil { + return nil, err + } + conf.JobGCThreshold = dur + } + if gcThreshold := agentConfig.Server.EvalGCThreshold; gcThreshold != "" { + dur, err := time.ParseDuration(gcThreshold) + if err != nil { + return nil, err + } + conf.EvalGCThreshold = dur + } if heartbeatGrace := agentConfig.Server.HeartbeatGrace; heartbeatGrace != "" { dur, err := time.ParseDuration(heartbeatGrace) diff --git a/command/agent/config-test-fixtures/basic.hcl b/command/agent/config-test-fixtures/basic.hcl index 1c5e2001d..3ad81148b 100644 --- a/command/agent/config-test-fixtures/basic.hcl +++ b/command/agent/config-test-fixtures/basic.hcl @@ -65,6 +65,8 @@ server { num_schedulers = 2 enabled_schedulers = ["test"] node_gc_threshold = "12h" + job_gc_threshold = "12h" + eval_gc_threshold = "12h" heartbeat_grace = "30s" retry_join = [ "1.1.1.1", "2.2.2.2" ] start_join = [ "1.1.1.1", "2.2.2.2" ] diff --git a/command/agent/config.go b/command/agent/config.go index 9efac4b4d..9412e4567 100644 --- a/command/agent/config.go +++ b/command/agent/config.go @@ -238,8 +238,20 @@ type ServerConfig struct { EnabledSchedulers []string `mapstructure:"enabled_schedulers"` // NodeGCThreshold controls how "old" a node must be to be collected by GC. + // Age is not the only requirement for a node to be GCed but the threshold + // can be used to filter by age. NodeGCThreshold string `mapstructure:"node_gc_threshold"` + // JobGCThreshold controls how "old" a job must be to be collected by GC. + // Age is not the only requirement for a Job to be GCed but the threshold + // can be used to filter by age. + JobGCThreshold string `mapstructure:"job_gc_threshold"` + + // EvalGCThreshold controls how "old" an eval must be to be collected by GC. + // Age is not the only requirement for a eval to be GCed but the threshold + // can be used to filter by age. + EvalGCThreshold string `mapstructure:"eval_gc_threshold"` + // HeartbeatGrace is the grace period beyond the TTL to account for network, // processing delays and clock skew before marking a node as "down". HeartbeatGrace string `mapstructure:"heartbeat_grace"` @@ -834,6 +846,12 @@ func (a *ServerConfig) Merge(b *ServerConfig) *ServerConfig { if b.NodeGCThreshold != "" { result.NodeGCThreshold = b.NodeGCThreshold } + if b.JobGCThreshold != "" { + result.JobGCThreshold = b.JobGCThreshold + } + if b.EvalGCThreshold != "" { + result.EvalGCThreshold = b.EvalGCThreshold + } if b.HeartbeatGrace != "" { result.HeartbeatGrace = b.HeartbeatGrace } diff --git a/command/agent/config_parse.go b/command/agent/config_parse.go index a9320e539..35229d805 100644 --- a/command/agent/config_parse.go +++ b/command/agent/config_parse.go @@ -498,6 +498,8 @@ func parseServer(result **ServerConfig, list *ast.ObjectList) error { "num_schedulers", "enabled_schedulers", "node_gc_threshold", + "eval_gc_threshold", + "job_gc_threshold", "heartbeat_grace", "start_join", "retry_join", diff --git a/command/agent/config_parse_test.go b/command/agent/config_parse_test.go index 29cf3aef8..ba9016d7a 100644 --- a/command/agent/config_parse_test.go +++ b/command/agent/config_parse_test.go @@ -82,6 +82,8 @@ func TestConfig_Parse(t *testing.T) { NumSchedulers: 2, EnabledSchedulers: []string{"test"}, NodeGCThreshold: "12h", + EvalGCThreshold: "12h", + JobGCThreshold: "12h", HeartbeatGrace: "30s", RetryJoin: []string{"1.1.1.1", "2.2.2.2"}, StartJoin: []string{"1.1.1.1", "2.2.2.2"}, diff --git a/website/source/docs/agent/configuration/server.html.md b/website/source/docs/agent/configuration/server.html.md index 901b518b1..15c6d9f6e 100644 --- a/website/source/docs/agent/configuration/server.html.md +++ b/website/source/docs/agent/configuration/server.html.md @@ -68,6 +68,14 @@ server { terminal state before it is garbage collected and purged from the system. This is specified using a label suffix like "30s" or "1h". +- `job_gc_threshold` `(string: "4h")` - Specifies the minimum time a job must be + in the terminal state before it is eligible for garbage collection. This is + specified using a label suffix like "30s" or "1h". + +- `eval_gc_threshold` `(string: "1h")` - Specifies the minimum time an + evaluation must be in the terminal state before it is eligible for garbage + collection. This is specified using a label suffix like "30s" or "1h". + - `num_schedulers` `(int: [num-cores])` - Specifies the number of parallel scheduler threads to run. This can be as many as one per core, or `0` to disallow this server from making any scheduling decisions. This defaults to