Skip to content

Commit

Permalink
feat: add profile to control if name processor is used or not
Browse files Browse the repository at this point in the history
  • Loading branch information
blumamir committed Oct 22, 2024
1 parent 421987d commit 9ec5678
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 64 deletions.
11 changes: 5 additions & 6 deletions autoscaler/controllers/collectorsgroup_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"github.com/odigos-io/odigos/autoscaler/controllers/datacollection"
"github.com/odigos-io/odigos/autoscaler/controllers/gateway"

"github.com/odigos-io/odigos/common"
"sigs.k8s.io/controller-runtime/pkg/log"

"k8s.io/apimachinery/pkg/runtime"
Expand All @@ -34,10 +33,10 @@ import (
// CollectorsGroupReconciler reconciles a CollectorsGroup object
type CollectorsGroupReconciler struct {
client.Client
Scheme *runtime.Scheme
ImagePullSecrets []string
OdigosVersion string
OdigosTier common.OdigosTier
Scheme *runtime.Scheme
ImagePullSecrets []string
OdigosVersion string
DisableNameProcessor bool
}

//+kubebuilder:rbac:groups=odigos.io,namespace=odigos-system,resources=collectorsgroups,verbs=get;list;watch;create;update;patch;delete
Expand Down Expand Up @@ -67,7 +66,7 @@ func (r *CollectorsGroupReconciler) Reconcile(ctx context.Context, req ctrl.Requ
return ctrl.Result{}, err
}

err = datacollection.Sync(ctx, r.Client, r.Scheme, r.ImagePullSecrets, r.OdigosVersion, r.OdigosTier)
err = datacollection.Sync(ctx, r.Client, r.Scheme, r.ImagePullSecrets, r.OdigosVersion, r.DisableNameProcessor)
if err != nil {
return ctrl.Result{}, err
}
Expand Down
18 changes: 9 additions & 9 deletions autoscaler/controllers/datacollection/configmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (

func SyncConfigMap(apps *odigosv1.InstrumentedApplicationList, dests *odigosv1.DestinationList, allProcessors *odigosv1.ProcessorList,
datacollection *odigosv1.CollectorsGroup, ctx context.Context,
c client.Client, scheme *runtime.Scheme, tier common.OdigosTier) (string, error) {
c client.Client, scheme *runtime.Scheme, disableNameProcessor bool) (string, error) {
logger := log.FromContext(ctx)

processors := commonconf.FilterAndSortProcessorsByOrderHint(allProcessors, odigosv1.CollectorsGroupRoleNodeCollector)
Expand All @@ -38,7 +38,7 @@ func SyncConfigMap(apps *odigosv1.InstrumentedApplicationList, dests *odigosv1.D
SamplingExists := commonconf.FindFirstProcessorByType(allProcessors, "odigossampling")
setTracesLoadBalancer := SamplingExists != nil

desired, err := getDesiredConfigMap(apps, dests, processors, datacollection, scheme, setTracesLoadBalancer, tier)
desired, err := getDesiredConfigMap(apps, dests, processors, datacollection, scheme, setTracesLoadBalancer, disableNameProcessor)
if err != nil {
logger.Error(err, "failed to get desired config map")
return "", err
Expand Down Expand Up @@ -97,8 +97,8 @@ func createConfigMap(desired *v1.ConfigMap, ctx context.Context, c client.Client
}

func getDesiredConfigMap(apps *odigosv1.InstrumentedApplicationList, dests *odigosv1.DestinationList, processors []*odigosv1.Processor,
datacollection *odigosv1.CollectorsGroup, scheme *runtime.Scheme, setTracesLoadBalancer bool, tier common.OdigosTier) (*v1.ConfigMap, error) {
cmData, err := calculateConfigMapData(apps, dests, processors, setTracesLoadBalancer, tier)
datacollection *odigosv1.CollectorsGroup, scheme *runtime.Scheme, setTracesLoadBalancer bool, disableNameProcessor bool) (*v1.ConfigMap, error) {
cmData, err := calculateConfigMapData(apps, dests, processors, setTracesLoadBalancer, disableNameProcessor)
if err != nil {
return nil, err
}
Expand All @@ -125,7 +125,7 @@ func getDesiredConfigMap(apps *odigosv1.InstrumentedApplicationList, dests *odig
}

func calculateConfigMapData(apps *odigosv1.InstrumentedApplicationList, dests *odigosv1.DestinationList, processors []*odigosv1.Processor,
setTracesLoadBalancer bool, tier common.OdigosTier) (string, error) {
setTracesLoadBalancer bool, disableNameProcessor bool) (string, error) {

empty := struct{}{}

Expand All @@ -136,7 +136,7 @@ func calculateConfigMapData(apps *odigosv1.InstrumentedApplicationList, dests *o
}
}

if tier != common.OnPremOdigosTier {
if !disableNameProcessor {
processorsCfg["odigosresourcename"] = empty
}

Expand Down Expand Up @@ -277,7 +277,7 @@ func calculateConfigMapData(apps *odigosv1.InstrumentedApplicationList, dests *o
}
}

commonProcessors := getCommonProcessorsByTier(tier)
commonProcessors := getCommonProcessors(disableNameProcessor)

if collectLogs {
includes := make([]string, 0)
Expand Down Expand Up @@ -402,9 +402,9 @@ func getSignalsFromOtelcolConfig(otelcolConfigContent string) ([]common.Observab
return signals, nil
}

func getCommonProcessorsByTier(tier common.OdigosTier) []string {
func getCommonProcessors(disableNameProcessor bool) []string {
processors := []string{"batch"}
if tier != common.OnPremOdigosTier {
if !disableNameProcessor {
processors = append(processors, "odigosresourcename")
}
processors = append(processors, "resource", "resourcedetection", "odigostrafficmetrics")
Expand Down
9 changes: 4 additions & 5 deletions autoscaler/controllers/datacollection/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"time"

odigosv1 "github.com/odigos-io/odigos/api/odigos/v1alpha1"
"github.com/odigos-io/odigos/common"
"github.com/odigos-io/odigos/k8sutils/pkg/consts"
"github.com/odigos-io/odigos/k8sutils/pkg/env"
"k8s.io/apimachinery/pkg/runtime"
Expand All @@ -19,7 +18,7 @@ const (
syncDaemonsetRetry = 3
)

func Sync(ctx context.Context, c client.Client, scheme *runtime.Scheme, imagePullSecrets []string, odigosVersion string, tier common.OdigosTier) error {
func Sync(ctx context.Context, c client.Client, scheme *runtime.Scheme, imagePullSecrets []string, odigosVersion string, disableNameProcessor bool) error {
logger := log.FromContext(ctx)

var instApps odigosv1.InstrumentedApplicationList
Expand Down Expand Up @@ -52,16 +51,16 @@ func Sync(ctx context.Context, c client.Client, scheme *runtime.Scheme, imagePul
return err
}

return syncDataCollection(&instApps, &dests, &processors, &dataCollectionCollectorGroup, ctx, c, scheme, imagePullSecrets, odigosVersion, tier)
return syncDataCollection(&instApps, &dests, &processors, &dataCollectionCollectorGroup, ctx, c, scheme, imagePullSecrets, odigosVersion, disableNameProcessor)
}

func syncDataCollection(instApps *odigosv1.InstrumentedApplicationList, dests *odigosv1.DestinationList, processors *odigosv1.ProcessorList,
dataCollection *odigosv1.CollectorsGroup, ctx context.Context, c client.Client,
scheme *runtime.Scheme, imagePullSecrets []string, odigosVersion string, tier common.OdigosTier) error {
scheme *runtime.Scheme, imagePullSecrets []string, odigosVersion string, disableNameProcessor bool) error {
logger := log.FromContext(ctx)
logger.V(0).Info("Syncing data collection")

_, err := SyncConfigMap(instApps, dests, processors, dataCollection, ctx, c, scheme, tier)
_, err := SyncConfigMap(instApps, dests, processors, dataCollection, ctx, c, scheme, disableNameProcessor)
if err != nil {
logger.Error(err, "Failed to sync config map")
return err
Expand Down
11 changes: 5 additions & 6 deletions autoscaler/controllers/instrumentedapplication_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (

odigosv1 "github.com/odigos-io/odigos/api/odigos/v1alpha1"
"github.com/odigos-io/odigos/autoscaler/controllers/datacollection"
"github.com/odigos-io/odigos/common"
"k8s.io/apimachinery/pkg/runtime"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand All @@ -31,10 +30,10 @@ import (
// InstrumentedApplicationReconciler reconciles a InstrumentedApplication object
type InstrumentedApplicationReconciler struct {
client.Client
Scheme *runtime.Scheme
ImagePullSecrets []string
OdigosVersion string
OdigosTier common.OdigosTier
Scheme *runtime.Scheme
ImagePullSecrets []string
OdigosVersion string
DisableNameProcessor bool
}

//+kubebuilder:rbac:groups=odigos.io,resources=instrumentedapplications,verbs=get;list;watch;create;update;patch;delete
Expand All @@ -52,7 +51,7 @@ type InstrumentedApplicationReconciler struct {
func (r *InstrumentedApplicationReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
logger := log.FromContext(ctx)
logger.V(0).Info("Reconciling InstrumentedApps")
err := datacollection.Sync(ctx, r.Client, r.Scheme, r.ImagePullSecrets, r.OdigosVersion, r.OdigosTier)
err := datacollection.Sync(ctx, r.Client, r.Scheme, r.ImagePullSecrets, r.OdigosVersion, r.DisableNameProcessor)
if err != nil {
return ctrl.Result{}, err
}
Expand Down
11 changes: 5 additions & 6 deletions autoscaler/controllers/processor_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
v1 "github.com/odigos-io/odigos/api/odigos/v1alpha1"
"github.com/odigos-io/odigos/autoscaler/controllers/datacollection"
"github.com/odigos-io/odigos/autoscaler/controllers/gateway"
"github.com/odigos-io/odigos/common"
"k8s.io/apimachinery/pkg/runtime"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand All @@ -15,10 +14,10 @@ import (

type ProcessorReconciler struct {
client.Client
Scheme *runtime.Scheme
ImagePullSecrets []string
OdigosVersion string
OdigosTier common.OdigosTier
Scheme *runtime.Scheme
ImagePullSecrets []string
OdigosVersion string
DisableNameProcessor bool
}

func (r *ProcessorReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
Expand All @@ -31,7 +30,7 @@ func (r *ProcessorReconciler) Reconcile(ctx context.Context, req ctrl.Request) (
return ctrl.Result{}, err
}

err = datacollection.Sync(ctx, r.Client, r.Scheme, r.ImagePullSecrets, r.OdigosVersion, r.OdigosTier)
err = datacollection.Sync(ctx, r.Client, r.Scheme, r.ImagePullSecrets, r.OdigosVersion, r.DisableNameProcessor)
if err != nil {
return ctrl.Result{}, err
}
Expand Down
46 changes: 20 additions & 26 deletions autoscaler/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ import (
appsv1 "k8s.io/api/apps/v1"
"sigs.k8s.io/controller-runtime/pkg/client"

k8sClient "github.com/odigos-io/odigos/k8sutils/pkg/client"
k8sUtils "github.com/odigos-io/odigos/k8sutils/pkg/utils"
"sigs.k8s.io/controller-runtime/pkg/cache"

"github.com/go-logr/zapr"
Expand Down Expand Up @@ -165,15 +163,11 @@ func main() {
os.Exit(1)
}

client, err := k8sClient.GetK8sClientset()
if err != nil {
setupLog.Error(err, "unable to create k8s clientset")
}

tier, err := k8sUtils.GetCurrentOdigosTier(context.Background(), odigosNs, client)
if err != nil {
setupLog.Error(err, "unable to get current odigos tier")
}
// The name processor is used to transform device ids injected with the virtual device,
// to service names and k8s attributes.
// it is not needed for eBPF instrumentation or OpAMP implementations.
// at the time of writing (2024-10-22) only dotnet and java native agent are using the name processor.
_, disableNameProcessor := os.LookupEnv("DISABLE_NAME_PROCESSOR")

if err = (&controllers.DestinationReconciler{
Client: mgr.GetClient(),
Expand All @@ -186,31 +180,31 @@ func main() {
}

if err = (&controllers.ProcessorReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
ImagePullSecrets: imagePullSecrets,
OdigosVersion: odigosVersion,
OdigosTier: tier,
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
ImagePullSecrets: imagePullSecrets,
OdigosVersion: odigosVersion,
DisableNameProcessor: disableNameProcessor,
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "Processor")
os.Exit(1)
}
if err = (&controllers.CollectorsGroupReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
ImagePullSecrets: imagePullSecrets,
OdigosVersion: odigosVersion,
OdigosTier: tier,
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
ImagePullSecrets: imagePullSecrets,
OdigosVersion: odigosVersion,
DisableNameProcessor: disableNameProcessor,
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "CollectorsGroup")
os.Exit(1)
}
if err = (&controllers.InstrumentedApplicationReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
ImagePullSecrets: imagePullSecrets,
OdigosVersion: odigosVersion,
OdigosTier: tier,
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
ImagePullSecrets: imagePullSecrets,
OdigosVersion: odigosVersion,
DisableNameProcessor: disableNameProcessor,
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "InstrumentedApplication")
os.Exit(1)
Expand Down
23 changes: 19 additions & 4 deletions cli/cmd/resources/autoscaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package resources

import (
"context"
"slices"

"github.com/odigos-io/odigos/cli/cmd/resources/resourcemanager"
"github.com/odigos-io/odigos/cli/pkg/containers"
Expand Down Expand Up @@ -393,7 +394,18 @@ func NewAutoscalerLeaderElectionRoleBinding(ns string) *rbacv1.RoleBinding {
}
}

func NewAutoscalerDeployment(ns string, version string, imagePrefix string, imageName string) *appsv1.Deployment {
func NewAutoscalerDeployment(ns string, version string, imagePrefix string, imageName string, disableNameProcessor bool) *appsv1.Deployment {

optionalEnvs := []corev1.EnvVar{}

if disableNameProcessor {
// temporary until we migrate java and dotnet to OpAMP
optionalEnvs = append(optionalEnvs, corev1.EnvVar{
Name: "DISABLE_NAME_PROCESSOR",
Value: "true",
})
}

dep := &appsv1.Deployment{
TypeMeta: metav1.TypeMeta{
Kind: "Deployment",
Expand Down Expand Up @@ -435,7 +447,7 @@ func NewAutoscalerDeployment(ns string, version string, imagePrefix string, imag
"--metrics-bind-address=127.0.0.1:8080",
"--leader-elect",
},
Env: []corev1.EnvVar{
Env: append([]corev1.EnvVar{
{
Name: "OTEL_SERVICE_NAME",
Value: AutoScalerServiceName,
Expand All @@ -448,7 +460,7 @@ func NewAutoscalerDeployment(ns string, version string, imagePrefix string, imag
},
},
},
},
}, optionalEnvs...),
EnvFrom: []corev1.EnvFromSource{
{
ConfigMapRef: &corev1.ConfigMapEnvSource{
Expand Down Expand Up @@ -528,14 +540,17 @@ func NewAutoScalerResourceManager(client *kube.Client, ns string, config *common
func (a *autoScalerResourceManager) Name() string { return "AutoScaler" }

func (a *autoScalerResourceManager) InstallFromScratch(ctx context.Context) error {

disableNameProcessor := slices.Contains(a.config.Profiles, "disable-name-processor") || slices.Contains(a.config.Profiles, "kratos")

resources := []client.Object{
NewAutoscalerServiceAccount(a.ns),
NewAutoscalerRole(a.ns),
NewAutoscalerRoleBinding(a.ns),
NewAutoscalerClusterRole(),
NewAutoscalerClusterRoleBinding(a.ns),
NewAutoscalerLeaderElectionRoleBinding(a.ns),
NewAutoscalerDeployment(a.ns, a.odigosVersion, a.config.ImagePrefix, a.config.AutoscalerImage),
NewAutoscalerDeployment(a.ns, a.odigosVersion, a.config.ImagePrefix, a.config.AutoscalerImage, disableNameProcessor),
}
return a.client.ApplyResources(ctx, a.config.ConfigVersion, resources)
}
8 changes: 6 additions & 2 deletions cli/cmd/resources/profiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,19 @@ var (
ProfileName: common.ProfileName("code-attributes"),
ShortDescription: "Record span attributes in 'code' namespace where supported",
}
disableNameProcessorProfile = Profile{
ProfileName: common.ProfileName("disable-name-processor"),
ShortDescription: "If not using dotnet or java native instrumentations, disable the name processor which is not needed",
}
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"},
Dependencies: []common.ProfileName{"db-payload-collection", "semconv", "category-attributes", "copy-scope", "hostname-as-podname", "java-native-instrumentations", "code-attributes", "query-operation-detector", "disableNameProcessorProfile"},
}
)

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

func GetAvailableOnPremProfiles() []Profile {
Expand Down

0 comments on commit 9ec5678

Please sign in to comment.