Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Activitylog Issues #10377

Merged
merged 1 commit into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions changelog/unreleased/fix-activitylog-issues.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Bugfix: Fix Activitylog issues

Fixes multiple activititylog issues. There was an error about `max payload exceeded` when there were too many activities on one folder. Listing would take very long even with a limit activated. All of these
issues are now fixed.

https://github.com/owncloud/ocis/pull/10376
21 changes: 11 additions & 10 deletions services/activitylog/pkg/service/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,17 @@ func (s *ActivitylogService) HandleGetItemActivities(w http.ResponseWriter, r *h
return
}

evs := evRes.GetEvents()
sort(evs)

resp := GetActivitiesResponse{Activities: make([]libregraph.Activity, 0, len(evRes.GetEvents()))}
for _, e := range evRes.GetEvents() {
for _, e := range evs {
delete(toDelete, e.GetId())

if limit > 0 && limit <= len(resp.Activities) {
continue
}

if !activityAccepted(e) {
continue
}
Expand Down Expand Up @@ -230,12 +237,6 @@ func (s *ActivitylogService) HandleGetItemActivities(w http.ResponseWriter, r *h
}()
}

sort(resp.Activities)

if limit > 0 && limit < len(resp.Activities) {
resp.Activities = resp.Activities[:limit]
}

b, err := json.Marshal(resp)
if err != nil {
s.log.Error().Err(err).Msg("error marshalling activities")
Expand Down Expand Up @@ -267,7 +268,7 @@ func (s *ActivitylogService) unwrapEvent(e *ehmsg.Event) interface{} {
return einterface
}

func (s *ActivitylogService) getFilters(query string) (*provider.ResourceId, int, func(RawActivity) bool, func(*ehmsg.Event) bool, func([]libregraph.Activity), error) {
func (s *ActivitylogService) getFilters(query string) (*provider.ResourceId, int, func(RawActivity) bool, func(*ehmsg.Event) bool, func([]*ehmsg.Event), error) {
qast, err := kql.Builder{}.Build(query)
if err != nil {
return nil, 0, nil, nil, nil, err
Expand All @@ -276,7 +277,7 @@ func (s *ActivitylogService) getFilters(query string) (*provider.ResourceId, int
prefilters := make([]func(RawActivity) bool, 0)
postfilters := make([]func(*ehmsg.Event) bool, 0)

sortby := func(_ []libregraph.Activity) {}
sortby := func(_ []*ehmsg.Event) {}

var (
itemID string
Expand Down Expand Up @@ -313,7 +314,7 @@ func (s *ActivitylogService) getFilters(query string) (*provider.ResourceId, int
case "asc":
// nothing to do - already ascending
case "desc":
sortby = func(activities []libregraph.Activity) {
sortby = func(activities []*ehmsg.Event) {
slices.Reverse(activities)
}
}
Expand Down
8 changes: 7 additions & 1 deletion services/activitylog/pkg/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ import (
"github.com/owncloud/ocis/v2/services/activitylog/pkg/config"
)

// Nats runs into max payload exceeded errors at around 7k activities. Let's keep a buffer.
var _maxActivities = 6000

// RawActivity represents an activity as it is stored in the activitylog store
type RawActivity struct {
EventID string `json:"event_id"`
Expand Down Expand Up @@ -311,7 +314,10 @@ func (a *ActivitylogService) storeActivity(resourceID string, eventID string, de
}
}

// TODO: max len check?
if l := len(activities); l >= _maxActivities {
activities = activities[l-_maxActivities+1:]
}

activities = append(activities, RawActivity{
EventID: eventID,
Depth: depth,
Expand Down