-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: health status of individual agents
- Loading branch information
1 parent
3e7a940
commit 40ac6af
Showing
5 changed files
with
106 additions
and
4 deletions.
There are no files selected for viewing
This file contains 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,26 @@ | ||
package agent | ||
|
||
import ( | ||
"net/http" | ||
|
||
"github.com/distantmagic/paddler/goroutine" | ||
) | ||
|
||
type RespondToHealth struct { | ||
ServerEventsChannel chan<- goroutine.ResultMessage | ||
} | ||
|
||
func (self *RespondToHealth) ServeHTTP(response http.ResponseWriter, request *http.Request) { | ||
response.Header().Set("Content-Type", "text/plain") | ||
response.WriteHeader(http.StatusOK) | ||
|
||
_, err := response.Write([]byte("OK")) | ||
|
||
if err != nil { | ||
self.ServerEventsChannel <- goroutine.ResultMessage{ | ||
Error: err, | ||
} | ||
|
||
return | ||
} | ||
} |
This file contains 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,37 @@ | ||
package agent | ||
|
||
import ( | ||
"net/http" | ||
|
||
"github.com/distantmagic/paddler/goroutine" | ||
"github.com/hashicorp/go-hclog" | ||
) | ||
|
||
type StatusServer struct { | ||
StatusServerConfiguration *StatusServerConfiguration | ||
Logger hclog.Logger | ||
RespondToHealth http.Handler | ||
} | ||
|
||
func (self *StatusServer) Serve(serverEventsChannel chan<- goroutine.ResultMessage) { | ||
self.Logger.Debug( | ||
"listen", | ||
"host", self.StatusServerConfiguration.HttpAddress.GetHostWithPort(), | ||
) | ||
|
||
mux := http.NewServeMux() | ||
|
||
mux.Handle("/health", self.RespondToHealth) | ||
|
||
err := http.ListenAndServe( | ||
self.StatusServerConfiguration.HttpAddress.GetHostWithPort(), | ||
mux, | ||
) | ||
|
||
if err != nil { | ||
serverEventsChannel <- goroutine.ResultMessage{ | ||
Comment: "failed to listen", | ||
Error: err, | ||
} | ||
} | ||
} |
This file contains 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,7 @@ | ||
package agent | ||
|
||
import "github.com/distantmagic/paddler/netcfg" | ||
|
||
type StatusServerConfiguration struct { | ||
HttpAddress *netcfg.HttpAddressConfiguration | ||
} |
This file contains 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 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