mirror of
https://github.com/ceph/ceph-csi.git
synced 2024-11-25 15:50:20 +00:00
rbd: log sitestatuses and description
This commit logs sitestatues and description in GetVolumeReplicationInfo RPC call for better debuging. Fixes: #4430 Signed-off-by: Yati Padia <ypadia@redhat.com>
This commit is contained in:
parent
0a82f17671
commit
fbaf9d5485
@ -718,7 +718,7 @@ func (rs *ReplicationServer) ResyncVolume(ctx context.Context,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if !ready {
|
if !ready {
|
||||||
err = checkVolumeResyncStatus(localStatus)
|
err = checkVolumeResyncStatus(ctx, localStatus)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, status.Error(codes.Internal, err.Error())
|
return nil, status.Error(codes.Internal, err.Error())
|
||||||
}
|
}
|
||||||
@ -862,7 +862,7 @@ func (rs *ReplicationServer) GetVolumeReplicationInfo(ctx context.Context,
|
|||||||
return nil, status.Error(codes.Internal, err.Error())
|
return nil, status.Error(codes.Internal, err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
remoteStatus, err := RemoteStatus(mirrorStatus)
|
remoteStatus, err := RemoteStatus(ctx, mirrorStatus)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.ErrorLog(ctx, err.Error())
|
log.ErrorLog(ctx, err.Error())
|
||||||
|
|
||||||
@ -870,7 +870,7 @@ func (rs *ReplicationServer) GetVolumeReplicationInfo(ctx context.Context,
|
|||||||
}
|
}
|
||||||
|
|
||||||
description := remoteStatus.Description
|
description := remoteStatus.Description
|
||||||
resp, err := getLastSyncInfo(description)
|
resp, err := getLastSyncInfo(ctx, description)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, corerbd.ErrLastSyncTimeNotFound) {
|
if errors.Is(err, corerbd.ErrLastSyncTimeNotFound) {
|
||||||
return nil, status.Errorf(codes.NotFound, "failed to get last sync info: %v", err)
|
return nil, status.Errorf(codes.NotFound, "failed to get last sync info: %v", err)
|
||||||
@ -886,12 +886,22 @@ func (rs *ReplicationServer) GetVolumeReplicationInfo(ctx context.Context,
|
|||||||
// RemoteStatus returns one SiteMirrorImageStatus item from the SiteStatuses
|
// RemoteStatus returns one SiteMirrorImageStatus item from the SiteStatuses
|
||||||
// slice that corresponds to the remote site's status. If the remote status
|
// slice that corresponds to the remote site's status. If the remote status
|
||||||
// is not found than the error ErrNotExist will be returned.
|
// 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 (
|
var (
|
||||||
ss librbd.SiteMirrorImageStatus
|
ss librbd.SiteMirrorImageStatus
|
||||||
err error = librbd.ErrNotExist
|
err error = librbd.ErrNotExist
|
||||||
)
|
)
|
||||||
|
|
||||||
for i := range gmis.SiteStatuses {
|
for i := range gmis.SiteStatuses {
|
||||||
|
log.DebugLog(
|
||||||
|
ctx,
|
||||||
|
"Site status of MirrorUUID: %s, state: %s, description: %s, lastUpdate: %v, up: %t",
|
||||||
|
gmis.SiteStatuses[i].MirrorUUID,
|
||||||
|
gmis.SiteStatuses[i].State,
|
||||||
|
gmis.SiteStatuses[i].Description,
|
||||||
|
gmis.SiteStatuses[i].LastUpdate,
|
||||||
|
gmis.SiteStatuses[i].Up)
|
||||||
|
|
||||||
if gmis.SiteStatuses[i].MirrorUUID != "" {
|
if gmis.SiteStatuses[i].MirrorUUID != "" {
|
||||||
ss = gmis.SiteStatuses[i]
|
ss = gmis.SiteStatuses[i]
|
||||||
err = nil
|
err = nil
|
||||||
@ -906,7 +916,7 @@ func RemoteStatus(gmis *librbd.GlobalMirrorImageStatus) (librbd.SiteMirrorImageS
|
|||||||
// This function gets the local snapshot time, last sync snapshot seconds
|
// This function gets the local snapshot time, last sync snapshot seconds
|
||||||
// and last sync bytes from the description of localStatus and convert
|
// and last sync bytes from the description of localStatus and convert
|
||||||
// it into required types.
|
// 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:
|
// Format of the description will be as followed:
|
||||||
// description = `replaying, {"bytes_per_second":0.0,"bytes_per_snapshot":81920.0,
|
// description = `replaying, {"bytes_per_second":0.0,"bytes_per_snapshot":81920.0,
|
||||||
// "last_snapshot_bytes":81920,"last_snapshot_sync_seconds":0,
|
// "last_snapshot_bytes":81920,"last_snapshot_sync_seconds":0,
|
||||||
@ -924,6 +934,7 @@ func getLastSyncInfo(description string) (*replication.GetVolumeReplicationInfoR
|
|||||||
if description == "" {
|
if description == "" {
|
||||||
return nil, fmt.Errorf("empty description: %w", corerbd.ErrLastSyncTimeNotFound)
|
return nil, fmt.Errorf("empty description: %w", corerbd.ErrLastSyncTimeNotFound)
|
||||||
}
|
}
|
||||||
|
log.DebugLog(ctx, "description: %s", description)
|
||||||
splittedString := strings.SplitN(description, ",", 2)
|
splittedString := strings.SplitN(description, ",", 2)
|
||||||
if len(splittedString) == 1 {
|
if len(splittedString) == 1 {
|
||||||
return nil, fmt.Errorf("no snapshot details: %w", corerbd.ErrLastSyncTimeNotFound)
|
return nil, fmt.Errorf("no snapshot details: %w", corerbd.ErrLastSyncTimeNotFound)
|
||||||
@ -968,13 +979,13 @@ func getLastSyncInfo(description string) (*replication.GetVolumeReplicationInfoR
|
|||||||
return &response, nil
|
return &response, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func checkVolumeResyncStatus(localStatus librbd.SiteMirrorImageStatus) error {
|
func checkVolumeResyncStatus(ctx context.Context, localStatus librbd.SiteMirrorImageStatus) error {
|
||||||
// we are considering local snapshot timestamp to check if the resync is
|
// we are considering local snapshot timestamp to check if the resync is
|
||||||
// started or not, if we dont see local_snapshot_timestamp in the
|
// started or not, if we dont see local_snapshot_timestamp in the
|
||||||
// description of localStatus, we are returning error. if we see the local
|
// description of localStatus, we are returning error. if we see the local
|
||||||
// snapshot timestamp in the description we return resyncing started.
|
// snapshot timestamp in the description we return resyncing started.
|
||||||
description := localStatus.Description
|
description := localStatus.Description
|
||||||
resp, err := getLastSyncInfo(description)
|
resp, err := getLastSyncInfo(ctx, description)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to get last sync info: %w", err)
|
return fmt.Errorf("failed to get last sync info: %w", err)
|
||||||
}
|
}
|
||||||
|
@ -218,6 +218,7 @@ func TestGetSchedulingDetails(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestCheckVolumeResyncStatus(t *testing.T) {
|
func TestCheckVolumeResyncStatus(t *testing.T) {
|
||||||
|
ctx := context.TODO()
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
@ -253,7 +254,7 @@ func TestCheckVolumeResyncStatus(t *testing.T) {
|
|||||||
ts := tt
|
ts := tt
|
||||||
t.Run(ts.name, func(t *testing.T) {
|
t.Run(ts.name, func(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
if err := checkVolumeResyncStatus(ts.args); (err != nil) != ts.wantErr {
|
if err := checkVolumeResyncStatus(ctx, ts.args); (err != nil) != ts.wantErr {
|
||||||
t.Errorf("checkVolumeResyncStatus() error = %v, expect error = %v", err, ts.wantErr)
|
t.Errorf("checkVolumeResyncStatus() error = %v, expect error = %v", err, ts.wantErr)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -399,6 +400,7 @@ func TestCheckRemoteSiteStatus(t *testing.T) {
|
|||||||
|
|
||||||
func TestValidateLastSyncInfo(t *testing.T) {
|
func TestValidateLastSyncInfo(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
ctx := context.TODO()
|
||||||
duration, err := time.ParseDuration(strconv.Itoa(int(56743)) + "s")
|
duration, err := time.ParseDuration(strconv.Itoa(int(56743)) + "s")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to parse duration)")
|
t.Errorf("failed to parse duration)")
|
||||||
@ -502,7 +504,7 @@ func TestValidateLastSyncInfo(t *testing.T) {
|
|||||||
tt := tt
|
tt := tt
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
teststruct, err := getLastSyncInfo(tt.description)
|
teststruct, err := getLastSyncInfo(ctx, tt.description)
|
||||||
if err != nil && !strings.Contains(err.Error(), tt.expectedErr) {
|
if err != nil && !strings.Contains(err.Error(), tt.expectedErr) {
|
||||||
// returned error
|
// returned error
|
||||||
t.Errorf("getLastSyncInfo() returned error, expected: %v, got: %v",
|
t.Errorf("getLastSyncInfo() returned error, expected: %v, got: %v",
|
||||||
|
Loading…
Reference in New Issue
Block a user