fix: support to report all error when reloading (#540)

This commit is contained in:
mzz 2024-06-15 16:41:07 +08:00 committed by GitHub
parent 2051612931
commit 795bd0560e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 13 additions and 2 deletions

View File

@ -147,6 +147,7 @@ func Run(log *logrus.Logger, conf *config.Config, externGeoDataDirs []string) (e
sigs <- nil
}()
reloading := false
reloadingErr := error(nil)
isSuspend := false
abortConnections := false
loop:
@ -170,7 +171,11 @@ loop:
}()
<-readyChan
sdnotify.Ready()
_ = os.WriteFile(SignalProgressFilePath, append([]byte{consts.ReloadDone}, []byte("\nOK")...), 0644)
if reloadingErr == nil {
_ = os.WriteFile(SignalProgressFilePath, append([]byte{consts.ReloadDone}, []byte("\nOK")...), 0644)
} else {
_ = os.WriteFile(SignalProgressFilePath, append([]byte{consts.ReloadError}, []byte("\n"+reloadingErr.Error())...), 0644)
}
log.Warnln("[Reload] Finished")
} else {
// Listening error.
@ -188,6 +193,7 @@ loop:
}
sdnotify.Reloading()
_ = os.WriteFile(SignalProgressFilePath, []byte{consts.ReloadProcessing}, 0644)
reloadingErr = nil
// Load new config.
abortConnections = os.Remove(AbortFile) == nil
@ -237,6 +243,7 @@ loop:
log.Warnln("[Reload] Load new control plane")
newC, err := newControlPlane(log, obj, dnsCache, newConf, externGeoDataDirs)
if err != nil {
reloadingErr = err
log.WithFields(logrus.Fields{
"err": err,
}).Errorln("[Reload] Failed to reload; try to roll back configuration")

View File

@ -152,7 +152,11 @@ func (f *Function) String(compact bool, quoteVal bool, omitEmpty bool) string {
if !(omitEmpty && len(f.Params) == 0) {
builder.WriteString("(")
var strParamList []string
for _, p := range f.Params {
for i, p := range f.Params {
if i >= 5 {
strParamList = append(strParamList, "...")
break
}
strParamList = append(strParamList, p.String(compact, quoteVal))
}
if compact {