Refactor StatsRecorder
Signed-off-by: Emile Vauge <emile@vauge.com>
This commit is contained in:
parent
6adb346cee
commit
3ebfd729cf
3 changed files with 11 additions and 6 deletions
|
@ -1,4 +1,4 @@
|
|||
package main
|
||||
package middlewares
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
@ -16,6 +16,13 @@ type StatsRecorder struct {
|
|||
recentErrors []*statsError
|
||||
}
|
||||
|
||||
// NewStatsRecorder returns a new StatsRecorder
|
||||
func NewStatsRecorder(numRecentErrors int) *StatsRecorder {
|
||||
return &StatsRecorder{
|
||||
numRecentErrors: numRecentErrors,
|
||||
}
|
||||
}
|
||||
|
||||
// Stats includes all of the stats gathered by the recorder.
|
||||
type Stats struct {
|
||||
RecentErrors []*statsError `json:"recent_errors"`
|
|
@ -169,9 +169,7 @@ func (server *Server) startHTTPServers() {
|
|||
for newServerEntryPointName, newServerEntryPoint := range server.serverEntryPoints {
|
||||
serverMiddlewares := []negroni.Handler{server.loggerMiddleware, metrics}
|
||||
if server.globalConfiguration.Web != nil && server.globalConfiguration.Web.Statistics != nil {
|
||||
statsRecorder = &StatsRecorder{
|
||||
numRecentErrors: server.globalConfiguration.Web.Statistics.RecentErrors,
|
||||
}
|
||||
statsRecorder = middlewares.NewStatsRecorder(server.globalConfiguration.Web.Statistics.RecentErrors)
|
||||
serverMiddlewares = append(serverMiddlewares, statsRecorder)
|
||||
}
|
||||
if server.globalConfiguration.EntryPoints[newServerEntryPointName].Auth != nil {
|
||||
|
|
4
web.go
4
web.go
|
@ -23,7 +23,7 @@ import (
|
|||
|
||||
var (
|
||||
metrics = thoas_stats.New()
|
||||
statsRecorder *StatsRecorder
|
||||
statsRecorder *middlewares.StatsRecorder
|
||||
)
|
||||
|
||||
// WebProvider is a provider.Provider implementation that provides the UI.
|
||||
|
@ -141,7 +141,7 @@ func (provider *WebProvider) Provide(configurationChan chan<- types.ConfigMessag
|
|||
// they are enabled).
|
||||
type healthResponse struct {
|
||||
*thoas_stats.Data
|
||||
*Stats
|
||||
*middlewares.Stats
|
||||
}
|
||||
|
||||
func (provider *WebProvider) getHealthHandler(response http.ResponseWriter, request *http.Request) {
|
||||
|
|
Loading…
Reference in a new issue