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

chore: improvments to how schedualer uses profiles #2201

Merged
merged 4 commits into from
Jan 13, 2025
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
3 changes: 2 additions & 1 deletion cli/cmd/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/odigos-io/odigos/cli/pkg/autodetect"
"github.com/odigos-io/odigos/common/consts"
"github.com/odigos-io/odigos/profiles"

"github.com/odigos-io/odigos/cli/pkg/labels"

Expand Down Expand Up @@ -186,7 +187,7 @@ func createNamespace(ctx context.Context, cmd *cobra.Command, client *kube.Clien

func validateUserInputProfiles(tier common.OdigosTier) {
// Fetch available profiles for the given tier
availableProfiles := resources.GetAvailableProfilesForTier(tier)
availableProfiles := profiles.GetAvailableProfilesForTier(tier)

// Create a map for fast lookups of valid profile names
profileMap := make(map[string]struct{})
Expand Down
5 changes: 3 additions & 2 deletions cli/cmd/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
cmdcontext "github.com/odigos-io/odigos/cli/pkg/cmd_context"
"github.com/odigos-io/odigos/common"
"github.com/odigos-io/odigos/k8sutils/pkg/getters"
"github.com/odigos-io/odigos/profiles"
"github.com/odigos-io/odigos/profiles/profile"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -44,7 +45,7 @@ var profileCmd = &cobra.Command{

if availableFlag {
fmt.Println("Listing available profiles for", currentTier, "tier:")
profiles := resources.GetAvailableProfilesForTier(currentTier)
profiles := profiles.GetAvailableProfilesForTier(currentTier)
if len(profiles) == 0 {
fmt.Println("No profiles are available for the current tier")
os.Exit(0)
Expand Down Expand Up @@ -102,7 +103,7 @@ var addProfileCmd = &cobra.Command{
}

// Fetch the available profiles for the current tier
profiles := resources.GetAvailableProfilesForTier(currentTier)
profiles := profiles.GetAvailableProfilesForTier(currentTier)
var selectedProfile *profile.Profile

// Search for the specified profile in the available profiles
Expand Down
5 changes: 2 additions & 3 deletions cli/cmd/resources/instrumentor.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"github.com/odigos-io/odigos/common/consts"

k8sconsts "github.com/odigos-io/odigos/k8sutils/pkg/consts"
k8sutilsconsts "github.com/odigos-io/odigos/k8sutils/pkg/consts"
admissionregistrationv1 "k8s.io/api/admissionregistration/v1"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -291,7 +290,7 @@ func NewMutatingWebhookConfiguration(ns string, caBundle []byte) *admissionregis
TimeoutSeconds: intPtr(10),
ObjectSelector: &metav1.LabelSelector{
MatchLabels: map[string]string{
k8sutilsconsts.OdigosInjectInstrumentationLabel: "true",
k8sconsts.OdigosInjectInstrumentationLabel: "true",
},
},
AdmissionReviewVersions: []string{
Expand Down Expand Up @@ -406,7 +405,7 @@ func NewInstrumentorDeployment(ns string, version string, telemetryEnabled bool,
ValueFrom: &corev1.EnvVarSource{
ConfigMapKeyRef: &corev1.ConfigMapKeySelector{
LocalObjectReference: corev1.LocalObjectReference{
Name: k8sutilsconsts.OdigosDeploymentConfigMapName,
Name: k8sconsts.OdigosDeploymentConfigMapName,
},
Key: k8sconsts.OdigosDeploymentConfigMapTierKey,
},
Expand Down
13 changes: 1 addition & 12 deletions cli/cmd/resources/profiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
)

func GetResourcesForProfileName(profileName common.ProfileName, tier common.OdigosTier) ([]profile.K8sObject, error) {
allAvailableProfiles := GetAvailableProfilesForTier(tier)
allAvailableProfiles := profiles.GetAvailableProfilesForTier(tier)
for _, p := range allAvailableProfiles {
if p.ProfileName == common.ProfileName(profileName) {
if p.KubeObject != nil {
Expand All @@ -38,17 +38,6 @@ func GetResourcesForProfileName(profileName common.ProfileName, tier common.Odig
return nil, nil
}

func GetAvailableProfilesForTier(odigosTier common.OdigosTier) []profile.Profile {
switch odigosTier {
case common.CommunityOdigosTier:
return profiles.CommunityProfiles
case common.OnPremOdigosTier:
return profiles.OnPremProfiles
default:
return []profile.Profile{}
}
}

type profilesResourceManager struct {
client *kube.Client
ns string
Expand Down
12 changes: 12 additions & 0 deletions cli/cmd/resources/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/odigos-io/odigos/cli/pkg/kube"
"github.com/odigos-io/odigos/common"
"github.com/odigos-io/odigos/common/consts"
k8sconsts "github.com/odigos-io/odigos/k8sutils/pkg/consts"

appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -230,6 +231,17 @@ func NewSchedulerDeployment(ns string, version string, imagePrefix string) *apps
},
},
},
{
Name: consts.OdigosTierEnvVarName,
ValueFrom: &corev1.EnvVarSource{
ConfigMapKeyRef: &corev1.ConfigMapKeySelector{
LocalObjectReference: corev1.LocalObjectReference{
Name: k8sconsts.OdigosDeploymentConfigMapName,
},
Key: k8sconsts.OdigosDeploymentConfigMapTierKey,
},
},
},
},
EnvFrom: []corev1.EnvFromSource{
{
Expand Down
5 changes: 5 additions & 0 deletions helm/odigos/templates/scheduler/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ spec:
valueFrom:
fieldRef:
fieldPath: metadata.namespace
- name: ODIGOS_TIER
valueFrom:
configMapKeyRef:
key: ODIGOS_TIER
name: odigos-deployment
envFrom:
- configMapRef:
name: odigos-own-telemetry-otel-config
Expand Down
2 changes: 1 addition & 1 deletion profiles/aggregators/kratos.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ var KratosProfile = profile.Profile{
ProfileName: common.ProfileName("kratos"),
MinimumTier: common.OdigosTier(common.OnPremOdigosTier),
ShortDescription: "Bundle profile that includes db-payload-collection, semconv, category-attributes, copy-scope, hostname-as-podname, code-attributes, query-operation-detector, disableNameProcessorProfile, small-batches, size_m, allow_concurrent_agents",
Dependencies: []common.ProfileName{"db-payload-collection", "semconv", "category-attributes", "copy-scope", "hostname-as-podname", "code-attributes", "query-operation-detector", "disableNameProcessorProfile", "small-batches", "size_m", "allow_concurrent_agents"},
Dependencies: []common.ProfileName{"db-payload-collection", "semconv", "category-attributes", "copy-scope", "hostname-as-podname", "code-attributes", "query-operation-detector", "disable-name-processor", "small-batches", "size_m", "allow_concurrent_agents"},
}
11 changes: 11 additions & 0 deletions profiles/allprofiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,14 @@ func init() {
}
}
}

func GetAvailableProfilesForTier(odigosTier common.OdigosTier) []profile.Profile {
switch odigosTier {
case common.CommunityOdigosTier:
return CommunityProfiles
case common.OnPremOdigosTier:
return OnPremProfiles
default:
return []profile.Profile{}
}
}
4 changes: 3 additions & 1 deletion scheduler/controllers/odigosconfig/manager.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package odigosconfig

import (
"github.com/odigos-io/odigos/common"
odigospredicates "github.com/odigos-io/odigos/k8sutils/pkg/predicate"
corev1 "k8s.io/api/core/v1"
ctrl "sigs.k8s.io/controller-runtime"
)

func SetupWithManager(mgr ctrl.Manager) error {
func SetupWithManager(mgr ctrl.Manager, tier common.OdigosTier) error {

err := ctrl.NewControllerManagedBy(mgr).
For(&corev1.ConfigMap{}).
Expand All @@ -15,6 +16,7 @@ func SetupWithManager(mgr ctrl.Manager) error {
Complete(&odigosConfigController{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
Tier: tier,
})
if err != nil {
return err
Expand Down
54 changes: 41 additions & 13 deletions scheduler/controllers/odigosconfig/odigosconfig_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
k8sconsts "github.com/odigos-io/odigos/k8sutils/pkg/consts"
"github.com/odigos-io/odigos/k8sutils/pkg/env"
"github.com/odigos-io/odigos/profiles"
"github.com/odigos-io/odigos/profiles/profile"
"github.com/odigos-io/odigos/profiles/sizing"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand All @@ -21,6 +22,7 @@ import (
type odigosConfigController struct {
client.Client
Scheme *runtime.Scheme
Tier common.OdigosTier
}

func (r *odigosConfigController) Reconcile(ctx context.Context, _ ctrl.Request) (ctrl.Result, error) {
Expand All @@ -37,7 +39,11 @@ func (r *odigosConfigController) Reconcile(ctx context.Context, _ ctrl.Request)
// make sure the default ignored containers are always present
odigosConfig.IgnoredContainers = mergeIgnoredItemLists(odigosConfig.IgnoredContainers, k8sconsts.DefaultIgnoredContainers)

applyProfilesToOdigosConfig(odigosConfig)
// effective profiles are what is actually used in the cluster
availableProfiles := profiles.GetAvailableProfilesForTier(r.Tier)
effectiveProfiles := calculateEffectiveProfiles(odigosConfig.Profiles, availableProfiles)
odigosConfig.Profiles = effectiveProfiles
modifyConfigWithEffectiveProfiles(effectiveProfiles, odigosConfig)

// if none of the profiles set sizing for collectors, use size_s as default, so the values are never nil
// if the values were already set (by user or profile) this is a no-op
Expand Down Expand Up @@ -111,23 +117,45 @@ func (r *odigosConfigController) persistEffectiveConfig(ctx context.Context, eff
return nil
}

func applySingleProfile(profile common.ProfileName, odigosConfig *common.OdigosConfiguration) {
profileConfig, found := profiles.ProfilesByName[profile]
if !found {
return
func modifyConfigWithEffectiveProfiles(effectiveProfiles []common.ProfileName, odigosConfig *common.OdigosConfiguration) {
for _, profileName := range effectiveProfiles {
p := profiles.ProfilesByName[profileName]
if p.ModifyConfigFunc != nil {
p.ModifyConfigFunc(odigosConfig)
}
}
}

if profileConfig.ModifyConfigFunc != nil {
profileConfig.ModifyConfigFunc(odigosConfig)
}
// from the list of input profiles, calculate the effective profiles:
// - check the dependencies of each profile and add them to the list
// - remove profiles which are not present in the profiles list
func calculateEffectiveProfiles(configProfiles []common.ProfileName, availableProfiles []profile.Profile) []common.ProfileName {

effectiveProfiles := []common.ProfileName{}
for _, profileName := range configProfiles {

// ignored missing profiles (either not available for tier or typos)
p, found := findProfileNameInAvailableList(profileName, availableProfiles)
if !found {
continue
}

effectiveProfiles = append(effectiveProfiles, profileName)

for _, dependency := range profileConfig.Dependencies {
applySingleProfile(dependency, odigosConfig)
// if this profile has dependencies, add them to the list
if p.Dependencies != nil {
effectiveProfiles = append(effectiveProfiles, calculateEffectiveProfiles(p.Dependencies, availableProfiles)...)
}
}
return effectiveProfiles
}

func applyProfilesToOdigosConfig(odigosConfig *common.OdigosConfiguration) {
for _, profile := range odigosConfig.Profiles {
applySingleProfile(profile, odigosConfig)
func findProfileNameInAvailableList(profileName common.ProfileName, availableProfiles []profile.Profile) (profile.Profile, bool) {
// there aren't many profiles, so a linear search is fine
for _, p := range availableProfiles {
if p.ProfileName == profileName {
return p, true
}
}
return profile.Profile{}, false
}
3 changes: 2 additions & 1 deletion scheduler/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ func main() {
logger := zapr.NewLogger(zapLogger)
ctrl.SetLogger(logger)

tier := env.GetOdigosTierFromEnv()
odigosNs := env.GetCurrentNamespace()
nsSelector := client.InNamespace(odigosNs).AsSelector()

Expand Down Expand Up @@ -118,7 +119,7 @@ func main() {
setupLog.Error(err, "unable to create controllers for node collectors group")
os.Exit(1)
}
err = odigosconfig.SetupWithManager(mgr)
err = odigosconfig.SetupWithManager(mgr, tier)
if err != nil {
setupLog.Error(err, "unable to create controllers for odigos config")
os.Exit(1)
Expand Down
Loading