Skip to content

Commit

Permalink
RHCLOUD-34213 - Expose Readyz and Livez endpoints (project-kessel#106)
Browse files Browse the repository at this point in the history
* WIP: Expose Readyz and Livez endpoints

* Seperate logic into respective layers

* fix: Change Hosts -> Health

* Added health check for relation api pod, refactored health.go

* make relations check based on authz config

* Added KesselStatus method to Authorizer interface

* Changes

* Added health checks with logging

* update response message

* Change: check relations when kessel is enabled

* Add check for if kessel is enabled

* Moved CheckAuthorizer to authz.go

* removed unused code

* Add readyz and livez example to README
  • Loading branch information
Adam0Brien authored Sep 17, 2024
1 parent d6c5e90 commit 479e031
Show file tree
Hide file tree
Showing 11 changed files with 218 additions and 70 deletions.
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,23 @@ make init

## Example Usage

### Health check endpoints

The inventory API includes health check endpoints for readiness and liveness probes.

#### Readyz
The readyz endpoint checks if the service is ready to handle requests.
```bash
curl http://localhost:8081/api/inventory/v1/readyz
```

#### Livez
The livez endpoint checks if the service is alive and functioning correctly.
```bash
curl http://localhost:8081/api/inventory/v1/livez
```

### Add hosts to inventory
To add hosts to the inventory, use the following `curl` command:

```bash
Expand Down
9 changes: 6 additions & 3 deletions cmd/serve/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import (
"os/signal"
"syscall"

"github.com/project-kessel/inventory-api/internal/service/health"

"github.com/spf13/cobra"
"gorm.io/gorm"

Expand All @@ -27,18 +25,21 @@ import (
rel "github.com/project-kessel/inventory-api/api/kessel/inventory/v1beta1/relationships"
pb "github.com/project-kessel/inventory-api/api/kessel/inventory/v1beta1/resources"

healthrepo "github.com/project-kessel/inventory-api/internal/data/health"
hostsrepo "github.com/project-kessel/inventory-api/internal/data/hosts"
k8sclustersrepo "github.com/project-kessel/inventory-api/internal/data/k8sclusters"
k8spoliciesrepo "github.com/project-kessel/inventory-api/internal/data/k8spolicies"
notifsrepo "github.com/project-kessel/inventory-api/internal/data/notificationsintegrations"
relationshipsrepo "github.com/project-kessel/inventory-api/internal/data/relationships"

healthctl "github.com/project-kessel/inventory-api/internal/biz/health"
hostsctl "github.com/project-kessel/inventory-api/internal/biz/hosts"
k8sclustersctl "github.com/project-kessel/inventory-api/internal/biz/k8sclusters"
k8spoliciesctl "github.com/project-kessel/inventory-api/internal/biz/k8spolicies"
notifsctl "github.com/project-kessel/inventory-api/internal/biz/notificationsintegrations"
relationshipsctl "github.com/project-kessel/inventory-api/internal/biz/relationships"

healthssvc "github.com/project-kessel/inventory-api/internal/service/health"
hostssvc "github.com/project-kessel/inventory-api/internal/service/hosts"
k8sclusterssvc "github.com/project-kessel/inventory-api/internal/service/k8sclusters"
k8spoliciessvc "github.com/project-kessel/inventory-api/internal/service/k8spolicies"
Expand Down Expand Up @@ -184,7 +185,9 @@ func NewCommand(
rel.RegisterKesselK8SPolicyIsPropagatedToK8SClusterServiceServer(server.GrpcServer, relationships_service)
rel.RegisterKesselK8SPolicyIsPropagatedToK8SClusterServiceHTTPServer(server.HttpServer, relationships_service)

health_service := health.NewHealthService()
health_repo := healthrepo.New(db, authorizer, authzConfig)
health_controller := healthctl.New(health_repo, log.With(logger, "subsystem", "health_controller"))
health_service := healthssvc.New(health_controller)
hb.RegisterKesselInventoryHealthServiceServer(server.GrpcServer, health_service)
hb.RegisterKesselInventoryHealthServiceHTTPServer(server.HttpServer, health_service)

Expand Down
33 changes: 16 additions & 17 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@ require (
github.com/golang-jwt/jwt/v5 v5.2.1
github.com/google/wire v0.6.0
github.com/patrickmn/go-cache v2.1.0+incompatible
github.com/project-kessel/relations-api v0.0.0-20240801131134-0f51350f3c3d
github.com/project-kessel/relations-api v0.0.0-20240912181134-54bbd73bdde7
github.com/prometheus/client_golang v1.20.3
github.com/spf13/cobra v1.8.1
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.19.0
github.com/stretchr/testify v1.9.0
go.opentelemetry.io/otel v1.29.0
go.opentelemetry.io/otel/exporters/prometheus v0.51.0
go.opentelemetry.io/otel/metric v1.29.0
go.opentelemetry.io/otel/sdk v1.29.0
go.opentelemetry.io/otel/sdk/metric v1.29.0
google.golang.org/genproto/googleapis/api v0.0.0-20240604185151-ef581f913117
go.opentelemetry.io/otel v1.30.0
go.opentelemetry.io/otel/exporters/prometheus v0.52.0
go.opentelemetry.io/otel/metric v1.30.0
go.opentelemetry.io/otel/sdk v1.30.0
go.opentelemetry.io/otel/sdk/metric v1.30.0
google.golang.org/genproto/googleapis/api v0.0.0-20240903143218-8af14fe29dc1
google.golang.org/grpc v1.66.2
google.golang.org/protobuf v1.34.2
gopkg.in/yaml.v3 v3.0.1
Expand All @@ -42,7 +42,6 @@ require (
github.com/containerd/platforms v0.2.1 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/docker/docker v27.2.0+incompatible // indirect
github.com/envoyproxy/protoc-gen-validate v1.1.0 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/go-jose/go-jose/v4 v4.0.2 // indirect
github.com/go-kratos/aegis v0.2.0 // indirect
Expand Down Expand Up @@ -73,7 +72,7 @@ require (
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/prometheus/client_model v0.6.1 // indirect
github.com/prometheus/common v0.55.0 // indirect
github.com/prometheus/common v0.59.1 // indirect
github.com/prometheus/procfs v0.15.1 // indirect
github.com/sagikazarmark/locafero v0.4.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
Expand All @@ -83,17 +82,17 @@ require (
github.com/stoewer/go-strcase v1.3.0 // indirect
github.com/stretchr/objx v0.5.2 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
go.opentelemetry.io/otel/trace v1.29.0 // indirect
go.opentelemetry.io/otel/trace v1.30.0 // indirect
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/multierr v1.9.0 // indirect
go.uber.org/zap v1.21.0 // indirect
golang.org/x/crypto v0.25.0 // indirect
golang.org/x/crypto v0.27.0 // indirect
golang.org/x/exp v0.0.0-20240325151524-a685a6edb6d8 // indirect
golang.org/x/net v0.27.0 // indirect
golang.org/x/oauth2 v0.21.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.24.0 // indirect
golang.org/x/text v0.16.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240604185151-ef581f913117 // indirect
golang.org/x/net v0.29.0 // indirect
golang.org/x/oauth2 v0.22.0 // indirect
golang.org/x/sync v0.8.0 // indirect
golang.org/x/sys v0.25.0 // indirect
golang.org/x/text v0.18.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240903143218-8af14fe29dc1 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
)
Loading

0 comments on commit 479e031

Please sign in to comment.