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

Nobids/throttle service status updates #2958

Merged
merged 4 commits into from
Sep 30, 2024
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
15 changes: 5 additions & 10 deletions handlers/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,8 @@ func SearchAhead(w http.ResponseWriter, r *http.Request) {
} else {
err = db.ReaderDb.Select(result, `
SELECT validatorindex AS index, pubkeyhex AS pubkey
FROM validators
LEFT JOIN validator_names ON validators.pubkey = validator_names.publickey
WHERE LOWER(validator_names.name) LIKE LOWER($1)
ORDER BY index LIMIT 10`, search+"%")
FROM validators WHERE pubkey IN
(SELECT publickey FROM validator_names WHERE LOWER(validator_names.name) LIKE LOWER($1) LIMIT 10)`, search+"%")
}
case "eth1_addresses":
if utils.IsValidEnsDomain(search) {
Expand Down Expand Up @@ -216,12 +214,9 @@ func SearchAhead(w http.ResponseWriter, r *http.Request) {
} else if thresholdHexLikeRE.MatchString(lowerStrippedSearch) {
err = db.ReaderDb.Select(result, `SELECT validatorindex AS index, pubkeyhex as pubkey FROM validators WHERE pubkeyhex LIKE ($1 || '%')`, lowerStrippedSearch)
} else {
err = db.ReaderDb.Select(result, `
SELECT validatorindex AS index, pubkeyhex AS pubkey
FROM validators
LEFT JOIN validator_names ON validators.pubkey = validator_names.publickey
WHERE LOWER(validator_names.name) LIKE LOWER($1)
ORDER BY index LIMIT 10`, search+"%")
err = db.ReaderDb.Select(result, `SELECT validatorindex AS index, pubkeyhex AS pubkey
FROM validators WHERE pubkey IN
(SELECT publickey FROM validator_names WHERE LOWER(validator_names.name) LIKE LOWER($1) LIMIT 10)`, search+"%")
}
case "validators_by_pubkey":
if !thresholdHexLikeRE.MatchString(lowerStrippedSearch) {
Expand Down
11 changes: 11 additions & 0 deletions services/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,27 @@ package services
import (
"encoding/json"
"os"
"time"

"github.com/gobitfly/eth2-beaconchain-explorer/db"
"github.com/gobitfly/eth2-beaconchain-explorer/utils"
"github.com/gobitfly/eth2-beaconchain-explorer/version"
)

var lastStatusUpdate = make(map[string]time.Time)

// Report the status of a particular service, will add current Pid and executable name
// Throttle calls to 1/min for each service name so that we don't report too often
func ReportStatus(name, status string, metadata *json.RawMessage) {
if !utils.Config.ReportServiceStatus {
return
}

if lastUpdate, ok := lastStatusUpdate[name]; ok {
if time.Since(lastUpdate) < time.Minute {
return
}
}
pid := os.Getpid()
execName, err := os.Executable()
if err != nil {
Expand All @@ -33,4 +43,5 @@ func ReportStatus(name, status string, metadata *json.RawMessage) {
if err != nil {
utils.LogError(err, "error reporting service status", 0, map[string]interface{}{"name": name, "status": status})
}
lastStatusUpdate[name] = time.Now()
}
Loading