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

added version check before starting reconciliation #64

Merged
merged 1 commit into from
Feb 26, 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
8 changes: 8 additions & 0 deletions adapters/backend/v1/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,14 @@ func (a *Adapter) startReconciliationPeriodicTask(mainCtx context.Context, cfg *
logger.L().Error("expected to find client for reconciliation in clients map", helpers.String("clientId", clientId.String()))
continue
}

if !utils.IsBatchMessageSupported(clientId.Version) {
logger.L().Info("skipping reconciliation request for client because it does not support batch messages",
helpers.String("version", clientId.Version),
helpers.Interface("clientId", clientId.String()))
continue
}

clientCtx := utils.ContextFromIdentifiers(mainCtx, clientId)
err := client.SendReconciliationRequestMessage(clientCtx)
if err != nil {
Expand Down
19 changes: 18 additions & 1 deletion utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@ import (
"errors"
"flag"
"fmt"
"github.com/cenkalti/backoff/v4"
"net/http"
"net/http/pprof"
"path/filepath"
"reflect"
"strconv"
"time"

"github.com/cenkalti/backoff/v4"
"golang.org/x/mod/semver"

"github.com/SergJa/jsonhash"
"github.com/apache/pulsar-client-go/pulsar"
"github.com/davecgh/go-spew/spew"
Expand Down Expand Up @@ -272,3 +274,18 @@ func NewBackOff() backoff.BackOff {
b.MaxElapsedTime = 0
return b
}

// GreaterOrEqualVersion returns true if a version is greater or equal to b
func GreaterOrEqualVersion(a string, b string) bool {
return semver.Compare(a, b) >= 0
}

func IsBatchMessageSupported(version string) bool {
const minimumSupportedVersion = "v0.0.57"

if version == "" {
return false
}

return GreaterOrEqualVersion(version, minimumSupportedVersion)
}
41 changes: 41 additions & 0 deletions utils/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,44 @@ func TestRemoveManagedFields(t *testing.T) {
})
}
}

func TestGreaterOrEqualVersion(t *testing.T) {
testCases := []struct {
a string
b string
expected bool
}{
{"v0.0.2", "v0.0.1", true},
{"v0.0.1", "v0.0.2", false},
{"v0.0.1", "v0.0.1", true},
}

for _, tc := range testCases {
result := GreaterOrEqualVersion(tc.a, tc.b)
if result != tc.expected {
t.Errorf("For version %s >= %s, expected %v but got %v", tc.a, tc.b, tc.expected, result)
}
}
}

func TestIsBatchMessageSupported(t *testing.T) {
testCases := []struct {
version string
expected bool
}{
{"", false}, // Empty version should return false
{"v0.0.56", false}, // Version less than the minimum supported version should return false
{"v0.0.57", true}, // Minimum supported version should return true
{"v0.0.58", true}, // Version greater than the minimum supported version should return true
{"v1.0.0", true}, // Version with a major version greater than 0 should return true
{"v1.2.3", true}, // Version with a major version greater than 0 should return true
{"invalid_version", false}, // Invalid version should return false
}

for _, tc := range testCases {
result := IsBatchMessageSupported(tc.version)
if result != tc.expected {
t.Errorf("For version %s, expected %v but got %v", tc.version, tc.expected, result)
}
}
}
Loading