From 58e9170880d6041b1389346e18064d5ef3ff4cab Mon Sep 17 00:00:00 2001 From: Keran Yang Date: Tue, 17 Sep 2024 18:59:56 -0400 Subject: [PATCH] fix logs Signed-off-by: Keran Yang --- pkg/sdkclient/serverinfo/serverinfo.go | 6 +++--- pkg/sdkclient/serverinfo/serverinfo_test.go | 14 +++++++------- pkg/sdkclient/serverinfo/types.go | 21 +++++++++++++++++++++ 3 files changed, 31 insertions(+), 10 deletions(-) diff --git a/pkg/sdkclient/serverinfo/serverinfo.go b/pkg/sdkclient/serverinfo/serverinfo.go index 932ab2ff50..bb098744ef 100644 --- a/pkg/sdkclient/serverinfo/serverinfo.go +++ b/pkg/sdkclient/serverinfo/serverinfo.go @@ -170,7 +170,7 @@ func checkNumaflowCompatibility(numaflowVersion string, minNumaflowVersion strin numaflowConstraint := fmt.Sprintf(">= %s", minNumaflowVersion) if err = checkConstraint(numaflowVersionSemVer, numaflowConstraint); err != nil { return fmt.Errorf("numaflow version %s must be upgraded to at least %s, in order to work with current SDK version: %w", - numaflowVersionSemVer.String(), minNumaflowVersion, err) + numaflowVersionSemVer.String(), getRealMinimumVersion(minNumaflowVersion), err) } return nil } @@ -193,7 +193,7 @@ func checkSDKCompatibility(sdkVersion string, sdkLanguage Language, minSupported if !c.Check(sdkVersionPEP440) { return fmt.Errorf("SDK version %s must be upgraded to at least %s, in order to work with current numaflow version: %w", - sdkVersionPEP440.String(), sdkRequiredVersion, err) + sdkVersionPEP440.String(), getRealMinimumVersion(sdkRequiredVersion), err) } } else { sdkVersionSemVer, err := semver.NewVersion(sdkVersion) @@ -203,7 +203,7 @@ func checkSDKCompatibility(sdkVersion string, sdkLanguage Language, minSupported if err := checkConstraint(sdkVersionSemVer, sdkConstraint); err != nil { return fmt.Errorf("SDK version %s must be upgraded to at least %s, in order to work with current numaflow version: %w", - sdkVersionSemVer.String(), sdkRequiredVersion, err) + sdkVersionSemVer.String(), getRealMinimumVersion(sdkRequiredVersion), err) } } } diff --git a/pkg/sdkclient/serverinfo/serverinfo_test.go b/pkg/sdkclient/serverinfo/serverinfo_test.go index de22f32be6..0c2fe80b43 100644 --- a/pkg/sdkclient/serverinfo/serverinfo_test.go +++ b/pkg/sdkclient/serverinfo/serverinfo_test.go @@ -101,7 +101,7 @@ func Test_CheckNumaflowCompatibility(t *testing.T) { numaflowVersion: "v1.1.6", minNumaflowVersion: "1.1.7-z", shouldErr: true, - errMessage: "numaflow version 1.1.6 must be upgraded to at least 1.1.7-z, in order to work with current SDK version", + errMessage: "numaflow version 1.1.6 must be upgraded to at least 1.1.7, in order to work with current SDK version", }, { name: "Test with compatible numaflow version - min is a stable version 1.1.6", @@ -114,7 +114,7 @@ func Test_CheckNumaflowCompatibility(t *testing.T) { numaflowVersion: "v1.1.7-rc1", minNumaflowVersion: "1.1.7-z", shouldErr: true, - errMessage: "numaflow version 1.1.7-rc1 must be upgraded to at least 1.1.7-z, in order to work with current SDK version", + errMessage: "numaflow version 1.1.7-rc1 must be upgraded to at least 1.1.7, in order to work with current SDK version", }, { name: "Test with compatible numaflow version - min is a stable version 1.1.6, numaflow version is a pre-release version", @@ -190,7 +190,7 @@ func Test_CheckSDKCompatibility(t *testing.T) { sdkLanguage: Python, minimumSupportedSDKVersions: testMinimumSupportedSDKVersions, shouldErr: true, - errMessage: "SDK version 0.5.3a1 must be upgraded to at least 0.6.0rc100, in order to work with current numaflow version", + errMessage: "SDK version 0.5.3a1 must be upgraded to at least 0.6.0, in order to work with current numaflow version", }, { name: "python pre-release version is compatible with minimum supported version", @@ -212,7 +212,7 @@ func Test_CheckSDKCompatibility(t *testing.T) { sdkLanguage: Python, minimumSupportedSDKVersions: testMinimumSupportedSDKVersions, shouldErr: true, - errMessage: "SDK version 0.5.3 must be upgraded to at least 0.6.0rc100, in order to work with current numaflow version", + errMessage: "SDK version 0.5.3 must be upgraded to at least 0.6.0, in order to work with current numaflow version", }, { name: "python release version is compatible with minimum supported version", @@ -247,7 +247,7 @@ func Test_CheckSDKCompatibility(t *testing.T) { sdkLanguage: Rust, minimumSupportedSDKVersions: testMinimumSupportedSDKVersions, shouldErr: true, - errMessage: "SDK version 0.0.3 must be upgraded to at least 0.1.0-z, in order to work with current numaflow version", + errMessage: "SDK version 0.0.3 must be upgraded to at least 0.1.0, in order to work with current numaflow version", }, { name: "java rc release version is lower than minimum supported version", @@ -255,7 +255,7 @@ func Test_CheckSDKCompatibility(t *testing.T) { sdkLanguage: Java, minimumSupportedSDKVersions: testMinimumSupportedSDKVersions, shouldErr: true, - errMessage: "SDK version 0.6.0-rc1 must be upgraded to at least 0.6.0-z, in order to work with current numaflow version", + errMessage: "SDK version 0.6.0-rc1 must be upgraded to at least 0.6.0, in order to work with current numaflow version", }, { name: "golang pre-release version is lower than minimum supported version", @@ -263,7 +263,7 @@ func Test_CheckSDKCompatibility(t *testing.T) { sdkLanguage: Go, minimumSupportedSDKVersions: testMinimumSupportedSDKVersions, shouldErr: true, - errMessage: "SDK version 0.6.0-0.20240913163521-4910018031a7 must be upgraded to at least 0.6.0-z, in order to work with current numaflow version", + errMessage: "SDK version 0.6.0-0.20240913163521-4910018031a7 must be upgraded to at least 0.6.0, in order to work with current numaflow version", }, } for _, tt := range tests { diff --git a/pkg/sdkclient/serverinfo/types.go b/pkg/sdkclient/serverinfo/types.go index 283e12fa87..46ac8ec363 100644 --- a/pkg/sdkclient/serverinfo/types.go +++ b/pkg/sdkclient/serverinfo/types.go @@ -16,6 +16,8 @@ limitations under the License. package serverinfo +import "strings" + type Language string const ( @@ -72,6 +74,25 @@ var minimumSupportedSDKVersions = sdkConstraints{ Rust: "0.1.0-z", } +// getRealMinimumVersion returns the real minimum supported version for the given version. +// it's used to help log the correct minimum supported version in the error message. +// it translates the version we used in the sdkConstraints map to the real minimum supported version. +// e.g., if the given version is "0.8.0rc100", the real minimum supported version is "0.8.0". +// if the given version is "0.8.0-z", the real minimum supported version is "0.8.0". +// if the given version is "0.8.0-rc1", the real minimum supported version is "0.8.0-rc1". +func getRealMinimumVersion(ver string) string { + if ver == "" { + return "" + } + if strings.HasSuffix(ver, "-z") { + return ver[:len(ver)-2] + } + if strings.HasSuffix(ver, "rc100") { + return ver[:len(ver)-5] + } + return ver +} + type Protocol string const (