checks: populate interval and timeout when registering services (#11138)

This commit is contained in:
Evan Culver 2022-02-18 12:05:33 -08:00 committed by GitHub
parent 9c03b5dc3d
commit 067223337d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 0 deletions

3
.changelog/11138.txt Normal file
View File

@ -0,0 +1,3 @@
```release-note:bug
checks: populate interval and timeout when registering services
```

View File

@ -2120,10 +2120,22 @@ func (a *Agent) addServiceInternal(req addServiceInternalRequest) error {
if name == "" { if name == "" {
name = fmt.Sprintf("Service '%s' check", service.Service) 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{ check := &structs.HealthCheck{
Node: a.config.NodeName, Node: a.config.NodeName,
CheckID: types.CheckID(checkID), CheckID: types.CheckID(checkID),
Name: name, Name: name,
Interval: intervalStr,
Timeout: timeoutStr,
Status: api.HealthCritical, Status: api.HealthCritical,
Notes: chkType.Notes, Notes: chkType.Notes,
ServiceID: service.ID, ServiceID: service.ID,

View File

@ -452,6 +452,8 @@ func testAgent_AddService(t *testing.T, extraHCL string) {
Node: "node1", Node: "node1",
CheckID: "check1", CheckID: "check1",
Name: "name1", Name: "name1",
Interval: "",
Timeout: "", // these are empty because a TTL was provided
Status: "critical", Status: "critical",
Notes: "note1", Notes: "note1",
ServiceID: "svcid1", ServiceID: "svcid1",
@ -500,6 +502,8 @@ func testAgent_AddService(t *testing.T, extraHCL string) {
Node: "node1", Node: "node1",
CheckID: "check1", CheckID: "check1",
Name: "name1", Name: "name1",
Interval: "",
Timeout: "", // these are empty bcause a TTL was provided
Status: "critical", Status: "critical",
Notes: "note1", Notes: "note1",
ServiceID: "svcid2", ServiceID: "svcid2",
@ -512,6 +516,8 @@ func testAgent_AddService(t *testing.T, extraHCL string) {
Node: "node1", Node: "node1",
CheckID: "check-noname", CheckID: "check-noname",
Name: "Service 'svcname2' check", Name: "Service 'svcname2' check",
Interval: "",
Timeout: "", // these are empty because a TTL was provided
Status: "critical", Status: "critical",
ServiceID: "svcid2", ServiceID: "svcid2",
ServiceName: "svcname2", ServiceName: "svcname2",
@ -523,6 +529,8 @@ func testAgent_AddService(t *testing.T, extraHCL string) {
Node: "node1", Node: "node1",
CheckID: "service:svcid2:3", CheckID: "service:svcid2:3",
Name: "check-noid", Name: "check-noid",
Interval: "",
Timeout: "", // these are empty becuase a TTL was provided
Status: "critical", Status: "critical",
ServiceID: "svcid2", ServiceID: "svcid2",
ServiceName: "svcname2", ServiceName: "svcname2",
@ -534,6 +542,8 @@ func testAgent_AddService(t *testing.T, extraHCL string) {
Node: "node1", Node: "node1",
CheckID: "service:svcid2:4", CheckID: "service:svcid2:4",
Name: "Service 'svcname2' check", Name: "Service 'svcname2' check",
Interval: "",
Timeout: "", // these are empty because a TTL was provided
Status: "critical", Status: "critical",
ServiceID: "svcid2", ServiceID: "svcid2",
ServiceName: "svcname2", ServiceName: "svcname2",