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

Activity API #9361

Merged
merged 13 commits into from
Jun 25, 2024
Merged

Activity API #9361

merged 13 commits into from
Jun 25, 2024

Conversation

kobergj
Copy link
Collaborator

@kobergj kobergj commented Jun 12, 2024

Adds an API to retrieve activities

Fixes #9196

@micbar
Copy link
Contributor

micbar commented Jun 12, 2024

Question: Do we use the generated libregraph types?

@kobergj
Copy link
Collaborator Author

kobergj commented Jun 13, 2024

No. We are barely using them. No need to use created ones imho.

@micbar
Copy link
Contributor

micbar commented Jun 14, 2024

I think we have a problem. This api endpoint needs to work with our generated clients. Is the spec already added to libregraph?

@kobergj
Copy link
Collaborator Author

kobergj commented Jun 17, 2024

Yes. Then we really have a problem. We need to discuss this.

@micbar
Copy link
Contributor

micbar commented Jun 17, 2024

What needs to be discussed?

We are using libregraph. So our normal workflow is to create the spec and then the implementation.

Why should it be different here?

@kobergj
Copy link
Collaborator Author

kobergj commented Jun 17, 2024

Well the only thing we have in common with the graph spec is the url. We are returning a different response and expect a different request. That is because we are misusing the endpoint as it doesn't exist as we need it to be.

@kobergj kobergj force-pushed the ActivityApi branch 9 times, most recently from 332fdb6 to a18ac33 Compare June 21, 2024 13:17
@kobergj kobergj marked this pull request as ready for review June 24, 2024 08:10
if err := json.Unmarshal(records[0].Value, &activities); err != nil {
return nil, fmt.Errorf("could not unmarshal activities: %w", err)
}

return activities, nil
}

// RemoveActivities removes the activities from the given resource
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we add a mutex to the ActivitylogService structure?
We are consuming and writing the events in Run() and at the same time we are doing threads unsafe read write sequence in a RemoveActivities

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes you are right. But adding a mutex wont fix the problem. In a distributed environment there might be multiple activitylog services running 🤔 I'll add a mutex for now, but we need a better solution.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now it is deadlock
You locked for the r/w a.lock.Lock() in RemoveActivities and after that try to a.lock.RLock() in Activities with waits forever

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The proper solution could be to split the Activities method and use the private in case if we have to read write

func (a *ActivitylogService) Activities(rid *provider.ResourceId) ([]RawActivity, error) {
       	a.lock.RLock()
	defer a.lock.RUnlock()
        return s.activities(rid)
}

func (a *ActivitylogService) activities(rid *provider.ResourceId) ([]RawActivity, error) {
	resourceID := storagespace.FormatResourceID(*rid)

        records, err := a.store.Read(resourceID)
        if err != nil && err != microstore.ErrNotFound {
		return nil, fmt.Errorf("could not read activities: %w", err)
	}

	if len(records) == 0 {
		return []RawActivity{}, nil
	}

	var activities []RawActivity
	if err := json.Unmarshal(records[0].Value, &activities); err != nil {
		return nil, fmt.Errorf("could not unmarshal activities: %w", err)
	}

	return activities, nil
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good for me

services/activitylog/pkg/service/http.go Show resolved Hide resolved
if err := json.Unmarshal(records[0].Value, &activities); err != nil {
return nil, fmt.Errorf("could not unmarshal activities: %w", err)
}

return activities, nil
}

// RemoveActivities removes the activities from the given resource
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now it is deadlock
You locked for the r/w a.lock.Lock() in RemoveActivities and after that try to a.lock.RLock() in Activities with waits forever

@mmattel
Copy link
Contributor

mmattel commented Jun 24, 2024

@kobergj mind to fix a typo from your former ActivityLog PR that would fit in here:
ACTIVITYLOG_STORE_SIZE: though not exclicitly set as default --> though not explicitly set as default
(the missing p in exclicitly...)

@kobergj
Copy link
Collaborator Author

kobergj commented Jun 24, 2024

Only rebased to master - no code changes

mux *chi.Mux
evHistory ehsvc.EventHistoryService
valService settingssvc.ValueService
lock sync.RWMutex
Copy link
Contributor

@2403905 2403905 Jun 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is a nitpick but could we use mu sync.RWMutex which is the de facto standard?
Nevermind

Copy link

@kobergj kobergj merged commit 73a2f19 into owncloud:master Jun 25, 2024
4 checks passed
@kobergj kobergj deleted the ActivityApi branch June 25, 2024 07:18
ownclouders pushed a commit that referenced this pull request Jun 25, 2024
@micbar micbar mentioned this pull request Jul 8, 2024
19 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[ocis] implement "activity" api
6 participants