Skip to content

Commit

Permalink
feat: Healthz api check appId support
Browse files Browse the repository at this point in the history
related: dapr/components-contrib#2489

Signed-off-by: AlbertHuang <[email protected]>
  • Loading branch information
alberthuang24 committed Feb 1, 2023
1 parent 4888ae0 commit 6b29b3e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
10 changes: 8 additions & 2 deletions pkg/http/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ func (a *api) constructHealthzEndpoints() []Endpoint {
return []Endpoint{
{
Methods: []string{fasthttp.MethodGet},
Route: "healthz",
Route: "healthz/{appId:*}",
Version: apiVersionV1,
Handler: a.onGetHealthz,
AlwaysAllowed: true,
Expand Down Expand Up @@ -2593,7 +2593,13 @@ func (a *api) onGetHealthz(reqCtx *fasthttp.RequestCtx) {
respond(reqCtx, withError(fasthttp.StatusInternalServerError, msg))
log.Debug(msg)
} else {
respond(reqCtx, withEmpty())
matchAppId := reqCtx.UserValue("appId").(string)
if matchAppId != "" && matchAppId != a.id {
msg := NewErrorResponse("ERR_HEALTH_APPID_NOT_MATCH", messages.ErrHealthAppIdNotMatch)
respond(reqCtx, withError(fasthttp.StatusInternalServerError, msg))
} else {
respond(reqCtx, withEmpty())
}
}
}

Expand Down
3 changes: 2 additions & 1 deletion pkg/messages/api_errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ const (
ErrMetadataGet = "failed deserializing metadata: %s"

// Healthz.
ErrHealthNotReady = "dapr is not ready"
ErrHealthNotReady = "dapr is not ready"
ErrHealthAppIdNotMatch = "dapr appId is not match"

// Configuration.
ErrConfigurationStoresNotConfigured = "configuration stores not configured"
Expand Down

0 comments on commit 6b29b3e

Please sign in to comment.