Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add detailed logs for special customized logs #1408

Merged
merged 1 commit into from
May 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 21 additions & 20 deletions modular/gater/admin_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/hex"
"encoding/json"
"encoding/xml"
"fmt"
"io"
"net/http"
"strings"
Expand Down Expand Up @@ -318,7 +319,7 @@ func (g *GateModular) getChallengeInfoHandler(w http.ResponseWriter, r *http.Req
if strings.Contains(err.Error(), "No such object") {
err = ErrNoSuchObject
} else {
err = ErrConsensusWithDetail("failed to get object info from consensus, error: " + err.Error())
err = ErrConsensusWithDetail("failed to get object info from consensus, object_id: " + fmt.Sprint(objectID) + "error: " + err.Error())
}
return
}
Expand All @@ -342,7 +343,7 @@ func (g *GateModular) getChallengeInfoHandler(w http.ResponseWriter, r *http.Req
metrics.PerfChallengeTimeHistogram.WithLabelValues("challenge_get_bucket_time").Observe(time.Since(getBucketTime).Seconds())
if err != nil {
log.CtxErrorw(reqCtx.Context(), "failed to get bucket info from consensus", "error", err)
err = ErrConsensusWithDetail("failed to get bucket info from consensus, error: " + err.Error())
err = ErrConsensusWithDetail("failed to get bucket info from consensus, bucket_name: " + objectInfo.GetBucketName() + ", error: " + err.Error())
return
}
redundancyIdx, err := util.StringToInt32(reqCtx.request.Header.Get(GnfdRedundancyIndexHeader))
Expand Down Expand Up @@ -459,7 +460,7 @@ func (g *GateModular) getChallengeInfoV2Handler(w http.ResponseWriter, r *http.R
if strings.Contains(err.Error(), "No such object") {
err = ErrNoSuchObject
} else {
err = ErrConsensusWithDetail("failed to get object info from consensus, error: " + err.Error())
err = ErrConsensusWithDetail("failed to get object info from consensus, object_id:" + reqCtx.request.Header.Get(GnfdObjectIDHeader) + ", error: " + err.Error())
}
return
}
Expand All @@ -483,7 +484,7 @@ func (g *GateModular) getChallengeInfoV2Handler(w http.ResponseWriter, r *http.R
metrics.PerfChallengeTimeHistogram.WithLabelValues("challenge_get_bucket_time").Observe(time.Since(getBucketTime).Seconds())
if err != nil {
log.CtxErrorw(reqCtx.Context(), "failed to get bucket info from consensus", "error", err)
err = ErrConsensusWithDetail("failed to get bucket info from consensus, error: " + err.Error())
err = ErrConsensusWithDetail("failed to get bucket info from consensus, bucket_name: " + objectInfo.GetBucketName() + ", error: " + err.Error())
return
}
redundancyIdx, err := util.StringToInt32(reqCtx.request.Header.Get(GnfdRedundancyIndexHeader))
Expand Down Expand Up @@ -549,7 +550,7 @@ func (g *GateModular) getChallengeInfoV2Handler(w http.ResponseWriter, r *http.R
xmlBody, err := xml.Marshal(&xmlInfo)
if err != nil {
log.Errorw("failed to marshal xml", "error", err)
err = ErrEncodeResponseWithDetail("failed to marshal xml, error: " + err.Error())
err = ErrEncodeResponseWithDetail("failed to marshal xml, object_id: " + reqCtx.request.Header.Get(GnfdObjectIDHeader) + "error: " + err.Error())
return
}
w.Header().Set(ContentTypeHeader, ContentTypeXMLHeaderValue)
Expand Down Expand Up @@ -695,7 +696,7 @@ func (g *GateModular) checkReplicatePermission(ctx context.Context, receiveTask
for retry := 0; retry < checkPermissionRetry; retry++ {
objectInfo, err = g.baseApp.Consensus().QueryObjectInfo(ctx, receiveTask.ObjectInfo.BucketName, receiveTask.ObjectInfo.ObjectName)
if err != nil {
err = ErrConsensusWithDetail("failed to get object info from consensus, error:" + err.Error())
err = ErrConsensusWithDetail("failed to get object info from consensus, object_name: " + receiveTask.ObjectInfo.ObjectName + "bucket_name: " + receiveTask.ObjectInfo.BucketName + ", error:" + err.Error())
time.Sleep(checkPermissionSleepTime)
continue
}
Expand All @@ -722,17 +723,17 @@ func (g *GateModular) checkReplicatePermission(ctx context.Context, receiveTask
// check if the request account is the primary SP of the object of the receiving task
gvg, err := g.baseApp.GfSpClient().GetGlobalVirtualGroupByGvgID(ctx, receiveTask.GetGlobalVirtualGroupID())
if err != nil {
return ErrConsensusWithDetail("QueryGVGInfo error: " + err.Error())
return ErrConsensusWithDetail("failed to get queryGVGInfo, gvg id: " + fmt.Sprint(receiveTask.GetGlobalVirtualGroupID()) + ", error: " + err.Error())
}

if gvg == nil {
return ErrConsensusWithDetail("QueryGVGInfo nil")
return ErrConsensusWithDetail("QueryGVGInfo nil, with gvg id: " + fmt.Sprint(receiveTask.GetGlobalVirtualGroupID()))
}

// judge if sender is the primary sp of the gvg
primarySp, err := g.baseApp.Consensus().QuerySPByID(ctx, gvg.PrimarySpId)
if err != nil {
return ErrConsensusWithDetail("QuerySPInfo error: " + err.Error())
return ErrConsensusWithDetail("failed to querySPInfo, primarySpId: " + fmt.Sprint(gvg.PrimarySpId) + ", error: " + err.Error())
}

if primarySp.GetOperatorAccAddress().String() != signatureAddr {
Expand All @@ -744,7 +745,7 @@ func (g *GateModular) checkReplicatePermission(ctx context.Context, receiveTask
// judge if myself is the right secondary sp of the gvg
spID, err := g.getSPID()
if err != nil {
return ErrConsensusWithDetail("getSPID error: " + err.Error())
return ErrConsensusWithDetail("failed to getSPID, gvg info:" + gvg.String() + ", error: " + err.Error())
}

expectSecondarySPID := gvg.GetSecondarySpIds()[int(receiveTask.GetRedundancyIdx())]
Expand Down Expand Up @@ -858,12 +859,12 @@ func (g *GateModular) getRecoverDataHandler(w http.ResponseWriter, r *http.Reque

spID, err := g.getSPID()
if err != nil {
err = ErrConsensusWithDetail("getSPID error: " + err.Error())
err = ErrConsensusWithDetail("failed to getSPID, operator_address: " + g.baseApp.OperatorAddress() + ", error: " + err.Error())
return
}
bucketSPID, err := util.GetBucketPrimarySPID(reqCtx.Context(), g.baseApp.Consensus(), bucketInfo)
if err != nil {
err = ErrConsensusWithDetail("GetBucketPrimarySPID error: " + err.Error())
err = ErrConsensusWithDetail("failed to getBucketPrimarySPID, bucket_name: " + bucketInfo.GetBucketName() + ", error: " + err.Error())
return
}

Expand Down Expand Up @@ -930,19 +931,19 @@ func (g *GateModular) getRecoverPiece(ctx context.Context, objectInfo *storagety
if err == nil {
successorSP, err = g.baseApp.Consensus().QuerySPByID(ctx, swapInInfo.SuccessorSpId)
if err != nil {
return nil, ErrConsensusWithDetail("query sp err: " + err.Error())
return nil, ErrConsensusWithDetail("failed to query sp, SuccessorSpId: " + fmt.Sprint(swapInInfo.SuccessorSpId) + ", err: " + err.Error())
}
if primarySp.Id == swapInInfo.TargetSpId && successorSP.OperatorAddress == signatureAddr.String() {
isSuccessorPrimary = true
}
} else {
swapInInfo, err = g.baseApp.Consensus().QuerySwapInInfo(ctx, virtualgrouptypes.NoSpecifiedFamilyId, gvg.Id)
if err != nil {
return nil, ErrConsensusWithDetail("query swapInInfo err: " + err.Error())
return nil, ErrConsensusWithDetail("failed to query swapInInfo, gvg_id: " + fmt.Sprint(gvg.Id) + ", err: " + err.Error())
}
successorSP, err = g.baseApp.Consensus().QuerySPByID(ctx, swapInInfo.SuccessorSpId)
if err != nil {
return nil, ErrConsensusWithDetail("query sp err: " + err.Error())
return nil, ErrConsensusWithDetail("failed to query sp, SuccessorSpId: " + fmt.Sprint(swapInInfo.SuccessorSpId) + ", err: " + err.Error())
}
for _, sspID := range gvg.SecondarySpIds {
if sspID == swapInInfo.TargetSpId && successorSP.OperatorAddress == signatureAddr.String() {
Expand Down Expand Up @@ -1015,11 +1016,11 @@ func (g *GateModular) getRecoverSegment(ctx context.Context, objectInfo *storage
// if the handler is not the primary SP of the object, return error
spID, err := g.getSPID()
if err != nil {
return nil, ErrConsensusWithDetail("getSPID error: " + err.Error())
return nil, ErrConsensusWithDetail("failed to getSPID , object_name: " + objectInfo.GetObjectName() + "bucket_name:" + bucketInfo.GetBucketName() + ", error: " + err.Error())
}
bucketSPID, err := util.GetBucketPrimarySPID(ctx, g.baseApp.Consensus(), bucketInfo)
if err != nil {
return nil, ErrConsensusWithDetail("GetBucketPrimarySPID error: " + err.Error())
return nil, ErrConsensusWithDetail("GetBucketPrimarySPID, bucket_name: " + bucketInfo.GetBucketName() + ", error: " + err.Error())
}

if bucketSPID != spID {
Expand All @@ -1042,19 +1043,19 @@ func (g *GateModular) getRecoverSegment(ctx context.Context, objectInfo *storage
if recoveryTask.GetBySuccessorSp() {
swapInInfo, err = g.baseApp.Consensus().QuerySwapInInfo(ctx, 0, gvg.Id)
if err != nil {
return nil, ErrConsensusWithDetail("query swapInInfo err: " + err.Error())
return nil, ErrConsensusWithDetail("failed to query swapInInfo, gvg_id: " + fmt.Sprint(gvg.Id) + ", err: " + err.Error())
}
successorSP, err = g.baseApp.Consensus().QuerySPByID(ctx, swapInInfo.SuccessorSpId)
if err != nil {
return nil, ErrConsensusWithDetail("query sp err: " + err.Error())
return nil, ErrConsensusWithDetail("failed to query sp, swapInInfo.SuccessorSpId: " + fmt.Sprint(swapInInfo.SuccessorSpId) + ", err: " + err.Error())
}
}

for idx, sspId := range gvg.GetSecondarySpIds() {
ssp, err := g.baseApp.Consensus().QuerySPByID(ctx, sspId)
if err != nil {
log.CtxErrorw(ctx, "failed to query SP by ID", "sp_id", sspId, "error", err)
return nil, ErrConsensusWithDetail("QuerySPByID error: " + err.Error())
return nil, ErrConsensusWithDetail("failed to querySPByID, sp_id : " + fmt.Sprint(sspId) + ", error: " + err.Error())
}

if ssp.OperatorAddress == signatureAddr.String() {
Expand Down
36 changes: 18 additions & 18 deletions modular/gater/bucket_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ func (g *GateModular) getBucketReadQuotaHandler(w http.ResponseWriter, r *http.R

bucketInfo, err = g.baseApp.Consensus().QueryBucketInfo(ctx, bucketName)
if err != nil {
log.CtxErrorw(ctx, "failed to get bucket info from consensus", "error", err)
err = ErrConsensusWithDetail("failed to get bucket info from consensus, error: " + err.Error())
log.CtxErrorw(ctx, "failed to get bucket info from consensus", "bucket_name", bucketName, "error", err)
err = ErrConsensusWithDetail("failed to get bucket info from consensus,bucket_name: " + bucketName + ", error: " + err.Error())
return
}
spID, err := g.getSPID()
Expand Down Expand Up @@ -100,13 +100,13 @@ func (g *GateModular) getBucketReadQuotaHandler(w http.ResponseWriter, r *http.R
xmlBody, err := xml.Marshal(&xmlInfo)
if err != nil {
log.Errorw("failed to marshal xml", "error", err)
err = ErrEncodeResponseWithDetail("failed to marshal xml, error: " + err.Error())
err = ErrEncodeResponseWithDetail("failed to marshal xml, bucket_name: " + bucketInfo.GetBucketName() + ", error: " + err.Error())
return
}
w.Header().Set(ContentTypeHeader, ContentTypeXMLHeaderValue)
if _, err = w.Write(xmlBody); err != nil {
log.Errorw("failed to write body", "error", err)
err = ErrEncodeResponseWithDetail("failed to write body, error: " + err.Error())
err = ErrEncodeResponseWithDetail("failed to write body, bucket_name: " + bucketInfo.GetBucketName() + " ,error: " + err.Error())
return
}
log.CtxDebugw(ctx, "succeed to get bucket quota", "xml_info", xmlInfo)
Expand Down Expand Up @@ -140,8 +140,8 @@ func (g *GateModular) listBucketReadRecordHandler(w http.ResponseWriter, r *http

bucketInfo, err := g.baseApp.Consensus().QueryBucketInfo(ctx, bucketName)
if err != nil {
log.CtxErrorw(ctx, "failed to get bucket info from consensus", "error", err)
err = ErrConsensusWithDetail("failed to get bucket info from consensus, error: " + err.Error())
log.CtxErrorw(ctx, "failed to get bucket info from consensus", "bucketName", bucketName, "error", err)
err = ErrConsensusWithDetail("failed to get bucket info from consensus, bucket_name: " + bucketName + ", error: " + err.Error())
return
}
spID, err := g.getSPID()
Expand Down Expand Up @@ -219,14 +219,14 @@ func (g *GateModular) listBucketReadRecordHandler(w http.ResponseWriter, r *http
xmlBody, err := xml.Marshal(&xmlInfo)
if err != nil {
log.Errorw("failed to marshal xml", "error", err)
err = ErrEncodeResponseWithDetail("failed to marshal xml, error: " + err.Error())
err = ErrEncodeResponseWithDetail("failed to marshal xml for bucket read records, bucket_name: " + bucketName + " ,error: " + err.Error())
return
}

w.Header().Set(ContentTypeHeader, ContentTypeXMLHeaderValue)
if _, err = w.Write(xmlBody); err != nil {
log.Errorw("failed to write body", "error", err)
err = ErrEncodeResponseWithDetail("failed to write body, error: " + err.Error())
err = ErrEncodeResponseWithDetail("failed to write body for bucket read records, bucket_name: " + bucketName + " ,error: " + err.Error())
return
}
log.Debugw("succeed to list bucket read records", "xml_info", xmlInfo)
Expand Down Expand Up @@ -277,8 +277,8 @@ func (g *GateModular) queryBucketMigrationProgressHandler(w http.ResponseWriter,
}

if bucketInfo, err = g.baseApp.Consensus().QueryBucketInfo(reqCtx.Context(), reqCtx.bucketName); err != nil {
log.CtxErrorw(reqCtx.Context(), "failed to get bucket info from consensus", "error", err)
err = ErrConsensusWithDetail("failed to get bucket info from consensus, error: " + err.Error())
log.CtxErrorw(reqCtx.Context(), "failed to get bucket info from consensus", "bucket_name", reqCtx.bucketName, "error", err)
err = ErrConsensusWithDetail("failed to get bucket info from consensus, bucket_name: " + reqCtx.bucketName + " ,error: " + err.Error())
return
}

Expand Down Expand Up @@ -308,13 +308,13 @@ func (g *GateModular) queryBucketMigrationProgressHandler(w http.ResponseWriter,
xmlBody, err := xml.Marshal(&xmlInfo)
if err != nil {
log.Errorw("failed to marshal xml", "error", err)
err = ErrEncodeResponseWithDetail("failed to marshal xml, error: " + err.Error())
err = ErrEncodeResponseWithDetail("failed to marshal xml for query bucket migration progress, bucket_name: " + reqCtx.bucketName + " ,error: " + err.Error())
return
}
w.Header().Set(ContentTypeHeader, ContentTypeXMLHeaderValue)
if _, err = w.Write(xmlBody); err != nil {
log.Errorw("failed to write body", "error", err)
err = ErrEncodeResponseWithDetail("failed to write body, error: " + err.Error())
err = ErrEncodeResponseWithDetail("failed to write body for query bucket migration progress, bucket_name: " + reqCtx.bucketName + " ,error: " + err.Error())
return
}
log.Debugw("succeed to query bucket migration progress", "xml_info", xmlInfo)
Expand Down Expand Up @@ -381,13 +381,13 @@ func (g *GateModular) listBucketReadQuotaHandler(w http.ResponseWriter, r *http.
xmlBody, err := xml.Marshal(&xmlInfo)
if err != nil {
log.Errorw("failed to marshal xml", "error", err)
err = ErrEncodeResponseWithDetail("failed to marshal xml, error: " + err.Error())
err = ErrEncodeResponseWithDetail("failed to marshal xml for list bucket read quota, error: " + err.Error())
return
}
w.Header().Set(ContentTypeHeader, ContentTypeXMLHeaderValue)
if _, err = w.Write(xmlBody); err != nil {
log.Errorw("failed to write body", "error", err)
err = ErrEncodeResponseWithDetail("failed to write body, error: " + err.Error())
err = ErrEncodeResponseWithDetail("failed to write body for list bucket read quota, error: " + err.Error())
return
}
log.CtxDebugw(ctx, "succeed to get bucket quota", "xml_info", xmlInfo)
Expand Down Expand Up @@ -434,13 +434,13 @@ func (g *GateModular) getBucketReadQuotaCountHandler(w http.ResponseWriter, r *h
xmlBody, err := xml.Marshal(&xmlInfo)
if err != nil {
log.Errorw("failed to marshal xml", "error", err)
err = ErrEncodeResponseWithDetail("failed to marshal xml, error: " + err.Error())
err = ErrEncodeResponseWithDetail("failed to marshal xml for get bucket read quota count, error: " + err.Error())
return
}
w.Header().Set(ContentTypeHeader, ContentTypeXMLHeaderValue)
if _, err = w.Write(xmlBody); err != nil {
log.Errorw("failed to write body", "error", err)
err = ErrEncodeResponseWithDetail("failed to write body, error: " + err.Error())
err = ErrEncodeResponseWithDetail("failed to write body for get bucket read quota count, error: " + err.Error())
return
}
log.CtxDebugw(ctx, "succeed to get bucket quota count", "xml_info", xmlInfo)
Expand Down Expand Up @@ -493,14 +493,14 @@ func (g *GateModular) getRecommendedVGFIDHandler(w http.ResponseWriter, r *http.
xmlBody, err := xml.Marshal(&xmlInfo)
if err != nil {
log.Errorw("failed to marshal xml", "error", err)
err = ErrEncodeResponseWithDetail("failed to marshal xml, error: " + err.Error())
err = ErrEncodeResponseWithDetail("failed to marshal xml for get recommended vgf id, error: " + err.Error())
return
}
w.Header().Set(ContentTypeHeader, ContentTypeXMLHeaderValue)

if _, err = w.Write(xmlBody); err != nil {
log.Errorw("failed to write body", "error", err)
err = ErrEncodeResponseWithDetail("failed to write body, error: " + err.Error())
err = ErrEncodeResponseWithDetail("failed to write body for get recommended vgf id, error: " + err.Error())
return
}
log.CtxDebugw(reqCtx.Context(), "succeed to get recommended virtual group family", "xml_info", xmlInfo)
Expand Down
4 changes: 2 additions & 2 deletions modular/gater/migrate_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ func (g *GateModular) getSecondaryBlsMigrationBucketApprovalHandler(w http.Respo
signature, err := g.baseApp.GfSpClient().SignSecondarySPMigrationBucket(reqCtx.Context(), signDoc)
if err != nil {
log.CtxErrorw(reqCtx.Context(), "failed to sign secondary sp migration bucket", "error", err)
err = ErrMigrateApprovalWithDetail("failed to sign secondary sp migration bucket, error: " + err.Error())
err = ErrMigrateApprovalWithDetail("failed to sign secondary sp migration bucket, bucket_id: " + signDoc.BucketId.String() + " ,error: " + err.Error())
return
}
w.Header().Set(GnfdSecondarySPMigrationBucketApprovalHeader, hex.EncodeToString(signature))
Expand Down Expand Up @@ -354,7 +354,7 @@ func (g *GateModular) getSwapOutApproval(w http.ResponseWriter, r *http.Request)
signature, err := g.baseApp.GfSpClient().SignSwapOut(reqCtx.Context(), swapOutApproval)
if err != nil {
log.CtxErrorw(reqCtx.Context(), "failed to sign swap out", "error", err)
err = ErrMigrateApprovalWithDetail("failed to sign swap out, error: " + err.Error())
err = ErrMigrateApprovalWithDetail("failed to sign swap out, context:" + reqCtx.String() + ", error: " + err.Error())
return
}
swapOutApproval.SuccessorSpApproval.Sig = signature
Expand Down
Loading
Loading