-
Notifications
You must be signed in to change notification settings - Fork 187
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6992 from fschade/sse-service
enhancement: add sse service skeleton
- Loading branch information
Showing
35 changed files
with
869 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,6 +49,7 @@ protogen/buf.sha1.lock | |
/third-party-licenses | ||
|
||
# misc | ||
/tmp | ||
go.work | ||
go.work.sum | ||
.env | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 >}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" >}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
Oops, something went wrong.