Skip to content

Commit

Permalink
feat: set gateway sizing using profile + add sizing m to kratos
Browse files Browse the repository at this point in the history
  • Loading branch information
tamirdavid1 committed Dec 2, 2024
1 parent d7d3fd7 commit 8574da3
Show file tree
Hide file tree
Showing 5 changed files with 159 additions and 12 deletions.
23 changes: 17 additions & 6 deletions cli/cmd/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ import (

apierrors "k8s.io/apimachinery/pkg/api/errors"

"github.com/odigos-io/odigos/cli/cmd/resources"
"github.com/odigos-io/odigos/cli/cmd/resources/size"
cmdcontext "github.com/odigos-io/odigos/cli/pkg/cmd_context"
"github.com/odigos-io/odigos/cli/pkg/kube"
"github.com/odigos-io/odigos/cli/pkg/log"
"github.com/odigos-io/odigos/common"
"github.com/odigos-io/odigos/common/consts"
"github.com/odigos-io/odigos/common/utils"
k8sconsts "github.com/odigos-io/odigos/k8sutils/pkg/consts"

"github.com/odigos-io/odigos/cli/cmd/resources"
"github.com/odigos-io/odigos/cli/pkg/kube"
"github.com/odigos-io/odigos/cli/pkg/log"
cmdcontext "github.com/odigos-io/odigos/cli/pkg/cmd_context"

"github.com/spf13/cobra"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -203,7 +203,7 @@ func createOdigosConfig(odigosTier common.OdigosTier) common.OdigosConfiguration
}
}

return common.OdigosConfiguration{
odigosConfig := common.OdigosConfiguration{
ConfigVersion: 1, // config version starts at 1 and incremented on every config change
TelemetryEnabled: telemetryEnabled,
OpenshiftEnabled: openshiftEnabled,
Expand All @@ -216,6 +216,17 @@ func createOdigosConfig(odigosTier common.OdigosTier) common.OdigosConfiguration
AutoscalerImage: autoScalerImage,
Profiles: selectedProfiles,
}

// Set sizing profile if selected [by a profile or it's dependencies]
sizingProfile := size.FilterSizeProfiles(selectedProfiles)
if sizingProfile != "" {
size := size.GetGatewayConfigBasedOnSize(sizingProfile)
if size != nil {
odigosConfig.CollectorGateway = size
}
}

return odigosConfig
}

