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

refactor(autoscaler): query collector group directly instead of list #1425

Merged
merged 1 commit into from
Aug 5, 2024
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
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
Loading