Skip to content

Commit

Permalink
chore: reconcile profiles in schedualer (#2210)
Browse files Browse the repository at this point in the history
Instead of only calculating them in cli.

This PR makes it so that profiles can be added by helm, ui, gitOps.
anything that will end up updating the profiles list in `odigos-config`
will cause profiles to update in the cluster and get applied (unlike
today where only cli is supported)
  • Loading branch information
blumamir authored Jan 14, 2025
1 parent 4f63807 commit 7b7115e
Show file tree
Hide file tree
Showing 22 changed files with 262 additions and 400 deletions.
20 changes: 5 additions & 15 deletions cli/cmd/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cmd
import (
"fmt"
"os"
"slices"

"github.com/odigos-io/odigos/cli/cmd/resources"
"github.com/odigos-io/odigos/cli/cmd/resources/odigospro"
Expand Down Expand Up @@ -102,17 +103,8 @@ var addProfileCmd = &cobra.Command{
os.Exit(1)
}

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

// Search for the specified profile in the available profiles
for _, profile := range profiles {
if string(profile.ProfileName) == profileName {
selectedProfile = &profile
break
}
}
selectedProfile := profile.FindProfileByName(common.ProfileName(profileName), profiles)

if selectedProfile == nil {
fmt.Printf("\033[31mERROR\033[0m Profile '%s' not available.\n", profileName)
Expand All @@ -127,11 +119,9 @@ var addProfileCmd = &cobra.Command{
config.ConfigVersion += 1

// Check if the profile is already applied
for _, appliedProfile := range config.Profiles {
if string(appliedProfile) == profileName {
fmt.Println("\033[34mINFO\033[0m Profile", profileName, "is already applied.")
os.Exit(0)
}
if slices.Contains(config.Profiles, selectedProfile.ProfileName) {
fmt.Println("\033[34mINFO\033[0m Profile", profileName, "is already applied.")
os.Exit(0)
}

// Add the profile to the current configuration
Expand Down
1 change: 0 additions & 1 deletion cli/cmd/resources/managers.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ func CreateResourceManagers(client *kube.Client, odigosNs string, odigosTier com
NewOdigletResourceManager(client, odigosNs, config, odigosTier, odigosVersion),
NewAutoScalerResourceManager(client, odigosNs, config, odigosVersion),
NewUIResourceManager(client, odigosNs, config, odigosVersion),
NewProfilesResourceManager(client, odigosNs, config, odigosTier),
}...)

if odigosTier == common.CloudOdigosTier {
Expand Down
67 changes: 0 additions & 67 deletions cli/cmd/resources/profiles.go

This file was deleted.

16 changes: 16 additions & 0 deletions cli/cmd/resources/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@ func NewSchedulerRole(ns string) *rbacv1.Role {
Resources: []string{"destinations"},
Verbs: []string{"get", "list", "watch"},
},
{ // apply profiles
APIGroups: []string{"odigos.io"},
Resources: []string{"processors", "instrumentationrules"},
Verbs: []string{"get", "list", "watch", "patch", "delete", "create"},
},
},
}
}
Expand Down Expand Up @@ -242,6 +247,17 @@ func NewSchedulerDeployment(ns string, version string, imagePrefix string) *apps
},
},
},
{
Name: consts.OdigosVersionEnvVarName,
ValueFrom: &corev1.EnvVarSource{
ConfigMapKeyRef: &corev1.ConfigMapKeySelector{
LocalObjectReference: corev1.LocalObjectReference{
Name: k8sconsts.OdigosDeploymentConfigMapName,
},
Key: k8sconsts.OdigosDeploymentConfigMapVersionKey,
},
},
},
},
EnvFrom: []corev1.EnvFromSource{
{
Expand Down
12 changes: 12 additions & 0 deletions helm/odigos/templates/scheduler/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,15 @@ rules:
- get
- list
- watch
- apiGroups:
- odigos.io
resources:
- instrumentationrules
- processors
verbs:
- get
- list
- watch
- patch
- delete
- create
9 changes: 9 additions & 0 deletions k8sutils/pkg/consts/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@ const (
OdigosInjectInstrumentationLabel = "odigos.io/inject-instrumentation"
// OdigosCollectorRoleLabel is the label used to identify the role of the Odigos collector.
OdigosCollectorRoleLabel = "odigos.io/collector-role"

// used to label resources created by profiles with the hash that created them.
// when a new profiles is reconciled, we will apply them with a new hash
// and use the label to identify the resources that needs to be deleted.
OdigosProfilesHashLabel = "odigos.io/profiles-hash"

// for resources auto created by a profile, this annotation will record
// the name of the profile that created them.
OdigosProfileAnnotation = "odigos.io/profile"
)

const (
Expand Down
2 changes: 0 additions & 2 deletions profiles/attributes/categoryattributes.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package attributes

import (
odigosv1alpha1 "github.com/odigos-io/odigos/api/odigos/v1alpha1"
"github.com/odigos-io/odigos/common"
"github.com/odigos-io/odigos/profiles/profile"
)
Expand All @@ -10,5 +9,4 @@ var CategoryAttributesProfile = profile.Profile{
ProfileName: common.ProfileName("category-attributes"),
MinimumTier: common.OdigosTier(common.OnPremOdigosTier),
ShortDescription: "Add category attributes to the spans",
KubeObject: &odigosv1alpha1.Processor{},
}
2 changes: 0 additions & 2 deletions profiles/attributes/copyscope.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package attributes

import (
odigosv1alpha1 "github.com/odigos-io/odigos/api/odigos/v1alpha1"
"github.com/odigos-io/odigos/common"
"github.com/odigos-io/odigos/profiles/profile"
)
Expand All @@ -10,5 +9,4 @@ var CopyScopeProfile = profile.Profile{
ProfileName: common.ProfileName("copy-scope"),
MinimumTier: common.OdigosTier(common.CommunityOdigosTier),
ShortDescription: "Copy the scope name into a separate attribute for backends that do not support scopes",
KubeObject: &odigosv1alpha1.Processor{},
}
2 changes: 0 additions & 2 deletions profiles/attributes/hostnameaspodname.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package attributes

import (
odigosv1alpha1 "github.com/odigos-io/odigos/api/odigos/v1alpha1"
"github.com/odigos-io/odigos/common"
"github.com/odigos-io/odigos/profiles/profile"
)
Expand All @@ -10,5 +9,4 @@ var HostnameAsPodNameProfile = profile.Profile{
ProfileName: common.ProfileName("hostname-as-podname"),
MinimumTier: common.OdigosTier(common.OnPremOdigosTier),
ShortDescription: "Populate the spans resource `host.name` attribute with value of `k8s.pod.name`",
KubeObject: &odigosv1alpha1.Processor{},
}
3 changes: 0 additions & 3 deletions profiles/attributes/payloadcollection.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package attributes

import (
odigosv1alpha1 "github.com/odigos-io/odigos/api/odigos/v1alpha1"
"github.com/odigos-io/odigos/common"
"github.com/odigos-io/odigos/profiles/profile"
)
Expand All @@ -10,12 +9,10 @@ var FullPayloadCollectionProfile = profile.Profile{
ProfileName: common.ProfileName("full-payload-collection"),
MinimumTier: common.OdigosTier(common.OnPremOdigosTier),
ShortDescription: "Collect any payload from the cluster where supported with default settings",
KubeObject: &odigosv1alpha1.InstrumentationRule{},
}

var DbPayloadCollectionProfile = profile.Profile{
ProfileName: common.ProfileName("db-payload-collection"),
MinimumTier: common.OdigosTier(common.OnPremOdigosTier),
ShortDescription: "Collect db payload from the cluster where supported with default settings",
KubeObject: &odigosv1alpha1.InstrumentationRule{},
}
2 changes: 0 additions & 2 deletions profiles/attributes/queryoperationdetector.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package attributes

import (
odigosv1alpha1 "github.com/odigos-io/odigos/api/odigos/v1alpha1"
"github.com/odigos-io/odigos/common"
"github.com/odigos-io/odigos/profiles/profile"
)
Expand All @@ -10,5 +9,4 @@ var QueryOperationDetector = profile.Profile{
ProfileName: common.ProfileName("query-operation-detector"),
MinimumTier: common.OdigosTier(common.OnPremOdigosTier),
ShortDescription: "Detect the SQL operation name from the query text",
KubeObject: &odigosv1alpha1.Processor{},
}
2 changes: 0 additions & 2 deletions profiles/attributes/semconvupgrader.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package attributes

import (
odigosv1alpha1 "github.com/odigos-io/odigos/api/odigos/v1alpha1"
"github.com/odigos-io/odigos/common"
"github.com/odigos-io/odigos/profiles/profile"
)
Expand All @@ -10,5 +9,4 @@ var SemconvUpgraderProfile = profile.Profile{
ProfileName: common.ProfileName("semconv"),
MinimumTier: common.OdigosTier(common.CommunityOdigosTier),
ShortDescription: "Upgrade and align some attribute names to a newer version of the OpenTelemetry semantic conventions",
KubeObject: &odigosv1alpha1.Processor{},
}
51 changes: 2 additions & 49 deletions profiles/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,62 +2,15 @@ module github.com/odigos-io/odigos/profiles

go 1.23.0

require (
github.com/odigos-io/odigos/api v0.0.0
github.com/odigos-io/odigos/common v0.0.0
k8s.io/apimachinery v0.32.0
sigs.k8s.io/yaml v1.4.0
)
require github.com/odigos-io/odigos/common v0.0.0

require (
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/emicklei/go-restful/v3 v3.11.0 // indirect
github.com/evanphx/json-patch/v5 v5.9.0 // indirect
github.com/fatih/color v1.10.0 // indirect
github.com/fxamacker/cbor/v2 v2.7.0 // indirect
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-openapi/jsonpointer v0.21.0 // indirect
github.com/go-openapi/jsonreference v0.20.2 // indirect
github.com/go-openapi/swag v0.23.0 // indirect
github.com/goccy/go-yaml v1.11.3 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/gnostic-models v0.6.8 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/hashicorp/go-version v1.7.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-colorable v0.1.8 // indirect
github.com/mattn/go-isatty v0.0.12 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/odigos-io/odigos/k8sutils v0.0.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/x448/float16 v0.8.4 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
go.opentelemetry.io/otel v1.29.0 // indirect
go.opentelemetry.io/otel/trace v1.29.0 // indirect
golang.org/x/net v0.30.0 // indirect
golang.org/x/oauth2 v0.23.0 // indirect
golang.org/x/sys v0.26.0 // indirect
golang.org/x/term v0.25.0 // indirect
golang.org/x/text v0.19.0 // indirect
golang.org/x/time v0.7.0 // indirect
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
google.golang.org/protobuf v1.35.1 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/api v0.32.0 // indirect
k8s.io/client-go v0.32.0 // indirect
k8s.io/klog/v2 v2.130.1 // indirect
k8s.io/kube-openapi v0.0.0-20241105132330-32ad38e42d3f // indirect
k8s.io/utils v0.0.0-20241104100929-3ea5e8cea738 // indirect
sigs.k8s.io/controller-runtime v0.19.0 // indirect
sigs.k8s.io/json v0.0.0-20241010143419-9aa6b5e7a4b3 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.4.2 // indirect
)

replace (
Expand Down
Loading

0 comments on commit 7b7115e

Please sign in to comment.