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

Userlog Service #5610

Merged
merged 3 commits into from
Feb 23, 2023
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
1 change: 1 addition & 0 deletions .drone.star
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ config = {
"services/storage-users",
"services/store",
"services/thumbnails",
"services/userlog",
"services/users",
"services/web",
"services/webdav",
Expand Down
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ OCIS_MODULES = \
services/storage-users \
services/store \
services/thumbnails \
services/userlog \
services/users \
services/web \
services/webdav\
Expand Down
5 changes: 5 additions & 0 deletions changelog/unreleased/userlog-service.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Enhancement: Userlog Service

Introduces userlog service. It stores eventIDs the user is interested in and provides an API to retrieve the events.

https://github.com/owncloud/ocis/pull/5610
2 changes: 2 additions & 0 deletions ocis-pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
storageusers "github.com/owncloud/ocis/v2/services/storage-users/pkg/config"
store "github.com/owncloud/ocis/v2/services/store/pkg/config"
thumbnails "github.com/owncloud/ocis/v2/services/thumbnails/pkg/config"
userlog "github.com/owncloud/ocis/v2/services/userlog/pkg/config"
users "github.com/owncloud/ocis/v2/services/users/pkg/config"
web "github.com/owncloud/ocis/v2/services/web/pkg/config"
webdav "github.com/owncloud/ocis/v2/services/webdav/pkg/config"
Expand Down Expand Up @@ -106,6 +107,7 @@ type Config struct {
StorageUsers *storageusers.Config `yaml:"storage_users"`
Store *store.Config `yaml:"store"`
Thumbnails *thumbnails.Config `yaml:"thumbnails"`
Userlog *userlog.Config `yaml:"userlog"`
Users *users.Config `yaml:"users"`
Web *web.Config `yaml:"web"`
WebDAV *webdav.Config `yaml:"webdav"`
Expand Down
2 changes: 2 additions & 0 deletions ocis-pkg/config/defaultconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
storageusers "github.com/owncloud/ocis/v2/services/storage-users/pkg/config/defaults"
store "github.com/owncloud/ocis/v2/services/store/pkg/config/defaults"
thumbnails "github.com/owncloud/ocis/v2/services/thumbnails/pkg/config/defaults"
userlog "github.com/owncloud/ocis/v2/services/userlog/pkg/config/defaults"
users "github.com/owncloud/ocis/v2/services/users/pkg/config/defaults"
web "github.com/owncloud/ocis/v2/services/web/pkg/config/defaults"
webdav "github.com/owncloud/ocis/v2/services/webdav/pkg/config/defaults"
Expand Down Expand Up @@ -71,6 +72,7 @@ func DefaultConfig() *Config {
StorageUsers: storageusers.DefaultConfig(),
Store: store.DefaultConfig(),
Thumbnails: thumbnails.DefaultConfig(),
Userlog: userlog.DefaultConfig(),
Users: users.DefaultConfig(),
Web: web.DefaultConfig(),
WebDAV: webdav.DefaultConfig(),
Expand Down
2 changes: 2 additions & 0 deletions ocis/pkg/runtime/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import (
storageusers "github.com/owncloud/ocis/v2/services/storage-users/pkg/command"
store "github.com/owncloud/ocis/v2/services/store/pkg/command"
thumbnails "github.com/owncloud/ocis/v2/services/thumbnails/pkg/command"
userlog "github.com/owncloud/ocis/v2/services/userlog/pkg/command"
users "github.com/owncloud/ocis/v2/services/users/pkg/command"
web "github.com/owncloud/ocis/v2/services/web/pkg/command"
webdav "github.com/owncloud/ocis/v2/services/webdav/pkg/command"
Expand Down Expand Up @@ -131,6 +132,7 @@ func NewService(options ...Option) (*Service, error) {
s.ServicesRegistry[opts.Config.Search.Service.Name] = search.NewSutureService
s.ServicesRegistry[opts.Config.Postprocessing.Service.Name] = postprocessing.NewSutureService
s.ServicesRegistry[opts.Config.EventHistory.Service.Name] = eventhistory.NewSutureService
s.ServicesRegistry[opts.Config.Userlog.Service.Name] = userlog.NewSutureService

// populate delayed services
s.Delayed[opts.Config.Sharing.Service.Name] = sharing.NewSutureService
Expand Down
5 changes: 5 additions & 0 deletions services/proxy/pkg/config/defaults/defaultconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ func DefaultPolicies() []config.Policy {
Endpoint: "/archiver",
Service: "com.owncloud.web.frontend",
},
{
// reroute oc10 notifications endpoint to userlog service
Endpoint: "/ocs/v2.php/apps/notifications/api/v1/notifications",
Service: "com.owncloud.userlog.userlog",
},
{
Type: config.RegexRoute,
Endpoint: "/ocs/v[12].php/cloud/user/signing-key", // only `user/signing-key` is left in ocis-ocs
Expand Down
38 changes: 38 additions & 0 deletions services/userlog/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
SHELL := bash
NAME := userlog

include ../../.make/recursion.mk

############ tooling ############
ifneq (, $(shell command -v go 2> /dev/null)) # suppress `command not found warnings` for non go targets in CI
include ../../.bingo/Variables.mk
endif

############ go tooling ############
include ../../.make/go.mk

############ release ############
include ../../.make/release.mk

############ docs generate ############
include ../../.make/docs.mk

.PHONY: docs-generate
docs-generate: config-docs-generate

############ generate ############
include ../../.make/generate.mk

.PHONY: ci-go-generate
ci-go-generate: $(MOCKERY) # CI runs ci-node-generate automatically before this target
$(MOCKERY) --dir ../../protogen/gen/ocis/services/eventhistory/v0 --case underscore --name EventHistoryService

.PHONY: ci-node-generate
ci-node-generate:

############ licenses ############
.PHONY: ci-node-check-licenses
ci-node-check-licenses:

.PHONY: ci-node-save-licenses
ci-node-save-licenses:
33 changes: 33 additions & 0 deletions services/userlog/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Userlog Service

The `userlog` service is a mediator between the `eventhistory` service and clients who want to be informed about user related events. It provides an API to retrieve those.

## Prerequisites

Running the `userlog` service without running the `eventhistory` service is not possible.

## Storing

The `userlog` service persists information via the configured store in `USERLOG_STORE_TYPE`. Possible stores are:
- `mem`: Basic in-memory store and the default.
- `ocmem`: Advanced in-memory store allowing max size.
- `redis`: Stores data in a configured redis cluster.
- `etcd`: Stores data in a configured etcd cluster.
- `nats-js`: Stores data using key-value-store feature of [nats jetstream](https://docs.nats.io/nats-concepts/jetstream/key-value-store)
- `noop`: Stores nothing. Useful for testing. Not recommended in productive enviroments.

1. Note that in-memory stores are by nature not reboot persistent.
2. Though usually not necessary, a database name and a database table can be configured for event stores if the event store supports this. Generally not applicapable for stores of type `in-memory`. These settings are blank by default which means that the standard settings of the configured store applies.
kobergj marked this conversation as resolved.
Show resolved Hide resolved
3. The userlog service can be scaled if not using `in-memory` stores and the stores are configured identically over all instances.

## Configuring

For the time being, the configuration which user related events are of interest is hardcoded and cannot be changed.

## Retrieving

The `userlog` service provides an API to retrieve configured events. For now, this API is mostly following the [oc10 notification GET API](https://doc.owncloud.com/server/next/developer_manual/core/apis/ocs-notification-endpoint-v1.html#get-user-notifications).

## Deleting

To delete events for an user, use a `DELETE` request to `ocs/v2.php/apps/notifications/api/v1/notifications` containing the IDs to delete.
14 changes: 14 additions & 0 deletions services/userlog/cmd/userlog/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package main

import (
"os"

"github.com/owncloud/ocis/v2/services/userlog/pkg/command"
"github.com/owncloud/ocis/v2/services/userlog/pkg/config/defaults"
)

func main() {
if err := command.Execute(defaults.DefaultConfig()); err != nil {
os.Exit(1)
}
}
63 changes: 63 additions & 0 deletions services/userlog/mocks/event_history_service.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions services/userlog/pkg/command/health.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package command

import (
"github.com/owncloud/ocis/v2/services/userlog/pkg/config"
"github.com/urfave/cli/v2"
)

// Health is the entrypoint for the health command.
func Health(cfg *config.Config) *cli.Command {
return &cli.Command{
Name: "health",
Usage: "Check health status",
Action: func(c *cli.Context) error {
// Not implemented
return nil
},
}
}
59 changes: 59 additions & 0 deletions services/userlog/pkg/command/root.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package command

import (
"context"
"os"

"github.com/owncloud/ocis/v2/ocis-pkg/clihelper"
ociscfg "github.com/owncloud/ocis/v2/ocis-pkg/config"
"github.com/owncloud/ocis/v2/services/userlog/pkg/config"
"github.com/thejerf/suture/v4"
"github.com/urfave/cli/v2"
)

// GetCommands provides all commands for this service
func GetCommands(cfg *config.Config) cli.Commands {
return []*cli.Command{
// start this service
Server(cfg),

// interaction with this service

// infos about this service
Health(cfg),
Version(cfg),
}
}

// Execute is the entry point for the userlog command.
func Execute(cfg *config.Config) error {
app := clihelper.DefaultApp(&cli.App{
Name: "userlog",
Usage: "starts userlog service",
Commands: GetCommands(cfg),
})

return app.Run(os.Args)
}

// SutureService allows for the userlog command to be embedded and supervised by a suture supervisor tree.
type SutureService struct {
cfg *config.Config
}

// NewSutureService creates a new userlog.SutureService
func NewSutureService(cfg *ociscfg.Config) suture.Service {
cfg.Userlog.Commons = cfg.Commons
return SutureService{
cfg: cfg.Userlog,
}
}

func (s SutureService) Serve(ctx context.Context) error {
s.cfg.Context = ctx
if err := Execute(s.cfg); err != nil {
return err
}

return nil
}
Loading