Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

checks: Add Interval and Timeout to API response (release/1.10.x) #10868

Merged
merged 1 commit into from
Aug 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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