diff --git a/.changelog/14885.txt b/.changelog/14885.txt new file mode 100644 index 0000000000..532f1b2d49 --- /dev/null +++ b/.changelog/14885.txt @@ -0,0 +1,4 @@ +```release-note:bug +checks: Fixed a bug that prevented registration of UDP health checks from agent configuration files, such as service definition files with embedded health check definitions. +``` + diff --git a/agent/config/builder.go b/agent/config/builder.go index 1650df0ca8..d6b045c93d 100644 --- a/agent/config/builder.go +++ b/agent/config/builder.go @@ -1562,6 +1562,7 @@ func (b *builder) checkVal(v *CheckDefinition) *structs.CheckDefinition { Body: stringVal(v.Body), DisableRedirects: boolVal(v.DisableRedirects), TCP: stringVal(v.TCP), + UDP: stringVal(v.UDP), Interval: b.durationVal(fmt.Sprintf("check[%s].interval", id), v.Interval), DockerContainerID: stringVal(v.DockerContainerID), Shell: stringVal(v.Shell), diff --git a/agent/config/builder_test.go b/agent/config/builder_test.go index 1bd6d8653f..abb7be0e1d 100644 --- a/agent/config/builder_test.go +++ b/agent/config/builder_test.go @@ -326,6 +326,24 @@ func TestBuilder_ServiceVal_MultiError(t *testing.T) { require.Contains(t, b.err.Error(), "cannot have both socket path") } +func TestBuilder_ServiceVal_with_Check(t *testing.T) { + b := builder{} + svc := b.serviceVal(&ServiceDefinition{ + Name: strPtr("unbound"), + ID: strPtr("unbound"), + Port: intPtr(12345), + Checks: []CheckDefinition{ + { + Interval: strPtr("5s"), + UDP: strPtr("localhost:53"), + }, + }, + }) + require.NoError(t, b.err) + require.Equal(t, 1, len(svc.Checks)) + require.Equal(t, "localhost:53", svc.Checks[0].UDP) +} + func intPtr(v int) *int { return &v } diff --git a/docs/service-discovery/health-checks.md b/docs/service-discovery/health-checks.md index 8e1251cc53..dc6c42950d 100644 --- a/docs/service-discovery/health-checks.md +++ b/docs/service-discovery/health-checks.md @@ -24,10 +24,11 @@ be reviewed and tested. on `config.Config` in [agent/config/config.go]. 5. Config [Service.Checks](https://www.consul.io/docs/discovery/services) - the `Checks` and `Check` fields on `ServiceDefinition` in [agent/config/config.go]. -6. CLI [consul services register](https://www.consul.io/commands/services/register) - the +6. The returned fields of `ServiceDefinition` in [agent/config/builder.go]. +7. CLI [consul services register](https://www.consul.io/commands/services/register) - the `Checks` and `Check` fields on `api.AgentServiceRegistration`. The entrypoint is `ServicesFromFiles` in [command/services/config.go]. -7. API [/v1/txn](https://www.consul.io/api-docs/txn) - the `Transaction` API allows for registering a check. +8. API [/v1/txn](https://www.consul.io/api-docs/txn) - the `Transaction` API allows for registering a check. [agent/catalog_endpoint.go]: https://github.com/hashicorp/consul/blob/main/agent/catalog_endpoint.go