Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(dl): add health checks #62

Merged
merged 1 commit into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion charts/cloudevents-server/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type: application
# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.1.0
version: 0.2.0

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
Expand Down
4 changes: 2 additions & 2 deletions charts/dl/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ spec:
protocol: TCP
livenessProbe:
httpGet:
path: /
path: /livez
port: http
readinessProbe:
httpGet:
path: /
path: /healthz
port: http
resources:
{{- toYaml .Values.resources | nindent 12 }}
Expand Down
2 changes: 1 addition & 1 deletion charts/dl/templates/tests/test-connection.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ spec:
- name: wget
image: busybox
command: ['wget']
args: ['{{ include "dl.fullname" . }}:{{ .Values.service.port }}']
args: ['{{ include "dl.fullname" . }}:{{ .Values.service.port }}/healthz']
restartPolicy: Never
15 changes: 12 additions & 3 deletions dl/cmd/server/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"sync"
"time"

health "github.com/PingCAP-QE/ee-apps/dl/gen/health"
healthsvr "github.com/PingCAP-QE/ee-apps/dl/gen/http/health/server"
ks3svr "github.com/PingCAP-QE/ee-apps/dl/gen/http/ks3/server"
ocisvr "github.com/PingCAP-QE/ee-apps/dl/gen/http/oci/server"
ks3 "github.com/PingCAP-QE/ee-apps/dl/gen/ks3"
Expand All @@ -20,7 +22,7 @@ import (

// handleHTTPServer starts configures and starts a HTTP server on the given
// URL. It shuts down the server if any error is received in the error channel.
func handleHTTPServer(ctx context.Context, u *url.URL, ociEndpoints *oci.Endpoints, ks3Endpoints *ks3.Endpoints, wg *sync.WaitGroup, errc chan error, logger *log.Logger, debug bool) {
func handleHTTPServer(ctx context.Context, u *url.URL, healthEndpoints *health.Endpoints, ociEndpoints *oci.Endpoints, ks3Endpoints *ks3.Endpoints, wg *sync.WaitGroup, errc chan error, logger *log.Logger, debug bool) {

// Setup goa log adapter.
var (
Expand Down Expand Up @@ -51,22 +53,26 @@ func handleHTTPServer(ctx context.Context, u *url.URL, ociEndpoints *oci.Endpoin
// the service input and output data structures to HTTP requests and
// responses.
var (
ociServer *ocisvr.Server
ks3Server *ks3svr.Server
healthServer *healthsvr.Server
ociServer *ocisvr.Server
ks3Server *ks3svr.Server
)
{
eh := errorHandler(logger)
healthServer = healthsvr.New(healthEndpoints, mux, dec, enc, eh, nil)
ociServer = ocisvr.New(ociEndpoints, mux, dec, enc, eh, nil)
ks3Server = ks3svr.New(ks3Endpoints, mux, dec, enc, eh, nil)
if debug {
servers := goahttp.Servers{
healthServer,
ociServer,
ks3Server,
}
servers.Use(httpmdlwr.Debug(mux, os.Stdout))
}
}
// Configure the mux.
healthsvr.Mount(mux, healthServer)
ocisvr.Mount(mux, ociServer)
ks3svr.Mount(mux, ks3Server)

Expand All @@ -81,6 +87,9 @@ func handleHTTPServer(ctx context.Context, u *url.URL, ociEndpoints *oci.Endpoin
// Start HTTP server using default configuration, change the code to
// configure the server as required by your service.
srv := &http.Server{Addr: u.Host, Handler: handler, ReadHeaderTimeout: time.Second * 60}
for _, m := range healthServer.Mounts {
logger.Printf("HTTP %q mounted on %s %s", m.Method, m.Verb, m.Pattern)
}
for _, m := range ociServer.Mounts {
logger.Printf("HTTP %q mounted on %s %s", m.Method, m.Verb, m.Pattern)
}
Expand Down
15 changes: 10 additions & 5 deletions dl/cmd/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"syscall"

dl "github.com/PingCAP-QE/ee-apps/dl"
health "github.com/PingCAP-QE/ee-apps/dl/gen/health"
ks3 "github.com/PingCAP-QE/ee-apps/dl/gen/ks3"
oci "github.com/PingCAP-QE/ee-apps/dl/gen/oci"
)
Expand Down Expand Up @@ -40,21 +41,25 @@ func main() {

// Initialize the services.
var (
ociSvc oci.Service
ks3Svc ks3.Service
healthSvc health.Service
ociSvc oci.Service
ks3Svc ks3.Service
)
{
healthSvc = dl.NewHealth(logger)
ociSvc = dl.NewOci(logger)
ks3Svc = dl.NewKs3(logger, *ks3CfgPathF)
}

// Wrap the services in endpoints that can be invoked from other services
// potentially running in different processes.
var (
ociEndpoints *oci.Endpoints
ks3Endpoints *ks3.Endpoints
healthEndpoints *health.Endpoints
ociEndpoints *oci.Endpoints
ks3Endpoints *ks3.Endpoints
)
{
healthEndpoints = health.NewEndpoints(healthSvc)
ociEndpoints = oci.NewEndpoints(ociSvc)
ks3Endpoints = ks3.NewEndpoints(ks3Svc)
}
Expand Down Expand Up @@ -98,7 +103,7 @@ func main() {
} else if u.Port() == "" {
u.Host = net.JoinHostPort(u.Host, "80")
}
handleHTTPServer(ctx, u, ociEndpoints, ks3Endpoints, &wg, errc, logger, *dbgF)
handleHTTPServer(ctx, u, healthEndpoints, ociEndpoints, ks3Endpoints, &wg, errc, logger, *dbgF)
}

default:
Expand Down
18 changes: 18 additions & 0 deletions dl/design/design.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,24 @@ var _ = API("dl", func() {
})
})

var _ = Service("health", func() {
Description("Health service")

Method("healthz", func() {
Result(Boolean)
HTTP(func() {
GET("/healthz")
})
})

Method("livez", func() {
Result(Boolean)
HTTP(func() {
GET("/livez")
})
})
})

var _ = Service("oci", func() {
Description("OCI artifacts download service")

Expand Down
48 changes: 48 additions & 0 deletions dl/gen/health/client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

50 changes: 50 additions & 0 deletions dl/gen/health/endpoints.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions dl/gen/health/service.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading