Skip to content

Commit

Permalink
convert event to common type
Browse files Browse the repository at this point in the history
Signed-off-by: jkoberg <jkoberg@owncloud.com>
  • Loading branch information
kobergj committed Sep 7, 2023
1 parent da3f975 commit 35f2cd6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
8 changes: 4 additions & 4 deletions services/clientlog/pkg/config/tracing.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
28 changes: 17 additions & 11 deletions services/clientlog/pkg/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand All @@ -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 {
Expand All @@ -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
}
Expand Down

0 comments on commit 35f2cd6

Please sign in to comment.