From 35f2cd685a41fbbb5db08e5588596f55299874b4 Mon Sep 17 00:00:00 2001 From: jkoberg Date: Wed, 6 Sep 2023 11:33:14 +0200 Subject: [PATCH] convert event to common type Signed-off-by: jkoberg --- services/clientlog/pkg/config/tracing.go | 8 +++---- services/clientlog/pkg/service/service.go | 28 ++++++++++++++--------- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/services/clientlog/pkg/config/tracing.go b/services/clientlog/pkg/config/tracing.go index 66f0332ec15..dd041c63259 100644 --- a/services/clientlog/pkg/config/tracing.go +++ b/services/clientlog/pkg/config/tracing.go @@ -4,10 +4,10 @@ import "github.com/owncloud/ocis/v2/ocis-pkg/tracing" // Tracing defines the available tracing configuration. type Tracing struct { - Enabled bool `yaml:"enabled" env:"OCIS_TRACING_ENABLED;USERLOG_TRACING_ENABLED" desc:"Activates tracing."` - Type string `yaml:"type" env:"OCIS_TRACING_TYPE;USERLOG_TRACING_TYPE" desc:"The type of tracing. Defaults to '', which is the same as 'jaeger'. Allowed tracing types are 'jaeger' and '' as of now."` - Endpoint string `yaml:"endpoint" env:"OCIS_TRACING_ENDPOINT;USERLOG_TRACING_ENDPOINT" desc:"The endpoint of the tracing agent."` - Collector string `yaml:"collector" env:"OCIS_TRACING_COLLECTOR;USERLOG_TRACING_COLLECTOR" desc:"The HTTP endpoint for sending spans directly to a collector, i.e. http://jaeger-collector:14268/api/traces. Only used if the tracing endpoint is unset."` + Enabled bool `yaml:"enabled" env:"OCIS_TRACING_ENABLED;CLIENTLOG_TRACING_ENABLED" desc:"Activates tracing."` + Type string `yaml:"type" env:"OCIS_TRACING_TYPE;CLIENTLOG_TRACING_TYPE" desc:"The type of tracing. Defaults to '', which is the same as 'jaeger'. Allowed tracing types are 'jaeger' and '' as of now."` + Endpoint string `yaml:"endpoint" env:"OCIS_TRACING_ENDPOINT;CLIENTLOG_TRACING_ENDPOINT" desc:"The endpoint of the tracing agent."` + Collector string `yaml:"collector" env:"OCIS_TRACING_COLLECTOR;CLIENTLOG_TRACING_COLLECTOR" desc:"The HTTP endpoint for sending spans directly to a collector, i.e. http://jaeger-collector:14268/api/traces. Only used if the tracing endpoint is unset."` } // Convert Tracing to the tracing package's Config struct. diff --git a/services/clientlog/pkg/service/service.go b/services/clientlog/pkg/service/service.go index 4f9f6bdfd3b..f382c7b9727 100644 --- a/services/clientlog/pkg/service/service.go +++ b/services/clientlog/pkg/service/service.go @@ -10,12 +10,19 @@ import ( gateway "github.com/cs3org/go-cs3apis/cs3/gateway/v1beta1" "github.com/cs3org/reva/v2/pkg/events" "github.com/cs3org/reva/v2/pkg/rgrpc/todo/pool" + "github.com/cs3org/reva/v2/pkg/storagespace" "github.com/cs3org/reva/v2/pkg/utils" "github.com/owncloud/ocis/v2/ocis-pkg/log" "github.com/owncloud/ocis/v2/services/clientlog/pkg/config" "go.opentelemetry.io/otel/trace" ) +// ClientNotification is the event the clientlog service is sending to the client +type ClientNotification struct { + Type string + ItemID string +} + // ClientlogService is the service responsible for user activities type ClientlogService struct { log log.Logger @@ -85,7 +92,10 @@ func (cl *ClientlogService) processEvent(event events.Event) { return } - var users []string + var ( + users []string + noti ClientNotification + ) switch e := event.Event.(type) { default: err = errors.New("unhandled event") @@ -96,11 +106,10 @@ func (cl *ClientlogService) processEvent(event events.Event) { return } + noti.Type = "postprocessing-finished" + noti.ItemID = storagespace.FormatResourceID(*info.GetId()) + users, err = utils.GetSpaceMembers(ctx, info.GetSpace().GetId().GetOpaqueId(), gwc, utils.ViewerRole) - if err != nil { - cl.log.Error().Err(err).Interface("event", event).Msg("error getting space members") - return - } } if err != nil { @@ -110,18 +119,15 @@ func (cl *ClientlogService) processEvent(event events.Event) { // II) instruct sse service to send the information for _, id := range users { - if err := cl.sendSSE(id, event); err != nil { + if err := cl.sendSSE(id, noti); err != nil { cl.log.Error().Err(err).Str("userID", id).Str("eventid", event.ID).Msg("failed to store event for user") return } } } -func (cl *ClientlogService) sendSSE(userid string, event events.Event) error { - // TODO: convert event - ev := event - - b, err := json.Marshal(ev) +func (cl *ClientlogService) sendSSE(userid string, noti ClientNotification) error { + b, err := json.Marshal(noti) if err != nil { return err }