func createKubeResourceWithLogging(ctx context.Context, msg string, client *kube.Client, cmd *cobra.Command, ns string, create ResourceCreationFunc) {
Expand Down
11 changes: 11 additions & 0 deletions cli/cmd/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/odigos-io/odigos/cli/cmd/resources"
"github.com/odigos-io/odigos/cli/cmd/resources/odigospro"
"github.com/odigos-io/odigos/cli/cmd/resources/size"
cmdcontext "github.com/odigos-io/odigos/cli/pkg/cmd_context"
"github.com/odigos-io/odigos/common"
"github.com/odigos-io/odigos/k8sutils/pkg/getters"
Expand Down Expand Up @@ -135,6 +136,12 @@ var addProfileCmd = &cobra.Command{
// Add the profile to the current configuration
config.Profiles = append(config.Profiles, selectedProfile.ProfileName)

// Update the sizing configuration if the profile has a sizing configuration
gatewaySizing := size.GetGatewayConfigBasedOnSize(selectedProfile.ProfileName)
if gatewaySizing != nil {
config.CollectorGateway = gatewaySizing
}

// Apply the updated configuration
resourceManagers := resources.CreateResourceManagers(client, ns, currentTier, nil, config, currentOdigosVersion)
err = resources.ApplyResourceManagers(ctx, client, resourceManagers, "Updating")
Expand Down Expand Up @@ -209,6 +216,10 @@ var removeProfileCmd = &cobra.Command{

config.Profiles = newProfiles

// Removing the profile config from the sizing configuration
gatewaySizing := size.GetGatewayConfigBasedOnSize(common.ProfileName(profileName))
size.RemoveSizingProfileAddedValues(config.CollectorGateway, gatewaySizing)

// Apply the updated configuration
resourceManagers := resources.CreateResourceManagers(client, ns, currentTier, nil, config, currentOdigosVersion)
err = resources.ApplyResourceManagers(ctx, client, resourceManagers, "Updating")
Expand Down
4 changes: 2 additions & 2 deletions cli/cmd/resources/odigosconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@ package resources

import (
"context"
"encoding/json"

"github.com/odigos-io/odigos/cli/cmd/resources/resourcemanager"
"github.com/odigos-io/odigos/cli/pkg/kube"
"github.com/odigos-io/odigos/common"
"github.com/odigos-io/odigos/common/consts"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/yaml"
)

func NewOdigosConfiguration(ns string, config *common.OdigosConfiguration) (kube.Object, error) {
data, err := json.Marshal(config)
data, err := yaml.Marshal(config)
if err != nil {
return nil, err
}
Expand Down
41 changes: 37 additions & 4 deletions cli/cmd/resources/profiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,19 @@ type Profile struct {
}

var (
// sizing profiles for the collector gateway
sizeSProfile = Profile{
ProfileName: common.ProfileName("size_s"),
ShortDescription: "Small size deployment profile",
}
sizeMProfile = Profile{
ProfileName: common.ProfileName("size_m"),
ShortDescription: "Small size deployment profile",
}
sizeLProfile = Profile{
ProfileName: common.ProfileName("size_l"),
ShortDescription: "Small size deployment profile",
}
fullPayloadCollectionProfile = Profile{
ProfileName: common.ProfileName("full-payload-collection"),
ShortDescription: "Collect any payload from the cluster where supported with default settings",
Expand Down Expand Up @@ -75,17 +88,37 @@ var (
}
kratosProfile = Profile{
ProfileName: common.ProfileName("kratos"),
ShortDescription: "Bundle profile that includes db-payload-collection, semconv, category-attributes, copy-scope, hostname-as-podname, java-native-instrumentations, code-attributes, query-operation-detector",
Dependencies: []common.ProfileName{"db-payload-collection", "semconv", "category-attributes", "copy-scope", "hostname-as-podname", "java-native-instrumentations", "code-attributes", "query-operation-detector", "disableNameProcessorProfile", "small-batches"},
ShortDescription: "Bundle profile that includes db-payload-collection, semconv, category-attributes, copy-scope, hostname-as-podname, java-native-instrumentations, code-attributes, query-operation-detector, disableNameProcessorProfile, small-batches, size_m",
Dependencies: []common.ProfileName{"db-payload-collection", "semconv", "category-attributes", "copy-scope", "hostname-as-podname", "java-native-instrumentations", "code-attributes", "query-operation-detector", "disableNameProcessorProfile", "small-batches", "size_m"},
}
ProfilesMap = map[common.ProfileName]Profile{
sizeSProfile.ProfileName: sizeSProfile,
sizeMProfile.ProfileName: sizeMProfile,
sizeLProfile.ProfileName: sizeLProfile,
fullPayloadCollectionProfile.ProfileName: fullPayloadCollectionProfile,
dbPayloadCollectionProfile.ProfileName: dbPayloadCollectionProfile,
queryOperationDetector.ProfileName: queryOperationDetector,
semconvUpgraderProfile.ProfileName: semconvUpgraderProfile,
categoryAttributesProfile.ProfileName: categoryAttributesProfile,
copyScopeProfile.ProfileName: copyScopeProfile,
hostnameAsPodNameProfile.ProfileName: hostnameAsPodNameProfile,
javaNativeInstrumentationsProfile.ProfileName: javaNativeInstrumentationsProfile,
codeAttributesProfile.ProfileName: codeAttributesProfile,
disableNameProcessorProfile.ProfileName: disableNameProcessorProfile,
smallBatchesProfile.ProfileName: smallBatchesProfile,
kratosProfile.ProfileName: kratosProfile,
}
)

func GetAvailableCommunityProfiles() []Profile {
return []Profile{semconvUpgraderProfile, copyScopeProfile, disableNameProcessorProfile}
return []Profile{semconvUpgraderProfile, copyScopeProfile, disableNameProcessorProfile, sizeSProfile, sizeMProfile,
sizeLProfile}
}

func GetAvailableOnPremProfiles() []Profile {
return append([]Profile{fullPayloadCollectionProfile, dbPayloadCollectionProfile, categoryAttributesProfile, hostnameAsPodNameProfile, javaNativeInstrumentationsProfile, kratosProfile, queryOperationDetector, smallBatchesProfile},
return append([]Profile{fullPayloadCollectionProfile, dbPayloadCollectionProfile, categoryAttributesProfile,
hostnameAsPodNameProfile, javaNativeInstrumentationsProfile, kratosProfile, queryOperationDetector,
smallBatchesProfile, sizeSProfile, sizeMProfile, sizeLProfile},
GetAvailableCommunityProfiles()...)
}

Expand Down
92 changes: 92 additions & 0 deletions cli/cmd/resources/size/gateway_size.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package size

import (
"reflect"

"github.com/odigos-io/odigos/cli/cmd/resources"
"github.com/odigos-io/odigos/common"
)

const (
SizeS common.ProfileName = "size_s"
SizeM common.ProfileName = "size_m"
SizeL common.ProfileName = "size_l"
)

func GetGatewayConfigBasedOnSize(profile common.ProfileName) *common.CollectorGatewayConfiguration {

AggregateProfiles := append([]common.ProfileName{profile}, resources.ProfilesMap[profile].Dependencies...)

for _, profile := range AggregateProfiles {
switch profile {
case SizeS:
return &common.CollectorGatewayConfiguration{
MinReplicas: 1,
MaxReplicas: 5,
RequestCPUm: 150,
LimitCPUm: 300,
RequestMemoryMiB: 300,
}
case SizeM:
return &common.CollectorGatewayConfiguration{
MinReplicas: 2,
MaxReplicas: 8,
RequestCPUm: 500,
LimitCPUm: 1000,
RequestMemoryMiB: 500,
}
case SizeL:
return &common.CollectorGatewayConfiguration{
MinReplicas: 3,
MaxReplicas: 12,
RequestCPUm: 750,
LimitCPUm: 1250,
RequestMemoryMiB: 750,
}
}
}
// Return nil if no matching profile is found.
return nil
}

func RemoveSizingProfileAddedValues(target, source *common.CollectorGatewayConfiguration) {
if target == nil || source == nil {
return
}

// Use reflection to iterate over the fields of CollectorGatewayConfiguration.
tVal := reflect.ValueOf(target).Elem()
sVal := reflect.ValueOf(source).Elem()

tType := tVal.Type()
for i := 0; i < tVal.NumField(); i++ {
tField := tVal.Field(i)
sField := sVal.Field(i)

// Compare fields, and if they match, set the target field to its zero value.
if tField.CanSet() && reflect.DeepEqual(tField.Interface(), sField.Interface()) {
tField.Set(reflect.Zero(tType.Field(i).Type))
}
}
}

func FilterSizeProfiles(profiles []common.ProfileName) common.ProfileName {
for _, profile := range profiles {

// Check if the profile is a size profile.
switch profile {
case SizeS, SizeM, SizeL:
return profile
}

// Check if the profile has a dependency which is a size profile.
profileDependencies := resources.ProfilesMap[profile].Dependencies
for _, dependencyProfile := range profileDependencies {
switch dependencyProfile {
case SizeS, SizeM, SizeL:
return dependencyProfile
}
}
}
return ""
}

0 comments on commit 8574da3

Please sign in to comment.