Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 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
9 changes: 6 additions & 3 deletions docs/config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -1303,15 +1303,18 @@
"properties": {
"base-timeout": {
"description": "BaseTimeout is the initial delay between retry attempts, in milliseconds.",
"type": "integer"
"type": "integer",
"nullable": true
},
"max-retries": {
"description": "MaxRetries is the maximum number of retry attempts that will be made.\nIf set to 0, no retries will be performed.",
"type": "integer"
"type": "integer",
"nullable": true
},
"multiplier": {
"description": "Multiplier is used to increase the delay between subsequent retry attempts.\nThe actual delay is calculated as: BaseTimeout * (Multiplier ^ attemptNumber)",
"type": "number"
"type": "number",
"nullable": true
}
}
},
Expand Down
9 changes: 6 additions & 3 deletions docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -2958,15 +2958,18 @@ const docTemplate = `{
"properties": {
"base-timeout": {
"description": "BaseTimeout is the initial delay between retry attempts, in milliseconds.",
"type": "integer"
"type": "integer",
"x-nullable": true
},
"max-retries": {
"description": "MaxRetries is the maximum number of retry attempts that will be made.\nIf set to 0, no retries will be performed.",
"type": "integer"
"type": "integer",
"x-nullable": true
},
"multiplier": {
"description": "Multiplier is used to increase the delay between subsequent retry attempts.\nThe actual delay is calculated as: BaseTimeout * (Multiplier ^ attemptNumber)",
"type": "number"
"type": "number",
"x-nullable": true
}
}
},
Expand Down
9 changes: 6 additions & 3 deletions docs/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -3290,15 +3290,18 @@
"properties": {
"base-timeout": {
"description": "BaseTimeout is the initial delay between retry attempts, in milliseconds.",
"type": "integer"
"type": "integer",
"nullable": true
},
"max-retries": {
"description": "MaxRetries is the maximum number of retry attempts that will be made.\nIf set to 0, no retries will be performed.",
"type": "integer"
"type": "integer",
"nullable": true
},
"multiplier": {
"description": "Multiplier is used to increase the delay between subsequent retry attempts.\nThe actual delay is calculated as: BaseTimeout * (Multiplier ^ attemptNumber)",
"type": "number"
"type": "number",
"nullable": true
}
}
},
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ require (
github.com/aws/aws-sdk-go-v2/service/s3 v1.88.1
github.com/aws/smithy-go v1.23.0
github.com/go-logr/logr v1.4.3
github.com/google/go-cmp v0.7.0
github.com/googleapis/gax-go/v2 v2.15.0
github.com/prometheus/client_golang v1.21.1
github.com/reugn/go-quartz v0.15.2
Expand All @@ -30,6 +31,7 @@ require (
google.golang.org/api v0.247.0
gopkg.in/natefinch/lumberjack.v2 v2.2.1
gopkg.in/yaml.v3 v3.0.1
pgregory.net/rapid v1.2.0
)

require (
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -321,3 +321,5 @@ gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
k8s.io/apimachinery v0.32.3 h1:JmDuDarhDmA/Li7j3aPrwhpNBA94Nvk5zLeOge9HH1U=
k8s.io/apimachinery v0.32.3/go.mod h1:GpHVgxoKlTxClKcteaeuF1Ul/lDVb74KpZcxcmLDElE=
pgregory.net/rapid v1.2.0 h1:keKAYRcjm+e1F0oAuU5F5+YPAWcyxNNRK2wud503Gnk=
pgregory.net/rapid v1.2.0/go.mod h1:PY5XlDGj0+V1FCq0o192FdRhpKHGTRIWBgqjDBTrq04=
3 changes: 2 additions & 1 deletion pkg/dto/aerospike_cluster.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
//nolint:lll
package dto

import (
Expand Down Expand Up @@ -158,6 +157,8 @@ func (a *AerospikeCluster) seedNodesToModel() []model.SeedNode {

// Credentials represents authentication details to the Aerospike cluster.
// @Description Credentials represents authentication details to the Aerospike cluster.
//
//nolint:lll
type Credentials struct {
SecretAgentConfig `yaml:",inline"`
// The username for the cluster authentication.
Expand Down
6 changes: 6 additions & 0 deletions pkg/dto/backup_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,15 @@ func (p *BackupPolicy) Validate() error {
if p.SocketTimeout != nil && *p.SocketTimeout < 0 {
return errValidationNegative("socket-timeout", *p.SocketTimeout)
}
if p.SocketTimeout != nil && *p.SocketTimeout > maxTimeout {
return errValidationInvalidValue("socket-timeout", *p.SocketTimeout, "should not exceed 24 hours")
}
if p.TotalTimeout != nil && *p.TotalTimeout < 0 {
return errValidationNegative("total-timeout", *p.TotalTimeout)
}
if p.TotalTimeout != nil && *p.TotalTimeout > maxTimeout {
return errValidationInvalidValue("total-timeout", *p.TotalTimeout, "should not exceed 24 hours")
}
if err := p.RetryPolicy.Validate(); err != nil {
return fmt.Errorf("retryPolicy validation failed: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/dto/backup_policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ func TestBackupPolicyConversionIsLossless(t *testing.T) {
parallelWrite := 8
socketTimeout := int64(5000)
totalTimeout := int64(10000)
retryPolicy := &RetryPolicy{MaxRetries: 3}
retryPolicy := &RetryPolicy{MaxRetries: ptr.Of(3)}
noRecords := true
noIndexes := false
noUdfs := true
Expand Down
11 changes: 11 additions & 0 deletions pkg/dto/compression_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,17 @@ func (p *CompressionPolicy) ToModel() *model.CompressionPolicy {
}
}

func newCompressionPolicyFromModel(m *model.CompressionPolicy) *CompressionPolicy {
if m == nil {
return nil
}

c := &CompressionPolicy{}
c.fromModel(m)

return c
}

func (p *CompressionPolicy) fromModel(m *model.CompressionPolicy) {
p.Mode = m.Mode
p.Level = m.Level
Expand Down
5 changes: 4 additions & 1 deletion pkg/dto/constants.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package dto

import "time"

const (
// max possible value https://aerospike.com/docs/server/reference/configuration#namespace__rack-id
maxRack = 1000000
maxRack = 1000000
maxTimeout = int64(24 * time.Hour / 1e6)
)
41 changes: 41 additions & 0 deletions pkg/dto/model_roundtrip_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package dto

import (
"testing"

"github.com/aerospike/aerospike-backup-service/v3/pkg/model"
"github.com/aerospike/aerospike-backup-service/v3/pkg/util/ptr"
"pgregory.net/rapid"
)

// This test verifies that all valid permutation of a DTO struct can be converted to model and back lossless.

func Test_RetryPolicy_RoundTrip(t *testing.T) {
genDTO := RapidStruct[RetryPolicy](defaultRegistry())

runRoundTripTest[*RetryPolicy, model.RetryPolicy](
t,
func(rt *rapid.T) *RetryPolicy { return ptr.Of(genDTO.Draw(rt, "retry-policy")) },
newRetryPolicyFromModel,
)
}

func Test_PortRange_RoundTrip(t *testing.T) {
genDTO := RapidStruct[PortRange](defaultRegistry())

runRoundTripTest[*PortRange, model.PortRange](
t,
func(rt *rapid.T) *PortRange { return ptr.Of(genDTO.Draw(rt, "port")) },
newPortRangeFromModel,
)
}

func Test_Compression_RoundTrip(t *testing.T) {
genDTO := RapidStruct[CompressionPolicy](defaultRegistry())

runRoundTripTest[*CompressionPolicy, model.CompressionPolicy](
t,
func(rt *rapid.T) *CompressionPolicy { return ptr.Of(genDTO.Draw(rt, "compression")) },
newCompressionPolicyFromModel,
)
}
1 change: 0 additions & 1 deletion pkg/dto/port.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ func (p *PortRange) ToModel() *model.PortRange {
}
}

//nolint:unused
func newPortRangeFromModel(m *model.PortRange) *PortRange {
if m == nil {
return nil
Expand Down
Loading
Loading