Skip to content

Commit

Permalink
[Feature] [ArangoBackup] Propagate message during retries
Browse files Browse the repository at this point in the history
  • Loading branch information
ajanikow committed Mar 7, 2024
1 parent 25542de commit b72a65b
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
- (Bugfix) Check Connection to the ArangoDB before creating Backup
- (Feature) Deployment & Members Condition metrics
- (Maintenance) Update Go to 1.21.8 & Dependencies
- (Feature) (ArangoBackup) Propagate message during retries

## [1.2.38](https://github.com/arangodb/kube-arangodb/tree/1.2.38) (2024-02-22)
- (Feature) Extract GRPC Server
Expand Down
5 changes: 3 additions & 2 deletions pkg/handlers/backup/state_createerror.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// DISCLAIMER
//
// Copyright 2023 ArangoDB GmbH, Cologne, Germany
// Copyright 2023-2024 ArangoDB GmbH, Cologne, Germany
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -29,7 +29,8 @@ import (
func stateCreateErrorHandler(h *handler, backup *backupApi.ArangoBackup) (*backupApi.ArangoBackupStatus, error) {
if !backup.Spec.Backoff.Enabled() {
return wrapUpdateStatus(backup,
updateStatusState(backupApi.ArangoBackupStateFailed, "retries are disabled"),
updateStatusStateOnly(backupApi.ArangoBackupStateFailed),
cleanBackOff(),
cleanStatusJob())
}

Expand Down
42 changes: 39 additions & 3 deletions pkg/handlers/backup/state_createerror_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// DISCLAIMER
//
// Copyright 2023 ArangoDB GmbH, Cologne, Germany
// Copyright 2023-2024 ArangoDB GmbH, Cologne, Germany
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -97,7 +97,8 @@ func Test_State_CreateError_Retry_WhenBackoffDisabled_C1(t *testing.T) {
// Assert
newObj := refreshArangoBackup(t, handler, obj)
require.Equal(t, newObj.Status.State, backupApi.ArangoBackupStateFailed)
require.Equal(t, newObj.Status.Message, "retries are disabled")
require.Nil(t, newObj.Status.Backoff)
require.Equal(t, newObj.Status.Message, "")
}

func Test_State_CreateError_Retry_WhenBackoffDisabled_C2(t *testing.T) {
Expand Down Expand Up @@ -126,7 +127,42 @@ func Test_State_CreateError_Retry_WhenBackoffDisabled_C2(t *testing.T) {
// Assert
newObj := refreshArangoBackup(t, handler, obj)
require.Equal(t, newObj.Status.State, backupApi.ArangoBackupStateFailed)
require.Equal(t, newObj.Status.Message, "retries are disabled")
require.Nil(t, newObj.Status.Backoff)
require.Equal(t, newObj.Status.Message, "")
}

func Test_State_CreateError_Retry_WhenBackoffDisabled_C3(t *testing.T) {
// Arrange
message := "SomeRandomErrorMessage"

handler, mock := newErrorsFakeHandler(mockErrorsArangoClientBackup{})

obj, deployment := newObjectSet(t, backupApi.ArangoBackupStateCreateError)

obj.Status.Message = message

backupMeta, err := mock.Create()
require.NoError(t, err)

obj.Status.Backup = &backupApi.ArangoBackupDetails{
ID: string(backupMeta.ID),
Version: backupMeta.Version,
CreationTimestamp: meta.Now(),
}

obj.Status.Time.Time = time.Now().Add(-2 * downloadDelay)

// Act
createArangoDeployment(t, handler, deployment)
createArangoBackup(t, handler, obj)

require.NoError(t, handler.Handle(context.Background(), tests.NewItem(t, operation.Update, obj)))

// Assert
newObj := refreshArangoBackup(t, handler, obj)
require.Equal(t, newObj.Status.State, backupApi.ArangoBackupStateFailed)
require.Nil(t, newObj.Status.Backoff)
require.Equal(t, newObj.Status.Message, message)
}

func Test_State_CreateError_Transfer_To_Failed(t *testing.T) {
Expand Down
5 changes: 3 additions & 2 deletions pkg/handlers/backup/state_uploaderror.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// DISCLAIMER
//
// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany
// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -30,7 +30,8 @@ func stateUploadErrorHandler(h *handler, backup *backupApi.ArangoBackup) (*backu
// no more retries - move to failed state
if !backup.Status.Backoff.ShouldBackoff(backup.Spec.Backoff) {
return wrapUpdateStatus(backup,
updateStatusState(backupApi.ArangoBackupStateFailed, "out of Upload retries"),
updateStatusStateOnly(backupApi.ArangoBackupStateFailed),
cleanBackOff(),
cleanStatusJob())
}

Expand Down
11 changes: 10 additions & 1 deletion pkg/handlers/backup/status.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// DISCLAIMER
//
// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany
// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -50,6 +50,15 @@ func updateStatus(backup *backupApi.ArangoBackup, update ...updateStatusFunc) *b
return s
}

func updateStatusStateOnly(state state.State) updateStatusFunc {
return func(status *backupApi.ArangoBackupStatus) {
if status.State != state {
status.Time = meta.Now()
}
status.State = state
}
}

func updateStatusState(state state.State, template string, a ...interface{}) updateStatusFunc {
return func(status *backupApi.ArangoBackupStatus) {
if status.State != state {
Expand Down

0 comments on commit b72a65b

Please sign in to comment.