This repository was archived by the owner on Jul 13, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 287
Fixing linter issues #513
Merged
+32
−13
Merged
Fixing linter issues #513
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
9eb6ba7
refactoring files
927bff0
changing package names
624707a
adding licenses to files
e8c86e4
edit comment
89573f3
adding missing method
251b5c7
removing unused imports
3e9cb60
fixing linter errors for http.go
267e828
fixing up linter
66be49e
Merge branch 'greg/backport/metrics' into alex/monitor-refactor
88c0461
removing extra import
4650a3d
handling graceful shutdown
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,9 +31,9 @@ type httpMetricOptions struct { | |
| core *core.Core | ||
| } | ||
|
|
||
| type chain struct { | ||
| id int | ||
| } | ||
| //type chain struct { | ||
| // id int | ||
| //} | ||
|
|
||
| func newHTTPMetricServer(opts httpMetricOptions) *HttpMetricServer { | ||
| return &HttpMetricServer{ | ||
|
|
@@ -52,7 +52,13 @@ func (s HttpMetricServer) Start() { | |
|
|
||
| // Start http server | ||
| // TODO Push strconv to cli parser | ||
| http.ListenAndServe(":"+strconv.Itoa(s.port), nil) | ||
| err := http.ListenAndServe(":"+strconv.Itoa(s.port), nil) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we handle a graceful shutdown? |
||
|
|
||
| if err == http.ErrServerClosed { | ||
| log.Info("Server is shutting down", err) | ||
| } else { | ||
| log.Error("Shutting down, server error: ", err) | ||
| } | ||
| } | ||
|
|
||
| // healthStatus is a catch-all update that grabs the latest updates on the running chains | ||
|
|
@@ -73,7 +79,10 @@ func (s HttpMetricServer) healthStatus(w http.ResponseWriter, r *http.Request) { | |
| // TODO better error messaging | ||
| errorMsg := fmt.Sprintf("%s%d%s%s", "Failed to receive latest head for: ", chain.Id(), "Error:", err) | ||
| w.WriteHeader(http.StatusInternalServerError) | ||
| w.Write([]byte(errorMsg)) | ||
| _, err = w.Write([]byte(errorMsg)) | ||
| if err != nil { | ||
| log.Error("Failed to write, failed to get latest height and writing error", err) | ||
| } | ||
| } | ||
|
|
||
| // Get old blockheight | ||
|
|
@@ -89,14 +98,20 @@ func (s HttpMetricServer) healthStatus(w http.ResponseWriter, r *http.Request) { | |
| } else { | ||
| if timeDiff.Seconds() > 120 { | ||
| // Error if we exceeded the time limit | ||
| errorMsg := fmt.Sprintf("%s%s%s%s%s", "Chain height hasn't changed in: ", timeDiff, "Current height", latestHeight) | ||
| errorMsg := fmt.Sprintf("%s%s%s%s", "Chain height hasn't changed in: ", timeDiff, "Current height", latestHeight) | ||
| w.WriteHeader(http.StatusInternalServerError) | ||
| w.Write([]byte(errorMsg)) | ||
| _, err = w.Write([]byte(errorMsg)) | ||
| if err != nil { | ||
| log.Error("Failed to write, chain height hasn't changed in: %d seconds, Current height: %d", timeDiff.Seconds(), latestHeight, err) | ||
| } | ||
| } else { | ||
| // Error for having a smaller blockheight than previous | ||
| errorMsg := fmt.Sprintf("%s%s%s%s%s", "latestHeight is <= previousHeight", "previousHeight", prevHeight.height, "latestHeight", latestHeight) | ||
| w.WriteHeader(http.StatusInternalServerError) | ||
| w.Write([]byte(errorMsg)) | ||
| _, err := w.Write([]byte(errorMsg)) | ||
| if err != nil { | ||
| log.Error("Failed to write, latest height less than previous height, latest height: %d, previous height: %d", latestHeight, prevHeight.height, err) | ||
| } | ||
| } | ||
| } | ||
| } else { | ||
|
|
@@ -109,5 +124,8 @@ func (s HttpMetricServer) healthStatus(w http.ResponseWriter, r *http.Request) { | |
| } | ||
| } | ||
| w.WriteHeader(http.StatusOK) | ||
| w.Write([]byte("200 - Operational")) | ||
| _, err := w.Write([]byte("200 - Operational")) | ||
| if err != nil { | ||
| log.Error("Failed to write, 200 - Operational") | ||
| } | ||
| } | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Commented the struct out because it wasn't being used