-
Notifications
You must be signed in to change notification settings - Fork 183
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: jkoberg <jkoberg@owncloud.com>
- Loading branch information
Showing
31 changed files
with
818 additions
and
0 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
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,5 @@ | ||
Enhancement: Introduce clientlog service | ||
|
||
Add the clientlog service which will send machine readable notifications to clients | ||
|
||
https://github.com/owncloud/ocis/pull/7217 |
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
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,38 @@ | ||
SHELL := bash | ||
NAME := clientlog | ||
|
||
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: |
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 @@ | ||
# Clientlog service | ||
|
||
The `clientlog` service is responsible for composing machine readable notifications for clients | ||
|
||
## The `...log` service ecosystem | ||
|
||
`...log` services (`userlog`, `clientlog`) are responsible for composing notifications for a certain audience. | ||
- `userlog` service translates and adjust messages to be human readable | ||
- `clientlog` service composes machine readable messages so clients can act without needing to query the server | ||
- `sse` service is only responsible for sending these messages. It does not care about their form or language | ||
|
||
## `clientlog` events | ||
|
||
The messages the `clientlog` service sends are meant to be used by clients, not by users. The client might for example be informed that a file is finished postprocessing, so it can make the file available to the user without needing to make another call to the server. |
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/clientlog/pkg/command" | ||
"github.com/owncloud/ocis/v2/services/clientlog/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,18 @@ | ||
package command | ||
|
||
import ( | ||
"github.com/owncloud/ocis/v2/services/clientlog/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 | ||
}, | ||
} | ||
} |
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,34 @@ | ||
package command | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/owncloud/ocis/v2/ocis-pkg/clihelper" | ||
"github.com/owncloud/ocis/v2/services/clientlog/pkg/config" | ||
"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 clientlog command. | ||
func Execute(cfg *config.Config) error { | ||
app := clihelper.DefaultApp(&cli.App{ | ||
Name: "clientlog", | ||
Usage: "starts clientlog service", | ||
Commands: GetCommands(cfg), | ||
}) | ||
|
||
return app.Run(os.Args) | ||
} |
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,137 @@ | ||
package command | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/cs3org/reva/v2/pkg/events" | ||
"github.com/cs3org/reva/v2/pkg/events/stream" | ||
"github.com/cs3org/reva/v2/pkg/rgrpc/todo/pool" | ||
"github.com/oklog/run" | ||
"github.com/owncloud/ocis/v2/ocis-pkg/config/configlog" | ||
"github.com/owncloud/ocis/v2/ocis-pkg/handlers" | ||
"github.com/owncloud/ocis/v2/ocis-pkg/registry" | ||
"github.com/owncloud/ocis/v2/ocis-pkg/service/debug" | ||
"github.com/owncloud/ocis/v2/ocis-pkg/tracing" | ||
"github.com/owncloud/ocis/v2/ocis-pkg/version" | ||
"github.com/owncloud/ocis/v2/services/clientlog/pkg/config" | ||
"github.com/owncloud/ocis/v2/services/clientlog/pkg/config/parser" | ||
"github.com/owncloud/ocis/v2/services/clientlog/pkg/logging" | ||
"github.com/owncloud/ocis/v2/services/clientlog/pkg/metrics" | ||
"github.com/owncloud/ocis/v2/services/clientlog/pkg/service" | ||
"github.com/urfave/cli/v2" | ||
) | ||
|
||
// all events we care about | ||
var _registeredEvents = []events.Unmarshaller{ | ||
events.UploadReady{}, | ||
} | ||
|
||
// Server is the entrypoint for the server command. | ||
func Server(cfg *config.Config) *cli.Command { | ||
return &cli.Command{ | ||
Name: "server", | ||
Usage: fmt.Sprintf("start the %s service without runtime (unsupervised mode)", cfg.Service.Name), | ||
Category: "server", | ||
Before: func(c *cli.Context) error { | ||
return configlog.ReturnFatal(parser.ParseConfig(cfg)) | ||
}, | ||
Action: func(c *cli.Context) error { | ||
logger := logging.Configure(cfg.Service.Name, cfg.Log) | ||
tracerProvider, err := tracing.GetServiceTraceProvider(cfg.Tracing, cfg.Service.Name) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
/* | ||
grpcClient, err := ogrpc.NewClient( | ||
append(ogrpc.GetClientOptions(cfg.GRPCClientTLS), ogrpc.WithTraceProvider(tracerProvider))..., | ||
) | ||
if err != nil { | ||
return err | ||
} | ||
*/ // TODO: remove | ||
|
||
gr := run.Group{} | ||
ctx, cancel := func() (context.Context, context.CancelFunc) { | ||
if cfg.Context == nil { | ||
return context.WithCancel(context.Background()) | ||
} | ||
return context.WithCancel(cfg.Context) | ||
}() | ||
|
||
mtrcs := metrics.New() | ||
mtrcs.BuildInfo.WithLabelValues(version.GetString()).Set(1) | ||
|
||
defer cancel() | ||
|
||
stream, err := stream.NatsFromConfig(cfg.Service.Name, stream.NatsConfig(cfg.Events)) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
tm, err := pool.StringToTLSMode(cfg.GRPCClientTLS.Mode) | ||
if err != nil { | ||
return err | ||
} | ||
gatewaySelector, err := pool.GatewaySelector( | ||
cfg.RevaGateway, | ||
pool.WithTLSCACert(cfg.GRPCClientTLS.CACert), | ||
pool.WithTLSMode(tm), | ||
pool.WithRegistry(registry.GetRegistry()), | ||
pool.WithTracerProvider(tracerProvider), | ||
) | ||
if err != nil { | ||
return fmt.Errorf("could not get reva client selector: %s", err) | ||
} | ||
|
||
{ | ||
svc, err := service.NewClientlogService( | ||
service.Logger(logger), | ||
service.Config(cfg), | ||
service.Stream(stream), | ||
service.GatewaySelector(gatewaySelector), | ||
service.RegisteredEvents(_registeredEvents), | ||
service.TraceProvider(tracerProvider), | ||
) | ||
|
||
if err != nil { | ||
logger.Info().Err(err).Str("transport", "http").Msg("Failed to initialize server") | ||
return err | ||
} | ||
|
||
gr.Add(func() error { | ||
return svc.Run() | ||
}, func(err error) { | ||
logger.Error(). | ||
Str("transport", "http"). | ||
Err(err). | ||
Msg("Shutting down server") | ||
|
||
cancel() | ||
}) | ||
} | ||
|
||
{ | ||
server := debug.NewService( | ||
debug.Logger(logger), | ||
debug.Name(cfg.Service.Name), | ||
debug.Version(version.GetString()), | ||
debug.Address(cfg.Debug.Addr), | ||
debug.Token(cfg.Debug.Token), | ||
debug.Pprof(cfg.Debug.Pprof), | ||
debug.Zpages(cfg.Debug.Zpages), | ||
debug.Health(handlers.Health), | ||
debug.Ready(handlers.Ready), | ||
) | ||
|
||
gr.Add(server.ListenAndServe, func(_ error) { | ||
_ = server.Shutdown(ctx) | ||
cancel() | ||
}) | ||
} | ||
|
||
return gr.Run() | ||
}, | ||
} | ||
} |
Oops, something went wrong.