Skip to content

Commit

Permalink
fix: OCI client is slow (#3432)
Browse files Browse the repository at this point in the history
fixes: #3400
  • Loading branch information
stuartwdouglas authored Nov 19, 2024
1 parent d9a9b81 commit e17d58d
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 8 deletions.
18 changes: 14 additions & 4 deletions backend/controller/artefacts/oci_registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ type OCIArtefactService struct {
repoFactory func() (*remote.Repository, error)
auth authn.AuthConfig
allowInsecure bool
puller *googleremote.Puller
}

type ArtefactRepository struct {
Expand All @@ -56,11 +57,19 @@ type ArtefactBlobs struct {
}

func NewForTesting() *OCIArtefactService {
return NewOCIRegistryStorage(RegistryConfig{Registry: "127.0.0.1:15000/ftl-tests", AllowInsecure: true})
storage, err := NewOCIRegistryStorage(RegistryConfig{Registry: "127.0.0.1:15000/ftl-tests", AllowInsecure: true})
if err != nil {
panic(err)
}
return storage
}

func NewOCIRegistryStorage(c RegistryConfig) *OCIArtefactService {
func NewOCIRegistryStorage(c RegistryConfig) (*OCIArtefactService, error) {
// Connect the registry targeting the specified container
puller, err := googleremote.NewPuller()
if err != nil {
return nil, fmt.Errorf("unable to create puller for registry '%s': %w", c.Registry, err)
}
repoFactory := func() (*remote.Repository, error) {
reg, err := remote.NewRepository(c.Registry)
if err != nil {
Expand All @@ -85,7 +94,8 @@ func NewOCIRegistryStorage(c RegistryConfig) *OCIArtefactService {
repoFactory: repoFactory,
auth: authn.AuthConfig{Username: c.Username, Password: c.Password},
allowInsecure: c.AllowInsecure,
}
puller: puller,
}, nil
}

func (s *OCIArtefactService) GetDigestsKeys(ctx context.Context, digests []sha256.SHA256) (keys []ArtefactKey, missing []sha256.SHA256, err error) {
Expand Down Expand Up @@ -180,7 +190,7 @@ func (s *OCIArtefactService) Download(ctx context.Context, dg sha256.SHA256) (io
if err != nil {
return nil, fmt.Errorf("unable to create digest '%s': %w", dg, err)
}
layer, err := googleremote.Layer(newDigest, googleremote.WithAuthFromKeychain(authn.DefaultKeychain))
layer, err := googleremote.Layer(newDigest, googleremote.WithAuthFromKeychain(authn.DefaultKeychain), googleremote.Reuse(s.puller))
if err != nil {
return nil, fmt.Errorf("unable to read layer '%s': %w", newDigest, err)
}
Expand Down
6 changes: 5 additions & 1 deletion backend/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,11 @@ func New(
}
svc.schemaState.Store(schemaState{routes: map[string]Route{}, schema: &schema.Schema{}})

svc.registry = artefacts.NewOCIRegistryStorage(config.Registry)
storage, err := artefacts.NewOCIRegistryStorage(config.Registry)
if err != nil {
return nil, fmt.Errorf("failed to create OCI registry storage: %w", err)
}
svc.registry = storage

timelineSvc := timeline.New(ctx, conn, encryption)
svc.timeline = timelineSvc
Expand Down
6 changes: 5 additions & 1 deletion backend/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,11 @@ func (s *Service) deploy(ctx context.Context) error {
return fmt.Errorf("failed to create deployment directory: %w", err)
}
}
err = download.ArtefactsFromOCI(ctx, s.controllerClient, key, deploymentDir, artefacts.NewOCIRegistryStorage(s.config.Registry))
storage, err := artefacts.NewOCIRegistryStorage(s.config.Registry)
if err != nil {
return fmt.Errorf("failed to create OCI registry storage: %w", err)
}
err = download.ArtefactsFromOCI(ctx, s.controllerClient, key, deploymentDir, storage)
if err != nil {
observability.Deployment.Failure(ctx, optional.Some(key.String()))
return fmt.Errorf("failed to download artefacts: %w", err)
Expand Down
7 changes: 5 additions & 2 deletions frontend/cli/cmd_release.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ func createContainerService(release *releaseCmd) (*artefacts.OCIArtefactService,
}
conn.SetMaxIdleConns(release.MaxIdleDBConnections)
conn.SetMaxOpenConns(release.MaxOpenDBConnections)

return artefacts.NewOCIRegistryStorage(release.Registry), nil
storage, err := artefacts.NewOCIRegistryStorage(release.Registry)
if err != nil {
return nil, fmt.Errorf("failed to create OCI registry storage: %w", err)
}
return storage, nil
}

0 comments on commit e17d58d

Please sign in to comment.