lib/api, lib/db: Add file debug endpoint (#7095)
This commit is contained in:
@@ -324,6 +324,7 @@ func (s *service) serve(ctx context.Context) {
|
|||||||
debugMux.HandleFunc("/rest/debug/cpuprof", s.getCPUProf) // duration
|
debugMux.HandleFunc("/rest/debug/cpuprof", s.getCPUProf) // duration
|
||||||
debugMux.HandleFunc("/rest/debug/heapprof", s.getHeapProf)
|
debugMux.HandleFunc("/rest/debug/heapprof", s.getHeapProf)
|
||||||
debugMux.HandleFunc("/rest/debug/support", s.getSupportBundle)
|
debugMux.HandleFunc("/rest/debug/support", s.getSupportBundle)
|
||||||
|
debugMux.HandleFunc("/rest/debug/file", s.getDebugFile)
|
||||||
restMux.Handler(http.MethodGet, "/rest/debug/*method", s.whenDebugging(debugMux))
|
restMux.Handler(http.MethodGet, "/rest/debug/*method", s.whenDebugging(debugMux))
|
||||||
|
|
||||||
// A handler that disables caching
|
// A handler that disables caching
|
||||||
@@ -847,6 +848,30 @@ func (s *service) getDBFile(w http.ResponseWriter, r *http.Request) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *service) getDebugFile(w http.ResponseWriter, r *http.Request) {
|
||||||
|
qs := r.URL.Query()
|
||||||
|
folder := qs.Get("folder")
|
||||||
|
file := qs.Get("file")
|
||||||
|
|
||||||
|
snap, err := s.model.DBSnapshot(folder)
|
||||||
|
if err != nil {
|
||||||
|
http.Error(w, err.Error(), http.StatusNotFound)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
lf, _ := snap.Get(protocol.LocalDeviceID, file)
|
||||||
|
gf, _ := snap.GetGlobal(file)
|
||||||
|
av := snap.Availability(file)
|
||||||
|
vl := snap.DebugGlobalVersions(file)
|
||||||
|
|
||||||
|
sendJSON(w, map[string]interface{}{
|
||||||
|
"global": jsonFileInfo(gf),
|
||||||
|
"local": jsonFileInfo(lf),
|
||||||
|
"availability": av,
|
||||||
|
"globalVersions": vl.String(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func (s *service) postSystemRestart(w http.ResponseWriter, r *http.Request) {
|
func (s *service) postSystemRestart(w http.ResponseWriter, r *http.Request) {
|
||||||
s.flushResponse(`{"ok": "restarting"}`, w)
|
s.flushResponse(`{"ok": "restarting"}`, w)
|
||||||
go s.contr.Restart()
|
go s.contr.Restart()
|
||||||
|
|||||||
@@ -290,6 +290,18 @@ func (s *Snapshot) Availability(file string) []protocol.DeviceID {
|
|||||||
return av
|
return av
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *Snapshot) DebugGlobalVersions(file string) VersionList {
|
||||||
|
opStr := fmt.Sprintf("%s DebugGlobalVersions(%v)", s.folder, file)
|
||||||
|
l.Debugf(opStr)
|
||||||
|
vl, err := s.t.getGlobalVersions(nil, []byte(s.folder), []byte(osutil.NormalizedFilename(file)))
|
||||||
|
if backend.IsClosed(err) {
|
||||||
|
return VersionList{}
|
||||||
|
} else if err != nil {
|
||||||
|
s.fatalError(err, opStr)
|
||||||
|
}
|
||||||
|
return vl
|
||||||
|
}
|
||||||
|
|
||||||
func (s *Snapshot) Sequence(device protocol.DeviceID) int64 {
|
func (s *Snapshot) Sequence(device protocol.DeviceID) int64 {
|
||||||
return s.meta.Counts(device, 0).Sequence
|
return s.meta.Counts(device, 0).Sequence
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user