Skip to content

Commit

Permalink
refactor(autoscaler): query collector group directly instead of list (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
blumamir authored Aug 5, 2024
1 parent 50a3342 commit 8790906
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 40 deletions.
28 changes: 9 additions & 19 deletions autoscaler/controllers/datacollection/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ package datacollection

import (
"context"
"time"

odigosv1 "github.com/odigos-io/odigos/api/odigos/v1alpha1"
"github.com/odigos-io/odigos/k8sutils/pkg/consts"
"github.com/odigos-io/odigos/k8sutils/pkg/env"
"k8s.io/apimachinery/pkg/runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/log"
"time"
)

var dm = &DelayManager{}
Expand All @@ -30,23 +32,11 @@ func Sync(ctx context.Context, c client.Client, scheme *runtime.Scheme, imagePul
return nil
}

var collectorGroups odigosv1.CollectorsGroupList
if err := c.List(ctx, &collectorGroups); err != nil {
logger.Error(err, "Failed to list collectors groups")
return err
}

var dataCollectionCollectorGroup *odigosv1.CollectorsGroup
for _, collectorGroup := range collectorGroups.Items {
if collectorGroup.Spec.Role == odigosv1.CollectorsGroupRoleNodeCollector {
dataCollectionCollectorGroup = &collectorGroup
break
}
}

if dataCollectionCollectorGroup == nil {
logger.V(3).Info("Data collection collector group doesn't exist, nothing to sync")
return nil
odigosNs := env.GetCurrentNamespace()
var dataCollectionCollectorGroup odigosv1.CollectorsGroup
err := c.Get(ctx, client.ObjectKey{Namespace: odigosNs, Name: consts.OdigosNodeCollectorCollectorGroupName}, &dataCollectionCollectorGroup)
if err != nil {
return client.IgnoreNotFound(err)
}

var dests odigosv1.DestinationList
Expand All @@ -61,7 +51,7 @@ 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)
return syncDataCollection(&instApps, &dests, &processors, &dataCollectionCollectorGroup, ctx, c, scheme, imagePullSecrets, odigosVersion)
}

func syncDataCollection(instApps *odigosv1.InstrumentedApplicationList, dests *odigosv1.DestinationList, processors *odigosv1.ProcessorList,
Expand Down
32 changes: 11 additions & 21 deletions autoscaler/controllers/gateway/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
odigosv1 "github.com/odigos-io/odigos/api/odigos/v1alpha1"
commonconf "github.com/odigos-io/odigos/autoscaler/controllers/common"
"github.com/odigos-io/odigos/common/consts"
k8sconsts "github.com/odigos-io/odigos/k8sutils/pkg/consts"
"github.com/odigos-io/odigos/k8sutils/pkg/env"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
Expand All @@ -25,35 +26,24 @@ var (
}
)

func Sync(ctx context.Context, client client.Client, scheme *runtime.Scheme, imagePullSecrets []string, odigosVersion string) error {
func Sync(ctx context.Context, k8sClient client.Client, scheme *runtime.Scheme, imagePullSecrets []string, odigosVersion string) error {
logger := log.FromContext(ctx)
var collectorGroups odigosv1.CollectorsGroupList
if err := client.List(ctx, &collectorGroups); err != nil {
logger.Error(err, "Failed to list collectors groups")
return err
}

var gatewayCollectorGroup *odigosv1.CollectorsGroup
for _, collectorGroup := range collectorGroups.Items {
if collectorGroup.Spec.Role == odigosv1.CollectorsGroupRoleClusterGateway {
gatewayCollectorGroup = &collectorGroup
break
}
}

if gatewayCollectorGroup == nil {
logger.V(3).Info("Gateway collector group doesn't exist, nothing to sync")
return nil
odigosNs := env.GetCurrentNamespace()
var gatewayCollectorGroup odigosv1.CollectorsGroup
err := k8sClient.Get(ctx, client.ObjectKey{Namespace: odigosNs, Name: k8sconsts.OdigosClusterCollectorConfigMapName}, &gatewayCollectorGroup)
if err != nil {
return client.IgnoreNotFound(err)
}

var dests odigosv1.DestinationList
if err := client.List(ctx, &dests); err != nil {
if err := k8sClient.List(ctx, &dests); err != nil {
logger.Error(err, "Failed to list destinations")
return err
}

var processors odigosv1.ProcessorList
if err := client.List(ctx, &processors); err != nil {
if err := k8sClient.List(ctx, &processors); err != nil {
logger.Error(err, "Failed to list processors")
return err
}
Expand All @@ -62,12 +52,12 @@ func Sync(ctx context.Context, client client.Client, scheme *runtime.Scheme, ima

odigosSystemNamespaceName := env.GetCurrentNamespace()
var odigosConfig odigosv1.OdigosConfiguration
if err := client.Get(ctx, types.NamespacedName{Namespace: odigosSystemNamespaceName, Name: consts.OdigosConfigurationName}, &odigosConfig); err != nil {
if err := k8sClient.Get(ctx, types.NamespacedName{Namespace: odigosSystemNamespaceName, Name: consts.OdigosConfigurationName}, &odigosConfig); err != nil {
logger.Error(err, "failed to get odigos config")
return err
}

return syncGateway(&dests, &processors, gatewayCollectorGroup, ctx, client, scheme, imagePullSecrets, odigosVersion, &odigosConfig)
return syncGateway(&dests, &processors, &gatewayCollectorGroup, ctx, k8sClient, scheme, imagePullSecrets, odigosVersion, &odigosConfig)
}

func syncGateway(dests *odigosv1.DestinationList, processors *odigosv1.ProcessorList,
Expand Down

0 comments on commit 8790906

Please sign in to comment.