Skip to content

Commit

Permalink
checks: Add Interval and Timeout to API response (#10717)
Browse files Browse the repository at this point in the history
  • Loading branch information
eculver authored and freddygv committed Aug 18, 2021
1 parent 9cb722b commit 06d2140
Show file tree
Hide file tree
Showing 10 changed files with 207 additions and 72 deletions.
3 changes: 3 additions & 0 deletions .changelog/10717.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:improvement
checks: Add Interval and Timeout to API response.
```
19 changes: 15 additions & 4 deletions agent/agent_endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -678,10 +678,12 @@ func TestAgent_Checks(t *testing.T) {

testrpc.WaitForTestAgent(t, a.RPC, "dc1")
chk1 := &structs.HealthCheck{
Node: a.Config.NodeName,
CheckID: "mysql",
Name: "mysql",
Status: api.HealthPassing,
Node: a.Config.NodeName,
CheckID: "mysql",
Name: "mysql",
Interval: "30s",
Timeout: "5s",
Status: api.HealthPassing,
}
a.State.AddCheck(chk1, "")

Expand All @@ -697,6 +699,15 @@ func TestAgent_Checks(t *testing.T) {
if val["mysql"].Status != api.HealthPassing {
t.Fatalf("bad check: %v", obj)
}
if val["mysql"].Node != chk1.Node {
t.Fatalf("bad check: %v", obj)
}
if val["mysql"].Interval != chk1.Interval {
t.Fatalf("bad check: %v", obj)
}
if val["mysql"].Timeout != chk1.Timeout {
t.Fatalf("bad check: %v", obj)
}
}

func TestAgent_ChecksWithFilter(t *testing.T) {
Expand Down
3 changes: 3 additions & 0 deletions agent/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2631,6 +2631,7 @@ func TestAgent_PurgeCheckOnDuplicate(t *testing.T) {
notes = "my cool notes"
args = ["/bin/check-redis.py"]
interval = "30s"
timeout = "5s"
}
`})
defer a2.Shutdown()
Expand All @@ -2647,6 +2648,8 @@ func TestAgent_PurgeCheckOnDuplicate(t *testing.T) {
Name: "memory check",
Status: api.HealthCritical,
Notes: "my cool notes",
Interval: "30s",
Timeout: "5s",
EnterpriseMeta: *structs.DefaultEnterpriseMeta(),
}
require.Equal(t, expected, result)
Expand Down
2 changes: 2 additions & 0 deletions agent/structs/check_definition.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ func (c *CheckDefinition) HealthCheck(node string) *HealthCheck {
Status: api.HealthCritical,
Notes: c.Notes,
ServiceID: c.ServiceID,
Interval: c.Interval.String(),
Timeout: c.Timeout.String(),
EnterpriseMeta: c.EnterpriseMeta,
}
if c.Status != "" {
Expand Down
3 changes: 3 additions & 0 deletions agent/structs/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -1430,6 +1430,9 @@ type HealthCheck struct {
ServiceTags []string // optional service tags
Type string // Check type: http/ttl/tcp/etc

Interval string // from definition
Timeout string // from definition

// ExposedPort is the port of the exposed Envoy listener representing the
// HTTP or GRPC health check of the service.
ExposedPort int
Expand Down
13 changes: 13 additions & 0 deletions agent/structs/structs_filtering_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,19 @@ var expectedFieldConfigHealthCheck bexpr.FieldConfigurations = bexpr.FieldConfig
SupportedOperations: []bexpr.MatchOperator{bexpr.MatchEqual, bexpr.MatchNotEqual, bexpr.MatchIn, bexpr.MatchNotIn, bexpr.MatchMatches, bexpr.MatchNotMatches},
StructFieldName: "Type",
},

"Interval": &bexpr.FieldConfiguration{
CoerceFn: bexpr.CoerceString,
SupportedOperations: []bexpr.MatchOperator{bexpr.MatchEqual, bexpr.MatchNotEqual, bexpr.MatchIn, bexpr.MatchNotIn, bexpr.MatchMatches, bexpr.MatchNotMatches},
StructFieldName: "Interval",
},

"Timeout": &bexpr.FieldConfiguration{
CoerceFn: bexpr.CoerceString,
SupportedOperations: []bexpr.MatchOperator{bexpr.MatchEqual, bexpr.MatchNotEqual, bexpr.MatchIn, bexpr.MatchNotIn, bexpr.MatchMatches, bexpr.MatchNotMatches},
StructFieldName: "Timeout",
},

"ExposedPort": &bexpr.FieldConfiguration{
CoerceFn: bexpr.CoerceInt,
SupportedOperations: []bexpr.MatchOperator{bexpr.MatchEqual, bexpr.MatchNotEqual},
Expand Down
4 changes: 4 additions & 0 deletions proto/pbservice/healthcheck.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

227 changes: 159 additions & 68 deletions proto/pbservice/healthcheck.pb.go

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions proto/pbservice/healthcheck.proto
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ message HealthCheck {

// mog: func-to=int func-from=int32
int32 ExposedPort = 14;

string Interval = 15;
string Timeout = 16;
}

message HeaderValue {
Expand Down
2 changes: 2 additions & 0 deletions website/content/api-docs/agent/check.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ $ curl \
"ServiceID": "redis",
"ServiceName": "redis",
"ServiceTags": ["primary"],
"Interval": "10s",
"Timeout": "1s"
"Type": "tcp",
"ExposedPort": 0,
"Definition": {},
Expand Down

0 comments on commit 06d2140

Please sign in to comment.