Skip to content

Commit

Permalink
Remove the script field from checks in favor of args
Browse files Browse the repository at this point in the history
  • Loading branch information
kyhavlov committed May 8, 2018
1 parent cc214d4 commit b73323a
Show file tree
Hide file tree
Showing 14 changed files with 33 additions and 93 deletions.
12 changes: 0 additions & 12 deletions agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -1823,11 +1823,6 @@ func (a *Agent) AddCheck(check *structs.HealthCheck, chkType *structs.CheckType,
check.CheckID, checks.MinInterval))
chkType.Interval = checks.MinInterval
}
if chkType.Script != "" {
a.logger.Printf("[WARN] agent: check %q has the 'script' field, which has been deprecated "+
"and replaced with the 'args' field. See https://www.consul.io/docs/agent/checks.html",
check.CheckID)
}

if a.dockerClient == nil {
dc, err := checks.NewDockerClient(os.Getenv("DOCKER_HOST"), checks.BufSize)
Expand All @@ -1844,7 +1839,6 @@ func (a *Agent) AddCheck(check *structs.HealthCheck, chkType *structs.CheckType,
CheckID: check.CheckID,
DockerContainerID: chkType.DockerContainerID,
Shell: chkType.Shell,
Script: chkType.Script,
ScriptArgs: chkType.ScriptArgs,
Interval: chkType.Interval,
Logger: a.logger,
Expand All @@ -1866,16 +1860,10 @@ func (a *Agent) AddCheck(check *structs.HealthCheck, chkType *structs.CheckType,
check.CheckID, checks.MinInterval)
chkType.Interval = checks.MinInterval
}
if chkType.Script != "" {
a.logger.Printf("[WARN] agent: check %q has the 'script' field, which has been deprecated "+
"and replaced with the 'args' field. See https://www.consul.io/docs/agent/checks.html",
check.CheckID)
}

monitor := &checks.CheckMonitor{
Notify: a.State,
CheckID: check.CheckID,
Script: chkType.Script,
ScriptArgs: chkType.ScriptArgs,
Interval: chkType.Interval,
Timeout: chkType.Timeout,
Expand Down
8 changes: 0 additions & 8 deletions agent/agent_endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -716,14 +716,6 @@ func TestAgent_RegisterCheck_Scripts(t *testing.T) {
name string
check map[string]interface{}
}{
{
"< Consul 1.0.0",
map[string]interface{}{
"Name": "test",
"Interval": "2s",
"Script": "true",
},
},
{
"== Consul 1.0.0",
map[string]interface{}{
Expand Down
30 changes: 15 additions & 15 deletions agent/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -651,8 +651,8 @@ func TestAgent_AddCheck(t *testing.T) {
Status: api.HealthCritical,
}
chk := &structs.CheckType{
Script: "exit 0",
Interval: 15 * time.Second,
ScriptArgs: []string{"exit", "0"},
Interval: 15 * time.Second,
}
err := a.AddCheck(health, chk, false, "")
if err != nil {
Expand Down Expand Up @@ -690,8 +690,8 @@ func TestAgent_AddCheck_StartPassing(t *testing.T) {
Status: api.HealthPassing,
}
chk := &structs.CheckType{
Script: "exit 0",
Interval: 15 * time.Second,
ScriptArgs: []string{"exit", "0"},
Interval: 15 * time.Second,
}
err := a.AddCheck(health, chk, false, "")
if err != nil {
Expand Down Expand Up @@ -729,8 +729,8 @@ func TestAgent_AddCheck_MinInterval(t *testing.T) {
Status: api.HealthCritical,
}
chk := &structs.CheckType{
Script: "exit 0",
Interval: time.Microsecond,
ScriptArgs: []string{"exit", "0"},
Interval: time.Microsecond,
}
err := a.AddCheck(health, chk, false, "")
if err != nil {
Expand Down Expand Up @@ -764,8 +764,8 @@ func TestAgent_AddCheck_MissingService(t *testing.T) {
ServiceID: "baz",
}
chk := &structs.CheckType{
Script: "exit 0",
Interval: time.Microsecond,
ScriptArgs: []string{"exit", "0"},
Interval: time.Microsecond,
}
err := a.AddCheck(health, chk, false, "")
if err == nil || err.Error() != `ServiceID "baz" does not exist` {
Expand Down Expand Up @@ -829,8 +829,8 @@ func TestAgent_AddCheck_ExecDisable(t *testing.T) {
Status: api.HealthCritical,
}
chk := &structs.CheckType{
Script: "exit 0",
Interval: 15 * time.Second,
ScriptArgs: []string{"exit", "0"},
Interval: 15 * time.Second,
}
err := a.AddCheck(health, chk, false, "")
if err == nil || !strings.Contains(err.Error(), "Scripts are disabled on this agent") {
Expand Down Expand Up @@ -904,8 +904,8 @@ func TestAgent_RemoveCheck(t *testing.T) {
Status: api.HealthCritical,
}
chk := &structs.CheckType{
Script: "exit 0",
Interval: 15 * time.Second,
ScriptArgs: []string{"exit", "0"},
Interval: 15 * time.Second,
}
err := a.AddCheck(health, chk, false, "")
if err != nil {
Expand Down Expand Up @@ -1315,8 +1315,8 @@ func TestAgent_PersistCheck(t *testing.T) {
Status: api.HealthPassing,
}
chkType := &structs.CheckType{
Script: "/bin/true",
Interval: 10 * time.Second,
ScriptArgs: []string{"/bin/true"},
Interval: 10 * time.Second,
}

file := filepath.Join(a.Config.DataDir, checksDir, checkIDHash(check.CheckID))
Expand Down Expand Up @@ -1473,7 +1473,7 @@ func TestAgent_PurgeCheckOnDuplicate(t *testing.T) {
id = "mem"
name = "memory check"
notes = "my cool notes"
script = "/bin/check-redis.py"
args = ["/bin/check-redis.py"]
interval = "30s"
}
`)
Expand Down
1 change: 0 additions & 1 deletion agent/config/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -967,7 +967,6 @@ func (b *Builder) checkVal(v *CheckDefinition) *structs.CheckDefinition {
ServiceID: b.stringVal(v.ServiceID),
Token: b.stringVal(v.Token),
Status: b.stringVal(v.Status),
Script: b.stringVal(v.Script),
ScriptArgs: v.ScriptArgs,
HTTP: b.stringVal(v.HTTP),
Header: v.Header,
Expand Down
1 change: 0 additions & 1 deletion agent/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,6 @@ type CheckDefinition struct {
ServiceID *string `json:"service_id,omitempty" hcl:"service_id" mapstructure:"service_id"`
Token *string `json:"token,omitempty" hcl:"token" mapstructure:"token"`
Status *string `json:"status,omitempty" hcl:"status" mapstructure:"status"`
Script *string `json:"script,omitempty" hcl:"script" mapstructure:"script"`
ScriptArgs []string `json:"args,omitempty" hcl:"args" mapstructure:"args"`
HTTP *string `json:"http,omitempty" hcl:"http" mapstructure:"http"`
Header map[string][]string `json:"header,omitempty" hcl:"header" mapstructure:"header"`
Expand Down
Loading

0 comments on commit b73323a

Please sign in to comment.