Skip to content

Commit

Permalink
Adapt healthcheck to new metal-lib.
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerrit91 committed Jul 31, 2024
1 parent d5e5fcf commit 4784c36
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 40 deletions.
14 changes: 7 additions & 7 deletions cmd/metal-api/internal/datastore/health.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/metal-api/internal/datastore/health_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
14 changes: 7 additions & 7 deletions cmd/metal-api/internal/ipam/ipam.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
}

Expand Down Expand Up @@ -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
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
22 changes: 1 addition & 21 deletions spec/metal-api.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down

0 comments on commit 4784c36

Please sign in to comment.