-
Notifications
You must be signed in to change notification settings - Fork 7
Improve health check for wallet backend services #251
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
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
4200c50
Improve health check
aditya1702 ec0698f
Start health check server for ingest service
aditya1702 468f520
Gracefully shutdown the server
aditya1702 363bd51
make check
aditya1702 76f7eca
Update global_options.go
aditya1702 9e10582
return a different error code when ledgers are not in sync
aditya1702 d15b6bc
Make sure both api and ingest containers spin up and are healthy for …
aditya1702 056448c
Update docker-compose.yaml
aditya1702 23bab24
Update health.go
aditya1702 c138de2
for integration tests, start ingestion from rpc latest ledger
aditya1702 993ad20
fix make check
aditya1702 9488491
Add extras field when not in sync
aditya1702 7f144e9
change var to const
aditya1702 e774007
wrap error for verbose messages
aditya1702 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package httphandler | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"net/http" | ||
|
||
"github.com/stellar/go/support/render/httpjson" | ||
|
||
"github.com/stellar/wallet-backend/internal/apptracker" | ||
"github.com/stellar/wallet-backend/internal/data" | ||
"github.com/stellar/wallet-backend/internal/serve/httperror" | ||
"github.com/stellar/wallet-backend/internal/services" | ||
) | ||
|
||
type HealthHandler struct { | ||
Models *data.Models | ||
RPCService services.RPCService | ||
AppTracker apptracker.AppTracker | ||
} | ||
|
||
const ( | ||
ledgerCursorName = "live_ingest_cursor" | ||
ledgerHealthThreshold = uint32(50) | ||
) | ||
|
||
func (h HealthHandler) GetHealth(w http.ResponseWriter, r *http.Request) { | ||
ctx := r.Context() | ||
|
||
rpcHealth, err := h.RPCService.GetHealth() | ||
if err != nil { | ||
err = fmt.Errorf("failed to get RPC health: %w", err) | ||
httperror.InternalServerError(ctx, err.Error(), err, nil, h.AppTracker).Render(w) | ||
return | ||
} | ||
if rpcHealth.Status != "healthy" { | ||
err = errors.New("rpc is not healthy") | ||
httperror.ServiceUnavailable(ctx, err.Error(), err, nil, h.AppTracker).Render(w) | ||
return | ||
} | ||
|
||
backendLatestLedger, err := h.Models.IngestStore.GetLatestLedgerSynced(ctx, ledgerCursorName) | ||
if err != nil { | ||
err = fmt.Errorf("failed to get backend latest ledger: %w", err) | ||
httperror.InternalServerError(ctx, err.Error(), err, nil, h.AppTracker).Render(w) | ||
return | ||
} | ||
if rpcHealth.LatestLedger-backendLatestLedger > ledgerHealthThreshold { | ||
err = errors.New("wallet backend is not in sync with the RPC") | ||
httperror.ServiceUnavailable(ctx, err.Error(), err, map[string]interface{}{ | ||
"rpc_latest_ledger": rpcHealth.LatestLedger, | ||
"backend_latest_ledger": backendLatestLedger, | ||
}, h.AppTracker).Render(w) | ||
return | ||
} | ||
|
||
httpjson.Render(w, map[string]any{ | ||
"status": "ok", | ||
"backend_latest_ledger": backendLatestLedger, | ||
}, httpjson.JSON) | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.