Skip to content

Commit

Permalink
Perform the PersistNamespaces in parallel (#1175)
Browse files Browse the repository at this point in the history
  • Loading branch information
RonFed committed May 7, 2024
1 parent 275166d commit 23a7be8
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 8 deletions.
14 changes: 9 additions & 5 deletions frontend/endpoints/namespaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion frontend/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions frontend/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand All @@ -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=
Expand Down
12 changes: 12 additions & 0 deletions frontend/kube/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 23a7be8

Please sign in to comment.