Skip to content

Commit

Permalink
checks: populate interval and timeout when registering services (#11138)
Browse files Browse the repository at this point in the history
  • Loading branch information
eculver committed Feb 18, 2022
1 parent 362753c commit 602e08a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .changelog/11138.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
checks: populate interval and timeout when registering services
```
12 changes: 12 additions & 0 deletions agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -2120,10 +2120,22 @@ func (a *Agent) addServiceInternal(req addServiceInternalRequest) error {
if name == "" {
name = fmt.Sprintf("Service '%s' check", service.Service)
}

var intervalStr string
var timeoutStr string
if chkType.Interval != 0 {
intervalStr = chkType.Interval.String()
}
if chkType.Timeout != 0 {
timeoutStr = chkType.Interval.String()
}

check := &structs.HealthCheck{
Node: a.config.NodeName,
CheckID: types.CheckID(checkID),
Name: name,
Interval: intervalStr,
Timeout: timeoutStr,
Status: api.HealthCritical,
Notes: chkType.Notes,
ServiceID: service.ID,
Expand Down
10 changes: 10 additions & 0 deletions agent/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,8 @@ func testAgent_AddService(t *testing.T, extraHCL string) {
Node: "node1",
CheckID: "check1",
Name: "name1",
Interval: "",
Timeout: "", // these are empty because a TTL was provided
Status: "critical",
Notes: "note1",
ServiceID: "svcid1",
Expand Down Expand Up @@ -500,6 +502,8 @@ func testAgent_AddService(t *testing.T, extraHCL string) {
Node: "node1",
CheckID: "check1",
Name: "name1",
Interval: "",
Timeout: "", // these are empty bcause a TTL was provided
Status: "critical",
Notes: "note1",
ServiceID: "svcid2",
Expand All @@ -512,6 +516,8 @@ func testAgent_AddService(t *testing.T, extraHCL string) {
Node: "node1",
CheckID: "check-noname",
Name: "Service 'svcname2' check",
Interval: "",
Timeout: "", // these are empty because a TTL was provided
Status: "critical",
ServiceID: "svcid2",
ServiceName: "svcname2",
Expand All @@ -523,6 +529,8 @@ func testAgent_AddService(t *testing.T, extraHCL string) {
Node: "node1",
CheckID: "service:svcid2:3",
Name: "check-noid",
Interval: "",
Timeout: "", // these are empty becuase a TTL was provided
Status: "critical",
ServiceID: "svcid2",
ServiceName: "svcname2",
Expand All @@ -534,6 +542,8 @@ func testAgent_AddService(t *testing.T, extraHCL string) {
Node: "node1",
CheckID: "service:svcid2:4",
Name: "Service 'svcname2' check",
Interval: "",
Timeout: "", // these are empty because a TTL was provided
Status: "critical",
ServiceID: "svcid2",
ServiceName: "svcname2",
Expand Down

0 comments on commit 602e08a

Please sign in to comment.