Skip to content

Commit

Permalink
Merge pull request #2958 from gobitfly/NOBIDS/throttle_service_status…
Browse files Browse the repository at this point in the history
…_updates

Nobids/throttle service status updates
  • Loading branch information
guybrush authored Sep 30, 2024
2 parents bdbf2f1 + a4d958c commit a3bcdf8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
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()
}

0 comments on commit a3bcdf8

Please sign in to comment.