diff --git a/frontend/endpoints/namespaces.go b/frontend/endpoints/namespaces.go index 2c1d9dda9..72607eb3f 100644 --- a/frontend/endpoints/namespaces.go +++ b/frontend/endpoints/namespaces.go @@ -5,7 +5,7 @@ import ( "fmt" "net/http" - "go.uber.org/multierr" + "golang.org/x/sync/errgroup" "github.com/odigos-io/odigos/common/consts" "github.com/odigos-io/odigos/common/utils" @@ -117,12 +117,16 @@ func getJsonMergePatchForInstrumentationLabel(enabled *bool) []byte { return []byte(jsonMergePatchContent) } func syncWorkloadsInNamespace(ctx context.Context, nsName string, workloads []PersistNamespaceObject) error { - var errs error + g, ctx := errgroup.WithContext(ctx) + g.SetLimit(kube.K8sClientDefaultBurst) + for _, workload := range workloads { - err := setWorkloadInstrumentationLabel(ctx, nsName, workload.Name, workload.Kind, workload.Selected) - errs = multierr.Append(errs, err) + currWorkload := workload + g.Go(func() error { + return setWorkloadInstrumentationLabel(ctx, nsName, currWorkload.Name, currWorkload.Kind, currWorkload.Selected) + }) } - return errs + return g.Wait() } // returns a map, where the key is a namespace name and the value is the diff --git a/frontend/go.mod b/frontend/go.mod index 91c8907ef..7db0c1123 100644 --- a/frontend/go.mod +++ b/frontend/go.mod @@ -8,7 +8,7 @@ require ( github.com/odigos-io/odigos/api v0.0.0 github.com/odigos-io/odigos/common v1.0.48 github.com/odigos-io/odigos/destinations v0.0.0-20240223090638-df3328a088bc - go.uber.org/multierr v1.11.0 + golang.org/x/sync v0.6.0 k8s.io/api v0.30.0 k8s.io/apimachinery v0.30.0 k8s.io/client-go v0.30.0 diff --git a/frontend/go.sum b/frontend/go.sum index 62611607c..076f0bcb6 100644 --- a/frontend/go.sum +++ b/frontend/go.sum @@ -139,8 +139,6 @@ go.opentelemetry.io/otel v1.24.0 h1:0LAOdjNmQeSTzGBzduGe/rU4tZhMwL5rWgtp9Ku5Jfo= go.opentelemetry.io/otel v1.24.0/go.mod h1:W7b9Ozg4nkF5tWI5zsXkaKKDjdVjpD4oAt9Qi/MArHo= go.opentelemetry.io/otel/trace v1.24.0 h1:CsKnnL4dUAr/0llH9FKuc698G04IrpWV0MQA/Y1YELI= go.opentelemetry.io/otel/trace v1.24.0/go.mod h1:HPc3Xr/cOApsBI154IU0OI0HJexz+aw5uPdbs3UCjNU= -go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0= -go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y= golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8= golang.org/x/arch v0.3.0 h1:02VY4/ZcO/gBOH6PUaoiptASxtXU10jazRCP865E97k= golang.org/x/arch v0.3.0/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8= @@ -165,6 +163,8 @@ golang.org/x/oauth2 v0.12.0/go.mod h1:A74bZ3aGXgCY0qaIC9Ahg6Lglin4AMAco8cIv9baba golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ= +golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= diff --git a/frontend/kube/client.go b/frontend/kube/client.go index ec71c55d1..ad5f302fe 100644 --- a/frontend/kube/client.go +++ b/frontend/kube/client.go @@ -15,6 +15,15 @@ func SetDefaultClient(client *Client) { DefaultClient = client } +const ( + // These are currently "magic" numbers that we are using to set the QPS and Burst for the Kubernetes client. + // They allow for better performance relative to the default values, but with the cost of potentially + // overloading the Kubernetes API server. + // More info about these can be found in https://kubernetes.io/docs/reference/config-api/apiserver-eventratelimit.v1alpha1/ + K8sClientDefaultQPS = 100 + K8sClientDefaultBurst = 100 +) + type Client struct { kubernetes.Interface OdigosClient odigosv1alpha1.OdigosV1alpha1Interface @@ -27,6 +36,9 @@ func CreateClient(kubeConfig string) (*Client, error) { return nil, err } + config.QPS = K8sClientDefaultQPS + config.Burst = K8sClientDefaultBurst + clientset, err := kubernetes.NewForConfig(config) if err != nil { return nil, err