mirror of https://github.com/perkeep/perkeep.git
Aggregate all errors with their URLS in status.json in one place.
Change-Id: If7a540fc3d1a6caa94b5f04d44de3207f15ac4cf
This commit is contained in:
parent
1be26ea3a4
commit
f4740e77e8
|
@ -39,6 +39,7 @@ import (
|
||||||
"camlistore.org/pkg/search"
|
"camlistore.org/pkg/search"
|
||||||
"camlistore.org/pkg/server"
|
"camlistore.org/pkg/server"
|
||||||
"camlistore.org/pkg/syncutil"
|
"camlistore.org/pkg/syncutil"
|
||||||
|
"camlistore.org/pkg/types/camtypes"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -351,8 +352,9 @@ type accountStatus struct {
|
||||||
|
|
||||||
// AccountsStatus returns the currently configured accounts and their status for
|
// AccountsStatus returns the currently configured accounts and their status for
|
||||||
// inclusion in the status.json document, as rendered by the web UI.
|
// inclusion in the status.json document, as rendered by the web UI.
|
||||||
func (h *Host) AccountsStatus() interface{} {
|
func (h *Host) AccountsStatus() (interface{}, []camtypes.StatusError) {
|
||||||
var s []accountStatus
|
var s []accountStatus
|
||||||
|
var errs []camtypes.StatusError
|
||||||
for _, impName := range h.importers {
|
for _, impName := range h.importers {
|
||||||
imp := h.imp[impName]
|
imp := h.imp[impName]
|
||||||
accts, _ := imp.Accounts()
|
accts, _ := imp.Accounts()
|
||||||
|
@ -371,15 +373,16 @@ func (h *Host) AccountsStatus() interface{} {
|
||||||
}
|
}
|
||||||
if ia.lastRunErr != nil {
|
if ia.lastRunErr != nil {
|
||||||
as.LastError = ia.lastRunErr.Error()
|
as.LastError = ia.lastRunErr.Error()
|
||||||
|
errs = append(errs, camtypes.StatusError{
|
||||||
|
Error: ia.lastRunErr.Error(),
|
||||||
|
URL: ia.AccountURL(),
|
||||||
|
})
|
||||||
}
|
}
|
||||||
ia.mu.Unlock()
|
ia.mu.Unlock()
|
||||||
s = append(s, as)
|
s = append(s, as)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
s = append(s, accountStatus{
|
return s, errs
|
||||||
Name: "hi",
|
|
||||||
})
|
|
||||||
return s
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Host) InitHandler(hl blobserver.FindHandlerByTyper) error {
|
func (h *Host) InitHandler(hl blobserver.FindHandlerByTyper) error {
|
||||||
|
|
|
@ -22,6 +22,7 @@ import (
|
||||||
"html"
|
"html"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"os"
|
||||||
"reflect"
|
"reflect"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -33,6 +34,7 @@ import (
|
||||||
"camlistore.org/pkg/index"
|
"camlistore.org/pkg/index"
|
||||||
"camlistore.org/pkg/jsonconfig"
|
"camlistore.org/pkg/jsonconfig"
|
||||||
"camlistore.org/pkg/search"
|
"camlistore.org/pkg/search"
|
||||||
|
"camlistore.org/pkg/types/camtypes"
|
||||||
)
|
)
|
||||||
|
|
||||||
// StatusHandler publishes server status information.
|
// StatusHandler publishes server status information.
|
||||||
|
@ -100,7 +102,7 @@ func (sh *StatusHandler) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
|
||||||
|
|
||||||
type status struct {
|
type status struct {
|
||||||
Version string `json:"version"`
|
Version string `json:"version"`
|
||||||
Error string `json:"error,omitempty"`
|
Errors []camtypes.StatusError `json:"errors,omitempty"`
|
||||||
Sync map[string]syncStatus `json:"sync"`
|
Sync map[string]syncStatus `json:"sync"`
|
||||||
Storage map[string]storageStatus `json:"storage"`
|
Storage map[string]storageStatus `json:"storage"`
|
||||||
rootPrefix string
|
rootPrefix string
|
||||||
|
@ -109,6 +111,13 @@ type status struct {
|
||||||
ImporterAccounts interface{} `json:"importerAccounts"`
|
ImporterAccounts interface{} `json:"importerAccounts"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (st *status) addError(msg, url string) {
|
||||||
|
st.Errors = append(st.Errors, camtypes.StatusError{
|
||||||
|
Error: msg,
|
||||||
|
URL: url,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func (st *status) isHandler(pfx string) bool {
|
func (st *status) isHandler(pfx string) bool {
|
||||||
if pfx == st.ImporterRoot {
|
if pfx == st.ImporterRoot {
|
||||||
return true
|
return true
|
||||||
|
@ -137,9 +146,12 @@ func (sh *StatusHandler) currentStatus() *status {
|
||||||
Storage: make(map[string]storageStatus),
|
Storage: make(map[string]storageStatus),
|
||||||
Sync: make(map[string]syncStatus),
|
Sync: make(map[string]syncStatus),
|
||||||
}
|
}
|
||||||
|
if v := os.Getenv("CAMLI_FAKE_STATUS_ERROR"); v != "" {
|
||||||
|
res.addError(v, "/status/#fakeerror")
|
||||||
|
}
|
||||||
_, hi, err := sh.handlerFinder.FindHandlerByType("root")
|
_, hi, err := sh.handlerFinder.FindHandlerByType("root")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
res.Error = fmt.Sprintf("Error finding root handler: %v", err)
|
res.addError(fmt.Sprintf("Error finding root handler: %v", err), "")
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
rh := hi.(*RootHandler)
|
rh := hi.(*RootHandler)
|
||||||
|
@ -148,9 +160,11 @@ func (sh *StatusHandler) currentStatus() *status {
|
||||||
if pfx, h, err := sh.handlerFinder.FindHandlerByType("importer"); err == nil {
|
if pfx, h, err := sh.handlerFinder.FindHandlerByType("importer"); err == nil {
|
||||||
res.ImporterRoot = pfx
|
res.ImporterRoot = pfx
|
||||||
as := h.(interface {
|
as := h.(interface {
|
||||||
AccountsStatus() interface{}
|
AccountsStatus() (interface{}, []camtypes.StatusError)
|
||||||
})
|
})
|
||||||
res.ImporterAccounts = as.AccountsStatus()
|
var errs []camtypes.StatusError
|
||||||
|
res.ImporterAccounts, errs = as.AccountsStatus()
|
||||||
|
res.Errors = append(res.Errors, errs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
types, handlers := sh.handlerFinder.AllHandlers()
|
types, handlers := sh.handlerFinder.AllHandlers()
|
||||||
|
|
|
@ -0,0 +1,22 @@
|
||||||
|
/*
|
||||||
|
Copyright 2014 The Camlistore Authors
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package camtypes
|
||||||
|
|
||||||
|
type StatusError struct {
|
||||||
|
Error string `json:"error"`
|
||||||
|
URL string `json:"url,omitempty"` // optional
|
||||||
|
}
|
Loading…
Reference in New Issue