diff --git a/cmd/metal-api/internal/datastore/health.go b/cmd/metal-api/internal/datastore/health.go index bff42e8ae..16f5394bd 100644 --- a/cmd/metal-api/internal/datastore/health.go +++ b/cmd/metal-api/internal/datastore/health.go @@ -4,7 +4,7 @@ import ( "context" "fmt" - "github.com/metal-stack/metal-lib/rest" + "github.com/metal-stack/metal-lib/pkg/healthstatus" r "gopkg.in/rethinkdb/rethinkdb-go.v6" ) @@ -13,18 +13,18 @@ func (rs *RethinkStore) ServiceName() string { } // Check implements the health interface and tests if the database is healthy. -func (rs *RethinkStore) Check(ctx context.Context) (rest.HealthResult, error) { +func (rs *RethinkStore) Check(ctx context.Context) (healthstatus.HealthResult, error) { var version string - returnStatus := func(err error) (rest.HealthResult, error) { + returnStatus := func(err error) (healthstatus.HealthResult, error) { if err != nil { - return rest.HealthResult{ - Status: rest.HealthStatusUnhealthy, + return healthstatus.HealthResult{ + Status: healthstatus.HealthStatusUnhealthy, }, err } - return rest.HealthResult{ - Status: rest.HealthStatusHealthy, + return healthstatus.HealthResult{ + Status: healthstatus.HealthStatusHealthy, Message: fmt.Sprintf("connected to rethinkdb version: %s", version), }, nil } diff --git a/cmd/metal-api/internal/datastore/health_integration_test.go b/cmd/metal-api/internal/datastore/health_integration_test.go index 9c6614773..f42f7da60 100644 --- a/cmd/metal-api/internal/datastore/health_integration_test.go +++ b/cmd/metal-api/internal/datastore/health_integration_test.go @@ -7,13 +7,13 @@ import ( "context" "testing" - "github.com/metal-stack/metal-lib/rest" + "github.com/metal-stack/metal-lib/pkg/healthstatus" "github.com/stretchr/testify/require" ) func TestRethinkStore_Health(t *testing.T) { result, err := sharedDS.Check(context.Background()) require.NoError(t, err) - require.Equal(t, rest.HealthStatusHealthy, result.Status) + require.Equal(t, healthstatus.HealthStatusHealthy, result.Status) require.Contains(t, result.Message, "connected to rethinkdb version: rethinkdb") } diff --git a/cmd/metal-api/internal/ipam/ipam.go b/cmd/metal-api/internal/ipam/ipam.go index df475ae80..3780ef8f6 100644 --- a/cmd/metal-api/internal/ipam/ipam.go +++ b/cmd/metal-api/internal/ipam/ipam.go @@ -6,7 +6,7 @@ import ( "fmt" "github.com/metal-stack/metal-api/cmd/metal-api/internal/metal" - "github.com/metal-stack/metal-lib/rest" + "github.com/metal-stack/metal-lib/pkg/healthstatus" "connectrpc.com/connect" goipam "github.com/metal-stack/go-ipam" @@ -29,7 +29,7 @@ type IPAMer interface { PrefixUsage(ctx context.Context, cidr string) (*metal.NetworkUsage, error) PrefixesOverlapping(existingPrefixes metal.Prefixes, newPrefixes metal.Prefixes) error // Required for healthcheck - Check(ctx context.Context) (rest.HealthResult, error) + Check(ctx context.Context) (healthstatus.HealthResult, error) ServiceName() string } @@ -174,17 +174,17 @@ func (i *ipam) ServiceName() string { return "ipam" } -func (i *ipam) Check(ctx context.Context) (rest.HealthResult, error) { +func (i *ipam) Check(ctx context.Context) (healthstatus.HealthResult, error) { resp, err := i.ip.Version(ctx, connect.NewRequest(&apiv1.VersionRequest{})) if err != nil { - return rest.HealthResult{ - Status: rest.HealthStatusUnhealthy, + return healthstatus.HealthResult{ + Status: healthstatus.HealthStatusUnhealthy, }, err } - return rest.HealthResult{ - Status: rest.HealthStatusHealthy, + return healthstatus.HealthResult{ + Status: healthstatus.HealthStatusHealthy, Message: fmt.Sprintf("connected to ipam service version:%q", resp.Msg.Revision), }, nil } diff --git a/go.mod b/go.mod index d20af46c8..cce472334 100644 --- a/go.mod +++ b/go.mod @@ -20,7 +20,7 @@ require ( github.com/looplab/fsm v1.0.2 github.com/metal-stack/go-ipam v1.14.3 github.com/metal-stack/masterdata-api v0.11.4 - github.com/metal-stack/metal-lib v0.17.2 + github.com/metal-stack/metal-lib v0.17.3-0.20240731105159-ed6e8a13670b github.com/metal-stack/security v0.8.0 github.com/metal-stack/v v1.0.3 github.com/nsqio/go-nsq v1.1.0 diff --git a/go.sum b/go.sum index 63d936879..7730cdb1f 100644 --- a/go.sum +++ b/go.sum @@ -299,8 +299,8 @@ github.com/metal-stack/go-ipam v1.14.3 h1:Iwk3N+Rttq+LS6BzfBjOutLPV3TP9ssNGHYjLv github.com/metal-stack/go-ipam v1.14.3/go.mod h1:p3iMIlDHhFoJzHaw2TmfEEthspbwJBl/i/38e/Ah750= github.com/metal-stack/masterdata-api v0.11.4 h1:bgRk7PbD5BjYbmAReaV7gTKKKrW5x/ZzCwj98VSWoJk= github.com/metal-stack/masterdata-api v0.11.4/go.mod h1:fD0AtsoNNaOLqRMBeZzDFljiQW9RlrOnxeZ20Pqhxas= -github.com/metal-stack/metal-lib v0.17.2 h1:T1rxCPgagHW/M0wWSrOj4hWsPZMSt1pYw90Z3vBm88Q= -github.com/metal-stack/metal-lib v0.17.2/go.mod h1:nyNGI4DZFOcWbSoq2Y6V3SHpFxuXBIqYBZHTb6cy//s= +github.com/metal-stack/metal-lib v0.17.3-0.20240731105159-ed6e8a13670b h1:avv0xhBBLLuOPO+bOOLGzM0de4RlPD9g1DVT3uMEeBo= +github.com/metal-stack/metal-lib v0.17.3-0.20240731105159-ed6e8a13670b/go.mod h1:nyNGI4DZFOcWbSoq2Y6V3SHpFxuXBIqYBZHTb6cy//s= github.com/metal-stack/security v0.8.0 h1:tVaSDB9m5clwYrnLyaXfPy7mQlJTnmeoHscG+RUy/xo= github.com/metal-stack/security v0.8.0/go.mod h1:7GAcQb+pOgflW30ohJygxpqc3i0dQ2ahGJK1CU5tqa0= github.com/metal-stack/v v1.0.3 h1:Sh2oBlnxrCUD+mVpzfC8HiqL045YWkxs0gpTvkjppqs= diff --git a/spec/metal-api.json b/spec/metal-api.json index 163f5f1cb..deac2690e 100644 --- a/spec/metal-api.json +++ b/spec/metal-api.json @@ -355,27 +355,7 @@ }, "services": { "additionalProperties": { - "$ref": "#/definitions/rest.HealthResult" - }, - "type": "object" - }, - "status": { - "type": "string" - } - }, - "required": [ - "message", - "status" - ] - }, - "rest.HealthResult": { - "properties": { - "message": { - "type": "string" - }, - "services": { - "additionalProperties": { - "$ref": "#/definitions/rest.HealthResult" + "$ref": "#/definitions/rest.HealthResponse" }, "type": "object" },