Skip to content

Commit

Permalink
Code cleanup and add important metrics to log
Browse files Browse the repository at this point in the history
  • Loading branch information
Mak Muftic committed Sep 23, 2020
1 parent 04cf4e0 commit 18a4409
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
9 changes: 6 additions & 3 deletions internal/controllers/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ func (c ApiController) SaveMetricsHandler(w http.ResponseWriter, r *http.Request
if err != nil {
var mr *util.MalformedRequest
if errors.As(err, &mr) {
// malformed request error
log.Errorf("Malformed request error: %v", err)
http.Error(w, mr.Msg, mr.Status)
} else {
Expand All @@ -45,11 +44,15 @@ func (c ApiController) SaveMetricsHandler(w http.ResponseWriter, r *http.Request
})

if err != nil {
// error on saving in database
log.Errorf("Unable to save metrics for node %v to database, error: %v", requestContext.NodeId, err)
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
return
}

log.Debugf("Node %s saved new metrics", requestContext.NodeId)
log.Debugf(
"Node %s saved new metrics { finalized_block_height: %d, best_block_height: %d }",
requestContext.NodeId,
metricsRequest.FinalizedBlockHeight,
metricsRequest.BestBlockHeight,
)
}
1 change: 0 additions & 1 deletion internal/controllers/ping.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ func (c ApiController) PingHandler(w http.ResponseWriter, r *http.Request) {
}
err := c.pingRepo.Save(&ping)
if err != nil {
// error on saving in database
log.Errorf("Unable to save ping %v to database, error: %v", ping, err)
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
return
Expand Down
2 changes: 0 additions & 2 deletions internal/controllers/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ func (c ApiController) RegisterHandler(w http.ResponseWriter, r *http.Request) {
if err != nil {
var mr *util.MalformedRequest
if errors.As(err, &mr) {
// malformed request error
log.Errorf("Malformed request error: %v", err)
http.Error(w, mr.Msg, mr.Status)
} else {
Expand Down Expand Up @@ -68,7 +67,6 @@ func (c ApiController) RegisterHandler(w http.ResponseWriter, r *http.Request) {
}
err = c.nodeRepo.Save(node)
if err != nil {
// error on saving in database
log.Errorf("Unable to save node %v to database, error: %v", node, err)
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
return
Expand Down

0 comments on commit 18a4409

Please sign in to comment.