convert event to common type

Signed-off-by: jkoberg <jkoberg@owncloud.com>
This commit is contained in:
jkoberg
2023-09-06 11:33:14 +02:00
parent da3f975d87
commit 35f2cd685a
2 changed files with 21 additions and 15 deletions

View File

@@ -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.

View File

@@ -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
}