fix(graph-metadata): lazy cs3 metadata storage initialization

This commit is contained in:
Florian Schade
2025-05-27 16:18:20 +02:00
parent b37a45f26f
commit f4d8e632fd
19 changed files with 226 additions and 109 deletions
+35 -16
View File
@@ -1,6 +1,8 @@
package http
import (
"context"
"errors"
"fmt"
stdhttp "net/http"
@@ -8,8 +10,7 @@ import (
chimiddleware "github.com/go-chi/chi/v5/middleware"
"github.com/opencloud-eu/reva/v2/pkg/events/stream"
"github.com/opencloud-eu/reva/v2/pkg/rgrpc/todo/pool"
"github.com/opencloud-eu/reva/v2/pkg/storage/utils/metadata"
"github.com/pkg/errors"
revaMetadata "github.com/opencloud-eu/reva/v2/pkg/storage/utils/metadata"
"go-micro.dev/v4"
"go-micro.dev/v4/events"
@@ -20,6 +21,7 @@ import (
"github.com/opencloud-eu/opencloud/pkg/registry"
"github.com/opencloud-eu/opencloud/pkg/service/grpc"
"github.com/opencloud-eu/opencloud/pkg/service/http"
"github.com/opencloud-eu/opencloud/pkg/storage/metadata"
"github.com/opencloud-eu/opencloud/pkg/version"
ehsvc "github.com/opencloud-eu/opencloud/protogen/gen/opencloud/services/eventhistory/v0"
searchsvc "github.com/opencloud-eu/opencloud/protogen/gen/opencloud/services/search/v0"
@@ -59,7 +61,7 @@ func Server(opts ...Option) (http.Service, error) {
options.Logger.Error().
Err(err).
Msg("Error initializing events publisher")
return http.Service{}, errors.Wrap(err, "could not initialize events publisher")
return http.Service{}, fmt.Errorf("could not initialize events publisher: %w", err)
}
}
@@ -106,7 +108,7 @@ func Server(opts ...Option) (http.Service, error) {
pool.WithTracerProvider(options.TraceProvider),
)...)
if err != nil {
return http.Service{}, errors.Wrap(err, "could not initialize gateway selector")
return http.Service{}, fmt.Errorf("could not initialize gateway selector: %w", err)
}
} else {
middlewares = append(middlewares, graphMiddleware.Token(options.Config.HTTP.APIToken))
@@ -129,21 +131,38 @@ func Server(opts ...Option) (http.Service, error) {
hClient := ehsvc.NewEventHistoryService("eu.opencloud.api.eventhistory", grpcClient)
storage, err := metadata.NewCS3Storage(
options.Config.Metadata.GatewayAddress,
options.Config.Metadata.StorageAddress,
options.Config.Metadata.SystemUserID,
options.Config.Metadata.SystemUserIDP,
options.Config.Metadata.SystemUserAPIKey,
)
if err != nil {
return http.Service{}, fmt.Errorf("could not initialize metadata storage: %w", err)
var userProfilePhotoService svc.UsersUserProfilePhotoProvider
{
photoStorage, err := revaMetadata.NewCS3Storage(
options.Config.Metadata.GatewayAddress,
options.Config.Metadata.StorageAddress,
options.Config.Metadata.SystemUserID,
options.Config.Metadata.SystemUserIDP,
options.Config.Metadata.SystemUserAPIKey,
)
if err != nil {
return http.Service{}, fmt.Errorf("could not initialize reva metadata storage: %w", err)
}
photoStorage, err = metadata.NewLazyStorage(photoStorage)
if err != nil {
return http.Service{}, fmt.Errorf("could not initialize lazy metadata storage: %w", err)
}
if err := photoStorage.Init(context.Background(), "f2bdd61a-da7c-49fc-8203-0558109d1b4f"); err != nil {
return http.Service{}, fmt.Errorf("could not initialize metadata storage: %w", err)
}
userProfilePhotoService, err = svc.NewUsersUserProfilePhotoService(photoStorage)
if err != nil {
return http.Service{}, fmt.Errorf("could not initialize user profile photo service: %w", err)
}
}
var handle svc.Service
handle, err = svc.NewService(
svc.Context(options.Context),
svc.MetadataStorage(storage),
svc.UserProfilePhotoService(userProfilePhotoService),
svc.Logger(options.Logger),
svc.Config(options.Config),
svc.Middleware(middlewares...),
@@ -160,11 +179,11 @@ func Server(opts ...Option) (http.Service, error) {
)
if err != nil {
return http.Service{}, errors.New("could not initialize graph service")
return http.Service{}, fmt.Errorf("could not initialize graph service: %w", err)
}
if err := micro.RegisterHandler(service.Server(), handle); err != nil {
return http.Service{}, err
return http.Service{}, fmt.Errorf("could not register graph service handler: %w", err)
}
return service, nil