chore: Separate repo and persistance paths

This commit is contained in:
Mike Greenberg 2021-09-17 18:01:26 -04:00
parent 595b51ecdd
commit f79d34be5c

View File

@ -14,11 +14,11 @@ import (
logging "github.com/ipfs/go-log/v2" logging "github.com/ipfs/go-log/v2"
) )
var panicLog = logging.Logger("panic_reporter") var panicLog = logging.Logger("panic-reporter")
// PanicReportingPath is the name of the subdir created within the repoPath path // PanicReportingPath is the name of the subdir created within the repoPath path
// provided to GeneratePanicReport // provided to GeneratePanicReport
var PanicReportingPath = "panic_reports" var PanicReportingPath = "lotus_panic_reports"
// PanicReportJournalTail is the number of lines captured from the end of // PanicReportJournalTail is the number of lines captured from the end of
// the lotus journal to be included in the panic report. // the lotus journal to be included in the panic report.
@ -26,19 +26,20 @@ var PanicReportJournalTail = 500
// GeneratePanicReport produces a timestamped dump of the application state // GeneratePanicReport produces a timestamped dump of the application state
// for inspection and debugging purposes. Call this function from any place // for inspection and debugging purposes. Call this function from any place
// where a panic or severe error needs to be examined. `repoPath` is the path // where a panic or severe error needs to be examined. `persistPath` is the
// where the report should be written. `label` is an optional string to include // path where the reports should be saved. `repoPath` is the path where the
// journal should be read from. `label` is an optional string to include
// next to the report timestamp. // next to the report timestamp.
func GeneratePanicReport(repoPath string, label string) { func GeneratePanicReport(persistPath, repoPath, label string) {
// make sure we always dump the latest logs on the way out // make sure we always dump the latest logs on the way out
// especially since we're probably panicking // especially since we're probably panicking
defer panicLog.Sync() defer panicLog.Sync()
if repoPath == "" { if persistPath == "" {
panicLog.Error("repo path is empty, aborting panic report generation") panicLog.Error("persist path is empty, aborting panic report generation")
return return
} }
reportPath := filepath.Join(repoPath, PanicReportingPath, generateReportName(label)) reportPath := filepath.Join(persistPath, PanicReportingPath, generateReportName(label))
panicLog.Warnf("generating panic report at %s", reportPath) panicLog.Warnf("generating panic report at %s", reportPath)
syscall.Umask(0) syscall.Umask(0)
err := os.MkdirAll(reportPath, 0755) err := os.MkdirAll(reportPath, 0755)
@ -85,6 +86,11 @@ func writeProfile(profileType string, file string) {
} }
func writeJournalTail(tailLen int, repoPath, file string) { func writeJournalTail(tailLen int, repoPath, file string) {
if repoPath == "" {
panicLog.Warn("repo path is empty, aborting copy of journal log")
return
}
f, err := os.Create(file) f, err := os.Create(file)
if err != nil { if err != nil {
panicLog.Error(err.Error()) panicLog.Error(err.Error())