Skip to content

Commit

Permalink
rbd: log sitestatuses and description
Browse files Browse the repository at this point in the history
This commit logs sitestatues and description in
GetVolumeReplicationInfo RPC call for better
debuging.

Fixes: #4430

Signed-off-by: Yati Padia <[email protected]>
  • Loading branch information
yati1998 committed Feb 13, 2024
1 parent fc6d34a commit 5eda7b6
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions internal/csi-addons/rbd/replication.go
Original file line number Diff line number Diff line change
Expand Up @@ -862,15 +862,15 @@ func (rs *ReplicationServer) GetVolumeReplicationInfo(ctx context.Context,
return nil, status.Error(codes.Internal, err.Error())
}

remoteStatus, err := RemoteStatus(mirrorStatus)
remoteStatus, err := RemoteStatus(ctx, mirrorStatus)
if err != nil {
log.ErrorLog(ctx, err.Error())

return nil, status.Errorf(codes.Internal, "failed to get remote status: %v", err)
}

description := remoteStatus.Description
resp, err := getLastSyncInfo(description)
resp, err := getLastSyncInfo(ctx, description)
if err != nil {
if errors.Is(err, corerbd.ErrLastSyncTimeNotFound) {
return nil, status.Errorf(codes.NotFound, "failed to get last sync info: %v", err)
Expand All @@ -886,11 +886,14 @@ func (rs *ReplicationServer) GetVolumeReplicationInfo(ctx context.Context,
// RemoteStatus returns one SiteMirrorImageStatus item from the SiteStatuses
// slice that corresponds to the remote site's status. If the remote status
// is not found than the error ErrNotExist will be returned.
func RemoteStatus(gmis *librbd.GlobalMirrorImageStatus) (librbd.SiteMirrorImageStatus, error) {
func RemoteStatus(ctx context.Context, gmis *librbd.GlobalMirrorImageStatus) (librbd.SiteMirrorImageStatus, error) {
var (
ss librbd.SiteMirrorImageStatus
err error = librbd.ErrNotExist
)
log.TraceLog(
ctx,
"Site Statuses: %s", gmis.SiteStatuses)
for i := range gmis.SiteStatuses {
if gmis.SiteStatuses[i].MirrorUUID != "" {
ss = gmis.SiteStatuses[i]
Expand All @@ -906,7 +909,7 @@ func RemoteStatus(gmis *librbd.GlobalMirrorImageStatus) (librbd.SiteMirrorImageS
// This function gets the local snapshot time, last sync snapshot seconds
// and last sync bytes from the description of localStatus and convert
// it into required types.
func getLastSyncInfo(description string) (*replication.GetVolumeReplicationInfoResponse, error) {
func getLastSyncInfo(ctx context.Context, description string) (*replication.GetVolumeReplicationInfoResponse, error) {
// Format of the description will be as followed:
// description = `replaying, {"bytes_per_second":0.0,"bytes_per_snapshot":81920.0,
// "last_snapshot_bytes":81920,"last_snapshot_sync_seconds":0,
Expand All @@ -924,6 +927,10 @@ func getLastSyncInfo(description string) (*replication.GetVolumeReplicationInfoR
if description == "" {
return nil, fmt.Errorf("empty description: %w", corerbd.ErrLastSyncTimeNotFound)
}
log.TraceLog(
ctx,
"description=%q",
description)
splittedString := strings.SplitN(description, ",", 2)
if len(splittedString) == 1 {
return nil, fmt.Errorf("no snapshot details: %w", corerbd.ErrLastSyncTimeNotFound)
Expand Down

0 comments on commit 5eda7b6

Please sign in to comment.