From 13ac6356a8f5efb1e0b9313b645a399edb113ae4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Gra=C3=B1a?= Date: Thu, 15 Sep 2022 13:39:48 -0300 Subject: [PATCH] [BUGFIX] Do not use interval as timeout (#14619) Do not use interval as timeout --- .changelog/14619.txt | 3 +++ agent/agent.go | 2 +- agent/agent_test.go | 47 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 .changelog/14619.txt diff --git a/.changelog/14619.txt b/.changelog/14619.txt new file mode 100644 index 000000000..944493124 --- /dev/null +++ b/.changelog/14619.txt @@ -0,0 +1,3 @@ +```release-note:bug +checks: Do not set interval as timeout value +``` diff --git a/agent/agent.go b/agent/agent.go index 097739acc..92f4a06e9 100644 --- a/agent/agent.go +++ b/agent/agent.go @@ -2287,7 +2287,7 @@ func (a *Agent) addServiceInternal(req addServiceInternalRequest) error { intervalStr = chkType.Interval.String() } if chkType.Timeout != 0 { - timeoutStr = chkType.Interval.String() + timeoutStr = chkType.Timeout.String() } check := &structs.HealthCheck{ diff --git a/agent/agent_test.go b/agent/agent_test.go index efd983e78..ea1535821 100644 --- a/agent/agent_test.go +++ b/agent/agent_test.go @@ -418,6 +418,9 @@ func testAgent_AddService(t *testing.T, extraHCL string) { `+extraHCL) defer a.Shutdown() + duration3s, _ := time.ParseDuration("3s") + duration10s, _ := time.ParseDuration("10s") + tests := []struct { desc string srv *structs.NodeService @@ -467,6 +470,50 @@ func testAgent_AddService(t *testing.T, extraHCL string) { }, }, }, + { + "one http check with interval and duration", + &structs.NodeService{ + ID: "svcid1", + Service: "svcname1", + Tags: []string{"tag1"}, + Weights: nil, // nil weights... + Port: 8100, + EnterpriseMeta: *structs.DefaultEnterpriseMetaInDefaultPartition(), + }, + // ... should be populated to avoid "IsSame" returning true during AE. + func(ns *structs.NodeService) { + ns.Weights = &structs.Weights{ + Passing: 1, + Warning: 1, + } + }, + []*structs.CheckType{ + { + CheckID: "check1", + Name: "name1", + HTTP: "http://localhost:8100/", + Interval: duration10s, + Timeout: duration3s, + Notes: "note1", + }, + }, + map[string]*structs.HealthCheck{ + "check1": { + Node: "node1", + CheckID: "check1", + Name: "name1", + Interval: "10s", + Timeout: "3s", + Status: "critical", + Notes: "note1", + ServiceID: "svcid1", + ServiceName: "svcname1", + ServiceTags: []string{"tag1"}, + Type: "http", + EnterpriseMeta: *structs.DefaultEnterpriseMetaInDefaultPartition(), + }, + }, + }, { "multiple checks", &structs.NodeService{