diff --git a/pkg/provider/tcp/README.md b/pkg/provider/tcp/README.md index 1c5777f..d806a5b 100644 --- a/pkg/provider/tcp/README.md +++ b/pkg/provider/tcp/README.md @@ -13,7 +13,7 @@ The TCP Provider is configured through the platform-health server's configuratio * `name` (required): The name of the TCP service instance, used to identify the service in the health reports. * `host` (required): The hostname or IP address of the TCP service to monitor. * `port` (default: `80`): The port number of the TCP service to monitor. -* `invert` (default: `false`): Reverse logic to report "unhealthy" if port is open and "healthy" if it is closed. +* `closed` (default: `false`): Reverse logic to report "healthy" if port is closed and "unhealthy" if it is open. * `timeout` (default: `1s`): The maximum time to wait for a connection to be established before timing out. ### Example diff --git a/pkg/provider/tcp/tcp.go b/pkg/provider/tcp/tcp.go index 8d65df8..5aa5c87 100644 --- a/pkg/provider/tcp/tcp.go +++ b/pkg/provider/tcp/tcp.go @@ -20,7 +20,7 @@ type TCP struct { Name string `mapstructure:"name"` Host string `mapstructure:"host"` Port int `mapstructure:"port" default:"80"` - Invert bool `mapstructure:"invert" default:"false"` + Closed bool `mapstructure:"closed" default:"false"` Timeout time.Duration `mapstructure:"timeout" default:"1s"` } @@ -33,8 +33,8 @@ func (i *TCP) LogValue() slog.Value { slog.String("name", i.Name), slog.String("host", i.Host), slog.Int("port", i.Port), + slog.Bool("closed", i.Closed), slog.Any("timeout", i.Timeout), - slog.Bool("invert", i.Invert), } return slog.GroupValue(logAttr...) } @@ -68,14 +68,14 @@ func (i *TCP) GetHealth(ctx context.Context) *ph.HealthCheckResponse { dialer := &net.Dialer{} conn, err := dialer.DialContext(ctx, "tcp", address) if err != nil { - if i.Invert { + if i.Closed { return component.Healthy() } else { return component.Unhealthy(err.Error()) } } else { _ = conn.Close() - if i.Invert { + if i.Closed { return component.Unhealthy("port open") } else { return component.Healthy() diff --git a/pkg/provider/tcp/tcp_test.go b/pkg/provider/tcp/tcp_test.go index fd3ffcc..dc8a72e 100644 --- a/pkg/provider/tcp/tcp_test.go +++ b/pkg/provider/tcp/tcp_test.go @@ -30,7 +30,7 @@ func TestTCP(t *testing.T) { tests := []struct { name string port int - invert bool + closed bool timeout time.Duration expected ph.Status }{ @@ -40,14 +40,14 @@ func TestTCP(t *testing.T) { expected: ph.Status_HEALTHY, }, { - name: "Port closed", + name: "Port closed, wanted open", port: 1, expected: ph.Status_UNHEALTHY, }, { - name: "Port closed, expect failure", + name: "Port closed, wanted closed", port: 1, - invert: true, + closed: true, expected: ph.Status_HEALTHY, }, { @@ -59,7 +59,7 @@ func TestTCP(t *testing.T) { { name: "Expected timeout", port: port, - invert: true, + closed: true, timeout: time.Nanosecond, expected: ph.Status_HEALTHY, }, @@ -71,7 +71,7 @@ func TestTCP(t *testing.T) { Name: tt.name, Host: "localhost", Port: tt.port, - Invert: tt.invert, + Closed: tt.closed, Timeout: tt.timeout, } instance.SetDefaults()