Skip to content

Commit

Permalink
Merge pull request #6992 from fschade/sse-service
Browse files Browse the repository at this point in the history
enhancement: add sse service skeleton
  • Loading branch information
kobergj authored Aug 30, 2023
2 parents 04fd0f0 + 91176db commit 9eb73f0
Show file tree
Hide file tree
Showing 35 changed files with 869 additions and 68 deletions.
1 change: 1 addition & 0 deletions .drone.star
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ config = {
"services/search",
"services/settings",
"services/sharing",
"services/sse",
"services/storage-system",
"services/storage-publiclink",
"services/storage-shares",
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ protogen/buf.sha1.lock
/third-party-licenses

# misc
/tmp
go.work
go.work.sum
.env
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/search \
services/settings \
services/sharing \
services/sse \
services/storage-system \
services/storage-publiclink \
services/storage-shares \
Expand Down
10 changes: 10 additions & 0 deletions changelog/unreleased/enhancement-sse-messaging.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Enhancement: SSE for messaging

So far, sse has only been used to exchange messages between the server and the client.
In order to be able to send more content to the client, we have moved the endpoint to a separate service and are now also using it for other notifications like:

* notify postprocessing state changes.
* notify file locking and unlocking.
* ... @toDo

https://github.com/owncloud/ocis/pull/6992
2 changes: 1 addition & 1 deletion docs/services/general-info/port-ranges.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ We also suggest to use the last port in your extensions' range as a debug/metric
| 9120-9124 | [graph]({{< ref "../graph/_index.md" >}}) |
| 9125-9129 | [policies]({{< ref "../policies/_index.md" >}}) |
| 9130-9134 | [idp]({{< ref "../idp/_index.md" >}}) |
| 9135-9139 | FREE (formerly used by graph-explorer) |
| 9135-9139 | [sse]({{< ref "../sse/_index.md" >}}) |
| 9140-9141 | [frontend]({{< ref "../frontend/_index.md" >}}) |
| 9142-9143 | [gateway]({{< ref "../gateway/_index.md" >}}) |
| 9144-9145 | [users]({{< ref "../users/_index.md" >}}) |
Expand Down
16 changes: 16 additions & 0 deletions docs/services/sse/_index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
title: SSE
date: 2022-08-08T00:00:00+00:00
weight: 20
geekdocRepo: https://github.com/owncloud/ocis
geekdocEditPath: edit/master/docs/services/sse
geekdocFilePath: _index.md
geekdocCollapseSection: true
---

## Abstract


## Table of Contents

{{< toc-tree >}}
15 changes: 15 additions & 0 deletions docs/services/sse/configuration.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
title: Service Configuration
date: 2018-08-08T00:00:00+00:00
weight: 20
geekdocRepo: https://github.com/owncloud/ocis
geekdocEditPath: edit/master/docs/services/sse
geekdocFilePath: configuration.md
geekdocCollapseSection: true
---

## Example YAML Config

{{< include file="services/_includes/app-provider-config-example.yaml" language="yaml" >}}

{{< include file="services/_includes/app-provider_configvars.md" >}}
2 changes: 2 additions & 0 deletions ocis-pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
search "github.com/owncloud/ocis/v2/services/search/pkg/config"
settings "github.com/owncloud/ocis/v2/services/settings/pkg/config"
sharing "github.com/owncloud/ocis/v2/services/sharing/pkg/config"
sse "github.com/owncloud/ocis/v2/services/sse/pkg/config"
storagepublic "github.com/owncloud/ocis/v2/services/storage-publiclink/pkg/config"
storageshares "github.com/owncloud/ocis/v2/services/storage-shares/pkg/config"
storagesystem "github.com/owncloud/ocis/v2/services/storage-system/pkg/config"
Expand Down Expand Up @@ -99,6 +100,7 @@ type Config struct {
Proxy *proxy.Config `yaml:"proxy"`
Settings *settings.Config `yaml:"settings"`
Sharing *sharing.Config `yaml:"sharing"`
SSE *sse.Config `yaml:"sse"`
StorageSystem *storagesystem.Config `yaml:"storage_system"`
StoragePublicLink *storagepublic.Config `yaml:"storage_public"`
StorageShares *storageshares.Config `yaml:"storage_shares"`
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 @@ -26,6 +26,7 @@ import (
search "github.com/owncloud/ocis/v2/services/search/pkg/config/defaults"
settings "github.com/owncloud/ocis/v2/services/settings/pkg/config/defaults"
sharing "github.com/owncloud/ocis/v2/services/sharing/pkg/config/defaults"
sse "github.com/owncloud/ocis/v2/services/sse/pkg/config/defaults"
storagepublic "github.com/owncloud/ocis/v2/services/storage-publiclink/pkg/config/defaults"
storageshares "github.com/owncloud/ocis/v2/services/storage-shares/pkg/config/defaults"
storageSystem "github.com/owncloud/ocis/v2/services/storage-system/pkg/config/defaults"
Expand Down Expand Up @@ -72,6 +73,7 @@ func DefaultConfig() *Config {
Search: search.FullDefaultConfig(),
Settings: settings.DefaultConfig(),
Sharing: sharing.DefaultConfig(),
SSE: sse.DefaultConfig(),
StoragePublicLink: storagepublic.DefaultConfig(),
StorageShares: storageshares.DefaultConfig(),
StorageSystem: storageSystem.DefaultConfig(),
Expand Down
10 changes: 8 additions & 2 deletions ocis/pkg/command/services.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package command

import (
"github.com/urfave/cli/v2"

"github.com/owncloud/ocis/v2/ocis-pkg/config"
"github.com/owncloud/ocis/v2/ocis-pkg/config/configlog"
"github.com/owncloud/ocis/v2/ocis-pkg/config/parser"
"github.com/owncloud/ocis/v2/ocis/pkg/command/helper"
"github.com/owncloud/ocis/v2/ocis/pkg/register"
"github.com/urfave/cli/v2"

antivirus "github.com/owncloud/ocis/v2/services/antivirus/pkg/command"
appprovider "github.com/owncloud/ocis/v2/services/app-provider/pkg/command"
appregistry "github.com/owncloud/ocis/v2/services/app-registry/pkg/command"
Expand All @@ -33,6 +33,7 @@ import (
search "github.com/owncloud/ocis/v2/services/search/pkg/command"
settings "github.com/owncloud/ocis/v2/services/settings/pkg/command"
sharing "github.com/owncloud/ocis/v2/services/sharing/pkg/command"
sse "github.com/owncloud/ocis/v2/services/sse/pkg/command"
storagepubliclink "github.com/owncloud/ocis/v2/services/storage-publiclink/pkg/command"
storageshares "github.com/owncloud/ocis/v2/services/storage-shares/pkg/command"
storagesystem "github.com/owncloud/ocis/v2/services/storage-system/pkg/command"
Expand Down Expand Up @@ -172,6 +173,11 @@ var svccmds = []register.Command{
cfg.Sharing.Commons = cfg.Commons
})
},
func(cfg *config.Config) *cli.Command {
return ServiceCommand(cfg, cfg.SSE.Service.Name, sse.GetCommands(cfg.SSE), func(c *config.Config) {
cfg.SSE.Commons = cfg.Commons
})
},
func(cfg *config.Config) *cli.Command {
return ServiceCommand(cfg, cfg.StoragePublicLink.Service.Name, storagepubliclink.GetCommands(cfg.StoragePublicLink), func(c *config.Config) {
cfg.StoragePublicLink.Commons = cfg.Commons
Expand Down
11 changes: 9 additions & 2 deletions ocis/pkg/runtime/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import (

"github.com/mohae/deepcopy"
"github.com/olekukonko/tablewriter"
"github.com/thejerf/suture/v4"

ociscfg "github.com/owncloud/ocis/v2/ocis-pkg/config"
"github.com/owncloud/ocis/v2/ocis-pkg/log"
"github.com/owncloud/ocis/v2/ocis-pkg/shared"
Expand Down Expand Up @@ -42,6 +44,7 @@ import (
search "github.com/owncloud/ocis/v2/services/search/pkg/command"
settings "github.com/owncloud/ocis/v2/services/settings/pkg/command"
sharing "github.com/owncloud/ocis/v2/services/sharing/pkg/command"
sse "github.com/owncloud/ocis/v2/services/sse/pkg/command"
storagepublic "github.com/owncloud/ocis/v2/services/storage-publiclink/pkg/command"
storageshares "github.com/owncloud/ocis/v2/services/storage-shares/pkg/command"
storageSystem "github.com/owncloud/ocis/v2/services/storage-system/pkg/command"
Expand All @@ -53,7 +56,6 @@ import (
web "github.com/owncloud/ocis/v2/services/web/pkg/command"
webdav "github.com/owncloud/ocis/v2/services/webdav/pkg/command"
webfinger "github.com/owncloud/ocis/v2/services/webfinger/pkg/command"
"github.com/thejerf/suture/v4"
)

var (
Expand Down Expand Up @@ -298,11 +300,16 @@ func NewService(options ...Option) (*Service, error) {
cfg.Sharing.Commons = cfg.Commons
return sharing.Execute(cfg.Sharing)
})
dreg(opts.Config.SSE.Service.Name, func(ctx context.Context, cfg *ociscfg.Config) error {
cfg.SSE.Context = ctx
cfg.SSE.Commons = cfg.Commons
return sse.Execute(cfg.SSE)
})

return s, nil
}

// Start an rpc service. By default the package scope Start will run all default services to provide with a working
// Start a rpc service. By default, the package scope Start will run all default services to provide with a working
// oCIS instance.
func Start(o ...Option) error {
// Start the runtime. Most likely this was called ONLY by the `ocis server` subcommand, but since we cannot protect
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 @@ -122,6 +122,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/sse",
Service: "com.owncloud.sse.sse",
},
{
// reroute oc10 notifications endpoint to userlog service
Endpoint: "/ocs/v2.php/apps/notifications/api/v1/notifications",
Expand Down
37 changes: 37 additions & 0 deletions services/sse/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
SHELL := bash
NAME := sse

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: # CI runs ci-node-generate automatically before this target

.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:
7 changes: 7 additions & 0 deletions services/sse/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# SSE

The `sse` service is responsible for sending sse (Server-Sent Events) to a user. See [What is Server-Sent Events](https://medium.com/yemeksepeti-teknoloji/what-is-server-sent-events-sse-and-how-to-implement-it-904938bffd73) for a simple introduction and examples of server sent events.

## Subscribing

Clients can subscribe to the `/sse` endpoint to be informed by the server when an event happens. The `sse` endpoint will respect language changes of the user without needing to reconnect. Note that SSE has a limitation of six open connections per browser which can be reached if one has opened various tabs of the Web UI pointing to the same Infinite Scale instance.
14 changes: 14 additions & 0 deletions services/sse/cmd/sse/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/sse/pkg/command"
"github.com/owncloud/ocis/v2/services/sse/pkg/config/defaults"
)

func main() {
if err := command.Execute(defaults.DefaultConfig()); err != nil {
os.Exit(1)
}
}
62 changes: 62 additions & 0 deletions services/sse/pkg/command/health.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package command

import (
"fmt"
"net/http"

"github.com/owncloud/ocis/v2/ocis-pkg/log"

"github.com/urfave/cli/v2"

"github.com/owncloud/ocis/v2/ocis-pkg/config/configlog"
"github.com/owncloud/ocis/v2/services/sse/pkg/config"
"github.com/owncloud/ocis/v2/services/sse/pkg/config/parser"
)

// Health is the entrypoint for the health command.
func Health(cfg *config.Config) *cli.Command {
return &cli.Command{
Name: "health",
Usage: "check health status",
Category: "info",
Before: func(c *cli.Context) error {
return configlog.ReturnError(parser.ParseConfig(cfg))
},
Action: func(c *cli.Context) error {
logger := log.NewLogger(
log.Name(cfg.Service.Name),
log.Level(cfg.Log.Level),
log.Pretty(cfg.Log.Pretty),
log.Color(cfg.Log.Color),
log.File(cfg.Log.File),
)

resp, err := http.Get(
fmt.Sprintf(
"http://%s/healthz",
cfg.Debug.Addr,
),
)

if err != nil {
logger.Fatal().
Err(err).
Msg("Failed to request health check")
}

defer resp.Body.Close()

if resp.StatusCode != http.StatusOK {
logger.Fatal().
Int("code", resp.StatusCode).
Msg("Health seems to be in bad state")
}

logger.Debug().
Int("code", resp.StatusCode).
Msg("Health got a good state")

return nil
},
}
}
30 changes: 30 additions & 0 deletions services/sse/pkg/command/root.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package command

import (
"os"

"github.com/urfave/cli/v2"

"github.com/owncloud/ocis/v2/ocis-pkg/clihelper"
"github.com/owncloud/ocis/v2/services/sse/pkg/config"
)

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

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

return app.Run(os.Args)
}
Loading

0 comments on commit 9eb73f0

Please sign in to comment.