fix(client): add audit log for cross region host #1000075110

Signed-off-by: clinx <chenlin1@oppo.com>
This commit is contained in:
clinx 2025-04-23 09:47:23 +08:00 committed by zhumingze1108
parent c296c6ff54
commit 4a38fa1418
2 changed files with 32 additions and 0 deletions

View File

@ -29,6 +29,7 @@ import (
"github.com/cubefs/cubefs/sdk/master"
"github.com/cubefs/cubefs/sdk/meta"
"github.com/cubefs/cubefs/util"
"github.com/cubefs/cubefs/util/auditlog"
"github.com/cubefs/cubefs/util/bloom"
"github.com/cubefs/cubefs/util/btree"
"github.com/cubefs/cubefs/util/errors"
@ -587,12 +588,14 @@ func (rc *RemoteCache) ClassifyHostsByAvgDelay(fgID uint64, hosts []string) (sor
}
if avgTime <= time.Duration(0) {
sortedHosts[UnknownZoneRank] = append(sortedHosts[UnknownZoneRank], host)
auditlog.LogOpMsg("ClassifyHostsByAvgDelay", fmt.Sprintf("add host %v to unknown region", host), nil)
} else if avgTime <= sameZoneTimeout {
sortedHosts[SameZoneRank] = append(sortedHosts[SameZoneRank], host)
} else if avgTime <= sameRegionTimeout {
sortedHosts[SameRegionRank] = append(sortedHosts[SameRegionRank], host)
} else {
sortedHosts[CrossRegionRank] = append(sortedHosts[CrossRegionRank], host)
auditlog.LogOpMsg("ClassifyHostsByAvgDelay", fmt.Sprintf("add host %v to cross region by time %v", host, avgTime.String()), nil)
}
}
log.LogInfof("ClassifyHostsByAvgDelay: fgID(%v) sortedHost:%v", fgID, sortedHosts)

View File

@ -349,6 +349,17 @@ func (a *Audit) formatMasterAudit(op, msg string, err error) (str string) {
return
}
func (a *Audit) formatOpAudit(op, msg string, err error) (str string) {
var errStr string
if err != nil {
errStr = err.Error()
} else {
errStr = "nil"
}
str = fmt.Sprintf("%v, %v, %v, ERR: %v", a.formatCommonHeader(), op, msg, errStr)
return
}
func (a *Audit) formatMasterLog(op, msg string, err error) {
if entry := a.formatMasterAudit(op, msg, err); entry != "" {
if a.prefix != nil {
@ -358,6 +369,15 @@ func (a *Audit) formatMasterLog(op, msg string, err error) {
}
}
func (a *Audit) formatOpLog(op, msg string, err error) {
if entry := a.formatOpAudit(op, msg, err); entry != "" {
if a.prefix != nil {
entry = fmt.Sprintf("%s%s", a.prefix.String(), entry)
}
a.AddLog(entry)
}
}
func (a *Audit) LogResetDpDecommission(status string, src string, disk string, dpId uint64, dst string) {
status = fmt.Sprintf("Prev: %v", status)
src = fmt.Sprintf("SrcAddr: %v", src)
@ -767,6 +787,15 @@ func isPathSafe(filePath string) bool {
return match
}
func LogOpMsg(op, msg string, err error) {
gAdtMutex.RLock()
defer gAdtMutex.RUnlock()
if gAdt == nil {
return
}
gAdt.formatOpLog(op, msg, err)
}
func LogMasterOp(op, msg string, err error) {
gAdtMutex.RLock()
defer gAdtMutex.RUnlock()