-
Notifications
You must be signed in to change notification settings - Fork 204
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
389 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
instrumentor/controllers/utils/versionsupport/dotnet_support.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package versionsupport | ||
|
||
import "github.com/hashicorp/go-version" | ||
|
||
type DotNetVersionCheck struct{} | ||
|
||
func (g DotNetVersionCheck) IsVersionSupported(version *version.Version) bool { | ||
return true | ||
} | ||
|
||
func (g DotNetVersionCheck) GetSupportedVersion() string { | ||
return "0.0.0" | ||
} |
15 changes: 15 additions & 0 deletions
15
instrumentor/controllers/utils/versionsupport/go_support.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package versionsupport | ||
|
||
import "github.com/hashicorp/go-version" | ||
|
||
type GoVersionCheck struct{} | ||
|
||
var goMinVersion, _ = version.NewVersion("1.17") | ||
|
||
func (g GoVersionCheck) IsVersionSupported(version *version.Version) bool { | ||
return version.GreaterThanOrEqual(goMinVersion) | ||
} | ||
|
||
func (g GoVersionCheck) GetSupportedVersion() string { | ||
return goMinVersion.String() | ||
} |
16 changes: 16 additions & 0 deletions
16
instrumentor/controllers/utils/versionsupport/java_support.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package versionsupport | ||
|
||
import "github.com/hashicorp/go-version" | ||
|
||
type JavaVersionChecker struct{} | ||
|
||
var JavaMinVersion, _ = version.NewVersion("17.0.11+8") | ||
|
||
func (j JavaVersionChecker) IsVersionSupported(version *version.Version) bool { | ||
return version.Metadata() >= JavaMinVersion.Metadata() && | ||
version.GreaterThanOrEqual(JavaMinVersion) | ||
} | ||
|
||
func (j JavaVersionChecker) GetSupportedVersion() string { | ||
return JavaMinVersion.String() | ||
} |
70 changes: 70 additions & 0 deletions
70
instrumentor/controllers/utils/versionsupport/language_version_support.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package versionsupport | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"github.com/hashicorp/go-version" | ||
"github.com/odigos-io/odigos/api/odigos/v1alpha1" | ||
"github.com/odigos-io/odigos/common" | ||
"sigs.k8s.io/controller-runtime/pkg/log" | ||
) | ||
|
||
type RuntimeVersionChecker interface { | ||
IsVersionSupported(version *version.Version) bool | ||
GetSupportedVersion() string | ||
} | ||
|
||
func IsRuntimeVersionSupported(ctx context.Context, details []v1alpha1.RuntimeDetailsByContainer) (bool, error) { | ||
logger := log.FromContext(ctx) | ||
|
||
for _, runtimeDetailsByContainer := range details { | ||
runtimeVersionSupporter := getRuntimeVersionCheck(runtimeDetailsByContainer.Language) | ||
if runtimeVersionSupporter == nil { | ||
logger.Info("Unsupported language", "language", runtimeDetailsByContainer.Language) | ||
return false, fmt.Errorf("Unsupported language: %s", runtimeDetailsByContainer.Language) | ||
} | ||
|
||
if runtimeDetailsByContainer.RuntimeVersion == "" { | ||
continue | ||
} | ||
|
||
runtimeVersion, err := version.NewVersion(runtimeDetailsByContainer.RuntimeVersion) | ||
if err != nil { | ||
logger.Info("Version format error: %s is not a valid version for language %s", | ||
runtimeDetailsByContainer.RuntimeVersion, runtimeDetailsByContainer.Language) | ||
return false, fmt.Errorf("Version format error: %s is not a valid version for language %s", | ||
runtimeDetailsByContainer.RuntimeVersion, runtimeDetailsByContainer.Language) | ||
} | ||
|
||
if !runtimeVersionSupporter.IsVersionSupported(runtimeVersion) { | ||
runtimeVersionOtelSDKSupport := runtimeVersionSupporter.GetSupportedVersion() | ||
logger.Info("%s runtime version not supported by OpenTelemetry SDK. Found: %s, supports: %s", | ||
runtimeDetailsByContainer.Language, runtimeDetailsByContainer.RuntimeVersion, runtimeVersionOtelSDKSupport) | ||
return false, fmt.Errorf("%s runtime version not supported by OpenTelemetry SDK. Found: %s, supports: %s", | ||
runtimeDetailsByContainer.Language, runtimeDetailsByContainer.RuntimeVersion, runtimeVersionOtelSDKSupport) | ||
} | ||
} | ||
|
||
return true, nil | ||
} | ||
|
||
func getRuntimeVersionCheck(language common.ProgrammingLanguage) RuntimeVersionChecker { | ||
switch language { | ||
case common.JavaProgrammingLanguage: | ||
return &JavaVersionChecker{} | ||
case common.GoProgrammingLanguage: | ||
return &GoVersionCheck{} | ||
case common.PythonProgrammingLanguage: | ||
return &PythonVersionCheck{} | ||
case common.DotNetProgrammingLanguage: | ||
return &DotNetVersionCheck{} | ||
case common.JavascriptProgrammingLanguage: | ||
return &NodeVersionCheck{} | ||
case common.NginxProgrammingLanguage: | ||
return &NginxVersionCheck{} | ||
case common.MySQLProgrammingLanguage: | ||
return &MySQLVersionCheck{} | ||
default: | ||
return nil | ||
} | ||
} |
177 changes: 177 additions & 0 deletions
177
instrumentor/controllers/utils/versionsupport/language_version_support_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,177 @@ | ||
package versionsupport | ||
|
||
import ( | ||
"github.com/odigos-io/odigos/api/odigos/v1alpha1" | ||
"github.com/odigos-io/odigos/common" | ||
"github.com/stretchr/testify/assert" | ||
"testing" | ||
) | ||
|
||
func TestIsRuntimeVersionSupported_NotSupported(t *testing.T) { | ||
testCases := []struct { | ||
name string | ||
language common.ProgrammingLanguage | ||
version string | ||
errorMsg string | ||
}{ | ||
{"java version not supported", common.JavaProgrammingLanguage, "17.0.10+9", "java runtime version not supported by OpenTelemetry SDK. Found: 17.0.10+9, supports: 17.0.11+8"}, | ||
{"jdk version not supported", common.JavaProgrammingLanguage, "17.0.11+7", "java runtime version not supported by OpenTelemetry SDK. Found: 17.0.11+7, supports: 17.0.11+8"}, | ||
{"go version not supported", common.GoProgrammingLanguage, "1.14", "go runtime version not supported by OpenTelemetry SDK. Found: 1.14, supports: 1.17.0"}, | ||
{"javascript version not supported", common.JavascriptProgrammingLanguage, "13.9.9", "javascript runtime version not supported by OpenTelemetry SDK. Found: 13.9.9, supports: 14.0.0"}, | ||
{"python version not supported", common.PythonProgrammingLanguage, "3.7", "python runtime version not supported by OpenTelemetry SDK. Found: 3.7, supports: 3.8.0"}, | ||
{"nginx version not supported", common.NginxProgrammingLanguage, "1.25.4", "nginx runtime version not supported by OpenTelemetry SDK. Found: 1.25.4, supports: 1.25.5, 1.26.0"}, | ||
{"nginx version not supported", common.NginxProgrammingLanguage, "1.26.1", "nginx runtime version not supported by OpenTelemetry SDK. Found: 1.26.1, supports: 1.25.5, 1.26.0"}, | ||
{"unknown language", common.UnknownProgrammingLanguage, "0.0.0", "Unsupported language: unknown"}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
t.Run(tc.name, func(t *testing.T) { | ||
|
||
runtimeDetails := []v1alpha1.RuntimeDetailsByContainer{ | ||
{Language: tc.language, RuntimeVersion: tc.version}, | ||
} | ||
|
||
supported, err := IsRuntimeVersionSupported(nil, runtimeDetails) | ||
assert.Equal(t, false, supported) | ||
assert.Error(t, err) | ||
assert.Equal(t, err.Error(), tc.errorMsg) | ||
}) | ||
} | ||
} | ||
|
||
func TestIsRuntimeVersionSupported_Support(t *testing.T) { | ||
testCases := []struct { | ||
name string | ||
language common.ProgrammingLanguage | ||
version string | ||
}{ | ||
{"java version not supported", common.JavaProgrammingLanguage, "17.0.11+9"}, | ||
{"go version not supported", common.GoProgrammingLanguage, "1.18"}, | ||
{"dotnet version not supported", common.DotNetProgrammingLanguage, "0.0.0"}, | ||
{"javascript version not supported", common.JavascriptProgrammingLanguage, "14.0.1"}, | ||
{"python version not supported", common.PythonProgrammingLanguage, "3.9"}, | ||
{"mySQL version not supported", common.MySQLProgrammingLanguage, "1.14.1"}, | ||
{"nginx version not supported", common.NginxProgrammingLanguage, "1.25.5"}, | ||
{"nginx version not supported", common.NginxProgrammingLanguage, "1.26"}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
|
||
t.Run(tc.name, func(t *testing.T) { | ||
|
||
runtimeDetails := []v1alpha1.RuntimeDetailsByContainer{ | ||
{Language: tc.language, RuntimeVersion: tc.version}, | ||
} | ||
|
||
supported, err := IsRuntimeVersionSupported(nil, runtimeDetails) | ||
assert.Equal(t, true, supported) | ||
assert.Nil(t, err) | ||
}) | ||
} | ||
} | ||
|
||
func TestIsRuntimeVersionSupported_MultiRuntimeContainer_NotSupport(t *testing.T) { | ||
testCases := []struct { | ||
name string | ||
language common.ProgrammingLanguage | ||
version string | ||
}{ | ||
{"java version not supported", common.JavaProgrammingLanguage, "17.0.11+9"}, | ||
{"go version not supported", common.GoProgrammingLanguage, "1.18"}, | ||
{"dotnet version not supported", common.DotNetProgrammingLanguage, "0.0.0"}, | ||
{"javascript version not supported", common.JavascriptProgrammingLanguage, "14.0.1"}, | ||
{"python version not supported", common.PythonProgrammingLanguage, "3.7"}, | ||
{"mySQL version not supported", common.MySQLProgrammingLanguage, "1.14.1"}, | ||
{"nginx version not supported", common.NginxProgrammingLanguage, "1.25.5"}, | ||
{"nginx version not supported", common.NginxProgrammingLanguage, "1.26"}, | ||
} | ||
|
||
runtimeDetails := []v1alpha1.RuntimeDetailsByContainer{} | ||
|
||
for _, tc := range testCases { | ||
runtimeDetails = append(runtimeDetails, v1alpha1.RuntimeDetailsByContainer{ | ||
Language: tc.language, | ||
RuntimeVersion: tc.version, | ||
}) | ||
} | ||
|
||
// Run the test for the combined runtimeDetails | ||
t.Run("multiple runtimes not supported", func(t *testing.T) { | ||
supported, err := IsRuntimeVersionSupported(nil, runtimeDetails) | ||
assert.Equal(t, false, supported) | ||
assert.Error(t, err) | ||
assert.Equal(t, err.Error(), "python runtime version not supported by OpenTelemetry SDK. Found: 3.7, supports: 3.8.0") | ||
}) | ||
} | ||
|
||
func TestIsRuntimeVersionSupported_MultiRuntimeContainer_Support(t *testing.T) { | ||
testCases := []struct { | ||
name string | ||
language common.ProgrammingLanguage | ||
version string | ||
}{ | ||
{"java version not supported", common.JavaProgrammingLanguage, "17.0.11+9"}, | ||
{"go version not supported", common.GoProgrammingLanguage, "1.18"}, | ||
{"dotnet version not supported", common.DotNetProgrammingLanguage, "0.0.0"}, | ||
{"javascript version not supported", common.JavascriptProgrammingLanguage, "14.0.1"}, | ||
{"python version not supported", common.PythonProgrammingLanguage, "3.9"}, | ||
{"mySQL version not supported", common.MySQLProgrammingLanguage, "1.14.1"}, | ||
{"nginx version not supported", common.NginxProgrammingLanguage, "1.25.5"}, | ||
{"nginx version not supported", common.NginxProgrammingLanguage, "1.26"}, | ||
} | ||
|
||
runtimeDetails := []v1alpha1.RuntimeDetailsByContainer{} | ||
|
||
for _, tc := range testCases { | ||
runtimeDetails = append(runtimeDetails, v1alpha1.RuntimeDetailsByContainer{ | ||
Language: tc.language, | ||
RuntimeVersion: tc.version, | ||
}) | ||
} | ||
|
||
// Run the test for the combined runtimeDetails | ||
t.Run("multiple runtimes not supported", func(t *testing.T) { | ||
supported, err := IsRuntimeVersionSupported(nil, runtimeDetails) | ||
assert.Equal(t, true, supported) | ||
assert.Nil(t, err) | ||
}) | ||
} | ||
|
||
func TestIsRuntimeVersionSupported_LanguageDoesNotExist_NotSupported(t *testing.T) { | ||
testCase := struct { | ||
name string | ||
language common.ProgrammingLanguage | ||
version string | ||
}{"ruby language is not supported", "ruby", "17.0.10+9"} | ||
|
||
t.Run(testCase.name, func(t *testing.T) { | ||
|
||
runtimeDetails := []v1alpha1.RuntimeDetailsByContainer{ | ||
{Language: testCase.language, RuntimeVersion: testCase.version}, | ||
} | ||
|
||
supported, err := IsRuntimeVersionSupported(nil, runtimeDetails) | ||
assert.Equal(t, false, supported) | ||
assert.Error(t, err) | ||
assert.Equal(t, err.Error(), "Unsupported language: ruby") | ||
}) | ||
} | ||
|
||
func TestIsRuntimeVersionSupported_VersionNotFound_Supported(t *testing.T) { | ||
testCase := struct { | ||
name string | ||
language common.ProgrammingLanguage | ||
version string | ||
}{"java version not supported", common.JavaProgrammingLanguage, ""} | ||
|
||
t.Run(testCase.name, func(t *testing.T) { | ||
|
||
runtimeDetails := []v1alpha1.RuntimeDetailsByContainer{ | ||
{Language: testCase.language, RuntimeVersion: testCase.version}, | ||
} | ||
|
||
supported, err := IsRuntimeVersionSupported(nil, runtimeDetails) | ||
assert.Equal(t, true, supported) | ||
assert.Nil(t, err) | ||
}) | ||
} |
13 changes: 13 additions & 0 deletions
13
instrumentor/controllers/utils/versionsupport/mysql_support.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package versionsupport | ||
|
||
import "github.com/hashicorp/go-version" | ||
|
||
type MySQLVersionCheck struct{} | ||
|
||
func (g MySQLVersionCheck) IsVersionSupported(version *version.Version) bool { | ||
return true | ||
} | ||
|
||
func (g MySQLVersionCheck) GetSupportedVersion() string { | ||
return "0.0.0" | ||
} |
Oops, something went wrong.