From 067223337d98506b0f994e18bbfe69e37cc8fb8d Mon Sep 17 00:00:00 2001 From: Evan Culver Date: Fri, 18 Feb 2022 12:05:33 -0800 Subject: [PATCH] checks: populate interval and timeout when registering services (#11138) --- .changelog/11138.txt | 3 +++ agent/agent.go | 12 ++++++++++++ agent/agent_test.go | 10 ++++++++++ 3 files changed, 25 insertions(+) create mode 100644 .changelog/11138.txt diff --git a/.changelog/11138.txt b/.changelog/11138.txt new file mode 100644 index 000000000..45b66d827 --- /dev/null +++ b/.changelog/11138.txt @@ -0,0 +1,3 @@ +```release-note:bug +checks: populate interval and timeout when registering services +``` diff --git a/agent/agent.go b/agent/agent.go index dd981a459..15b439be0 100644 --- a/agent/agent.go +++ b/agent/agent.go @@ -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, diff --git a/agent/agent_test.go b/agent/agent_test.go index b37564a61..25708ace6 100644 --- a/agent/agent_test.go +++ b/agent/agent_test.go @@ -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", @@ -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", @@ -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", @@ -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", @@ -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",