Skip to content

Commit ecc6e1d

Browse files
authored
Merge pull request #2370 from hashicorp/f-gc
Allow specification of eval/job gc threshold
2 parents 6a69a09 + e2d2911 commit ecc6e1d

File tree

6 files changed

+46
-0
lines changed

6 files changed

+46
-0
lines changed

command/agent/agent.go

+14
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,20 @@ func convertServerConfig(agentConfig *Config, logOutput io.Writer) (*nomad.Confi
165165
}
166166
conf.NodeGCThreshold = dur
167167
}
168+
if gcThreshold := agentConfig.Server.JobGCThreshold; gcThreshold != "" {
169+
dur, err := time.ParseDuration(gcThreshold)
170+
if err != nil {
171+
return nil, err
172+
}
173+
conf.JobGCThreshold = dur
174+
}
175+
if gcThreshold := agentConfig.Server.EvalGCThreshold; gcThreshold != "" {
176+
dur, err := time.ParseDuration(gcThreshold)
177+
if err != nil {
178+
return nil, err
179+
}
180+
conf.EvalGCThreshold = dur
181+
}
168182

169183
if heartbeatGrace := agentConfig.Server.HeartbeatGrace; heartbeatGrace != "" {
170184
dur, err := time.ParseDuration(heartbeatGrace)

command/agent/config-test-fixtures/basic.hcl

+2
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ server {
6565
num_schedulers = 2
6666
enabled_schedulers = ["test"]
6767
node_gc_threshold = "12h"
68+
job_gc_threshold = "12h"
69+
eval_gc_threshold = "12h"
6870
heartbeat_grace = "30s"
6971
retry_join = [ "1.1.1.1", "2.2.2.2" ]
7072
start_join = [ "1.1.1.1", "2.2.2.2" ]

command/agent/config.go

+18
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,20 @@ type ServerConfig struct {
238238
EnabledSchedulers []string `mapstructure:"enabled_schedulers"`
239239

240240
// NodeGCThreshold controls how "old" a node must be to be collected by GC.
241+
// Age is not the only requirement for a node to be GCed but the threshold
242+
// can be used to filter by age.
241243
NodeGCThreshold string `mapstructure:"node_gc_threshold"`
242244

245+
// JobGCThreshold controls how "old" a job must be to be collected by GC.
246+
// Age is not the only requirement for a Job to be GCed but the threshold
247+
// can be used to filter by age.
248+
JobGCThreshold string `mapstructure:"job_gc_threshold"`
249+
250+
// EvalGCThreshold controls how "old" an eval must be to be collected by GC.
251+
// Age is not the only requirement for a eval to be GCed but the threshold
252+
// can be used to filter by age.
253+
EvalGCThreshold string `mapstructure:"eval_gc_threshold"`
254+
243255
// HeartbeatGrace is the grace period beyond the TTL to account for network,
244256
// processing delays and clock skew before marking a node as "down".
245257
HeartbeatGrace string `mapstructure:"heartbeat_grace"`
@@ -834,6 +846,12 @@ func (a *ServerConfig) Merge(b *ServerConfig) *ServerConfig {
834846
if b.NodeGCThreshold != "" {
835847
result.NodeGCThreshold = b.NodeGCThreshold
836848
}
849+
if b.JobGCThreshold != "" {
850+
result.JobGCThreshold = b.JobGCThreshold
851+
}
852+
if b.EvalGCThreshold != "" {
853+
result.EvalGCThreshold = b.EvalGCThreshold
854+
}
837855
if b.HeartbeatGrace != "" {
838856
result.HeartbeatGrace = b.HeartbeatGrace
839857
}

command/agent/config_parse.go

+2
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,8 @@ func parseServer(result **ServerConfig, list *ast.ObjectList) error {
498498
"num_schedulers",
499499
"enabled_schedulers",
500500
"node_gc_threshold",
501+
"eval_gc_threshold",
502+
"job_gc_threshold",
501503
"heartbeat_grace",
502504
"start_join",
503505
"retry_join",

command/agent/config_parse_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ func TestConfig_Parse(t *testing.T) {
8282
NumSchedulers: 2,
8383
EnabledSchedulers: []string{"test"},
8484
NodeGCThreshold: "12h",
85+
EvalGCThreshold: "12h",
86+
JobGCThreshold: "12h",
8587
HeartbeatGrace: "30s",
8688
RetryJoin: []string{"1.1.1.1", "2.2.2.2"},
8789
StartJoin: []string{"1.1.1.1", "2.2.2.2"},

website/source/docs/agent/configuration/server.html.md

+8
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,14 @@ server {
6868
terminal state before it is garbage collected and purged from the system. This
6969
is specified using a label suffix like "30s" or "1h".
7070

71+
- `job_gc_threshold` `(string: "4h")` - Specifies the minimum time a job must be
72+
in the terminal state before it is eligible for garbage collection. This is
73+
specified using a label suffix like "30s" or "1h".
74+
75+
- `eval_gc_threshold` `(string: "1h")` - Specifies the minimum time an
76+
evaluation must be in the terminal state before it is eligible for garbage
77+
collection. This is specified using a label suffix like "30s" or "1h".
78+
7179
- `num_schedulers` `(int: [num-cores])` - Specifies the number of parallel
7280
scheduler threads to run. This can be as many as one per core, or `0` to
7381
disallow this server from making any scheduling decisions. This defaults to

0 commit comments

Comments
 (0)