Merge pull request #10163 from fschade/ready-health-checks
Bugfix: Improve Ready and Health Checks
This commit is contained in:
@@ -0,0 +1,117 @@
|
|||||||
|
package handlers
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"maps"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"golang.org/x/sync/errgroup"
|
||||||
|
|
||||||
|
"github.com/owncloud/ocis/v2/ocis-pkg/log"
|
||||||
|
)
|
||||||
|
|
||||||
|
// check is a function that performs a check.
|
||||||
|
type check func(ctx context.Context) error
|
||||||
|
|
||||||
|
// CheckHandlerConfiguration defines the configuration for the CheckHandler.
|
||||||
|
type CheckHandlerConfiguration struct {
|
||||||
|
logger log.Logger
|
||||||
|
checks map[string]check
|
||||||
|
limit int
|
||||||
|
statusFailed int
|
||||||
|
statusSuccess int
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewCheckHandlerConfiguration initializes a new CheckHandlerConfiguration.
|
||||||
|
func NewCheckHandlerConfiguration() CheckHandlerConfiguration {
|
||||||
|
return CheckHandlerConfiguration{
|
||||||
|
checks: make(map[string]check),
|
||||||
|
limit: -1,
|
||||||
|
statusFailed: http.StatusInternalServerError,
|
||||||
|
statusSuccess: http.StatusOK,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// WithLogger sets the logger for the CheckHandlerConfiguration.
|
||||||
|
func (c CheckHandlerConfiguration) WithLogger(l log.Logger) CheckHandlerConfiguration {
|
||||||
|
c.logger = l
|
||||||
|
return c
|
||||||
|
}
|
||||||
|
|
||||||
|
// WithCheck sets a check for the CheckHandlerConfiguration.
|
||||||
|
func (c CheckHandlerConfiguration) WithCheck(name string, f check) CheckHandlerConfiguration {
|
||||||
|
if _, ok := c.checks[name]; ok {
|
||||||
|
c.logger.Panic().Str("check", name).Msg("check already exists")
|
||||||
|
}
|
||||||
|
|
||||||
|
c.checks[name] = f
|
||||||
|
return c
|
||||||
|
}
|
||||||
|
|
||||||
|
// WithLimit limits the number of active goroutines for the checks to at most n
|
||||||
|
func (c CheckHandlerConfiguration) WithLimit(n int) CheckHandlerConfiguration {
|
||||||
|
c.limit = n
|
||||||
|
return c
|
||||||
|
}
|
||||||
|
|
||||||
|
// WithStatusFailed sets the status code for the failed checks.
|
||||||
|
func (c CheckHandlerConfiguration) WithStatusFailed(status int) CheckHandlerConfiguration {
|
||||||
|
c.statusFailed = status
|
||||||
|
return c
|
||||||
|
}
|
||||||
|
|
||||||
|
// WithStatusSuccess sets the status code for the successful checks.
|
||||||
|
func (c CheckHandlerConfiguration) WithStatusSuccess(status int) CheckHandlerConfiguration {
|
||||||
|
c.statusSuccess = status
|
||||||
|
return c
|
||||||
|
}
|
||||||
|
|
||||||
|
// CheckHandler is a http Handler that performs different checks.
|
||||||
|
type CheckHandler struct {
|
||||||
|
conf CheckHandlerConfiguration
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewCheckHandler initializes a new CheckHandler.
|
||||||
|
func NewCheckHandler(c CheckHandlerConfiguration) *CheckHandler {
|
||||||
|
c.checks = maps.Clone(c.checks) // prevent check duplication after initialization
|
||||||
|
return &CheckHandler{
|
||||||
|
conf: c,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddCheck adds a check to the CheckHandler.
|
||||||
|
func (h *CheckHandler) AddCheck(name string, c check) {
|
||||||
|
h.conf.WithCheck(name, c)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *CheckHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
|
g, ctx := errgroup.WithContext(r.Context())
|
||||||
|
g.SetLimit(h.conf.limit)
|
||||||
|
|
||||||
|
for name, check := range h.conf.checks {
|
||||||
|
checker := check
|
||||||
|
checkerName := name
|
||||||
|
g.Go(func() error { // https://go.dev/blog/loopvar-preview per iteration scope since go 1.22
|
||||||
|
if err := checker(ctx); err != nil { // since go 1.22 for loops have a per-iteration scope instead of per-loop scope, no need to pin the check...
|
||||||
|
return fmt.Errorf("'%s': %w", checkerName, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
status := h.conf.statusSuccess
|
||||||
|
if err := g.Wait(); err != nil {
|
||||||
|
status = h.conf.statusFailed
|
||||||
|
h.conf.logger.Error().Err(err).Msg("check failed")
|
||||||
|
}
|
||||||
|
|
||||||
|
w.Header().Set("Content-Type", "text/plain")
|
||||||
|
w.WriteHeader(status)
|
||||||
|
|
||||||
|
if _, err := io.WriteString(w, http.StatusText(status)); err != nil { // io.WriteString should not fail, but if it does, we want to know.
|
||||||
|
h.conf.logger.Panic().Err(err).Msg("failed to write response")
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
package handlers_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/owncloud/ocis/v2/ocis-pkg/handlers"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestCheckHandler_AddCheck(t *testing.T) {
|
||||||
|
c := handlers.NewCheckHandlerConfiguration().WithCheck("shared-check", func(ctx context.Context) error { return nil })
|
||||||
|
|
||||||
|
t.Run("configured checks are unique once added", func(t *testing.T) {
|
||||||
|
defer func() {
|
||||||
|
if r := recover(); r != nil {
|
||||||
|
t.Errorf("checks should be unique, got %v", r)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
h1 := handlers.NewCheckHandler(c)
|
||||||
|
h1.AddCheck("check-with-same-name", func(ctx context.Context) error { return nil })
|
||||||
|
|
||||||
|
h2 := handlers.NewCheckHandler(c)
|
||||||
|
h2.AddCheck("check-with-same-name", func(ctx context.Context) error { return nil })
|
||||||
|
|
||||||
|
fmt.Print(1)
|
||||||
|
})
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
package handlers
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/nats-io/nats.go"
|
||||||
|
)
|
||||||
|
|
||||||
|
// NewNatsCheck checks the reachability of a nats server.
|
||||||
|
func NewNatsCheck(natsCluster string, options ...nats.Option) func(context.Context) error {
|
||||||
|
return func(_ context.Context) error {
|
||||||
|
n, err := nats.Connect(natsCluster, options...)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("could not connect to nats server: %v", err)
|
||||||
|
}
|
||||||
|
defer n.Close()
|
||||||
|
if n.Status() != nats.CONNECTED {
|
||||||
|
return fmt.Errorf("nats server not connected")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
package handlers
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"net"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
// NewTCPCheck returns a check that connects to a given tcp endpoint.
|
||||||
|
func NewTCPCheck(address string) func(ctx context.Context) error {
|
||||||
|
return func(_ context.Context) error {
|
||||||
|
conn, err := net.DialTimeout("tcp", address, 3*time.Second)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = conn.Close()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
package handlers
|
|
||||||
|
|
||||||
import (
|
|
||||||
"io"
|
|
||||||
"net/http"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Health can be used for a health endpoint
|
|
||||||
func Health(w http.ResponseWriter, r *http.Request) {
|
|
||||||
w.Header().Set("Content-Type", "text/plain")
|
|
||||||
w.WriteHeader(http.StatusOK)
|
|
||||||
|
|
||||||
// TODO: check if services are up and running
|
|
||||||
|
|
||||||
_, err := io.WriteString(w, http.StatusText(http.StatusOK))
|
|
||||||
// io.WriteString should not fail but if it does, we want to know.
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Ready can be used as a ready endpoint
|
|
||||||
func Ready(w http.ResponseWriter, r *http.Request) {
|
|
||||||
w.Header().Set("Content-Type", "text/plain")
|
|
||||||
w.WriteHeader(http.StatusOK)
|
|
||||||
|
|
||||||
// TODO: check if services are up and running
|
|
||||||
|
|
||||||
_, err := io.WriteString(w, http.StatusText(http.StatusOK))
|
|
||||||
// io.WriteString should not fail but if it does, we want to know.
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -20,9 +20,9 @@ type Options struct {
|
|||||||
Token string
|
Token string
|
||||||
Pprof bool
|
Pprof bool
|
||||||
Zpages bool
|
Zpages bool
|
||||||
Health func(http.ResponseWriter, *http.Request)
|
Health http.Handler
|
||||||
Ready func(http.ResponseWriter, *http.Request)
|
Ready http.Handler
|
||||||
ConfigDump func(http.ResponseWriter, *http.Request)
|
ConfigDump http.Handler
|
||||||
CorsAllowedOrigins []string
|
CorsAllowedOrigins []string
|
||||||
CorsAllowedMethods []string
|
CorsAllowedMethods []string
|
||||||
CorsAllowedHeaders []string
|
CorsAllowedHeaders []string
|
||||||
@@ -97,21 +97,21 @@ func Zpages(z bool) Option {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Health provides a function to set the health option.
|
// Health provides a function to set the health option.
|
||||||
func Health(h func(http.ResponseWriter, *http.Request)) Option {
|
func Health(h http.Handler) Option {
|
||||||
return func(o *Options) {
|
return func(o *Options) {
|
||||||
o.Health = h
|
o.Health = h
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ready provides a function to set the ready option.
|
// Ready provides a function to set the ready option.
|
||||||
func Ready(r func(http.ResponseWriter, *http.Request)) Option {
|
func Ready(r http.Handler) Option {
|
||||||
return func(o *Options) {
|
return func(o *Options) {
|
||||||
o.Ready = r
|
o.Ready = r
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ConfigDump to be documented.
|
// ConfigDump to be documented.
|
||||||
func ConfigDump(r func(http.ResponseWriter, *http.Request)) Option {
|
func ConfigDump(r http.Handler) Option {
|
||||||
return func(o *Options) {
|
return func(o *Options) {
|
||||||
o.ConfigDump = r
|
o.ConfigDump = r
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,11 +8,12 @@ import (
|
|||||||
|
|
||||||
chimiddleware "github.com/go-chi/chi/v5/middleware"
|
chimiddleware "github.com/go-chi/chi/v5/middleware"
|
||||||
"github.com/justinas/alice"
|
"github.com/justinas/alice"
|
||||||
|
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||||
|
"go.opentelemetry.io/contrib/zpages"
|
||||||
|
|
||||||
"github.com/owncloud/ocis/v2/ocis-pkg/cors"
|
"github.com/owncloud/ocis/v2/ocis-pkg/cors"
|
||||||
"github.com/owncloud/ocis/v2/ocis-pkg/middleware"
|
"github.com/owncloud/ocis/v2/ocis-pkg/middleware"
|
||||||
graphMiddleware "github.com/owncloud/ocis/v2/services/graph/pkg/middleware"
|
graphMiddleware "github.com/owncloud/ocis/v2/services/graph/pkg/middleware"
|
||||||
"github.com/prometheus/client_golang/prometheus/promhttp"
|
|
||||||
"go.opentelemetry.io/contrib/zpages"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewService initializes a new debug service.
|
// NewService initializes a new debug service.
|
||||||
@@ -28,11 +29,16 @@ func NewService(opts ...Option) *http.Server {
|
|||||||
promhttp.Handler(),
|
promhttp.Handler(),
|
||||||
))
|
))
|
||||||
|
|
||||||
mux.HandleFunc("/healthz", dopts.Health)
|
if dopts.Health != nil {
|
||||||
mux.HandleFunc("/readyz", dopts.Ready)
|
mux.Handle("/healthz", dopts.Health)
|
||||||
|
}
|
||||||
|
|
||||||
|
if dopts.Ready != nil {
|
||||||
|
mux.Handle("/readyz", dopts.Ready)
|
||||||
|
}
|
||||||
|
|
||||||
if dopts.ConfigDump != nil {
|
if dopts.ConfigDump != nil {
|
||||||
mux.HandleFunc("/config", dopts.ConfigDump)
|
mux.Handle("/config", dopts.ConfigDump)
|
||||||
}
|
}
|
||||||
|
|
||||||
if dopts.Pprof {
|
if dopts.Pprof {
|
||||||
|
|||||||
@@ -1,29 +0,0 @@
|
|||||||
package shared
|
|
||||||
|
|
||||||
import "net"
|
|
||||||
|
|
||||||
// Check is a single health-check
|
|
||||||
type Check func() error
|
|
||||||
|
|
||||||
// RunChecklist runs all the given checks
|
|
||||||
func RunChecklist(checks ...Check) error {
|
|
||||||
for _, c := range checks {
|
|
||||||
err := c()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// TCPConnect connects to a given tcp endpoint
|
|
||||||
func TCPConnect(host string) Check {
|
|
||||||
return func() error {
|
|
||||||
conn, err := net.Dial("tcp", host)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
defer conn.Close()
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -9,10 +9,11 @@ import (
|
|||||||
"github.com/cs3org/reva/v2/pkg/rgrpc/todo/pool"
|
"github.com/cs3org/reva/v2/pkg/rgrpc/todo/pool"
|
||||||
"github.com/cs3org/reva/v2/pkg/store"
|
"github.com/cs3org/reva/v2/pkg/store"
|
||||||
"github.com/oklog/run"
|
"github.com/oklog/run"
|
||||||
|
"github.com/urfave/cli/v2"
|
||||||
|
microstore "go-micro.dev/v4/store"
|
||||||
|
|
||||||
"github.com/owncloud/ocis/v2/ocis-pkg/config/configlog"
|
"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/registry"
|
||||||
"github.com/owncloud/ocis/v2/ocis-pkg/service/debug"
|
|
||||||
ogrpc "github.com/owncloud/ocis/v2/ocis-pkg/service/grpc"
|
ogrpc "github.com/owncloud/ocis/v2/ocis-pkg/service/grpc"
|
||||||
"github.com/owncloud/ocis/v2/ocis-pkg/tracing"
|
"github.com/owncloud/ocis/v2/ocis-pkg/tracing"
|
||||||
"github.com/owncloud/ocis/v2/ocis-pkg/version"
|
"github.com/owncloud/ocis/v2/ocis-pkg/version"
|
||||||
@@ -22,9 +23,8 @@ import (
|
|||||||
"github.com/owncloud/ocis/v2/services/activitylog/pkg/config/parser"
|
"github.com/owncloud/ocis/v2/services/activitylog/pkg/config/parser"
|
||||||
"github.com/owncloud/ocis/v2/services/activitylog/pkg/logging"
|
"github.com/owncloud/ocis/v2/services/activitylog/pkg/logging"
|
||||||
"github.com/owncloud/ocis/v2/services/activitylog/pkg/metrics"
|
"github.com/owncloud/ocis/v2/services/activitylog/pkg/metrics"
|
||||||
|
"github.com/owncloud/ocis/v2/services/activitylog/pkg/server/debug"
|
||||||
"github.com/owncloud/ocis/v2/services/activitylog/pkg/server/http"
|
"github.com/owncloud/ocis/v2/services/activitylog/pkg/server/http"
|
||||||
"github.com/urfave/cli/v2"
|
|
||||||
microstore "go-micro.dev/v4/store"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var _registeredEvents = []events.Unmarshaller{
|
var _registeredEvents = []events.Unmarshaller{
|
||||||
@@ -120,7 +120,6 @@ func Server(cfg *config.Config) *cli.Command {
|
|||||||
http.Context(ctx), // NOTE: not passing this "option" leads to a panic in go-micro
|
http.Context(ctx), // NOTE: not passing this "option" leads to a panic in go-micro
|
||||||
http.TraceProvider(tracerProvider),
|
http.TraceProvider(tracerProvider),
|
||||||
http.Stream(evStream),
|
http.Stream(evStream),
|
||||||
http.RegisteredEvents(_registeredEvents),
|
|
||||||
http.Store(evStore),
|
http.Store(evStore),
|
||||||
http.GatewaySelector(gatewaySelector),
|
http.GatewaySelector(gatewaySelector),
|
||||||
http.HistoryClient(hClient),
|
http.HistoryClient(hClient),
|
||||||
@@ -146,20 +145,18 @@ func Server(cfg *config.Config) *cli.Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
server := debug.NewService(
|
debugServer, err := debug.Server(
|
||||||
debug.Logger(logger),
|
debug.Logger(logger),
|
||||||
debug.Name(cfg.Service.Name),
|
debug.Context(ctx),
|
||||||
debug.Version(version.GetString()),
|
debug.Config(cfg),
|
||||||
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),
|
|
||||||
)
|
)
|
||||||
|
if err != nil {
|
||||||
|
logger.Info().Err(err).Str("server", "debug").Msg("Failed to initialize server")
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
gr.Add(server.ListenAndServe, func(_ error) {
|
gr.Add(debugServer.ListenAndServe, func(_ error) {
|
||||||
_ = server.Shutdown(ctx)
|
_ = debugServer.Shutdown(ctx)
|
||||||
cancel()
|
cancel()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,50 @@
|
|||||||
|
package debug
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"github.com/owncloud/ocis/v2/ocis-pkg/log"
|
||||||
|
"github.com/owncloud/ocis/v2/services/activitylog/pkg/config"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Option defines a single option function.
|
||||||
|
type Option func(o *Options)
|
||||||
|
|
||||||
|
// Options defines the available options for this package.
|
||||||
|
type Options struct {
|
||||||
|
Logger log.Logger
|
||||||
|
Context context.Context
|
||||||
|
Config *config.Config
|
||||||
|
}
|
||||||
|
|
||||||
|
// newOptions initializes the available default options.
|
||||||
|
func newOptions(opts ...Option) Options {
|
||||||
|
opt := Options{}
|
||||||
|
|
||||||
|
for _, o := range opts {
|
||||||
|
o(&opt)
|
||||||
|
}
|
||||||
|
|
||||||
|
return opt
|
||||||
|
}
|
||||||
|
|
||||||
|
// Logger provides a function to set the logger option.
|
||||||
|
func Logger(val log.Logger) Option {
|
||||||
|
return func(o *Options) {
|
||||||
|
o.Logger = val
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Context provides a function to set the context option.
|
||||||
|
func Context(val context.Context) Option {
|
||||||
|
return func(o *Options) {
|
||||||
|
o.Context = val
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Config provides a function to set the config option.
|
||||||
|
func Config(val *config.Config) Option {
|
||||||
|
return func(o *Options) {
|
||||||
|
o.Config = val
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
package debug
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/owncloud/ocis/v2/ocis-pkg/handlers"
|
||||||
|
"github.com/owncloud/ocis/v2/ocis-pkg/service/debug"
|
||||||
|
"github.com/owncloud/ocis/v2/ocis-pkg/version"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Server initializes the debug service and server.
|
||||||
|
func Server(opts ...Option) (*http.Server, error) {
|
||||||
|
options := newOptions(opts...)
|
||||||
|
|
||||||
|
healthHandler := handlers.NewCheckHandler(
|
||||||
|
handlers.NewCheckHandlerConfiguration().
|
||||||
|
WithLogger(options.Logger),
|
||||||
|
)
|
||||||
|
|
||||||
|
readyHandler := handlers.NewCheckHandler(
|
||||||
|
handlers.NewCheckHandlerConfiguration().
|
||||||
|
WithLogger(options.Logger).
|
||||||
|
WithCheck("nats reachability", handlers.NewNatsCheck(options.Config.Events.Cluster)),
|
||||||
|
)
|
||||||
|
|
||||||
|
return debug.NewService(
|
||||||
|
debug.Logger(options.Logger),
|
||||||
|
debug.Name(options.Config.Service.Name),
|
||||||
|
debug.Version(version.GetString()),
|
||||||
|
debug.Address(options.Config.Debug.Addr),
|
||||||
|
debug.Token(options.Config.Debug.Token),
|
||||||
|
debug.Pprof(options.Config.Debug.Pprof),
|
||||||
|
debug.Zpages(options.Config.Debug.Zpages),
|
||||||
|
debug.Health(healthHandler),
|
||||||
|
debug.Ready(readyHandler),
|
||||||
|
), nil
|
||||||
|
}
|
||||||
@@ -5,16 +5,15 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/oklog/run"
|
"github.com/oklog/run"
|
||||||
|
"github.com/urfave/cli/v2"
|
||||||
|
|
||||||
"github.com/owncloud/ocis/v2/ocis-pkg/config/configlog"
|
"github.com/owncloud/ocis/v2/ocis-pkg/config/configlog"
|
||||||
"github.com/owncloud/ocis/v2/ocis-pkg/handlers"
|
|
||||||
"github.com/owncloud/ocis/v2/ocis-pkg/log"
|
"github.com/owncloud/ocis/v2/ocis-pkg/log"
|
||||||
"github.com/owncloud/ocis/v2/ocis-pkg/service/debug"
|
|
||||||
"github.com/owncloud/ocis/v2/ocis-pkg/tracing"
|
"github.com/owncloud/ocis/v2/ocis-pkg/tracing"
|
||||||
"github.com/owncloud/ocis/v2/ocis-pkg/version"
|
|
||||||
"github.com/owncloud/ocis/v2/services/antivirus/pkg/config"
|
"github.com/owncloud/ocis/v2/services/antivirus/pkg/config"
|
||||||
"github.com/owncloud/ocis/v2/services/antivirus/pkg/config/parser"
|
"github.com/owncloud/ocis/v2/services/antivirus/pkg/config/parser"
|
||||||
|
"github.com/owncloud/ocis/v2/services/antivirus/pkg/server/debug"
|
||||||
"github.com/owncloud/ocis/v2/services/antivirus/pkg/service"
|
"github.com/owncloud/ocis/v2/services/antivirus/pkg/service"
|
||||||
"github.com/urfave/cli/v2"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Server is the entrypoint for the server command.
|
// Server is the entrypoint for the server command.
|
||||||
@@ -55,20 +54,18 @@ func Server(cfg *config.Config) *cli.Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
server := debug.NewService(
|
debugServer, err := debug.Server(
|
||||||
debug.Logger(logger),
|
debug.Logger(logger),
|
||||||
debug.Name(cfg.Service.Name),
|
debug.Context(ctx),
|
||||||
debug.Version(version.GetString()),
|
debug.Config(cfg),
|
||||||
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),
|
|
||||||
)
|
)
|
||||||
|
if err != nil {
|
||||||
|
logger.Info().Err(err).Str("server", "debug").Msg("Failed to initialize server")
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
gr.Add(server.ListenAndServe, func(_ error) {
|
gr.Add(debugServer.ListenAndServe, func(_ error) {
|
||||||
_ = server.Shutdown(ctx)
|
_ = debugServer.Shutdown(ctx)
|
||||||
cancel()
|
cancel()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,50 @@
|
|||||||
|
package debug
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"github.com/owncloud/ocis/v2/ocis-pkg/log"
|
||||||
|
"github.com/owncloud/ocis/v2/services/antivirus/pkg/config"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Option defines a single option function.
|
||||||
|
type Option func(o *Options)
|
||||||
|
|
||||||
|
// Options defines the available options for this package.
|
||||||
|
type Options struct {
|
||||||
|
Logger log.Logger
|
||||||
|
Context context.Context
|
||||||
|
Config *config.Config
|
||||||
|
}
|
||||||
|
|
||||||
|
// newOptions initializes the available default options.
|
||||||
|
func newOptions(opts ...Option) Options {
|
||||||
|
opt := Options{}
|
||||||
|
|
||||||
|
for _, o := range opts {
|
||||||
|
o(&opt)
|
||||||
|
}
|
||||||
|
|
||||||
|
return opt
|
||||||
|
}
|
||||||
|
|
||||||
|
// Logger provides a function to set the logger option.
|
||||||
|
func Logger(val log.Logger) Option {
|
||||||
|
return func(o *Options) {
|
||||||
|
o.Logger = val
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Context provides a function to set the context option.
|
||||||
|
func Context(val context.Context) Option {
|
||||||
|
return func(o *Options) {
|
||||||
|
o.Context = val
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Config provides a function to set the config option.
|
||||||
|
func Config(val *config.Config) Option {
|
||||||
|
return func(o *Options) {
|
||||||
|
o.Config = val
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,51 @@
|
|||||||
|
package debug
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/dutchcoders/go-clamd"
|
||||||
|
"github.com/owncloud/ocis/v2/ocis-pkg/handlers"
|
||||||
|
"github.com/owncloud/ocis/v2/ocis-pkg/service/debug"
|
||||||
|
"github.com/owncloud/ocis/v2/ocis-pkg/version"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Server initializes the debug service and server.
|
||||||
|
func Server(opts ...Option) (*http.Server, error) {
|
||||||
|
options := newOptions(opts...)
|
||||||
|
|
||||||
|
healthHandler := handlers.NewCheckHandler(
|
||||||
|
handlers.NewCheckHandlerConfiguration().
|
||||||
|
WithLogger(options.Logger),
|
||||||
|
)
|
||||||
|
|
||||||
|
readyHandler := handlers.NewCheckHandler(
|
||||||
|
handlers.NewCheckHandlerConfiguration().
|
||||||
|
WithLogger(options.Logger).
|
||||||
|
WithCheck("nats reachability", handlers.NewNatsCheck(options.Config.Events.Cluster)).
|
||||||
|
WithCheck("antivirus reachability", func(ctx context.Context) error {
|
||||||
|
cfg := options.Config
|
||||||
|
switch cfg.Scanner.Type {
|
||||||
|
default:
|
||||||
|
return errors.New("no antivirus configured")
|
||||||
|
case "clamav":
|
||||||
|
return clamd.NewClamd(cfg.Scanner.ClamAV.Socket).Ping()
|
||||||
|
case "icap":
|
||||||
|
return handlers.NewTCPCheck(cfg.Scanner.ICAP.URL)(ctx)
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
|
||||||
|
return debug.NewService(
|
||||||
|
debug.Logger(options.Logger),
|
||||||
|
debug.Name(options.Config.Service.Name),
|
||||||
|
debug.Version(version.GetString()),
|
||||||
|
debug.Address(options.Config.Debug.Addr),
|
||||||
|
debug.Token(options.Config.Debug.Token),
|
||||||
|
debug.Pprof(options.Config.Debug.Pprof),
|
||||||
|
debug.Zpages(options.Config.Debug.Zpages),
|
||||||
|
debug.Health(healthHandler),
|
||||||
|
debug.Ready(readyHandler),
|
||||||
|
), nil
|
||||||
|
}
|
||||||
@@ -1,18 +1,22 @@
|
|||||||
package debug
|
package debug
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/owncloud/ocis/v2/ocis-pkg/handlers"
|
||||||
"github.com/owncloud/ocis/v2/ocis-pkg/service/debug"
|
"github.com/owncloud/ocis/v2/ocis-pkg/service/debug"
|
||||||
"github.com/owncloud/ocis/v2/ocis-pkg/version"
|
"github.com/owncloud/ocis/v2/ocis-pkg/version"
|
||||||
"github.com/owncloud/ocis/v2/services/app-provider/pkg/config"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Server initializes the debug service and server.
|
// Server initializes the debug service and server.
|
||||||
func Server(opts ...Option) (*http.Server, error) {
|
func Server(opts ...Option) (*http.Server, error) {
|
||||||
options := newOptions(opts...)
|
options := newOptions(opts...)
|
||||||
|
|
||||||
|
checkHandler := handlers.NewCheckHandler(
|
||||||
|
handlers.NewCheckHandlerConfiguration().
|
||||||
|
WithLogger(options.Logger),
|
||||||
|
)
|
||||||
|
|
||||||
return debug.NewService(
|
return debug.NewService(
|
||||||
debug.Logger(options.Logger),
|
debug.Logger(options.Logger),
|
||||||
debug.Name(options.Config.Service.Name),
|
debug.Name(options.Config.Service.Name),
|
||||||
@@ -21,43 +25,11 @@ func Server(opts ...Option) (*http.Server, error) {
|
|||||||
debug.Token(options.Config.Debug.Token),
|
debug.Token(options.Config.Debug.Token),
|
||||||
debug.Pprof(options.Config.Debug.Pprof),
|
debug.Pprof(options.Config.Debug.Pprof),
|
||||||
debug.Zpages(options.Config.Debug.Zpages),
|
debug.Zpages(options.Config.Debug.Zpages),
|
||||||
debug.Health(health(options.Config)),
|
debug.Health(checkHandler),
|
||||||
debug.Ready(ready(options.Config)),
|
debug.Ready(checkHandler),
|
||||||
//debug.CorsAllowedOrigins(options.Config.HTTP.CORS.AllowedOrigins),
|
//debug.CorsAllowedOrigins(options.Config.HTTP.CORS.AllowedOrigins),
|
||||||
//debug.CorsAllowedMethods(options.Config.HTTP.CORS.AllowedMethods),
|
//debug.CorsAllowedMethods(options.Config.HTTP.CORS.AllowedMethods),
|
||||||
//debug.CorsAllowedHeaders(options.Config.HTTP.CORS.AllowedHeaders),
|
//debug.CorsAllowedHeaders(options.Config.HTTP.CORS.AllowedHeaders),
|
||||||
//debug.CorsAllowCredentials(options.Config.HTTP.CORS.AllowCredentials),
|
//debug.CorsAllowCredentials(options.Config.HTTP.CORS.AllowCredentials),
|
||||||
), nil
|
), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// health implements the health check.
|
|
||||||
func health(cfg *config.Config) func(http.ResponseWriter, *http.Request) {
|
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
w.Header().Set("Content-Type", "text/plain")
|
|
||||||
w.WriteHeader(http.StatusOK)
|
|
||||||
|
|
||||||
// TODO: check if services are up and running
|
|
||||||
|
|
||||||
_, err := io.WriteString(w, http.StatusText(http.StatusOK))
|
|
||||||
// io.WriteString should not fail but if it does, we want to know.
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ready implements the ready check.
|
|
||||||
func ready(cfg *config.Config) func(http.ResponseWriter, *http.Request) {
|
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
w.Header().Set("Content-Type", "text/plain")
|
|
||||||
w.WriteHeader(http.StatusOK)
|
|
||||||
|
|
||||||
// TODO: check if services are up and running
|
|
||||||
|
|
||||||
_, err := io.WriteString(w, http.StatusText(http.StatusOK))
|
|
||||||
// io.WriteString should not fail but if it does, we want to know.
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -73,6 +73,7 @@ func Server(cfg *config.Config) *cli.Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
gr.Add(debugServer.ListenAndServe, func(_ error) {
|
gr.Add(debugServer.ListenAndServe, func(_ error) {
|
||||||
|
_ = debugServer.Shutdown(ctx)
|
||||||
cancel()
|
cancel()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -1,18 +1,22 @@
|
|||||||
package debug
|
package debug
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/owncloud/ocis/v2/ocis-pkg/handlers"
|
||||||
"github.com/owncloud/ocis/v2/ocis-pkg/service/debug"
|
"github.com/owncloud/ocis/v2/ocis-pkg/service/debug"
|
||||||
"github.com/owncloud/ocis/v2/ocis-pkg/version"
|
"github.com/owncloud/ocis/v2/ocis-pkg/version"
|
||||||
"github.com/owncloud/ocis/v2/services/app-registry/pkg/config"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Server initializes the debug service and server.
|
// Server initializes the debug service and server.
|
||||||
func Server(opts ...Option) (*http.Server, error) {
|
func Server(opts ...Option) (*http.Server, error) {
|
||||||
options := newOptions(opts...)
|
options := newOptions(opts...)
|
||||||
|
|
||||||
|
checkHandler := handlers.NewCheckHandler(
|
||||||
|
handlers.NewCheckHandlerConfiguration().
|
||||||
|
WithLogger(options.Logger),
|
||||||
|
)
|
||||||
|
|
||||||
return debug.NewService(
|
return debug.NewService(
|
||||||
debug.Logger(options.Logger),
|
debug.Logger(options.Logger),
|
||||||
debug.Name(options.Config.Service.Name),
|
debug.Name(options.Config.Service.Name),
|
||||||
@@ -21,43 +25,11 @@ func Server(opts ...Option) (*http.Server, error) {
|
|||||||
debug.Token(options.Config.Debug.Token),
|
debug.Token(options.Config.Debug.Token),
|
||||||
debug.Pprof(options.Config.Debug.Pprof),
|
debug.Pprof(options.Config.Debug.Pprof),
|
||||||
debug.Zpages(options.Config.Debug.Zpages),
|
debug.Zpages(options.Config.Debug.Zpages),
|
||||||
debug.Health(health(options.Config)),
|
debug.Health(checkHandler),
|
||||||
debug.Ready(ready(options.Config)),
|
debug.Ready(checkHandler),
|
||||||
//debug.CorsAllowedOrigins(options.Config.HTTP.CORS.AllowedOrigins),
|
//debug.CorsAllowedOrigins(options.Config.HTTP.CORS.AllowedOrigins),
|
||||||
//debug.CorsAllowedMethods(options.Config.HTTP.CORS.AllowedMethods),
|
//debug.CorsAllowedMethods(options.Config.HTTP.CORS.AllowedMethods),
|
||||||
//debug.CorsAllowedHeaders(options.Config.HTTP.CORS.AllowedHeaders),
|
//debug.CorsAllowedHeaders(options.Config.HTTP.CORS.AllowedHeaders),
|
||||||
//debug.CorsAllowCredentials(options.Config.HTTP.CORS.AllowCredentials),
|
//debug.CorsAllowCredentials(options.Config.HTTP.CORS.AllowCredentials),
|
||||||
), nil
|
), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// health implements the health check.
|
|
||||||
func health(cfg *config.Config) func(http.ResponseWriter, *http.Request) {
|
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
w.Header().Set("Content-Type", "text/plain")
|
|
||||||
w.WriteHeader(http.StatusOK)
|
|
||||||
|
|
||||||
// TODO: check if services are up and running
|
|
||||||
|
|
||||||
_, err := io.WriteString(w, http.StatusText(http.StatusOK))
|
|
||||||
// io.WriteString should not fail but if it does, we want to know.
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ready implements the ready check.
|
|
||||||
func ready(cfg *config.Config) func(http.ResponseWriter, *http.Request) {
|
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
w.Header().Set("Content-Type", "text/plain")
|
|
||||||
w.WriteHeader(http.StatusOK)
|
|
||||||
|
|
||||||
// TODO: check if services are up and running
|
|
||||||
|
|
||||||
_, err := io.WriteString(w, http.StatusText(http.StatusOK))
|
|
||||||
// io.WriteString should not fail but if it does, we want to know.
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -7,16 +7,15 @@ import (
|
|||||||
"github.com/cs3org/reva/v2/pkg/events"
|
"github.com/cs3org/reva/v2/pkg/events"
|
||||||
"github.com/cs3org/reva/v2/pkg/events/stream"
|
"github.com/cs3org/reva/v2/pkg/events/stream"
|
||||||
"github.com/oklog/run"
|
"github.com/oklog/run"
|
||||||
|
"github.com/urfave/cli/v2"
|
||||||
|
|
||||||
"github.com/owncloud/ocis/v2/ocis-pkg/config/configlog"
|
"github.com/owncloud/ocis/v2/ocis-pkg/config/configlog"
|
||||||
"github.com/owncloud/ocis/v2/ocis-pkg/handlers"
|
|
||||||
"github.com/owncloud/ocis/v2/ocis-pkg/service/debug"
|
|
||||||
"github.com/owncloud/ocis/v2/ocis-pkg/version"
|
|
||||||
"github.com/owncloud/ocis/v2/services/audit/pkg/config"
|
"github.com/owncloud/ocis/v2/services/audit/pkg/config"
|
||||||
"github.com/owncloud/ocis/v2/services/audit/pkg/config/parser"
|
"github.com/owncloud/ocis/v2/services/audit/pkg/config/parser"
|
||||||
"github.com/owncloud/ocis/v2/services/audit/pkg/logging"
|
"github.com/owncloud/ocis/v2/services/audit/pkg/logging"
|
||||||
|
"github.com/owncloud/ocis/v2/services/audit/pkg/server/debug"
|
||||||
svc "github.com/owncloud/ocis/v2/services/audit/pkg/service"
|
svc "github.com/owncloud/ocis/v2/services/audit/pkg/service"
|
||||||
"github.com/owncloud/ocis/v2/services/audit/pkg/types"
|
"github.com/owncloud/ocis/v2/services/audit/pkg/types"
|
||||||
"github.com/urfave/cli/v2"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Server is the entrypoint for the server command.
|
// Server is the entrypoint for the server command.
|
||||||
@@ -57,20 +56,18 @@ func Server(cfg *config.Config) *cli.Command {
|
|||||||
})
|
})
|
||||||
|
|
||||||
{
|
{
|
||||||
server := debug.NewService(
|
debugServer, err := debug.Server(
|
||||||
debug.Logger(logger),
|
debug.Logger(logger),
|
||||||
debug.Name(cfg.Service.Name),
|
debug.Context(ctx),
|
||||||
debug.Version(version.GetString()),
|
debug.Config(cfg),
|
||||||
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),
|
|
||||||
)
|
)
|
||||||
|
if err != nil {
|
||||||
|
logger.Info().Err(err).Str("server", "debug").Msg("Failed to initialize server")
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
gr.Add(server.ListenAndServe, func(_ error) {
|
gr.Add(debugServer.ListenAndServe, func(_ error) {
|
||||||
_ = server.Shutdown(ctx)
|
_ = debugServer.Shutdown(ctx)
|
||||||
cancel()
|
cancel()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,50 @@
|
|||||||
|
package debug
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"github.com/owncloud/ocis/v2/ocis-pkg/log"
|
||||||
|
"github.com/owncloud/ocis/v2/services/audit/pkg/config"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Option defines a single option function.
|
||||||
|
type Option func(o *Options)
|
||||||
|
|
||||||
|
// Options defines the available options for this package.
|
||||||
|
type Options struct {
|
||||||
|
Logger log.Logger
|
||||||
|
Context context.Context
|
||||||
|
Config *config.Config
|
||||||
|
}
|
||||||
|
|
||||||
|
// newOptions initializes the available default options.
|
||||||
|
func newOptions(opts ...Option) Options {
|
||||||
|
opt := Options{}
|
||||||
|
|
||||||
|
for _, o := range opts {
|
||||||
|
o(&opt)
|
||||||
|
}
|
||||||
|
|
||||||
|
return opt
|
||||||
|
}
|
||||||
|
|
||||||
|
// Logger provides a function to set the logger option.
|
||||||
|
func Logger(val log.Logger) Option {
|
||||||
|
return func(o *Options) {
|
||||||
|
o.Logger = val
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Context provides a function to set the context option.
|
||||||
|
func Context(val context.Context) Option {
|
||||||
|
return func(o *Options) {
|
||||||
|
o.Context = val
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Config provides a function to set the config option.
|
||||||
|
func Config(val *config.Config) Option {
|
||||||
|
return func(o *Options) {
|
||||||
|
o.Config = val
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
package debug
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/owncloud/ocis/v2/ocis-pkg/handlers"
|
||||||
|
"github.com/owncloud/ocis/v2/ocis-pkg/service/debug"
|
||||||
|
"github.com/owncloud/ocis/v2/ocis-pkg/version"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Server initializes the debug service and server.
|
||||||
|
func Server(opts ...Option) (*http.Server, error) {
|
||||||
|
options := newOptions(opts...)
|
||||||
|
|
||||||
|
checkHandler := handlers.NewCheckHandler(
|
||||||
|
handlers.NewCheckHandlerConfiguration().
|
||||||
|
WithLogger(options.Logger),
|
||||||
|
)
|
||||||
|
|
||||||
|
return debug.NewService(
|
||||||
|
debug.Logger(options.Logger),
|
||||||
|
debug.Name(options.Config.Service.Name),
|
||||||
|
debug.Version(version.GetString()),
|
||||||
|
debug.Address(options.Config.Debug.Addr),
|
||||||
|
debug.Token(options.Config.Debug.Token),
|
||||||
|
debug.Pprof(options.Config.Debug.Pprof),
|
||||||
|
debug.Zpages(options.Config.Debug.Zpages),
|
||||||
|
debug.Health(checkHandler),
|
||||||
|
debug.Ready(checkHandler),
|
||||||
|
), nil
|
||||||
|
}
|
||||||
@@ -82,6 +82,7 @@ func Server(cfg *config.Config) *cli.Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
gr.Add(debugServer.ListenAndServe, func(_ error) {
|
gr.Add(debugServer.ListenAndServe, func(_ error) {
|
||||||
|
_ = debugServer.Shutdown(ctx)
|
||||||
cancel()
|
cancel()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -1,18 +1,22 @@
|
|||||||
package debug
|
package debug
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/owncloud/ocis/v2/ocis-pkg/handlers"
|
||||||
"github.com/owncloud/ocis/v2/ocis-pkg/service/debug"
|
"github.com/owncloud/ocis/v2/ocis-pkg/service/debug"
|
||||||
"github.com/owncloud/ocis/v2/ocis-pkg/version"
|
"github.com/owncloud/ocis/v2/ocis-pkg/version"
|
||||||
"github.com/owncloud/ocis/v2/services/auth-app/pkg/config"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Server initializes the debug service and server.
|
// Server initializes the debug service and server.
|
||||||
func Server(opts ...Option) (*http.Server, error) {
|
func Server(opts ...Option) (*http.Server, error) {
|
||||||
options := newOptions(opts...)
|
options := newOptions(opts...)
|
||||||
|
|
||||||
|
checkHandler := handlers.NewCheckHandler(
|
||||||
|
handlers.NewCheckHandlerConfiguration().
|
||||||
|
WithLogger(options.Logger),
|
||||||
|
)
|
||||||
|
|
||||||
return debug.NewService(
|
return debug.NewService(
|
||||||
debug.Logger(options.Logger),
|
debug.Logger(options.Logger),
|
||||||
debug.Name(options.Config.Service.Name),
|
debug.Name(options.Config.Service.Name),
|
||||||
@@ -21,43 +25,11 @@ func Server(opts ...Option) (*http.Server, error) {
|
|||||||
debug.Token(options.Config.Debug.Token),
|
debug.Token(options.Config.Debug.Token),
|
||||||
debug.Pprof(options.Config.Debug.Pprof),
|
debug.Pprof(options.Config.Debug.Pprof),
|
||||||
debug.Zpages(options.Config.Debug.Zpages),
|
debug.Zpages(options.Config.Debug.Zpages),
|
||||||
debug.Health(health(options.Config)),
|
debug.Health(checkHandler),
|
||||||
debug.Ready(ready(options.Config)),
|
debug.Ready(checkHandler),
|
||||||
//debug.CorsAllowedOrigins(options.Config.HTTP.CORS.AllowedOrigins),
|
//debug.CorsAllowedOrigins(options.Config.HTTP.CORS.AllowedOrigins),
|
||||||
//debug.CorsAllowedMethods(options.Config.HTTP.CORS.AllowedMethods),
|
//debug.CorsAllowedMethods(options.Config.HTTP.CORS.AllowedMethods),
|
||||||
//debug.CorsAllowedHeaders(options.Config.HTTP.CORS.AllowedHeaders),
|
//debug.CorsAllowedHeaders(options.Config.HTTP.CORS.AllowedHeaders),
|
||||||
//debug.CorsAllowCredentials(options.Config.HTTP.CORS.AllowCredentials),
|
//debug.CorsAllowCredentials(options.Config.HTTP.CORS.AllowCredentials),
|
||||||
), nil
|
), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// health implements the health check.
|
|
||||||
func health(_ *config.Config) func(http.ResponseWriter, *http.Request) {
|
|
||||||
return func(w http.ResponseWriter, _ *http.Request) {
|
|
||||||
w.Header().Set("Content-Type", "text/plain")
|
|
||||||
w.WriteHeader(http.StatusOK)
|
|
||||||
|
|
||||||
// TODO: check if services are up and running
|
|
||||||
|
|
||||||
_, err := io.WriteString(w, http.StatusText(http.StatusOK))
|
|
||||||
// io.WriteString should not fail but if it does, we want to know.
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ready implements the ready check.
|
|
||||||
func ready(_ *config.Config) func(http.ResponseWriter, *http.Request) {
|
|
||||||
return func(w http.ResponseWriter, _ *http.Request) {
|
|
||||||
w.Header().Set("Content-Type", "text/plain")
|
|
||||||
w.WriteHeader(http.StatusOK)
|
|
||||||
|
|
||||||
// TODO: check if services are up and running
|
|
||||||
|
|
||||||
_, err := io.WriteString(w, http.StatusText(http.StatusOK))
|
|
||||||
// io.WriteString should not fail but if it does, we want to know.
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -87,6 +87,7 @@ func Server(cfg *config.Config) *cli.Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
gr.Add(debugServer.ListenAndServe, func(_ error) {
|
gr.Add(debugServer.ListenAndServe, func(_ error) {
|
||||||
|
_ = debugServer.Shutdown(ctx)
|
||||||
cancel()
|
cancel()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -1,18 +1,22 @@
|
|||||||
package debug
|
package debug
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/owncloud/ocis/v2/ocis-pkg/handlers"
|
||||||
"github.com/owncloud/ocis/v2/ocis-pkg/service/debug"
|
"github.com/owncloud/ocis/v2/ocis-pkg/service/debug"
|
||||||
"github.com/owncloud/ocis/v2/ocis-pkg/version"
|
"github.com/owncloud/ocis/v2/ocis-pkg/version"
|
||||||
"github.com/owncloud/ocis/v2/services/auth-basic/pkg/config"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Server initializes the debug service and server.
|
// Server initializes the debug service and server.
|
||||||
func Server(opts ...Option) (*http.Server, error) {
|
func Server(opts ...Option) (*http.Server, error) {
|
||||||
options := newOptions(opts...)
|
options := newOptions(opts...)
|
||||||
|
|
||||||
|
checkHandler := handlers.NewCheckHandler(
|
||||||
|
handlers.NewCheckHandlerConfiguration().
|
||||||
|
WithLogger(options.Logger),
|
||||||
|
)
|
||||||
|
|
||||||
return debug.NewService(
|
return debug.NewService(
|
||||||
debug.Logger(options.Logger),
|
debug.Logger(options.Logger),
|
||||||
debug.Name(options.Config.Service.Name),
|
debug.Name(options.Config.Service.Name),
|
||||||
@@ -21,43 +25,11 @@ func Server(opts ...Option) (*http.Server, error) {
|
|||||||
debug.Token(options.Config.Debug.Token),
|
debug.Token(options.Config.Debug.Token),
|
||||||
debug.Pprof(options.Config.Debug.Pprof),
|
debug.Pprof(options.Config.Debug.Pprof),
|
||||||
debug.Zpages(options.Config.Debug.Zpages),
|
debug.Zpages(options.Config.Debug.Zpages),
|
||||||
debug.Health(health(options.Config)),
|
debug.Health(checkHandler),
|
||||||
debug.Ready(ready(options.Config)),
|
debug.Ready(checkHandler),
|
||||||
//debug.CorsAllowedOrigins(options.Config.HTTP.CORS.AllowedOrigins),
|
//debug.CorsAllowedOrigins(options.Config.HTTP.CORS.AllowedOrigins),
|
||||||
//debug.CorsAllowedMethods(options.Config.HTTP.CORS.AllowedMethods),
|
//debug.CorsAllowedMethods(options.Config.HTTP.CORS.AllowedMethods),
|
||||||
//debug.CorsAllowedHeaders(options.Config.HTTP.CORS.AllowedHeaders),
|
//debug.CorsAllowedHeaders(options.Config.HTTP.CORS.AllowedHeaders),
|
||||||
//debug.CorsAllowCredentials(options.Config.HTTP.CORS.AllowCredentials),
|
//debug.CorsAllowCredentials(options.Config.HTTP.CORS.AllowCredentials),
|
||||||
), nil
|
), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// health implements the health check.
|
|
||||||
func health(cfg *config.Config) func(http.ResponseWriter, *http.Request) {
|
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
w.Header().Set("Content-Type", "text/plain")
|
|
||||||
w.WriteHeader(http.StatusOK)
|
|
||||||
|
|
||||||
// TODO: check if services are up and running
|
|
||||||
|
|
||||||
_, err := io.WriteString(w, http.StatusText(http.StatusOK))
|
|
||||||
// io.WriteString should not fail but if it does, we want to know.
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ready implements the ready check.
|
|
||||||
func ready(cfg *config.Config) func(http.ResponseWriter, *http.Request) {
|
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
w.Header().Set("Content-Type", "text/plain")
|
|
||||||
w.WriteHeader(http.StatusOK)
|
|
||||||
|
|
||||||
// TODO: check if services are up and running
|
|
||||||
|
|
||||||
_, err := io.WriteString(w, http.StatusText(http.StatusOK))
|
|
||||||
// io.WriteString should not fail but if it does, we want to know.
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -74,6 +74,7 @@ func Server(cfg *config.Config) *cli.Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
gr.Add(debugServer.ListenAndServe, func(_ error) {
|
gr.Add(debugServer.ListenAndServe, func(_ error) {
|
||||||
|
_ = debugServer.Shutdown(ctx)
|
||||||
cancel()
|
cancel()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -1,18 +1,22 @@
|
|||||||
package debug
|
package debug
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/owncloud/ocis/v2/ocis-pkg/handlers"
|
||||||
"github.com/owncloud/ocis/v2/ocis-pkg/service/debug"
|
"github.com/owncloud/ocis/v2/ocis-pkg/service/debug"
|
||||||
"github.com/owncloud/ocis/v2/ocis-pkg/version"
|
"github.com/owncloud/ocis/v2/ocis-pkg/version"
|
||||||
"github.com/owncloud/ocis/v2/services/auth-bearer/pkg/config"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Server initializes the debug service and server.
|
// Server initializes the debug service and server.
|
||||||
func Server(opts ...Option) (*http.Server, error) {
|
func Server(opts ...Option) (*http.Server, error) {
|
||||||
options := newOptions(opts...)
|
options := newOptions(opts...)
|
||||||
|
|
||||||
|
checkHandler := handlers.NewCheckHandler(
|
||||||
|
handlers.NewCheckHandlerConfiguration().
|
||||||
|
WithLogger(options.Logger),
|
||||||
|
)
|
||||||
|
|
||||||
return debug.NewService(
|
return debug.NewService(
|
||||||
debug.Logger(options.Logger),
|
debug.Logger(options.Logger),
|
||||||
debug.Name(options.Config.Service.Name),
|
debug.Name(options.Config.Service.Name),
|
||||||
@@ -21,43 +25,11 @@ func Server(opts ...Option) (*http.Server, error) {
|
|||||||
debug.Token(options.Config.Debug.Token),
|
debug.Token(options.Config.Debug.Token),
|
||||||
debug.Pprof(options.Config.Debug.Pprof),
|
debug.Pprof(options.Config.Debug.Pprof),
|
||||||
debug.Zpages(options.Config.Debug.Zpages),
|
debug.Zpages(options.Config.Debug.Zpages),
|
||||||
debug.Health(health(options.Config)),
|
debug.Health(checkHandler),
|
||||||
debug.Ready(ready(options.Config)),
|
debug.Ready(checkHandler),
|
||||||
//debug.CorsAllowedOrigins(options.Config.HTTP.CORS.AllowedOrigins),
|
//debug.CorsAllowedOrigins(options.Config.HTTP.CORS.AllowedOrigins),
|
||||||
//debug.CorsAllowedMethods(options.Config.HTTP.CORS.AllowedMethods),
|
//debug.CorsAllowedMethods(options.Config.HTTP.CORS.AllowedMethods),
|
||||||
//debug.CorsAllowedHeaders(options.Config.HTTP.CORS.AllowedHeaders),
|
//debug.CorsAllowedHeaders(options.Config.HTTP.CORS.AllowedHeaders),
|
||||||
//debug.CorsAllowCredentials(options.Config.HTTP.CORS.AllowCredentials),
|
//debug.CorsAllowCredentials(options.Config.HTTP.CORS.AllowCredentials),
|
||||||
), nil
|
), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// health implements the health check.
|
|
||||||
func health(cfg *config.Config) func(http.ResponseWriter, *http.Request) {
|
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
w.Header().Set("Content-Type", "text/plain")
|
|
||||||
w.WriteHeader(http.StatusOK)
|
|
||||||
|
|
||||||
// TODO: check if services are up and running
|
|
||||||
|
|
||||||
_, err := io.WriteString(w, http.StatusText(http.StatusOK))
|
|
||||||
// io.WriteString should not fail but if it does, we want to know.
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ready implements the ready check.
|
|
||||||
func ready(cfg *config.Config) func(http.ResponseWriter, *http.Request) {
|
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
w.Header().Set("Content-Type", "text/plain")
|
|
||||||
w.WriteHeader(http.StatusOK)
|
|
||||||
|
|
||||||
// TODO: check if services are up and running
|
|
||||||
|
|
||||||
_, err := io.WriteString(w, http.StatusText(http.StatusOK))
|
|
||||||
// io.WriteString should not fail but if it does, we want to know.
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -74,6 +74,7 @@ func Server(cfg *config.Config) *cli.Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
gr.Add(debugServer.ListenAndServe, func(_ error) {
|
gr.Add(debugServer.ListenAndServe, func(_ error) {
|
||||||
|
_ = debugServer.Shutdown(ctx)
|
||||||
cancel()
|
cancel()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -1,18 +1,22 @@
|
|||||||
package debug
|
package debug
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/owncloud/ocis/v2/ocis-pkg/handlers"
|
||||||
"github.com/owncloud/ocis/v2/ocis-pkg/service/debug"
|
"github.com/owncloud/ocis/v2/ocis-pkg/service/debug"
|
||||||
"github.com/owncloud/ocis/v2/ocis-pkg/version"
|
"github.com/owncloud/ocis/v2/ocis-pkg/version"
|
||||||
"github.com/owncloud/ocis/v2/services/auth-machine/pkg/config"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Server initializes the debug service and server.
|
// Server initializes the debug service and server.
|
||||||
func Server(opts ...Option) (*http.Server, error) {
|
func Server(opts ...Option) (*http.Server, error) {
|
||||||
options := newOptions(opts...)
|
options := newOptions(opts...)
|
||||||
|
|
||||||
|
checkHandler := handlers.NewCheckHandler(
|
||||||
|
handlers.NewCheckHandlerConfiguration().
|
||||||
|
WithLogger(options.Logger),
|
||||||
|
)
|
||||||
|
|
||||||
return debug.NewService(
|
return debug.NewService(
|
||||||
debug.Logger(options.Logger),
|
debug.Logger(options.Logger),
|
||||||
debug.Name(options.Config.Service.Name),
|
debug.Name(options.Config.Service.Name),
|
||||||
@@ -21,43 +25,11 @@ func Server(opts ...Option) (*http.Server, error) {
|
|||||||
debug.Token(options.Config.Debug.Token),
|
debug.Token(options.Config.Debug.Token),
|
||||||
debug.Pprof(options.Config.Debug.Pprof),
|
debug.Pprof(options.Config.Debug.Pprof),
|
||||||
debug.Zpages(options.Config.Debug.Zpages),
|
debug.Zpages(options.Config.Debug.Zpages),
|
||||||
debug.Health(health(options.Config)),
|
debug.Health(checkHandler),
|
||||||
debug.Ready(ready(options.Config)),
|
debug.Ready(checkHandler),
|
||||||
//debug.CorsAllowedOrigins(options.Config.HTTP.CORS.AllowedOrigins),
|
//debug.CorsAllowedOrigins(options.Config.HTTP.CORS.AllowedOrigins),
|
||||||
//debug.CorsAllowedMethods(options.Config.HTTP.CORS.AllowedMethods),
|
//debug.CorsAllowedMethods(options.Config.HTTP.CORS.AllowedMethods),
|
||||||
//debug.CorsAllowedHeaders(options.Config.HTTP.CORS.AllowedHeaders),
|
//debug.CorsAllowedHeaders(options.Config.HTTP.CORS.AllowedHeaders),
|
||||||
//debug.CorsAllowCredentials(options.Config.HTTP.CORS.AllowCredentials),
|
//debug.CorsAllowCredentials(options.Config.HTTP.CORS.AllowCredentials),
|
||||||
), nil
|
), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// health implements the health check.
|
|
||||||
func health(cfg *config.Config) func(http.ResponseWriter, *http.Request) {
|
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
w.Header().Set("Content-Type", "text/plain")
|
|
||||||
w.WriteHeader(http.StatusOK)
|
|
||||||
|
|
||||||
// TODO: check if services are up and running
|
|
||||||
|
|
||||||
_, err := io.WriteString(w, http.StatusText(http.StatusOK))
|
|
||||||
// io.WriteString should not fail but if it does, we want to know.
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ready implements the ready check.
|
|
||||||
func ready(cfg *config.Config) func(http.ResponseWriter, *http.Request) {
|
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
w.Header().Set("Content-Type", "text/plain")
|
|
||||||
w.WriteHeader(http.StatusOK)
|
|
||||||
|
|
||||||
// TODO: check if services are up and running
|
|
||||||
|
|
||||||
_, err := io.WriteString(w, http.StatusText(http.StatusOK))
|
|
||||||
// io.WriteString should not fail but if it does, we want to know.
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -75,6 +75,7 @@ func Server(cfg *config.Config) *cli.Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
gr.Add(debugServer.ListenAndServe, func(_ error) {
|
gr.Add(debugServer.ListenAndServe, func(_ error) {
|
||||||
|
_ = debugServer.Shutdown(ctx)
|
||||||
cancel()
|
cancel()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -1,18 +1,22 @@
|
|||||||
package debug
|
package debug
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/owncloud/ocis/v2/ocis-pkg/handlers"
|
||||||
"github.com/owncloud/ocis/v2/ocis-pkg/service/debug"
|
"github.com/owncloud/ocis/v2/ocis-pkg/service/debug"
|
||||||
"github.com/owncloud/ocis/v2/ocis-pkg/version"
|
"github.com/owncloud/ocis/v2/ocis-pkg/version"
|
||||||
"github.com/owncloud/ocis/v2/services/auth-service/pkg/config"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Server initializes the debug service and server.
|
// Server initializes the debug service and server.
|
||||||
func Server(opts ...Option) (*http.Server, error) {
|
func Server(opts ...Option) (*http.Server, error) {
|
||||||
options := newOptions(opts...)
|
options := newOptions(opts...)
|
||||||
|
|
||||||
|
checkHandler := handlers.NewCheckHandler(
|
||||||
|
handlers.NewCheckHandlerConfiguration().
|
||||||
|
WithLogger(options.Logger),
|
||||||
|
)
|
||||||
|
|
||||||
return debug.NewService(
|
return debug.NewService(
|
||||||
debug.Logger(options.Logger),
|
debug.Logger(options.Logger),
|
||||||
debug.Name(options.Config.Service.Name),
|
debug.Name(options.Config.Service.Name),
|
||||||
@@ -21,43 +25,11 @@ func Server(opts ...Option) (*http.Server, error) {
|
|||||||
debug.Token(options.Config.Debug.Token),
|
debug.Token(options.Config.Debug.Token),
|
||||||
debug.Pprof(options.Config.Debug.Pprof),
|
debug.Pprof(options.Config.Debug.Pprof),
|
||||||
debug.Zpages(options.Config.Debug.Zpages),
|
debug.Zpages(options.Config.Debug.Zpages),
|
||||||
debug.Health(health(options.Config)),
|
debug.Health(checkHandler),
|
||||||
debug.Ready(ready(options.Config)),
|
debug.Ready(checkHandler),
|
||||||
//debug.CorsAllowedOrigins(options.Config.HTTP.CORS.AllowedOrigins),
|
//debug.CorsAllowedOrigins(options.Config.HTTP.CORS.AllowedOrigins),
|
||||||
//debug.CorsAllowedMethods(options.Config.HTTP.CORS.AllowedMethods),
|
//debug.CorsAllowedMethods(options.Config.HTTP.CORS.AllowedMethods),
|
||||||
//debug.CorsAllowedHeaders(options.Config.HTTP.CORS.AllowedHeaders),
|
//debug.CorsAllowedHeaders(options.Config.HTTP.CORS.AllowedHeaders),
|
||||||
//debug.CorsAllowCredentials(options.Config.HTTP.CORS.AllowCredentials),
|
//debug.CorsAllowCredentials(options.Config.HTTP.CORS.AllowCredentials),
|
||||||
), nil
|
), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// health implements the health check.
|
|
||||||
func health(cfg *config.Config) func(http.ResponseWriter, *http.Request) {
|
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
w.Header().Set("Content-Type", "text/plain")
|
|
||||||
w.WriteHeader(http.StatusOK)
|
|
||||||
|
|
||||||
// TODO: check if services are up and running
|
|
||||||
|
|
||||||
_, err := io.WriteString(w, http.StatusText(http.StatusOK))
|
|
||||||
// io.WriteString should not fail but if it does, we want to know.
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ready implements the ready check.
|
|
||||||
func ready(cfg *config.Config) func(http.ResponseWriter, *http.Request) {
|
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
w.Header().Set("Content-Type", "text/plain")
|
|
||||||
w.WriteHeader(http.StatusOK)
|
|
||||||
|
|
||||||
// TODO: check if services are up and running
|
|
||||||
|
|
||||||
_, err := io.WriteString(w, http.StatusText(http.StatusOK))
|
|
||||||
// io.WriteString should not fail but if it does, we want to know.
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -8,18 +8,18 @@ import (
|
|||||||
"github.com/cs3org/reva/v2/pkg/events/stream"
|
"github.com/cs3org/reva/v2/pkg/events/stream"
|
||||||
"github.com/cs3org/reva/v2/pkg/rgrpc/todo/pool"
|
"github.com/cs3org/reva/v2/pkg/rgrpc/todo/pool"
|
||||||
"github.com/oklog/run"
|
"github.com/oklog/run"
|
||||||
|
"github.com/urfave/cli/v2"
|
||||||
|
|
||||||
"github.com/owncloud/ocis/v2/ocis-pkg/config/configlog"
|
"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/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/tracing"
|
||||||
"github.com/owncloud/ocis/v2/ocis-pkg/version"
|
"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"
|
||||||
"github.com/owncloud/ocis/v2/services/clientlog/pkg/config/parser"
|
"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/logging"
|
||||||
"github.com/owncloud/ocis/v2/services/clientlog/pkg/metrics"
|
"github.com/owncloud/ocis/v2/services/clientlog/pkg/metrics"
|
||||||
|
"github.com/owncloud/ocis/v2/services/clientlog/pkg/server/debug"
|
||||||
"github.com/owncloud/ocis/v2/services/clientlog/pkg/service"
|
"github.com/owncloud/ocis/v2/services/clientlog/pkg/service"
|
||||||
"github.com/urfave/cli/v2"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// all events we care about
|
// all events we care about
|
||||||
@@ -116,20 +116,18 @@ func Server(cfg *config.Config) *cli.Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
server := debug.NewService(
|
debugServer, err := debug.Server(
|
||||||
debug.Logger(logger),
|
debug.Logger(logger),
|
||||||
debug.Name(cfg.Service.Name),
|
debug.Context(ctx),
|
||||||
debug.Version(version.GetString()),
|
debug.Config(cfg),
|
||||||
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),
|
|
||||||
)
|
)
|
||||||
|
if err != nil {
|
||||||
|
logger.Info().Err(err).Str("server", "debug").Msg("Failed to initialize server")
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
gr.Add(server.ListenAndServe, func(_ error) {
|
gr.Add(debugServer.ListenAndServe, func(_ error) {
|
||||||
_ = server.Shutdown(ctx)
|
_ = debugServer.Shutdown(ctx)
|
||||||
cancel()
|
cancel()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,50 @@
|
|||||||
|
package debug
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"github.com/owncloud/ocis/v2/ocis-pkg/log"
|
||||||
|
"github.com/owncloud/ocis/v2/services/clientlog/pkg/config"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Option defines a single option function.
|
||||||
|
type Option func(o *Options)
|
||||||
|
|
||||||
|
// Options defines the available options for this package.
|
||||||
|
type Options struct {
|
||||||
|
Logger log.Logger
|
||||||
|
Context context.Context
|
||||||
|
Config *config.Config
|
||||||
|
}
|
||||||
|
|
||||||
|
// newOptions initializes the available default options.
|
||||||
|
func newOptions(opts ...Option) Options {
|
||||||
|
opt := Options{}
|
||||||
|
|
||||||
|
for _, o := range opts {
|
||||||
|
o(&opt)
|
||||||
|
}
|
||||||
|
|
||||||
|
return opt
|
||||||
|
}
|
||||||
|
|
||||||
|
// Logger provides a function to set the logger option.
|
||||||
|
func Logger(val log.Logger) Option {
|
||||||
|
return func(o *Options) {
|
||||||
|
o.Logger = val
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Context provides a function to set the context option.
|
||||||
|
func Context(val context.Context) Option {
|
||||||
|
return func(o *Options) {
|
||||||
|
o.Context = val
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Config provides a function to set the config option.
|
||||||
|
func Config(val *config.Config) Option {
|
||||||
|
return func(o *Options) {
|
||||||
|
o.Config = val
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
package debug
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/owncloud/ocis/v2/ocis-pkg/handlers"
|
||||||
|
"github.com/owncloud/ocis/v2/ocis-pkg/service/debug"
|
||||||
|
"github.com/owncloud/ocis/v2/ocis-pkg/version"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Server initializes the debug service and server.
|
||||||
|
func Server(opts ...Option) (*http.Server, error) {
|
||||||
|
options := newOptions(opts...)
|
||||||
|
|
||||||
|
checkHandler := handlers.NewCheckHandler(
|
||||||
|
handlers.NewCheckHandlerConfiguration().
|
||||||
|
WithLogger(options.Logger),
|
||||||
|
)
|
||||||
|
|
||||||
|
return debug.NewService(
|
||||||
|
debug.Logger(options.Logger),
|
||||||
|
debug.Name(options.Config.Service.Name),
|
||||||
|
debug.Version(version.GetString()),
|
||||||
|
debug.Address(options.Config.Debug.Addr),
|
||||||
|
debug.Token(options.Config.Debug.Token),
|
||||||
|
debug.Pprof(options.Config.Debug.Pprof),
|
||||||
|
debug.Zpages(options.Config.Debug.Zpages),
|
||||||
|
debug.Health(checkHandler),
|
||||||
|
debug.Ready(checkHandler),
|
||||||
|
), nil
|
||||||
|
}
|
||||||
@@ -1,18 +1,22 @@
|
|||||||
package debug
|
package debug
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/owncloud/ocis/v2/ocis-pkg/handlers"
|
||||||
"github.com/owncloud/ocis/v2/ocis-pkg/service/debug"
|
"github.com/owncloud/ocis/v2/ocis-pkg/service/debug"
|
||||||
"github.com/owncloud/ocis/v2/ocis-pkg/version"
|
"github.com/owncloud/ocis/v2/ocis-pkg/version"
|
||||||
"github.com/owncloud/ocis/v2/services/collaboration/pkg/config"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Server initializes the debug service and server.
|
// Server initializes the debug service and server.
|
||||||
func Server(opts ...Option) (*http.Server, error) {
|
func Server(opts ...Option) (*http.Server, error) {
|
||||||
options := newOptions(opts...)
|
options := newOptions(opts...)
|
||||||
|
|
||||||
|
checkHandler := handlers.NewCheckHandler(
|
||||||
|
handlers.NewCheckHandlerConfiguration().
|
||||||
|
WithLogger(options.Logger),
|
||||||
|
)
|
||||||
|
|
||||||
return debug.NewService(
|
return debug.NewService(
|
||||||
debug.Logger(options.Logger),
|
debug.Logger(options.Logger),
|
||||||
debug.Name(options.Config.Service.Name+"."+options.Config.App.Name),
|
debug.Name(options.Config.Service.Name+"."+options.Config.App.Name),
|
||||||
@@ -21,43 +25,11 @@ func Server(opts ...Option) (*http.Server, error) {
|
|||||||
debug.Token(options.Config.Debug.Token),
|
debug.Token(options.Config.Debug.Token),
|
||||||
debug.Pprof(options.Config.Debug.Pprof),
|
debug.Pprof(options.Config.Debug.Pprof),
|
||||||
debug.Zpages(options.Config.Debug.Zpages),
|
debug.Zpages(options.Config.Debug.Zpages),
|
||||||
debug.Health(health(options.Config)),
|
debug.Health(checkHandler),
|
||||||
debug.Ready(ready(options.Config)),
|
debug.Ready(checkHandler),
|
||||||
//debug.CorsAllowedOrigins(options.Config.HTTP.CORS.AllowedOrigins),
|
//debug.CorsAllowedOrigins(options.Config.HTTP.CORS.AllowedOrigins),
|
||||||
//debug.CorsAllowedMethods(options.Config.HTTP.CORS.AllowedMethods),
|
//debug.CorsAllowedMethods(options.Config.HTTP.CORS.AllowedMethods),
|
||||||
//debug.CorsAllowedHeaders(options.Config.HTTP.CORS.AllowedHeaders),
|
//debug.CorsAllowedHeaders(options.Config.HTTP.CORS.AllowedHeaders),
|
||||||
//debug.CorsAllowCredentials(options.Config.HTTP.CORS.AllowCredentials),
|
//debug.CorsAllowCredentials(options.Config.HTTP.CORS.AllowCredentials),
|
||||||
), nil
|
), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// health implements the health check.
|
|
||||||
func health(cfg *config.Config) func(http.ResponseWriter, *http.Request) {
|
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
w.Header().Set("Content-Type", "text/plain")
|
|
||||||
w.WriteHeader(http.StatusOK)
|
|
||||||
|
|
||||||
// TODO: check if services are up and running
|
|
||||||
|
|
||||||
_, err := io.WriteString(w, http.StatusText(http.StatusOK))
|
|
||||||
// io.WriteString should not fail but if it does we want to know.
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ready implements the ready check.
|
|
||||||
func ready(cfg *config.Config) func(http.ResponseWriter, *http.Request) {
|
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
w.Header().Set("Content-Type", "text/plain")
|
|
||||||
w.WriteHeader(http.StatusOK)
|
|
||||||
|
|
||||||
// TODO: check if services are up and running
|
|
||||||
|
|
||||||
_, err := io.WriteString(w, http.StatusText(http.StatusOK))
|
|
||||||
// io.WriteString should not fail but if it does we want to know.
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -7,9 +7,10 @@ import (
|
|||||||
"github.com/cs3org/reva/v2/pkg/events/stream"
|
"github.com/cs3org/reva/v2/pkg/events/stream"
|
||||||
"github.com/cs3org/reva/v2/pkg/store"
|
"github.com/cs3org/reva/v2/pkg/store"
|
||||||
"github.com/oklog/run"
|
"github.com/oklog/run"
|
||||||
|
"github.com/urfave/cli/v2"
|
||||||
|
microstore "go-micro.dev/v4/store"
|
||||||
|
|
||||||
"github.com/owncloud/ocis/v2/ocis-pkg/config/configlog"
|
"github.com/owncloud/ocis/v2/ocis-pkg/config/configlog"
|
||||||
"github.com/owncloud/ocis/v2/ocis-pkg/handlers"
|
|
||||||
"github.com/owncloud/ocis/v2/ocis-pkg/service/debug"
|
|
||||||
ogrpc "github.com/owncloud/ocis/v2/ocis-pkg/service/grpc"
|
ogrpc "github.com/owncloud/ocis/v2/ocis-pkg/service/grpc"
|
||||||
"github.com/owncloud/ocis/v2/ocis-pkg/tracing"
|
"github.com/owncloud/ocis/v2/ocis-pkg/tracing"
|
||||||
"github.com/owncloud/ocis/v2/ocis-pkg/version"
|
"github.com/owncloud/ocis/v2/ocis-pkg/version"
|
||||||
@@ -17,9 +18,8 @@ import (
|
|||||||
"github.com/owncloud/ocis/v2/services/eventhistory/pkg/config/parser"
|
"github.com/owncloud/ocis/v2/services/eventhistory/pkg/config/parser"
|
||||||
"github.com/owncloud/ocis/v2/services/eventhistory/pkg/logging"
|
"github.com/owncloud/ocis/v2/services/eventhistory/pkg/logging"
|
||||||
"github.com/owncloud/ocis/v2/services/eventhistory/pkg/metrics"
|
"github.com/owncloud/ocis/v2/services/eventhistory/pkg/metrics"
|
||||||
|
"github.com/owncloud/ocis/v2/services/eventhistory/pkg/server/debug"
|
||||||
"github.com/owncloud/ocis/v2/services/eventhistory/pkg/server/grpc"
|
"github.com/owncloud/ocis/v2/services/eventhistory/pkg/server/grpc"
|
||||||
"github.com/urfave/cli/v2"
|
|
||||||
microstore "go-micro.dev/v4/store"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Server is the entrypoint for the server command.
|
// Server is the entrypoint for the server command.
|
||||||
@@ -93,20 +93,18 @@ func Server(cfg *config.Config) *cli.Command {
|
|||||||
})
|
})
|
||||||
|
|
||||||
{
|
{
|
||||||
server := debug.NewService(
|
debugServer, err := debug.Server(
|
||||||
debug.Logger(logger),
|
debug.Logger(logger),
|
||||||
debug.Name(cfg.Service.Name),
|
debug.Context(ctx),
|
||||||
debug.Version(version.GetString()),
|
debug.Config(cfg),
|
||||||
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),
|
|
||||||
)
|
)
|
||||||
|
if err != nil {
|
||||||
|
logger.Info().Err(err).Str("server", "debug").Msg("Failed to initialize server")
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
gr.Add(server.ListenAndServe, func(_ error) {
|
gr.Add(debugServer.ListenAndServe, func(_ error) {
|
||||||
_ = server.Shutdown(ctx)
|
_ = debugServer.Shutdown(ctx)
|
||||||
cancel()
|
cancel()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,50 @@
|
|||||||
|
package debug
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"github.com/owncloud/ocis/v2/ocis-pkg/log"
|
||||||
|
"github.com/owncloud/ocis/v2/services/eventhistory/pkg/config"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Option defines a single option function.
|
||||||
|
type Option func(o *Options)
|
||||||
|
|
||||||
|
// Options defines the available options for this package.
|
||||||
|
type Options struct {
|
||||||
|
Logger log.Logger
|
||||||
|
Context context.Context
|
||||||
|
Config *config.Config
|
||||||
|
}
|
||||||
|
|
||||||
|
// newOptions initializes the available default options.
|
||||||
|
func newOptions(opts ...Option) Options {
|
||||||
|
opt := Options{}
|
||||||
|
|
||||||
|
for _, o := range opts {
|
||||||
|
o(&opt)
|
||||||
|
}
|
||||||
|
|
||||||
|
return opt
|
||||||
|
}
|
||||||
|
|
||||||
|
// Logger provides a function to set the logger option.
|
||||||
|
func Logger(val log.Logger) Option {
|
||||||
|
return func(o *Options) {
|
||||||
|
o.Logger = val
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Context provides a function to set the context option.
|
||||||
|
func Context(val context.Context) Option {
|
||||||
|
return func(o *Options) {
|
||||||
|
o.Context = val
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Config provides a function to set the config option.
|
||||||
|
func Config(val *config.Config) Option {
|
||||||
|
return func(o *Options) {
|
||||||
|
o.Config = val
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
package debug
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/owncloud/ocis/v2/ocis-pkg/handlers"
|
||||||
|
"github.com/owncloud/ocis/v2/ocis-pkg/service/debug"
|
||||||
|
"github.com/owncloud/ocis/v2/ocis-pkg/version"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Server initializes the debug service and server.
|
||||||
|
func Server(opts ...Option) (*http.Server, error) {
|
||||||
|
options := newOptions(opts...)
|
||||||
|
|
||||||
|
checkHandler := handlers.NewCheckHandler(
|
||||||
|
handlers.NewCheckHandlerConfiguration().
|
||||||
|
WithLogger(options.Logger),
|
||||||
|
)
|
||||||
|
|
||||||
|
return debug.NewService(
|
||||||
|
debug.Logger(options.Logger),
|
||||||
|
debug.Name(options.Config.Service.Name),
|
||||||
|
debug.Version(version.GetString()),
|
||||||
|
debug.Address(options.Config.Debug.Addr),
|
||||||
|
debug.Token(options.Config.Debug.Token),
|
||||||
|
debug.Pprof(options.Config.Debug.Pprof),
|
||||||
|
debug.Zpages(options.Config.Debug.Zpages),
|
||||||
|
debug.Health(checkHandler),
|
||||||
|
debug.Ready(checkHandler),
|
||||||
|
), nil
|
||||||
|
}
|
||||||
@@ -78,6 +78,7 @@ func Server(cfg *config.Config) *cli.Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
gr.Add(debugServer.ListenAndServe, func(_ error) {
|
gr.Add(debugServer.ListenAndServe, func(_ error) {
|
||||||
|
_ = debugServer.Shutdown(ctx)
|
||||||
cancel()
|
cancel()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -1,18 +1,22 @@
|
|||||||
package debug
|
package debug
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/owncloud/ocis/v2/ocis-pkg/handlers"
|
||||||
"github.com/owncloud/ocis/v2/ocis-pkg/service/debug"
|
"github.com/owncloud/ocis/v2/ocis-pkg/service/debug"
|
||||||
"github.com/owncloud/ocis/v2/ocis-pkg/version"
|
"github.com/owncloud/ocis/v2/ocis-pkg/version"
|
||||||
"github.com/owncloud/ocis/v2/services/frontend/pkg/config"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Server initializes the debug service and server.
|
// Server initializes the debug service and server.
|
||||||
func Server(opts ...Option) (*http.Server, error) {
|
func Server(opts ...Option) (*http.Server, error) {
|
||||||
options := newOptions(opts...)
|
options := newOptions(opts...)
|
||||||
|
|
||||||
|
checkHandler := handlers.NewCheckHandler(
|
||||||
|
handlers.NewCheckHandlerConfiguration().
|
||||||
|
WithLogger(options.Logger),
|
||||||
|
)
|
||||||
|
|
||||||
return debug.NewService(
|
return debug.NewService(
|
||||||
debug.Logger(options.Logger),
|
debug.Logger(options.Logger),
|
||||||
debug.Name(options.Config.Service.Name),
|
debug.Name(options.Config.Service.Name),
|
||||||
@@ -21,43 +25,11 @@ func Server(opts ...Option) (*http.Server, error) {
|
|||||||
debug.Token(options.Config.Debug.Token),
|
debug.Token(options.Config.Debug.Token),
|
||||||
debug.Pprof(options.Config.Debug.Pprof),
|
debug.Pprof(options.Config.Debug.Pprof),
|
||||||
debug.Zpages(options.Config.Debug.Zpages),
|
debug.Zpages(options.Config.Debug.Zpages),
|
||||||
debug.Health(health(options.Config)),
|
debug.Health(checkHandler),
|
||||||
debug.Ready(ready(options.Config)),
|
debug.Ready(checkHandler),
|
||||||
//debug.CorsAllowedOrigins(options.Config.HTTP.CORS.AllowedOrigins),
|
//debug.CorsAllowedOrigins(options.Config.HTTP.CORS.AllowedOrigins),
|
||||||
//debug.CorsAllowedMethods(options.Config.HTTP.CORS.AllowedMethods),
|
//debug.CorsAllowedMethods(options.Config.HTTP.CORS.AllowedMethods),
|
||||||
//debug.CorsAllowedHeaders(options.Config.HTTP.CORS.AllowedHeaders),
|
//debug.CorsAllowedHeaders(options.Config.HTTP.CORS.AllowedHeaders),
|
||||||
//debug.CorsAllowCredentials(options.Config.HTTP.CORS.AllowCredentials),
|
//debug.CorsAllowCredentials(options.Config.HTTP.CORS.AllowCredentials),
|
||||||
), nil
|
), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// health implements the health check.
|
|
||||||
func health(cfg *config.Config) func(http.ResponseWriter, *http.Request) {
|
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
w.Header().Set("Content-Type", "text/plain")
|
|
||||||
w.WriteHeader(http.StatusOK)
|
|
||||||
|
|
||||||
// TODO: check if services are up and running
|
|
||||||
|
|
||||||
_, err := io.WriteString(w, http.StatusText(http.StatusOK))
|
|
||||||
// io.WriteString should not fail but if it does, we want to know.
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ready implements the ready check.
|
|
||||||
func ready(cfg *config.Config) func(http.ResponseWriter, *http.Request) {
|
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
w.Header().Set("Content-Type", "text/plain")
|
|
||||||
w.WriteHeader(http.StatusOK)
|
|
||||||
|
|
||||||
// TODO: check if services are up and running
|
|
||||||
|
|
||||||
_, err := io.WriteString(w, http.StatusText(http.StatusOK))
|
|
||||||
// io.WriteString should not fail but if it does, we want to know.
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -75,9 +75,7 @@ func Server(cfg *config.Config) *cli.Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
gr.Add(debugServer.ListenAndServe, func(_ error) {
|
gr.Add(debugServer.ListenAndServe, func(_ error) {
|
||||||
logger.Info().
|
_ = debugServer.Shutdown(ctx)
|
||||||
Str("server", cfg.Service.Name).
|
|
||||||
Msg("Shutting down debug erver")
|
|
||||||
cancel()
|
cancel()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -1,18 +1,22 @@
|
|||||||
package debug
|
package debug
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/owncloud/ocis/v2/ocis-pkg/handlers"
|
||||||
"github.com/owncloud/ocis/v2/ocis-pkg/service/debug"
|
"github.com/owncloud/ocis/v2/ocis-pkg/service/debug"
|
||||||
"github.com/owncloud/ocis/v2/ocis-pkg/version"
|
"github.com/owncloud/ocis/v2/ocis-pkg/version"
|
||||||
"github.com/owncloud/ocis/v2/services/gateway/pkg/config"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Server initializes the debug service and server.
|
// Server initializes the debug service and server.
|
||||||
func Server(opts ...Option) (*http.Server, error) {
|
func Server(opts ...Option) (*http.Server, error) {
|
||||||
options := newOptions(opts...)
|
options := newOptions(opts...)
|
||||||
|
|
||||||
|
checkHandler := handlers.NewCheckHandler(
|
||||||
|
handlers.NewCheckHandlerConfiguration().
|
||||||
|
WithLogger(options.Logger),
|
||||||
|
)
|
||||||
|
|
||||||
return debug.NewService(
|
return debug.NewService(
|
||||||
debug.Logger(options.Logger),
|
debug.Logger(options.Logger),
|
||||||
debug.Name(options.Config.Service.Name),
|
debug.Name(options.Config.Service.Name),
|
||||||
@@ -21,43 +25,11 @@ func Server(opts ...Option) (*http.Server, error) {
|
|||||||
debug.Token(options.Config.Debug.Token),
|
debug.Token(options.Config.Debug.Token),
|
||||||
debug.Pprof(options.Config.Debug.Pprof),
|
debug.Pprof(options.Config.Debug.Pprof),
|
||||||
debug.Zpages(options.Config.Debug.Zpages),
|
debug.Zpages(options.Config.Debug.Zpages),
|
||||||
debug.Health(health(options.Config)),
|
debug.Health(checkHandler),
|
||||||
debug.Ready(ready(options.Config)),
|
debug.Ready(checkHandler),
|
||||||
//debug.CorsAllowedOrigins(options.Config.HTTP.CORS.AllowedOrigins),
|
//debug.CorsAllowedOrigins(options.Config.HTTP.CORS.AllowedOrigins),
|
||||||
//debug.CorsAllowedMethods(options.Config.HTTP.CORS.AllowedMethods),
|
//debug.CorsAllowedMethods(options.Config.HTTP.CORS.AllowedMethods),
|
||||||
//debug.CorsAllowedHeaders(options.Config.HTTP.CORS.AllowedHeaders),
|
//debug.CorsAllowedHeaders(options.Config.HTTP.CORS.AllowedHeaders),
|
||||||
//debug.CorsAllowCredentials(options.Config.HTTP.CORS.AllowCredentials),
|
//debug.CorsAllowCredentials(options.Config.HTTP.CORS.AllowCredentials),
|
||||||
), nil
|
), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// health implements the health check.
|
|
||||||
func health(cfg *config.Config) func(http.ResponseWriter, *http.Request) {
|
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
w.Header().Set("Content-Type", "text/plain")
|
|
||||||
w.WriteHeader(http.StatusOK)
|
|
||||||
|
|
||||||
// TODO: check if services are up and running
|
|
||||||
|
|
||||||
_, err := io.WriteString(w, http.StatusText(http.StatusOK))
|
|
||||||
// io.WriteString should not fail but if it does, we want to know.
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ready implements the ready check.
|
|
||||||
func ready(cfg *config.Config) func(http.ResponseWriter, *http.Request) {
|
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
w.Header().Set("Content-Type", "text/plain")
|
|
||||||
w.WriteHeader(http.StatusOK)
|
|
||||||
|
|
||||||
// TODO: check if services are up and running
|
|
||||||
|
|
||||||
_, err := io.WriteString(w, http.StatusText(http.StatusOK))
|
|
||||||
// io.WriteString should not fail but if it does, we want to know.
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,18 +1,22 @@
|
|||||||
package debug
|
package debug
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/owncloud/ocis/v2/ocis-pkg/handlers"
|
||||||
"github.com/owncloud/ocis/v2/ocis-pkg/service/debug"
|
"github.com/owncloud/ocis/v2/ocis-pkg/service/debug"
|
||||||
"github.com/owncloud/ocis/v2/ocis-pkg/version"
|
"github.com/owncloud/ocis/v2/ocis-pkg/version"
|
||||||
"github.com/owncloud/ocis/v2/services/graph/pkg/config"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Server initializes the debug service and server.
|
// Server initializes the debug service and server.
|
||||||
func Server(opts ...Option) (*http.Server, error) {
|
func Server(opts ...Option) (*http.Server, error) {
|
||||||
options := newOptions(opts...)
|
options := newOptions(opts...)
|
||||||
|
|
||||||
|
checkHandler := handlers.NewCheckHandler(
|
||||||
|
handlers.NewCheckHandlerConfiguration().
|
||||||
|
WithLogger(options.Logger),
|
||||||
|
)
|
||||||
|
|
||||||
return debug.NewService(
|
return debug.NewService(
|
||||||
debug.Logger(options.Logger),
|
debug.Logger(options.Logger),
|
||||||
debug.Name(options.Config.Service.Name),
|
debug.Name(options.Config.Service.Name),
|
||||||
@@ -21,39 +25,7 @@ func Server(opts ...Option) (*http.Server, error) {
|
|||||||
debug.Token(options.Config.Debug.Token),
|
debug.Token(options.Config.Debug.Token),
|
||||||
debug.Pprof(options.Config.Debug.Pprof),
|
debug.Pprof(options.Config.Debug.Pprof),
|
||||||
debug.Zpages(options.Config.Debug.Zpages),
|
debug.Zpages(options.Config.Debug.Zpages),
|
||||||
debug.Health(health(options.Config)),
|
debug.Health(checkHandler),
|
||||||
debug.Ready(ready(options.Config)),
|
debug.Ready(checkHandler),
|
||||||
), nil
|
), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// health implements the health check.
|
|
||||||
func health(cfg *config.Config) func(http.ResponseWriter, *http.Request) {
|
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
w.Header().Set("Content-Type", "text/plain")
|
|
||||||
w.WriteHeader(http.StatusOK)
|
|
||||||
|
|
||||||
// TODO: check if services are up and running
|
|
||||||
|
|
||||||
_, err := io.WriteString(w, http.StatusText(http.StatusOK))
|
|
||||||
// io.WriteString should not fail but if it does, we want to know.
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ready implements the ready check.
|
|
||||||
func ready(cfg *config.Config) func(http.ResponseWriter, *http.Request) {
|
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
w.Header().Set("Content-Type", "text/plain")
|
|
||||||
w.WriteHeader(http.StatusOK)
|
|
||||||
|
|
||||||
// TODO: check if services are up and running
|
|
||||||
|
|
||||||
_, err := io.WriteString(w, http.StatusText(http.StatusOK))
|
|
||||||
// io.WriteString should not fail but if it does, we want to know.
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -87,6 +87,7 @@ func Server(cfg *config.Config) *cli.Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
gr.Add(debugServer.ListenAndServe, func(_ error) {
|
gr.Add(debugServer.ListenAndServe, func(_ error) {
|
||||||
|
_ = debugServer.Shutdown(ctx)
|
||||||
cancel()
|
cancel()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -1,18 +1,22 @@
|
|||||||
package debug
|
package debug
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/owncloud/ocis/v2/ocis-pkg/handlers"
|
||||||
"github.com/owncloud/ocis/v2/ocis-pkg/service/debug"
|
"github.com/owncloud/ocis/v2/ocis-pkg/service/debug"
|
||||||
"github.com/owncloud/ocis/v2/ocis-pkg/version"
|
"github.com/owncloud/ocis/v2/ocis-pkg/version"
|
||||||
"github.com/owncloud/ocis/v2/services/groups/pkg/config"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Server initializes the debug service and server.
|
// Server initializes the debug service and server.
|
||||||
func Server(opts ...Option) (*http.Server, error) {
|
func Server(opts ...Option) (*http.Server, error) {
|
||||||
options := newOptions(opts...)
|
options := newOptions(opts...)
|
||||||
|
|
||||||
|
checkHandler := handlers.NewCheckHandler(
|
||||||
|
handlers.NewCheckHandlerConfiguration().
|
||||||
|
WithLogger(options.Logger),
|
||||||
|
)
|
||||||
|
|
||||||
return debug.NewService(
|
return debug.NewService(
|
||||||
debug.Logger(options.Logger),
|
debug.Logger(options.Logger),
|
||||||
debug.Name(options.Config.Service.Name),
|
debug.Name(options.Config.Service.Name),
|
||||||
@@ -21,43 +25,11 @@ func Server(opts ...Option) (*http.Server, error) {
|
|||||||
debug.Token(options.Config.Debug.Token),
|
debug.Token(options.Config.Debug.Token),
|
||||||
debug.Pprof(options.Config.Debug.Pprof),
|
debug.Pprof(options.Config.Debug.Pprof),
|
||||||
debug.Zpages(options.Config.Debug.Zpages),
|
debug.Zpages(options.Config.Debug.Zpages),
|
||||||
debug.Health(health(options.Config)),
|
debug.Health(checkHandler),
|
||||||
debug.Ready(ready(options.Config)),
|
debug.Ready(checkHandler),
|
||||||
//debug.CorsAllowedOrigins(options.Config.HTTP.CORS.AllowedOrigins),
|
//debug.CorsAllowedOrigins(options.Config.HTTP.CORS.AllowedOrigins),
|
||||||
//debug.CorsAllowedMethods(options.Config.HTTP.CORS.AllowedMethods),
|
//debug.CorsAllowedMethods(options.Config.HTTP.CORS.AllowedMethods),
|
||||||
//debug.CorsAllowedHeaders(options.Config.HTTP.CORS.AllowedHeaders),
|
//debug.CorsAllowedHeaders(options.Config.HTTP.CORS.AllowedHeaders),
|
||||||
//debug.CorsAllowCredentials(options.Config.HTTP.CORS.AllowCredentials),
|
//debug.CorsAllowCredentials(options.Config.HTTP.CORS.AllowCredentials),
|
||||||
), nil
|
), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// health implements the health check.
|
|
||||||
func health(cfg *config.Config) func(http.ResponseWriter, *http.Request) {
|
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
w.Header().Set("Content-Type", "text/plain")
|
|
||||||
w.WriteHeader(http.StatusOK)
|
|
||||||
|
|
||||||
// TODO: check if services are up and running
|
|
||||||
|
|
||||||
_, err := io.WriteString(w, http.StatusText(http.StatusOK))
|
|
||||||
// io.WriteString should not fail but if it does, we want to know.
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ready implements the ready check.
|
|
||||||
func ready(cfg *config.Config) func(http.ResponseWriter, *http.Request) {
|
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
w.Header().Set("Content-Type", "text/plain")
|
|
||||||
w.WriteHeader(http.StatusOK)
|
|
||||||
|
|
||||||
// TODO: check if services are up and running
|
|
||||||
|
|
||||||
_, err := io.WriteString(w, http.StatusText(http.StatusOK))
|
|
||||||
// io.WriteString should not fail but if it does, we want to know.
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -14,17 +14,16 @@ import (
|
|||||||
"github.com/libregraph/idm/pkg/ldbbolt"
|
"github.com/libregraph/idm/pkg/ldbbolt"
|
||||||
"github.com/libregraph/idm/server"
|
"github.com/libregraph/idm/server"
|
||||||
"github.com/oklog/run"
|
"github.com/oklog/run"
|
||||||
|
"github.com/urfave/cli/v2"
|
||||||
|
|
||||||
"github.com/owncloud/ocis/v2/ocis-pkg/config/configlog"
|
"github.com/owncloud/ocis/v2/ocis-pkg/config/configlog"
|
||||||
pkgcrypto "github.com/owncloud/ocis/v2/ocis-pkg/crypto"
|
pkgcrypto "github.com/owncloud/ocis/v2/ocis-pkg/crypto"
|
||||||
"github.com/owncloud/ocis/v2/ocis-pkg/handlers"
|
|
||||||
"github.com/owncloud/ocis/v2/ocis-pkg/log"
|
"github.com/owncloud/ocis/v2/ocis-pkg/log"
|
||||||
"github.com/owncloud/ocis/v2/ocis-pkg/service/debug"
|
|
||||||
"github.com/owncloud/ocis/v2/ocis-pkg/version"
|
|
||||||
"github.com/owncloud/ocis/v2/services/idm"
|
"github.com/owncloud/ocis/v2/services/idm"
|
||||||
"github.com/owncloud/ocis/v2/services/idm/pkg/config"
|
"github.com/owncloud/ocis/v2/services/idm/pkg/config"
|
||||||
"github.com/owncloud/ocis/v2/services/idm/pkg/config/parser"
|
"github.com/owncloud/ocis/v2/services/idm/pkg/config/parser"
|
||||||
"github.com/owncloud/ocis/v2/services/idm/pkg/logging"
|
"github.com/owncloud/ocis/v2/services/idm/pkg/logging"
|
||||||
"github.com/urfave/cli/v2"
|
"github.com/owncloud/ocis/v2/services/idm/pkg/server/debug"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Server is the entrypoint for the server command.
|
// Server is the entrypoint for the server command.
|
||||||
@@ -94,20 +93,18 @@ func Server(cfg *config.Config) *cli.Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
server := debug.NewService(
|
debugServer, err := debug.Server(
|
||||||
debug.Logger(logger),
|
debug.Logger(logger),
|
||||||
debug.Name(cfg.Service.Name),
|
debug.Context(ctx),
|
||||||
debug.Version(version.GetString()),
|
debug.Config(cfg),
|
||||||
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),
|
|
||||||
)
|
)
|
||||||
|
if err != nil {
|
||||||
|
logger.Info().Err(err).Str("server", "debug").Msg("Failed to initialize server")
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
gr.Add(server.ListenAndServe, func(_ error) {
|
gr.Add(debugServer.ListenAndServe, func(_ error) {
|
||||||
_ = server.Shutdown(ctx)
|
_ = debugServer.Shutdown(ctx)
|
||||||
cancel()
|
cancel()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,18 +1,22 @@
|
|||||||
package debug
|
package debug
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/owncloud/ocis/v2/ocis-pkg/handlers"
|
||||||
"github.com/owncloud/ocis/v2/ocis-pkg/service/debug"
|
"github.com/owncloud/ocis/v2/ocis-pkg/service/debug"
|
||||||
"github.com/owncloud/ocis/v2/ocis-pkg/version"
|
"github.com/owncloud/ocis/v2/ocis-pkg/version"
|
||||||
"github.com/owncloud/ocis/v2/services/idm/pkg/config"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Server initializes the debug service and server.
|
// Server initializes the debug service and server.
|
||||||
func Server(opts ...Option) (*http.Server, error) {
|
func Server(opts ...Option) (*http.Server, error) {
|
||||||
options := newOptions(opts...)
|
options := newOptions(opts...)
|
||||||
|
|
||||||
|
checkHandler := handlers.NewCheckHandler(
|
||||||
|
handlers.NewCheckHandlerConfiguration().
|
||||||
|
WithLogger(options.Logger),
|
||||||
|
)
|
||||||
|
|
||||||
return debug.NewService(
|
return debug.NewService(
|
||||||
debug.Logger(options.Logger),
|
debug.Logger(options.Logger),
|
||||||
debug.Name(options.Config.Service.Name),
|
debug.Name(options.Config.Service.Name),
|
||||||
@@ -21,39 +25,7 @@ func Server(opts ...Option) (*http.Server, error) {
|
|||||||
debug.Token(options.Config.Debug.Token),
|
debug.Token(options.Config.Debug.Token),
|
||||||
debug.Pprof(options.Config.Debug.Pprof),
|
debug.Pprof(options.Config.Debug.Pprof),
|
||||||
debug.Zpages(options.Config.Debug.Zpages),
|
debug.Zpages(options.Config.Debug.Zpages),
|
||||||
debug.Health(health(options.Config)),
|
debug.Health(checkHandler),
|
||||||
debug.Ready(ready(options.Config)),
|
debug.Ready(checkHandler),
|
||||||
), nil
|
), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// health implements the health check.
|
|
||||||
func health(cfg *config.Config) func(http.ResponseWriter, *http.Request) {
|
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
w.Header().Set("Content-Type", "text/plain")
|
|
||||||
w.WriteHeader(http.StatusOK)
|
|
||||||
|
|
||||||
// TODO: check if services are up and running
|
|
||||||
|
|
||||||
_, err := io.WriteString(w, http.StatusText(http.StatusOK))
|
|
||||||
// io.WriteString should not fail but if it does, we want to know.
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ready implements the ready check.
|
|
||||||
func ready(cfg *config.Config) func(http.ResponseWriter, *http.Request) {
|
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
w.Header().Set("Content-Type", "text/plain")
|
|
||||||
w.WriteHeader(http.StatusOK)
|
|
||||||
|
|
||||||
// TODO: check if services are up and running
|
|
||||||
|
|
||||||
_, err := io.WriteString(w, http.StatusText(http.StatusOK))
|
|
||||||
// io.WriteString should not fail but if it does, we want to know.
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -36,7 +36,10 @@ func Server(cfg *config.Config) *cli.Command {
|
|||||||
Usage: fmt.Sprintf("start the %s service without runtime (unsupervised mode)", cfg.Service.Name),
|
Usage: fmt.Sprintf("start the %s service without runtime (unsupervised mode)", cfg.Service.Name),
|
||||||
Category: "server",
|
Category: "server",
|
||||||
Before: func(c *cli.Context) error {
|
Before: func(c *cli.Context) error {
|
||||||
configlog.ReturnFatal(parser.ParseConfig(cfg))
|
err := configlog.ReturnFatal(parser.ParseConfig(cfg))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
if cfg.IDP.EncryptionSecretFile != "" {
|
if cfg.IDP.EncryptionSecretFile != "" {
|
||||||
if err := ensureEncryptionSecretExists(cfg.IDP.EncryptionSecretFile); err != nil {
|
if err := ensureEncryptionSecretExists(cfg.IDP.EncryptionSecretFile); err != nil {
|
||||||
@@ -94,7 +97,7 @@ func Server(cfg *config.Config) *cli.Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
server, err := debug.Server(
|
debugServer, err := debug.Server(
|
||||||
debug.Logger(logger),
|
debug.Logger(logger),
|
||||||
debug.Context(ctx),
|
debug.Context(ctx),
|
||||||
debug.Config(cfg),
|
debug.Config(cfg),
|
||||||
@@ -104,8 +107,8 @@ func Server(cfg *config.Config) *cli.Command {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
gr.Add(server.ListenAndServe, func(_ error) {
|
gr.Add(debugServer.ListenAndServe, func(_ error) {
|
||||||
_ = server.Shutdown(ctx)
|
_ = debugServer.Shutdown(ctx)
|
||||||
cancel()
|
cancel()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,21 +1,36 @@
|
|||||||
package debug
|
package debug
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io"
|
"context"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
|
||||||
"github.com/owncloud/ocis/v2/ocis-pkg/log"
|
"github.com/owncloud/ocis/v2/ocis-pkg/handlers"
|
||||||
"github.com/owncloud/ocis/v2/ocis-pkg/service/debug"
|
"github.com/owncloud/ocis/v2/ocis-pkg/service/debug"
|
||||||
"github.com/owncloud/ocis/v2/ocis-pkg/shared"
|
|
||||||
"github.com/owncloud/ocis/v2/ocis-pkg/version"
|
"github.com/owncloud/ocis/v2/ocis-pkg/version"
|
||||||
"github.com/owncloud/ocis/v2/services/idp/pkg/config"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Server initializes the debug service and server.
|
// Server initializes the debug service and server.
|
||||||
func Server(opts ...Option) (*http.Server, error) {
|
func Server(opts ...Option) (*http.Server, error) {
|
||||||
options := newOptions(opts...)
|
options := newOptions(opts...)
|
||||||
|
|
||||||
|
checkHandler := handlers.NewCheckHandler(
|
||||||
|
handlers.NewCheckHandlerConfiguration().
|
||||||
|
WithLogger(options.Logger).
|
||||||
|
WithCheck("tcp-check", func(ctx context.Context) error {
|
||||||
|
tcpURL := options.Config.Ldap.URI
|
||||||
|
u, err := url.Parse(options.Config.Ldap.URI)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if u.Host != "" {
|
||||||
|
tcpURL = u.Host
|
||||||
|
}
|
||||||
|
|
||||||
|
return handlers.NewTCPCheck(tcpURL)(ctx)
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
|
||||||
return debug.NewService(
|
return debug.NewService(
|
||||||
debug.Logger(options.Logger),
|
debug.Logger(options.Logger),
|
||||||
debug.Name(options.Config.Service.Name),
|
debug.Name(options.Config.Service.Name),
|
||||||
@@ -24,47 +39,7 @@ func Server(opts ...Option) (*http.Server, error) {
|
|||||||
debug.Token(options.Config.Debug.Token),
|
debug.Token(options.Config.Debug.Token),
|
||||||
debug.Pprof(options.Config.Debug.Pprof),
|
debug.Pprof(options.Config.Debug.Pprof),
|
||||||
debug.Zpages(options.Config.Debug.Zpages),
|
debug.Zpages(options.Config.Debug.Zpages),
|
||||||
debug.Health(health(options.Config, options.Logger)),
|
debug.Health(checkHandler),
|
||||||
debug.Ready(ready(options.Config)),
|
debug.Ready(checkHandler),
|
||||||
), nil
|
), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// health implements the health check.
|
|
||||||
func health(cfg *config.Config, l log.Logger) func(http.ResponseWriter, *http.Request) {
|
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
targetHost, err := url.Parse(cfg.Ldap.URI)
|
|
||||||
if err != nil {
|
|
||||||
l.Fatal().Err(err).Str("uri", cfg.Ldap.URI).Msg("invalid LDAP URI")
|
|
||||||
}
|
|
||||||
err = shared.RunChecklist(shared.TCPConnect(targetHost.Host))
|
|
||||||
retVal := http.StatusOK
|
|
||||||
if err != nil {
|
|
||||||
l.Error().Err(err).Msg("Healtcheck failed")
|
|
||||||
retVal = http.StatusInternalServerError
|
|
||||||
}
|
|
||||||
w.Header().Set("Content-Type", "text/plain")
|
|
||||||
w.WriteHeader(retVal)
|
|
||||||
|
|
||||||
_, err = io.WriteString(w, http.StatusText(retVal))
|
|
||||||
if err != nil {
|
|
||||||
l.Fatal().Err(err).Msg("Could not write health check body")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ready implements the ready check.
|
|
||||||
func ready(cfg *config.Config) func(http.ResponseWriter, *http.Request) {
|
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
w.Header().Set("Content-Type", "text/plain")
|
|
||||||
w.WriteHeader(http.StatusOK)
|
|
||||||
// if we can call this function, a http(200) is a valid response as
|
|
||||||
// there is nothing we can check at this point for IDP
|
|
||||||
// if there is a mishap when initializing, there is a minimal (talking ms or ns window)
|
|
||||||
// timeframe where this code is callable
|
|
||||||
_, err := io.WriteString(w, http.StatusText(http.StatusOK))
|
|
||||||
// io.WriteString should not fail but if it does, we want to know.
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ func Server(cfg *config.Config) *cli.Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
server, err := debug.Server(
|
debugServer, err := debug.Server(
|
||||||
debug.Logger(logger),
|
debug.Logger(logger),
|
||||||
debug.Context(ctx),
|
debug.Context(ctx),
|
||||||
debug.Config(cfg),
|
debug.Config(cfg),
|
||||||
@@ -97,9 +97,8 @@ func Server(cfg *config.Config) *cli.Command {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
gr.Add(server.ListenAndServe, func(err error) {
|
gr.Add(debugServer.ListenAndServe, func(_ error) {
|
||||||
logger.Error().Err(err)
|
_ = debugServer.Shutdown(ctx)
|
||||||
_ = server.Shutdown(ctx)
|
|
||||||
cancel()
|
cancel()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,18 +1,22 @@
|
|||||||
package debug
|
package debug
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/owncloud/ocis/v2/ocis-pkg/handlers"
|
||||||
"github.com/owncloud/ocis/v2/ocis-pkg/service/debug"
|
"github.com/owncloud/ocis/v2/ocis-pkg/service/debug"
|
||||||
"github.com/owncloud/ocis/v2/ocis-pkg/version"
|
"github.com/owncloud/ocis/v2/ocis-pkg/version"
|
||||||
"github.com/owncloud/ocis/v2/services/invitations/pkg/config"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Server initializes the debug service and server.
|
// Server initializes the debug service and server.
|
||||||
func Server(opts ...Option) (*http.Server, error) {
|
func Server(opts ...Option) (*http.Server, error) {
|
||||||
options := newOptions(opts...)
|
options := newOptions(opts...)
|
||||||
|
|
||||||
|
checkHandler := handlers.NewCheckHandler(
|
||||||
|
handlers.NewCheckHandlerConfiguration().
|
||||||
|
WithLogger(options.Logger),
|
||||||
|
)
|
||||||
|
|
||||||
return debug.NewService(
|
return debug.NewService(
|
||||||
debug.Logger(options.Logger),
|
debug.Logger(options.Logger),
|
||||||
debug.Name(options.Config.Service.Name),
|
debug.Name(options.Config.Service.Name),
|
||||||
@@ -21,43 +25,11 @@ func Server(opts ...Option) (*http.Server, error) {
|
|||||||
debug.Token(options.Config.Debug.Token),
|
debug.Token(options.Config.Debug.Token),
|
||||||
debug.Pprof(options.Config.Debug.Pprof),
|
debug.Pprof(options.Config.Debug.Pprof),
|
||||||
debug.Zpages(options.Config.Debug.Zpages),
|
debug.Zpages(options.Config.Debug.Zpages),
|
||||||
debug.Health(health(options.Config)),
|
debug.Health(checkHandler),
|
||||||
debug.Ready(ready(options.Config)),
|
debug.Ready(checkHandler),
|
||||||
debug.CorsAllowedOrigins(options.Config.HTTP.CORS.AllowedOrigins),
|
debug.CorsAllowedOrigins(options.Config.HTTP.CORS.AllowedOrigins),
|
||||||
debug.CorsAllowedMethods(options.Config.HTTP.CORS.AllowedMethods),
|
debug.CorsAllowedMethods(options.Config.HTTP.CORS.AllowedMethods),
|
||||||
debug.CorsAllowedHeaders(options.Config.HTTP.CORS.AllowedHeaders),
|
debug.CorsAllowedHeaders(options.Config.HTTP.CORS.AllowedHeaders),
|
||||||
debug.CorsAllowCredentials(options.Config.HTTP.CORS.AllowCredentials),
|
debug.CorsAllowCredentials(options.Config.HTTP.CORS.AllowCredentials),
|
||||||
), nil
|
), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// health implements the health check.
|
|
||||||
func health(cfg *config.Config) func(http.ResponseWriter, *http.Request) {
|
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
w.Header().Set("Content-Type", "text/plain")
|
|
||||||
w.WriteHeader(http.StatusOK)
|
|
||||||
|
|
||||||
// TODO: check if services are up and running
|
|
||||||
|
|
||||||
_, err := io.WriteString(w, http.StatusText(http.StatusOK))
|
|
||||||
// io.WriteString should not fail but if it does, we want to know.
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ready implements the ready check.
|
|
||||||
func ready(cfg *config.Config) func(http.ResponseWriter, *http.Request) {
|
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
w.Header().Set("Content-Type", "text/plain")
|
|
||||||
w.WriteHeader(http.StatusOK)
|
|
||||||
|
|
||||||
// TODO: check if services are up and running
|
|
||||||
|
|
||||||
_, err := io.WriteString(w, http.StatusText(http.StatusOK))
|
|
||||||
// io.WriteString should not fail but if it does, we want to know.
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -7,16 +7,15 @@ import (
|
|||||||
|
|
||||||
"github.com/oklog/run"
|
"github.com/oklog/run"
|
||||||
|
|
||||||
|
"github.com/urfave/cli/v2"
|
||||||
|
|
||||||
"github.com/owncloud/ocis/v2/ocis-pkg/config/configlog"
|
"github.com/owncloud/ocis/v2/ocis-pkg/config/configlog"
|
||||||
pkgcrypto "github.com/owncloud/ocis/v2/ocis-pkg/crypto"
|
pkgcrypto "github.com/owncloud/ocis/v2/ocis-pkg/crypto"
|
||||||
"github.com/owncloud/ocis/v2/ocis-pkg/handlers"
|
|
||||||
"github.com/owncloud/ocis/v2/ocis-pkg/service/debug"
|
|
||||||
"github.com/owncloud/ocis/v2/ocis-pkg/version"
|
|
||||||
"github.com/owncloud/ocis/v2/services/nats/pkg/config"
|
"github.com/owncloud/ocis/v2/services/nats/pkg/config"
|
||||||
"github.com/owncloud/ocis/v2/services/nats/pkg/config/parser"
|
"github.com/owncloud/ocis/v2/services/nats/pkg/config/parser"
|
||||||
"github.com/owncloud/ocis/v2/services/nats/pkg/logging"
|
"github.com/owncloud/ocis/v2/services/nats/pkg/logging"
|
||||||
|
"github.com/owncloud/ocis/v2/services/nats/pkg/server/debug"
|
||||||
"github.com/owncloud/ocis/v2/services/nats/pkg/server/nats"
|
"github.com/owncloud/ocis/v2/services/nats/pkg/server/nats"
|
||||||
"github.com/urfave/cli/v2"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Server is the entrypoint for the server command.
|
// Server is the entrypoint for the server command.
|
||||||
@@ -37,20 +36,18 @@ func Server(cfg *config.Config) *cli.Command {
|
|||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
{
|
{
|
||||||
server := debug.NewService(
|
debugServer, err := debug.Server(
|
||||||
debug.Logger(logger),
|
debug.Logger(logger),
|
||||||
debug.Name(cfg.Service.Name),
|
debug.Context(ctx),
|
||||||
debug.Version(version.GetString()),
|
debug.Config(cfg),
|
||||||
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),
|
|
||||||
)
|
)
|
||||||
|
if err != nil {
|
||||||
|
logger.Info().Err(err).Str("transport", "debug").Msg("Failed to initialize server")
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
gr.Add(server.ListenAndServe, func(_ error) {
|
gr.Add(debugServer.ListenAndServe, func(_ error) {
|
||||||
_ = server.Shutdown(ctx)
|
_ = debugServer.Shutdown(ctx)
|
||||||
cancel()
|
cancel()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,50 @@
|
|||||||
|
package debug
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"github.com/owncloud/ocis/v2/ocis-pkg/log"
|
||||||
|
"github.com/owncloud/ocis/v2/services/nats/pkg/config"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Option defines a single option function.
|
||||||
|
type Option func(o *Options)
|
||||||
|
|
||||||
|
// Options defines the available options for this package.
|
||||||
|
type Options struct {
|
||||||
|
Logger log.Logger
|
||||||
|
Context context.Context
|
||||||
|
Config *config.Config
|
||||||
|
}
|
||||||
|
|
||||||
|
// newOptions initializes the available default options.
|
||||||
|
func newOptions(opts ...Option) Options {
|
||||||
|
opt := Options{}
|
||||||
|
|
||||||
|
for _, o := range opts {
|
||||||
|
o(&opt)
|
||||||
|
}
|
||||||
|
|
||||||
|
return opt
|
||||||
|
}
|
||||||
|
|
||||||
|
// Logger provides a function to set the logger option.
|
||||||
|
func Logger(val log.Logger) Option {
|
||||||
|
return func(o *Options) {
|
||||||
|
o.Logger = val
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Context provides a function to set the context option.
|
||||||
|
func Context(val context.Context) Option {
|
||||||
|
return func(o *Options) {
|
||||||
|
o.Context = val
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Config provides a function to set the config option.
|
||||||
|
func Config(val *config.Config) Option {
|
||||||
|
return func(o *Options) {
|
||||||
|
o.Config = val
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
package debug
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/owncloud/ocis/v2/ocis-pkg/handlers"
|
||||||
|
"github.com/owncloud/ocis/v2/ocis-pkg/service/debug"
|
||||||
|
"github.com/owncloud/ocis/v2/ocis-pkg/version"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Server initializes the debug service and server.
|
||||||
|
func Server(opts ...Option) (*http.Server, error) {
|
||||||
|
options := newOptions(opts...)
|
||||||
|
|
||||||
|
checkHandler := handlers.NewCheckHandler(
|
||||||
|
handlers.NewCheckHandlerConfiguration().
|
||||||
|
WithLogger(options.Logger),
|
||||||
|
)
|
||||||
|
|
||||||
|
return debug.NewService(
|
||||||
|
debug.Logger(options.Logger),
|
||||||
|
debug.Name(options.Config.Service.Name),
|
||||||
|
debug.Version(version.GetString()),
|
||||||
|
debug.Address(options.Config.Debug.Addr),
|
||||||
|
debug.Token(options.Config.Debug.Token),
|
||||||
|
debug.Pprof(options.Config.Debug.Pprof),
|
||||||
|
debug.Zpages(options.Config.Debug.Zpages),
|
||||||
|
debug.Health(checkHandler),
|
||||||
|
debug.Ready(checkHandler),
|
||||||
|
), nil
|
||||||
|
}
|
||||||
@@ -10,18 +10,17 @@ import (
|
|||||||
"github.com/cs3org/reva/v2/pkg/events"
|
"github.com/cs3org/reva/v2/pkg/events"
|
||||||
"github.com/cs3org/reva/v2/pkg/events/stream"
|
"github.com/cs3org/reva/v2/pkg/events/stream"
|
||||||
"github.com/cs3org/reva/v2/pkg/rgrpc/todo/pool"
|
"github.com/cs3org/reva/v2/pkg/rgrpc/todo/pool"
|
||||||
|
|
||||||
"github.com/owncloud/ocis/v2/ocis-pkg/config/configlog"
|
"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/registry"
|
||||||
"github.com/owncloud/ocis/v2/ocis-pkg/service/debug"
|
|
||||||
"github.com/owncloud/ocis/v2/ocis-pkg/service/grpc"
|
"github.com/owncloud/ocis/v2/ocis-pkg/service/grpc"
|
||||||
"github.com/owncloud/ocis/v2/ocis-pkg/tracing"
|
"github.com/owncloud/ocis/v2/ocis-pkg/tracing"
|
||||||
"github.com/owncloud/ocis/v2/ocis-pkg/version"
|
|
||||||
settingssvc "github.com/owncloud/ocis/v2/protogen/gen/ocis/services/settings/v0"
|
settingssvc "github.com/owncloud/ocis/v2/protogen/gen/ocis/services/settings/v0"
|
||||||
"github.com/owncloud/ocis/v2/services/notifications/pkg/channels"
|
"github.com/owncloud/ocis/v2/services/notifications/pkg/channels"
|
||||||
"github.com/owncloud/ocis/v2/services/notifications/pkg/config"
|
"github.com/owncloud/ocis/v2/services/notifications/pkg/config"
|
||||||
"github.com/owncloud/ocis/v2/services/notifications/pkg/config/parser"
|
"github.com/owncloud/ocis/v2/services/notifications/pkg/config/parser"
|
||||||
"github.com/owncloud/ocis/v2/services/notifications/pkg/logging"
|
"github.com/owncloud/ocis/v2/services/notifications/pkg/logging"
|
||||||
|
"github.com/owncloud/ocis/v2/services/notifications/pkg/server/debug"
|
||||||
"github.com/owncloud/ocis/v2/services/notifications/pkg/service"
|
"github.com/owncloud/ocis/v2/services/notifications/pkg/service"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -58,20 +57,18 @@ func Server(cfg *config.Config) *cli.Command {
|
|||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
{
|
{
|
||||||
server := debug.NewService(
|
debugServer, err := debug.Server(
|
||||||
debug.Logger(logger),
|
debug.Logger(logger),
|
||||||
debug.Name(cfg.Service.Name),
|
debug.Context(ctx),
|
||||||
debug.Version(version.GetString()),
|
debug.Config(cfg),
|
||||||
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),
|
|
||||||
)
|
)
|
||||||
|
if err != nil {
|
||||||
|
logger.Info().Err(err).Str("transport", "debug").Msg("Failed to initialize server")
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
gr.Add(server.ListenAndServe, func(_ error) {
|
gr.Add(debugServer.ListenAndServe, func(_ error) {
|
||||||
_ = server.Shutdown(ctx)
|
_ = debugServer.Shutdown(ctx)
|
||||||
cancel()
|
cancel()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,50 @@
|
|||||||
|
package debug
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"github.com/owncloud/ocis/v2/ocis-pkg/log"
|
||||||
|
"github.com/owncloud/ocis/v2/services/notifications/pkg/config"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Option defines a single option function.
|
||||||
|
type Option func(o *Options)
|
||||||
|
|
||||||
|
// Options defines the available options for this package.
|
||||||
|
type Options struct {
|
||||||
|
Logger log.Logger
|
||||||
|
Context context.Context
|
||||||
|
Config *config.Config
|
||||||
|
}
|
||||||
|
|
||||||
|
// newOptions initializes the available default options.
|
||||||
|
func newOptions(opts ...Option) Options {
|
||||||
|
opt := Options{}
|
||||||
|
|
||||||
|
for _, o := range opts {
|
||||||
|
o(&opt)
|
||||||
|
}
|
||||||
|
|
||||||
|
return opt
|
||||||
|
}
|
||||||
|
|
||||||
|
// Logger provides a function to set the logger option.
|
||||||
|
func Logger(val log.Logger) Option {
|
||||||
|
return func(o *Options) {
|
||||||
|
o.Logger = val
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Context provides a function to set the context option.
|
||||||
|
func Context(val context.Context) Option {
|
||||||
|
return func(o *Options) {
|
||||||
|
o.Context = val
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Config provides a function to set the config option.
|
||||||
|
func Config(val *config.Config) Option {
|
||||||
|
return func(o *Options) {
|
||||||
|
o.Config = val
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
package debug
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/owncloud/ocis/v2/ocis-pkg/handlers"
|
||||||
|
"github.com/owncloud/ocis/v2/ocis-pkg/service/debug"
|
||||||
|
"github.com/owncloud/ocis/v2/ocis-pkg/version"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Server initializes the debug service and server.
|
||||||
|
func Server(opts ...Option) (*http.Server, error) {
|
||||||
|
options := newOptions(opts...)
|
||||||
|
|
||||||
|
checkHandler := handlers.NewCheckHandler(
|
||||||
|
handlers.NewCheckHandlerConfiguration().
|
||||||
|
WithLogger(options.Logger),
|
||||||
|
)
|
||||||
|
|
||||||
|
return debug.NewService(
|
||||||
|
debug.Logger(options.Logger),
|
||||||
|
debug.Name(options.Config.Service.Name),
|
||||||
|
debug.Version(version.GetString()),
|
||||||
|
debug.Address(options.Config.Debug.Addr),
|
||||||
|
debug.Token(options.Config.Debug.Token),
|
||||||
|
debug.Pprof(options.Config.Debug.Pprof),
|
||||||
|
debug.Zpages(options.Config.Debug.Zpages),
|
||||||
|
debug.Health(checkHandler),
|
||||||
|
debug.Ready(checkHandler),
|
||||||
|
), nil
|
||||||
|
}
|
||||||
@@ -1,18 +1,22 @@
|
|||||||
package debug
|
package debug
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/owncloud/ocis/v2/ocis-pkg/handlers"
|
||||||
"github.com/owncloud/ocis/v2/ocis-pkg/service/debug"
|
"github.com/owncloud/ocis/v2/ocis-pkg/service/debug"
|
||||||
"github.com/owncloud/ocis/v2/ocis-pkg/version"
|
"github.com/owncloud/ocis/v2/ocis-pkg/version"
|
||||||
"github.com/owncloud/ocis/v2/services/ocdav/pkg/config"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Server initializes the debug service and server.
|
// Server initializes the debug service and server.
|
||||||
func Server(opts ...Option) (*http.Server, error) {
|
func Server(opts ...Option) (*http.Server, error) {
|
||||||
options := newOptions(opts...)
|
options := newOptions(opts...)
|
||||||
|
|
||||||
|
checkHandler := handlers.NewCheckHandler(
|
||||||
|
handlers.NewCheckHandlerConfiguration().
|
||||||
|
WithLogger(options.Logger),
|
||||||
|
)
|
||||||
|
|
||||||
return debug.NewService(
|
return debug.NewService(
|
||||||
debug.Logger(options.Logger),
|
debug.Logger(options.Logger),
|
||||||
debug.Name(options.Config.Service.Name),
|
debug.Name(options.Config.Service.Name),
|
||||||
@@ -21,43 +25,11 @@ func Server(opts ...Option) (*http.Server, error) {
|
|||||||
debug.Token(options.Config.Debug.Token),
|
debug.Token(options.Config.Debug.Token),
|
||||||
debug.Pprof(options.Config.Debug.Pprof),
|
debug.Pprof(options.Config.Debug.Pprof),
|
||||||
debug.Zpages(options.Config.Debug.Zpages),
|
debug.Zpages(options.Config.Debug.Zpages),
|
||||||
debug.Health(health(options.Config)),
|
debug.Health(checkHandler),
|
||||||
debug.Ready(ready(options.Config)),
|
debug.Ready(checkHandler),
|
||||||
//debug.CorsAllowedOrigins(options.Config.HTTP.CORS.AllowedOrigins),
|
//debug.CorsAllowedOrigins(options.Config.HTTP.CORS.AllowedOrigins),
|
||||||
//debug.CorsAllowedMethods(options.Config.HTTP.CORS.AllowedMethods),
|
//debug.CorsAllowedMethods(options.Config.HTTP.CORS.AllowedMethods),
|
||||||
//debug.CorsAllowedHeaders(options.Config.HTTP.CORS.AllowedHeaders),
|
//debug.CorsAllowedHeaders(options.Config.HTTP.CORS.AllowedHeaders),
|
||||||
//debug.CorsAllowCredentials(options.Config.HTTP.CORS.AllowCredentials),
|
//debug.CorsAllowCredentials(options.Config.HTTP.CORS.AllowCredentials),
|
||||||
), nil
|
), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// health implements the health check.
|
|
||||||
func health(cfg *config.Config) func(http.ResponseWriter, *http.Request) {
|
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
w.Header().Set("Content-Type", "text/plain")
|
|
||||||
w.WriteHeader(http.StatusOK)
|
|
||||||
|
|
||||||
// TODO: check if services are up and running
|
|
||||||
|
|
||||||
_, err := io.WriteString(w, http.StatusText(http.StatusOK))
|
|
||||||
// io.WriteString should not fail but if it does, we want to know.
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ready implements the ready check.
|
|
||||||
func ready(cfg *config.Config) func(http.ResponseWriter, *http.Request) {
|
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
w.Header().Set("Content-Type", "text/plain")
|
|
||||||
w.WriteHeader(http.StatusOK)
|
|
||||||
|
|
||||||
// TODO: check if services are up and running
|
|
||||||
|
|
||||||
_, err := io.WriteString(w, http.StatusText(http.StatusOK))
|
|
||||||
// io.WriteString should not fail but if it does, we want to know.
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -75,6 +75,7 @@ func Server(cfg *config.Config) *cli.Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
gr.Add(debugServer.ListenAndServe, func(_ error) {
|
gr.Add(debugServer.ListenAndServe, func(_ error) {
|
||||||
|
_ = debugServer.Shutdown(ctx)
|
||||||
cancel()
|
cancel()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -1,18 +1,22 @@
|
|||||||
package debug
|
package debug
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/owncloud/ocis/v2/ocis-pkg/handlers"
|
||||||
"github.com/owncloud/ocis/v2/ocis-pkg/service/debug"
|
"github.com/owncloud/ocis/v2/ocis-pkg/service/debug"
|
||||||
"github.com/owncloud/ocis/v2/ocis-pkg/version"
|
"github.com/owncloud/ocis/v2/ocis-pkg/version"
|
||||||
"github.com/owncloud/ocis/v2/services/ocm/pkg/config"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Server initializes the debug service and server.
|
// Server initializes the debug service and server.
|
||||||
func Server(opts ...Option) (*http.Server, error) {
|
func Server(opts ...Option) (*http.Server, error) {
|
||||||
options := newOptions(opts...)
|
options := newOptions(opts...)
|
||||||
|
|
||||||
|
checkHandler := handlers.NewCheckHandler(
|
||||||
|
handlers.NewCheckHandlerConfiguration().
|
||||||
|
WithLogger(options.Logger),
|
||||||
|
)
|
||||||
|
|
||||||
return debug.NewService(
|
return debug.NewService(
|
||||||
debug.Logger(options.Logger),
|
debug.Logger(options.Logger),
|
||||||
debug.Name(options.Config.Service.Name),
|
debug.Name(options.Config.Service.Name),
|
||||||
@@ -21,43 +25,11 @@ func Server(opts ...Option) (*http.Server, error) {
|
|||||||
debug.Token(options.Config.Debug.Token),
|
debug.Token(options.Config.Debug.Token),
|
||||||
debug.Pprof(options.Config.Debug.Pprof),
|
debug.Pprof(options.Config.Debug.Pprof),
|
||||||
debug.Zpages(options.Config.Debug.Zpages),
|
debug.Zpages(options.Config.Debug.Zpages),
|
||||||
debug.Health(health(options.Config)),
|
debug.Health(checkHandler),
|
||||||
debug.Ready(ready(options.Config)),
|
debug.Ready(checkHandler),
|
||||||
//debug.CorsAllowedOrigins(options.Config.HTTP.CORS.AllowedOrigins),
|
//debug.CorsAllowedOrigins(options.Config.HTTP.CORS.AllowedOrigins),
|
||||||
//debug.CorsAllowedMethods(options.Config.HTTP.CORS.AllowedMethods),
|
//debug.CorsAllowedMethods(options.Config.HTTP.CORS.AllowedMethods),
|
||||||
//debug.CorsAllowedHeaders(options.Config.HTTP.CORS.AllowedHeaders),
|
//debug.CorsAllowedHeaders(options.Config.HTTP.CORS.AllowedHeaders),
|
||||||
//debug.CorsAllowCredentials(options.Config.HTTP.CORS.AllowCredentials),
|
//debug.CorsAllowCredentials(options.Config.HTTP.CORS.AllowCredentials),
|
||||||
), nil
|
), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// health implements the health check.
|
|
||||||
func health(cfg *config.Config) func(http.ResponseWriter, *http.Request) {
|
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
w.Header().Set("Content-Type", "text/plain")
|
|
||||||
w.WriteHeader(http.StatusOK)
|
|
||||||
|
|
||||||
// TODO: check if services are up and running
|
|
||||||
|
|
||||||
_, err := io.WriteString(w, http.StatusText(http.StatusOK))
|
|
||||||
// io.WriteString should not fail but if it does, we want to know.
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ready implements the ready check.
|
|
||||||
func ready(cfg *config.Config) func(http.ResponseWriter, *http.Request) {
|
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
w.Header().Set("Content-Type", "text/plain")
|
|
||||||
w.WriteHeader(http.StatusOK)
|
|
||||||
|
|
||||||
// TODO: check if services are up and running
|
|
||||||
|
|
||||||
_, err := io.WriteString(w, http.StatusText(http.StatusOK))
|
|
||||||
// io.WriteString should not fail but if it does, we want to know.
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,18 +1,22 @@
|
|||||||
package debug
|
package debug
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/owncloud/ocis/v2/ocis-pkg/handlers"
|
||||||
"github.com/owncloud/ocis/v2/ocis-pkg/service/debug"
|
"github.com/owncloud/ocis/v2/ocis-pkg/service/debug"
|
||||||
"github.com/owncloud/ocis/v2/ocis-pkg/version"
|
"github.com/owncloud/ocis/v2/ocis-pkg/version"
|
||||||
"github.com/owncloud/ocis/v2/services/ocs/pkg/config"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Server initializes the debug service and server.
|
// Server initializes the debug service and server.
|
||||||
func Server(opts ...Option) (*http.Server, error) {
|
func Server(opts ...Option) (*http.Server, error) {
|
||||||
options := newOptions(opts...)
|
options := newOptions(opts...)
|
||||||
|
|
||||||
|
checkHandler := handlers.NewCheckHandler(
|
||||||
|
handlers.NewCheckHandlerConfiguration().
|
||||||
|
WithLogger(options.Logger),
|
||||||
|
)
|
||||||
|
|
||||||
return debug.NewService(
|
return debug.NewService(
|
||||||
debug.Logger(options.Logger),
|
debug.Logger(options.Logger),
|
||||||
debug.Name(options.Config.Service.Name),
|
debug.Name(options.Config.Service.Name),
|
||||||
@@ -21,43 +25,11 @@ func Server(opts ...Option) (*http.Server, error) {
|
|||||||
debug.Token(options.Config.Debug.Token),
|
debug.Token(options.Config.Debug.Token),
|
||||||
debug.Pprof(options.Config.Debug.Pprof),
|
debug.Pprof(options.Config.Debug.Pprof),
|
||||||
debug.Zpages(options.Config.Debug.Zpages),
|
debug.Zpages(options.Config.Debug.Zpages),
|
||||||
debug.Health(health(options.Config)),
|
debug.Health(checkHandler),
|
||||||
debug.Ready(ready(options.Config)),
|
debug.Ready(checkHandler),
|
||||||
debug.CorsAllowedOrigins(options.Config.HTTP.CORS.AllowedOrigins),
|
debug.CorsAllowedOrigins(options.Config.HTTP.CORS.AllowedOrigins),
|
||||||
debug.CorsAllowedMethods(options.Config.HTTP.CORS.AllowedMethods),
|
debug.CorsAllowedMethods(options.Config.HTTP.CORS.AllowedMethods),
|
||||||
debug.CorsAllowedHeaders(options.Config.HTTP.CORS.AllowedHeaders),
|
debug.CorsAllowedHeaders(options.Config.HTTP.CORS.AllowedHeaders),
|
||||||
debug.CorsAllowCredentials(options.Config.HTTP.CORS.AllowCredentials),
|
debug.CorsAllowCredentials(options.Config.HTTP.CORS.AllowCredentials),
|
||||||
), nil
|
), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// health implements the health check.
|
|
||||||
func health(cfg *config.Config) func(http.ResponseWriter, *http.Request) {
|
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
w.Header().Set("Content-Type", "text/plain")
|
|
||||||
w.WriteHeader(http.StatusOK)
|
|
||||||
|
|
||||||
// TODO: check if services are up and running
|
|
||||||
|
|
||||||
_, err := io.WriteString(w, http.StatusText(http.StatusOK))
|
|
||||||
// io.WriteString should not fail but if it does, we want to know.
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ready implements the ready check.
|
|
||||||
func ready(cfg *config.Config) func(http.ResponseWriter, *http.Request) {
|
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
w.Header().Set("Content-Type", "text/plain")
|
|
||||||
w.WriteHeader(http.StatusOK)
|
|
||||||
|
|
||||||
// TODO: check if services are up and running
|
|
||||||
|
|
||||||
_, err := io.WriteString(w, http.StatusText(http.StatusOK))
|
|
||||||
// io.WriteString should not fail but if it does, we want to know.
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -3,14 +3,13 @@ package command
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
|
||||||
"net/http"
|
|
||||||
|
|
||||||
"github.com/cs3org/reva/v2/pkg/events/stream"
|
"github.com/cs3org/reva/v2/pkg/events/stream"
|
||||||
"github.com/oklog/run"
|
"github.com/oklog/run"
|
||||||
|
"github.com/urfave/cli/v2"
|
||||||
|
|
||||||
"github.com/owncloud/ocis/v2/ocis-pkg/config/configlog"
|
"github.com/owncloud/ocis/v2/ocis-pkg/config/configlog"
|
||||||
"github.com/owncloud/ocis/v2/ocis-pkg/log"
|
"github.com/owncloud/ocis/v2/ocis-pkg/log"
|
||||||
"github.com/owncloud/ocis/v2/ocis-pkg/service/debug"
|
|
||||||
"github.com/owncloud/ocis/v2/ocis-pkg/service/grpc"
|
"github.com/owncloud/ocis/v2/ocis-pkg/service/grpc"
|
||||||
"github.com/owncloud/ocis/v2/ocis-pkg/tracing"
|
"github.com/owncloud/ocis/v2/ocis-pkg/tracing"
|
||||||
"github.com/owncloud/ocis/v2/ocis-pkg/version"
|
"github.com/owncloud/ocis/v2/ocis-pkg/version"
|
||||||
@@ -18,9 +17,9 @@ import (
|
|||||||
"github.com/owncloud/ocis/v2/services/policies/pkg/config"
|
"github.com/owncloud/ocis/v2/services/policies/pkg/config"
|
||||||
"github.com/owncloud/ocis/v2/services/policies/pkg/config/parser"
|
"github.com/owncloud/ocis/v2/services/policies/pkg/config/parser"
|
||||||
"github.com/owncloud/ocis/v2/services/policies/pkg/engine/opa"
|
"github.com/owncloud/ocis/v2/services/policies/pkg/engine/opa"
|
||||||
|
"github.com/owncloud/ocis/v2/services/policies/pkg/server/debug"
|
||||||
svcEvent "github.com/owncloud/ocis/v2/services/policies/pkg/service/event"
|
svcEvent "github.com/owncloud/ocis/v2/services/policies/pkg/service/event"
|
||||||
svcGRPC "github.com/owncloud/ocis/v2/services/policies/pkg/service/grpc"
|
svcGRPC "github.com/owncloud/ocis/v2/services/policies/pkg/service/grpc"
|
||||||
"github.com/urfave/cli/v2"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Server is the entrypoint for the server command.
|
// Server is the entrypoint for the server command.
|
||||||
@@ -121,46 +120,18 @@ func Server(cfg *config.Config) *cli.Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
server := debug.NewService(
|
debugServer, err := debug.Server(
|
||||||
debug.Logger(logger),
|
debug.Logger(logger),
|
||||||
debug.Name(cfg.Service.Name),
|
debug.Context(ctx),
|
||||||
debug.Version(version.GetString()),
|
debug.Config(cfg),
|
||||||
debug.Address(cfg.Debug.Addr),
|
|
||||||
debug.Token(cfg.Debug.Token),
|
|
||||||
debug.Pprof(cfg.Debug.Pprof),
|
|
||||||
debug.Zpages(cfg.Debug.Zpages),
|
|
||||||
debug.Health(
|
|
||||||
func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
w.Header().Set("Content-Type", "text/plain")
|
|
||||||
w.WriteHeader(http.StatusOK)
|
|
||||||
|
|
||||||
// TODO: check if services are up and running
|
|
||||||
|
|
||||||
_, err := io.WriteString(w, http.StatusText(http.StatusOK))
|
|
||||||
// io.WriteString should not fail but if it does, we want to know.
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
),
|
|
||||||
debug.Ready(
|
|
||||||
func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
w.Header().Set("Content-Type", "text/plain")
|
|
||||||
w.WriteHeader(http.StatusOK)
|
|
||||||
|
|
||||||
// TODO: check if services are up and running
|
|
||||||
|
|
||||||
_, err := io.WriteString(w, http.StatusText(http.StatusOK))
|
|
||||||
// io.WriteString should not fail but if it does, we want to know.
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
|
if err != nil {
|
||||||
|
logger.Info().Err(err).Str("transport", "debug").Msg("Failed to initialize server")
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
gr.Add(server.ListenAndServe, func(_ error) {
|
gr.Add(debugServer.ListenAndServe, func(_ error) {
|
||||||
_ = server.Shutdown(ctx)
|
_ = debugServer.Shutdown(ctx)
|
||||||
cancel()
|
cancel()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,50 @@
|
|||||||
|
package debug
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"github.com/owncloud/ocis/v2/ocis-pkg/log"
|
||||||
|
"github.com/owncloud/ocis/v2/services/policies/pkg/config"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Option defines a single option function.
|
||||||
|
type Option func(o *Options)
|
||||||
|
|
||||||
|
// Options defines the available options for this package.
|
||||||
|
type Options struct {
|
||||||
|
Logger log.Logger
|
||||||
|
Context context.Context
|
||||||
|
Config *config.Config
|
||||||
|
}
|
||||||
|
|
||||||
|
// newOptions initializes the available default options.
|
||||||
|
func newOptions(opts ...Option) Options {
|
||||||
|
opt := Options{}
|
||||||
|
|
||||||
|
for _, o := range opts {
|
||||||
|
o(&opt)
|
||||||
|
}
|
||||||
|
|
||||||
|
return opt
|
||||||
|
}
|
||||||
|
|
||||||
|
// Logger provides a function to set the logger option.
|
||||||
|
func Logger(val log.Logger) Option {
|
||||||
|
return func(o *Options) {
|
||||||
|
o.Logger = val
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Context provides a function to set the context option.
|
||||||
|
func Context(val context.Context) Option {
|
||||||
|
return func(o *Options) {
|
||||||
|
o.Context = val
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Config provides a function to set the config option.
|
||||||
|
func Config(val *config.Config) Option {
|
||||||
|
return func(o *Options) {
|
||||||
|
o.Config = val
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
package debug
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/owncloud/ocis/v2/ocis-pkg/handlers"
|
||||||
|
"github.com/owncloud/ocis/v2/ocis-pkg/service/debug"
|
||||||
|
"github.com/owncloud/ocis/v2/ocis-pkg/version"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Server initializes the debug service and server.
|
||||||
|
func Server(opts ...Option) (*http.Server, error) {
|
||||||
|
options := newOptions(opts...)
|
||||||
|
|
||||||
|
checkHandler := handlers.NewCheckHandler(
|
||||||
|
handlers.NewCheckHandlerConfiguration().
|
||||||
|
WithLogger(options.Logger),
|
||||||
|
)
|
||||||
|
|
||||||
|
return debug.NewService(
|
||||||
|
debug.Logger(options.Logger),
|
||||||
|
debug.Name(options.Config.Service.Name),
|
||||||
|
debug.Version(version.GetString()),
|
||||||
|
debug.Address(options.Config.Debug.Addr),
|
||||||
|
debug.Token(options.Config.Debug.Token),
|
||||||
|
debug.Pprof(options.Config.Debug.Pprof),
|
||||||
|
debug.Zpages(options.Config.Debug.Zpages),
|
||||||
|
debug.Health(checkHandler),
|
||||||
|
debug.Ready(checkHandler),
|
||||||
|
), nil
|
||||||
|
}
|
||||||
@@ -8,16 +8,15 @@ import (
|
|||||||
"github.com/cs3org/reva/v2/pkg/events/stream"
|
"github.com/cs3org/reva/v2/pkg/events/stream"
|
||||||
"github.com/cs3org/reva/v2/pkg/store"
|
"github.com/cs3org/reva/v2/pkg/store"
|
||||||
"github.com/oklog/run"
|
"github.com/oklog/run"
|
||||||
"github.com/owncloud/ocis/v2/ocis-pkg/handlers"
|
"github.com/urfave/cli/v2"
|
||||||
"github.com/owncloud/ocis/v2/ocis-pkg/service/debug"
|
microstore "go-micro.dev/v4/store"
|
||||||
|
|
||||||
"github.com/owncloud/ocis/v2/ocis-pkg/tracing"
|
"github.com/owncloud/ocis/v2/ocis-pkg/tracing"
|
||||||
"github.com/owncloud/ocis/v2/ocis-pkg/version"
|
|
||||||
"github.com/owncloud/ocis/v2/services/postprocessing/pkg/config"
|
"github.com/owncloud/ocis/v2/services/postprocessing/pkg/config"
|
||||||
"github.com/owncloud/ocis/v2/services/postprocessing/pkg/config/parser"
|
"github.com/owncloud/ocis/v2/services/postprocessing/pkg/config/parser"
|
||||||
"github.com/owncloud/ocis/v2/services/postprocessing/pkg/logging"
|
"github.com/owncloud/ocis/v2/services/postprocessing/pkg/logging"
|
||||||
|
"github.com/owncloud/ocis/v2/services/postprocessing/pkg/server/debug"
|
||||||
"github.com/owncloud/ocis/v2/services/postprocessing/pkg/service"
|
"github.com/owncloud/ocis/v2/services/postprocessing/pkg/service"
|
||||||
"github.com/urfave/cli/v2"
|
|
||||||
microstore "go-micro.dev/v4/store"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Server is the entrypoint for the server command.
|
// Server is the entrypoint for the server command.
|
||||||
@@ -86,20 +85,18 @@ func Server(cfg *config.Config) *cli.Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
server := debug.NewService(
|
debugServer, err := debug.Server(
|
||||||
debug.Logger(logger),
|
debug.Logger(logger),
|
||||||
debug.Name(cfg.Service.Name),
|
debug.Context(ctx),
|
||||||
debug.Version(version.GetString()),
|
debug.Config(cfg),
|
||||||
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),
|
|
||||||
)
|
)
|
||||||
|
if err != nil {
|
||||||
|
logger.Info().Err(err).Str("transport", "debug").Msg("Failed to initialize server")
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
gr.Add(server.ListenAndServe, func(_ error) {
|
gr.Add(debugServer.ListenAndServe, func(_ error) {
|
||||||
_ = server.Shutdown(ctx)
|
_ = debugServer.Shutdown(ctx)
|
||||||
cancel()
|
cancel()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,50 @@
|
|||||||
|
package debug
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"github.com/owncloud/ocis/v2/ocis-pkg/log"
|
||||||
|
"github.com/owncloud/ocis/v2/services/postprocessing/pkg/config"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Option defines a single option function.
|
||||||
|
type Option func(o *Options)
|
||||||
|
|
||||||
|
// Options defines the available options for this package.
|
||||||
|
type Options struct {
|
||||||
|
Logger log.Logger
|
||||||
|
Context context.Context
|
||||||
|
Config *config.Config
|
||||||
|
}
|
||||||
|
|
||||||
|
// newOptions initializes the available default options.
|
||||||
|
func newOptions(opts ...Option) Options {
|
||||||
|
opt := Options{}
|
||||||
|
|
||||||
|
for _, o := range opts {
|
||||||
|
o(&opt)
|
||||||
|
}
|
||||||
|
|
||||||
|
return opt
|
||||||
|
}
|
||||||
|
|
||||||
|
// Logger provides a function to set the logger option.
|
||||||
|
func Logger(val log.Logger) Option {
|
||||||
|
return func(o *Options) {
|
||||||
|
o.Logger = val
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Context provides a function to set the context option.
|
||||||
|
func Context(val context.Context) Option {
|
||||||
|
return func(o *Options) {
|
||||||
|
o.Context = val
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Config provides a function to set the config option.
|
||||||
|
func Config(val *config.Config) Option {
|
||||||
|
return func(o *Options) {
|
||||||
|
o.Config = val
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
package debug
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/owncloud/ocis/v2/ocis-pkg/handlers"
|
||||||
|
"github.com/owncloud/ocis/v2/ocis-pkg/service/debug"
|
||||||
|
"github.com/owncloud/ocis/v2/ocis-pkg/version"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Server initializes the debug service and server.
|
||||||
|
func Server(opts ...Option) (*http.Server, error) {
|
||||||
|
options := newOptions(opts...)
|
||||||
|
|
||||||
|
checkHandler := handlers.NewCheckHandler(
|
||||||
|
handlers.NewCheckHandlerConfiguration().
|
||||||
|
WithLogger(options.Logger),
|
||||||
|
)
|
||||||
|
|
||||||
|
return debug.NewService(
|
||||||
|
debug.Logger(options.Logger),
|
||||||
|
debug.Name(options.Config.Service.Name),
|
||||||
|
debug.Version(version.GetString()),
|
||||||
|
debug.Address(options.Config.Debug.Addr),
|
||||||
|
debug.Token(options.Config.Debug.Token),
|
||||||
|
debug.Pprof(options.Config.Debug.Pprof),
|
||||||
|
debug.Zpages(options.Config.Debug.Zpages),
|
||||||
|
debug.Health(checkHandler),
|
||||||
|
debug.Ready(checkHandler),
|
||||||
|
), nil
|
||||||
|
}
|
||||||
@@ -214,7 +214,7 @@ func Server(cfg *config.Config) *cli.Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
server, err := debug.Server(
|
debugServer, err := debug.Server(
|
||||||
debug.Logger(logger),
|
debug.Logger(logger),
|
||||||
debug.Context(ctx),
|
debug.Context(ctx),
|
||||||
debug.Config(cfg),
|
debug.Config(cfg),
|
||||||
@@ -224,8 +224,8 @@ func Server(cfg *config.Config) *cli.Command {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
gr.Add(server.ListenAndServe, func(_ error) {
|
gr.Add(debugServer.ListenAndServe, func(_ error) {
|
||||||
_ = server.Shutdown(ctx)
|
_ = debugServer.Shutdown(ctx)
|
||||||
cancel()
|
cancel()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,10 +2,11 @@ package debug
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"io"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
masker "github.com/ggwhite/go-masker"
|
"github.com/ggwhite/go-masker"
|
||||||
|
|
||||||
|
"github.com/owncloud/ocis/v2/ocis-pkg/handlers"
|
||||||
"github.com/owncloud/ocis/v2/ocis-pkg/service/debug"
|
"github.com/owncloud/ocis/v2/ocis-pkg/service/debug"
|
||||||
"github.com/owncloud/ocis/v2/ocis-pkg/version"
|
"github.com/owncloud/ocis/v2/ocis-pkg/version"
|
||||||
"github.com/owncloud/ocis/v2/services/proxy/pkg/config"
|
"github.com/owncloud/ocis/v2/services/proxy/pkg/config"
|
||||||
@@ -15,6 +16,12 @@ import (
|
|||||||
func Server(opts ...Option) (*http.Server, error) {
|
func Server(opts ...Option) (*http.Server, error) {
|
||||||
options := newOptions(opts...)
|
options := newOptions(opts...)
|
||||||
|
|
||||||
|
checkHandler := handlers.NewCheckHandler(
|
||||||
|
handlers.NewCheckHandlerConfiguration().
|
||||||
|
WithLogger(options.Logger),
|
||||||
|
)
|
||||||
|
|
||||||
|
var configDumpFunc http.HandlerFunc = configDump(options.Config)
|
||||||
return debug.NewService(
|
return debug.NewService(
|
||||||
debug.Logger(options.Logger),
|
debug.Logger(options.Logger),
|
||||||
debug.Name(options.Config.Service.Name),
|
debug.Name(options.Config.Service.Name),
|
||||||
@@ -23,44 +30,12 @@ func Server(opts ...Option) (*http.Server, error) {
|
|||||||
debug.Token(options.Config.Debug.Token),
|
debug.Token(options.Config.Debug.Token),
|
||||||
debug.Pprof(options.Config.Debug.Pprof),
|
debug.Pprof(options.Config.Debug.Pprof),
|
||||||
debug.Zpages(options.Config.Debug.Zpages),
|
debug.Zpages(options.Config.Debug.Zpages),
|
||||||
debug.Health(health(options.Config)),
|
debug.Health(checkHandler),
|
||||||
debug.Ready(ready(options.Config)),
|
debug.Ready(checkHandler),
|
||||||
debug.ConfigDump(configDump(options.Config)),
|
debug.ConfigDump(configDumpFunc),
|
||||||
), nil
|
), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// health implements the health check.
|
|
||||||
func health(cfg *config.Config) func(http.ResponseWriter, *http.Request) {
|
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
w.Header().Set("Content-Type", "text/plain")
|
|
||||||
w.WriteHeader(http.StatusOK)
|
|
||||||
|
|
||||||
// TODO: check if services are up and running
|
|
||||||
|
|
||||||
_, err := io.WriteString(w, http.StatusText(http.StatusOK))
|
|
||||||
// io.WriteString should not fail but if it does, we want to know.
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ready implements the ready check.
|
|
||||||
func ready(cfg *config.Config) func(http.ResponseWriter, *http.Request) {
|
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
w.Header().Set("Content-Type", "text/plain")
|
|
||||||
w.WriteHeader(http.StatusOK)
|
|
||||||
|
|
||||||
// TODO: check if services are up and running
|
|
||||||
|
|
||||||
_, err := io.WriteString(w, http.StatusText(http.StatusOK))
|
|
||||||
// io.WriteString should not fail but if it does, we want to know.
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// configDump implements the config dump
|
// configDump implements the config dump
|
||||||
func configDump(cfg *config.Config) func(http.ResponseWriter, *http.Request) {
|
func configDump(cfg *config.Config) func(http.ResponseWriter, *http.Request) {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ func Server(cfg *config.Config) *cli.Command {
|
|||||||
cancel()
|
cancel()
|
||||||
})
|
})
|
||||||
|
|
||||||
server, err := debug.Server(
|
debugServer, err := debug.Server(
|
||||||
debug.Logger(logger),
|
debug.Logger(logger),
|
||||||
debug.Context(ctx),
|
debug.Context(ctx),
|
||||||
debug.Config(cfg),
|
debug.Config(cfg),
|
||||||
@@ -80,8 +80,8 @@ func Server(cfg *config.Config) *cli.Command {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
gr.Add(server.ListenAndServe, func(_ error) {
|
gr.Add(debugServer.ListenAndServe, func(_ error) {
|
||||||
_ = server.Shutdown(ctx)
|
_ = debugServer.Shutdown(ctx)
|
||||||
cancel()
|
cancel()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -1,18 +1,22 @@
|
|||||||
package debug
|
package debug
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/owncloud/ocis/v2/ocis-pkg/handlers"
|
||||||
"github.com/owncloud/ocis/v2/ocis-pkg/service/debug"
|
"github.com/owncloud/ocis/v2/ocis-pkg/service/debug"
|
||||||
"github.com/owncloud/ocis/v2/ocis-pkg/version"
|
"github.com/owncloud/ocis/v2/ocis-pkg/version"
|
||||||
"github.com/owncloud/ocis/v2/services/search/pkg/config"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Server initializes the debug service and server.
|
// Server initializes the debug service and server.
|
||||||
func Server(opts ...Option) (*http.Server, error) {
|
func Server(opts ...Option) (*http.Server, error) {
|
||||||
options := newOptions(opts...)
|
options := newOptions(opts...)
|
||||||
|
|
||||||
|
checkHandler := handlers.NewCheckHandler(
|
||||||
|
handlers.NewCheckHandlerConfiguration().
|
||||||
|
WithLogger(options.Logger),
|
||||||
|
)
|
||||||
|
|
||||||
return debug.NewService(
|
return debug.NewService(
|
||||||
debug.Logger(options.Logger),
|
debug.Logger(options.Logger),
|
||||||
debug.Name(options.Config.Service.Name),
|
debug.Name(options.Config.Service.Name),
|
||||||
@@ -21,39 +25,7 @@ func Server(opts ...Option) (*http.Server, error) {
|
|||||||
debug.Token(options.Config.Debug.Token),
|
debug.Token(options.Config.Debug.Token),
|
||||||
debug.Pprof(options.Config.Debug.Pprof),
|
debug.Pprof(options.Config.Debug.Pprof),
|
||||||
debug.Zpages(options.Config.Debug.Zpages),
|
debug.Zpages(options.Config.Debug.Zpages),
|
||||||
debug.Health(health(options.Config)),
|
debug.Health(checkHandler),
|
||||||
debug.Ready(ready(options.Config)),
|
debug.Ready(checkHandler),
|
||||||
), nil
|
), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// health implements the health check.
|
|
||||||
func health(cfg *config.Config) func(http.ResponseWriter, *http.Request) {
|
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
w.Header().Set("Content-Type", "text/plain")
|
|
||||||
w.WriteHeader(http.StatusOK)
|
|
||||||
|
|
||||||
// TODO: check if services are up and running
|
|
||||||
|
|
||||||
_, err := io.WriteString(w, http.StatusText(http.StatusOK))
|
|
||||||
// io.WriteString should not fail but if it does, we want to know.
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ready implements the ready check.
|
|
||||||
func ready(cfg *config.Config) func(http.ResponseWriter, *http.Request) {
|
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
w.Header().Set("Content-Type", "text/plain")
|
|
||||||
w.WriteHeader(http.StatusOK)
|
|
||||||
|
|
||||||
// TODO: check if services are up and running
|
|
||||||
|
|
||||||
_, err := io.WriteString(w, http.StatusText(http.StatusOK))
|
|
||||||
// io.WriteString should not fail but if it does, we want to know.
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -94,7 +94,11 @@ func Server(cfg *config.Config) *cli.Command {
|
|||||||
})
|
})
|
||||||
|
|
||||||
// prepare a debug server and add it to the group run.
|
// prepare a debug server and add it to the group run.
|
||||||
debugServer, err := debug.Server(debug.Logger(logger), debug.Context(ctx), debug.Config(cfg))
|
debugServer, err := debug.Server(
|
||||||
|
debug.Logger(logger),
|
||||||
|
debug.Context(ctx),
|
||||||
|
debug.Config(cfg),
|
||||||
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Error().Err(err).Str("server", "debug").Msg("Failed to initialize server")
|
logger.Error().Err(err).Str("server", "debug").Msg("Failed to initialize server")
|
||||||
return err
|
return err
|
||||||
|
|||||||
@@ -1,18 +1,22 @@
|
|||||||
package debug
|
package debug
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/owncloud/ocis/v2/ocis-pkg/handlers"
|
||||||
"github.com/owncloud/ocis/v2/ocis-pkg/service/debug"
|
"github.com/owncloud/ocis/v2/ocis-pkg/service/debug"
|
||||||
"github.com/owncloud/ocis/v2/ocis-pkg/version"
|
"github.com/owncloud/ocis/v2/ocis-pkg/version"
|
||||||
"github.com/owncloud/ocis/v2/services/settings/pkg/config"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Server initializes the debug service and server.
|
// Server initializes the debug service and server.
|
||||||
func Server(opts ...Option) (*http.Server, error) {
|
func Server(opts ...Option) (*http.Server, error) {
|
||||||
options := newOptions(opts...)
|
options := newOptions(opts...)
|
||||||
|
|
||||||
|
checkHandler := handlers.NewCheckHandler(
|
||||||
|
handlers.NewCheckHandlerConfiguration().
|
||||||
|
WithLogger(options.Logger),
|
||||||
|
)
|
||||||
|
|
||||||
return debug.NewService(
|
return debug.NewService(
|
||||||
debug.Logger(options.Logger),
|
debug.Logger(options.Logger),
|
||||||
debug.Name(options.Config.Service.Name),
|
debug.Name(options.Config.Service.Name),
|
||||||
@@ -21,43 +25,11 @@ func Server(opts ...Option) (*http.Server, error) {
|
|||||||
debug.Token(options.Config.Debug.Token),
|
debug.Token(options.Config.Debug.Token),
|
||||||
debug.Pprof(options.Config.Debug.Pprof),
|
debug.Pprof(options.Config.Debug.Pprof),
|
||||||
debug.Zpages(options.Config.Debug.Zpages),
|
debug.Zpages(options.Config.Debug.Zpages),
|
||||||
debug.Health(health(options.Config)),
|
debug.Health(checkHandler),
|
||||||
debug.Ready(ready(options.Config)),
|
debug.Ready(checkHandler),
|
||||||
debug.CorsAllowedOrigins(options.Config.HTTP.CORS.AllowedOrigins),
|
debug.CorsAllowedOrigins(options.Config.HTTP.CORS.AllowedOrigins),
|
||||||
debug.CorsAllowedMethods(options.Config.HTTP.CORS.AllowedMethods),
|
debug.CorsAllowedMethods(options.Config.HTTP.CORS.AllowedMethods),
|
||||||
debug.CorsAllowedHeaders(options.Config.HTTP.CORS.AllowedHeaders),
|
debug.CorsAllowedHeaders(options.Config.HTTP.CORS.AllowedHeaders),
|
||||||
debug.CorsAllowCredentials(options.Config.HTTP.CORS.AllowCredentials),
|
debug.CorsAllowCredentials(options.Config.HTTP.CORS.AllowCredentials),
|
||||||
), nil
|
), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// health implements the health check.
|
|
||||||
func health(cfg *config.Config) func(http.ResponseWriter, *http.Request) {
|
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
w.Header().Set("Content-Type", "text/plain")
|
|
||||||
w.WriteHeader(http.StatusOK)
|
|
||||||
|
|
||||||
// TODO: check if services are up and running
|
|
||||||
|
|
||||||
_, err := io.WriteString(w, http.StatusText(http.StatusOK))
|
|
||||||
// io.WriteString should not fail but if it does, we want to know.
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ready implements the ready check.
|
|
||||||
func ready(cfg *config.Config) func(http.ResponseWriter, *http.Request) {
|
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
w.Header().Set("Content-Type", "text/plain")
|
|
||||||
w.WriteHeader(http.StatusOK)
|
|
||||||
|
|
||||||
// TODO: check if services are up and running
|
|
||||||
|
|
||||||
_, err := io.WriteString(w, http.StatusText(http.StatusOK))
|
|
||||||
// io.WriteString should not fail but if it does, we want to know.
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,18 +1,22 @@
|
|||||||
package debug
|
package debug
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/owncloud/ocis/v2/ocis-pkg/handlers"
|
||||||
"github.com/owncloud/ocis/v2/ocis-pkg/service/debug"
|
"github.com/owncloud/ocis/v2/ocis-pkg/service/debug"
|
||||||
"github.com/owncloud/ocis/v2/ocis-pkg/version"
|
"github.com/owncloud/ocis/v2/ocis-pkg/version"
|
||||||
"github.com/owncloud/ocis/v2/services/sharing/pkg/config"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Server initializes the debug service and server.
|
// Server initializes the debug service and server.
|
||||||
func Server(opts ...Option) (*http.Server, error) {
|
func Server(opts ...Option) (*http.Server, error) {
|
||||||
options := newOptions(opts...)
|
options := newOptions(opts...)
|
||||||
|
|
||||||
|
checkHandler := handlers.NewCheckHandler(
|
||||||
|
handlers.NewCheckHandlerConfiguration().
|
||||||
|
WithLogger(options.Logger),
|
||||||
|
)
|
||||||
|
|
||||||
return debug.NewService(
|
return debug.NewService(
|
||||||
debug.Logger(options.Logger),
|
debug.Logger(options.Logger),
|
||||||
debug.Name(options.Config.Service.Name),
|
debug.Name(options.Config.Service.Name),
|
||||||
@@ -21,43 +25,11 @@ func Server(opts ...Option) (*http.Server, error) {
|
|||||||
debug.Token(options.Config.Debug.Token),
|
debug.Token(options.Config.Debug.Token),
|
||||||
debug.Pprof(options.Config.Debug.Pprof),
|
debug.Pprof(options.Config.Debug.Pprof),
|
||||||
debug.Zpages(options.Config.Debug.Zpages),
|
debug.Zpages(options.Config.Debug.Zpages),
|
||||||
debug.Health(health(options.Config)),
|
debug.Health(checkHandler),
|
||||||
debug.Ready(ready(options.Config)),
|
debug.Ready(checkHandler),
|
||||||
//debug.CorsAllowedOrigins(options.Config.HTTP.CORS.AllowedOrigins),
|
//debug.CorsAllowedOrigins(options.Config.HTTP.CORS.AllowedOrigins),
|
||||||
//debug.CorsAllowedMethods(options.Config.HTTP.CORS.AllowedMethods),
|
//debug.CorsAllowedMethods(options.Config.HTTP.CORS.AllowedMethods),
|
||||||
//debug.CorsAllowedHeaders(options.Config.HTTP.CORS.AllowedHeaders),
|
//debug.CorsAllowedHeaders(options.Config.HTTP.CORS.AllowedHeaders),
|
||||||
//debug.CorsAllowCredentials(options.Config.HTTP.CORS.AllowCredentials),
|
//debug.CorsAllowCredentials(options.Config.HTTP.CORS.AllowCredentials),
|
||||||
), nil
|
), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// health implements the health check.
|
|
||||||
func health(cfg *config.Config) func(http.ResponseWriter, *http.Request) {
|
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
w.Header().Set("Content-Type", "text/plain")
|
|
||||||
w.WriteHeader(http.StatusOK)
|
|
||||||
|
|
||||||
// TODO: check if services are up and running
|
|
||||||
|
|
||||||
_, err := io.WriteString(w, http.StatusText(http.StatusOK))
|
|
||||||
// io.WriteString should not fail but if it does, we want to know.
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ready implements the ready check.
|
|
||||||
func ready(cfg *config.Config) func(http.ResponseWriter, *http.Request) {
|
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
w.Header().Set("Content-Type", "text/plain")
|
|
||||||
w.WriteHeader(http.StatusOK)
|
|
||||||
|
|
||||||
// TODO: check if services are up and running
|
|
||||||
|
|
||||||
_, err := io.WriteString(w, http.StatusText(http.StatusOK))
|
|
||||||
// io.WriteString should not fail but if it does, we want to know.
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -10,13 +10,11 @@ import (
|
|||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v2"
|
||||||
|
|
||||||
"github.com/owncloud/ocis/v2/ocis-pkg/config/configlog"
|
"github.com/owncloud/ocis/v2/ocis-pkg/config/configlog"
|
||||||
"github.com/owncloud/ocis/v2/ocis-pkg/handlers"
|
|
||||||
"github.com/owncloud/ocis/v2/ocis-pkg/log"
|
"github.com/owncloud/ocis/v2/ocis-pkg/log"
|
||||||
"github.com/owncloud/ocis/v2/ocis-pkg/service/debug"
|
|
||||||
"github.com/owncloud/ocis/v2/ocis-pkg/tracing"
|
"github.com/owncloud/ocis/v2/ocis-pkg/tracing"
|
||||||
"github.com/owncloud/ocis/v2/ocis-pkg/version"
|
|
||||||
"github.com/owncloud/ocis/v2/services/sse/pkg/config"
|
"github.com/owncloud/ocis/v2/services/sse/pkg/config"
|
||||||
"github.com/owncloud/ocis/v2/services/sse/pkg/config/parser"
|
"github.com/owncloud/ocis/v2/services/sse/pkg/config/parser"
|
||||||
|
"github.com/owncloud/ocis/v2/services/sse/pkg/server/debug"
|
||||||
"github.com/owncloud/ocis/v2/services/sse/pkg/server/http"
|
"github.com/owncloud/ocis/v2/services/sse/pkg/server/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -77,20 +75,18 @@ func Server(cfg *config.Config) *cli.Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
server := debug.NewService(
|
debugServer, err := debug.Server(
|
||||||
debug.Logger(logger),
|
debug.Logger(logger),
|
||||||
debug.Name(cfg.Service.Name),
|
debug.Context(ctx),
|
||||||
debug.Version(version.GetString()),
|
debug.Config(cfg),
|
||||||
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),
|
|
||||||
)
|
)
|
||||||
|
if err != nil {
|
||||||
|
logger.Info().Err(err).Str("transport", "debug").Msg("Failed to initialize server")
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
gr.Add(server.ListenAndServe, func(_ error) {
|
gr.Add(debugServer.ListenAndServe, func(_ error) {
|
||||||
_ = server.Shutdown(ctx)
|
_ = debugServer.Shutdown(ctx)
|
||||||
cancel()
|
cancel()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,50 @@
|
|||||||
|
package debug
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"github.com/owncloud/ocis/v2/ocis-pkg/log"
|
||||||
|
"github.com/owncloud/ocis/v2/services/sse/pkg/config"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Option defines a single option function.
|
||||||
|
type Option func(o *Options)
|
||||||
|
|
||||||
|
// Options defines the available options for this package.
|
||||||
|
type Options struct {
|
||||||
|
Logger log.Logger
|
||||||
|
Context context.Context
|
||||||
|
Config *config.Config
|
||||||
|
}
|
||||||
|
|
||||||
|
// newOptions initializes the available default options.
|
||||||
|
func newOptions(opts ...Option) Options {
|
||||||
|
opt := Options{}
|
||||||
|
|
||||||
|
for _, o := range opts {
|
||||||
|
o(&opt)
|
||||||
|
}
|
||||||
|
|
||||||
|
return opt
|
||||||
|
}
|
||||||
|
|
||||||
|
// Logger provides a function to set the logger option.
|
||||||
|
func Logger(val log.Logger) Option {
|
||||||
|
return func(o *Options) {
|
||||||
|
o.Logger = val
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Context provides a function to set the context option.
|
||||||
|
func Context(val context.Context) Option {
|
||||||
|
return func(o *Options) {
|
||||||
|
o.Context = val
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Config provides a function to set the config option.
|
||||||
|
func Config(val *config.Config) Option {
|
||||||
|
return func(o *Options) {
|
||||||
|
o.Config = val
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
package debug
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/owncloud/ocis/v2/ocis-pkg/handlers"
|
||||||
|
"github.com/owncloud/ocis/v2/ocis-pkg/service/debug"
|
||||||
|
"github.com/owncloud/ocis/v2/ocis-pkg/version"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Server initializes the debug service and server.
|
||||||
|
func Server(opts ...Option) (*http.Server, error) {
|
||||||
|
options := newOptions(opts...)
|
||||||
|
|
||||||
|
checkHandler := handlers.NewCheckHandler(
|
||||||
|
handlers.NewCheckHandlerConfiguration().
|
||||||
|
WithLogger(options.Logger),
|
||||||
|
)
|
||||||
|
|
||||||
|
return debug.NewService(
|
||||||
|
debug.Logger(options.Logger),
|
||||||
|
debug.Name(options.Config.Service.Name),
|
||||||
|
debug.Version(version.GetString()),
|
||||||
|
debug.Address(options.Config.Debug.Addr),
|
||||||
|
debug.Token(options.Config.Debug.Token),
|
||||||
|
debug.Pprof(options.Config.Debug.Pprof),
|
||||||
|
debug.Zpages(options.Config.Debug.Zpages),
|
||||||
|
debug.Health(checkHandler),
|
||||||
|
debug.Ready(checkHandler),
|
||||||
|
), nil
|
||||||
|
}
|
||||||
@@ -74,6 +74,7 @@ func Server(cfg *config.Config) *cli.Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
gr.Add(debugServer.ListenAndServe, func(_ error) {
|
gr.Add(debugServer.ListenAndServe, func(_ error) {
|
||||||
|
_ = debugServer.Shutdown(ctx)
|
||||||
cancel()
|
cancel()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -1,18 +1,22 @@
|
|||||||
package debug
|
package debug
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/owncloud/ocis/v2/ocis-pkg/handlers"
|
||||||
"github.com/owncloud/ocis/v2/ocis-pkg/service/debug"
|
"github.com/owncloud/ocis/v2/ocis-pkg/service/debug"
|
||||||
"github.com/owncloud/ocis/v2/ocis-pkg/version"
|
"github.com/owncloud/ocis/v2/ocis-pkg/version"
|
||||||
"github.com/owncloud/ocis/v2/services/storage-publiclink/pkg/config"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Server initializes the debug service and server.
|
// Server initializes the debug service and server.
|
||||||
func Server(opts ...Option) (*http.Server, error) {
|
func Server(opts ...Option) (*http.Server, error) {
|
||||||
options := newOptions(opts...)
|
options := newOptions(opts...)
|
||||||
|
|
||||||
|
checkHandler := handlers.NewCheckHandler(
|
||||||
|
handlers.NewCheckHandlerConfiguration().
|
||||||
|
WithLogger(options.Logger),
|
||||||
|
)
|
||||||
|
|
||||||
return debug.NewService(
|
return debug.NewService(
|
||||||
debug.Logger(options.Logger),
|
debug.Logger(options.Logger),
|
||||||
debug.Name(options.Config.Service.Name),
|
debug.Name(options.Config.Service.Name),
|
||||||
@@ -21,43 +25,11 @@ func Server(opts ...Option) (*http.Server, error) {
|
|||||||
debug.Token(options.Config.Debug.Token),
|
debug.Token(options.Config.Debug.Token),
|
||||||
debug.Pprof(options.Config.Debug.Pprof),
|
debug.Pprof(options.Config.Debug.Pprof),
|
||||||
debug.Zpages(options.Config.Debug.Zpages),
|
debug.Zpages(options.Config.Debug.Zpages),
|
||||||
debug.Health(health(options.Config)),
|
debug.Health(checkHandler),
|
||||||
debug.Ready(ready(options.Config)),
|
debug.Ready(checkHandler),
|
||||||
//debug.CorsAllowedOrigins(options.Config.HTTP.CORS.AllowedOrigins),
|
//debug.CorsAllowedOrigins(options.Config.HTTP.CORS.AllowedOrigins),
|
||||||
//debug.CorsAllowedMethods(options.Config.HTTP.CORS.AllowedMethods),
|
//debug.CorsAllowedMethods(options.Config.HTTP.CORS.AllowedMethods),
|
||||||
//debug.CorsAllowedHeaders(options.Config.HTTP.CORS.AllowedHeaders),
|
//debug.CorsAllowedHeaders(options.Config.HTTP.CORS.AllowedHeaders),
|
||||||
//debug.CorsAllowCredentials(options.Config.HTTP.CORS.AllowCredentials),
|
//debug.CorsAllowCredentials(options.Config.HTTP.CORS.AllowCredentials),
|
||||||
), nil
|
), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// health implements the health check.
|
|
||||||
func health(cfg *config.Config) func(http.ResponseWriter, *http.Request) {
|
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
w.Header().Set("Content-Type", "text/plain")
|
|
||||||
w.WriteHeader(http.StatusOK)
|
|
||||||
|
|
||||||
// TODO: check if services are up and running
|
|
||||||
|
|
||||||
_, err := io.WriteString(w, http.StatusText(http.StatusOK))
|
|
||||||
// io.WriteString should not fail but if it does, we want to know.
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ready implements the ready check.
|
|
||||||
func ready(cfg *config.Config) func(http.ResponseWriter, *http.Request) {
|
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
w.Header().Set("Content-Type", "text/plain")
|
|
||||||
w.WriteHeader(http.StatusOK)
|
|
||||||
|
|
||||||
// TODO: check if services are up and running
|
|
||||||
|
|
||||||
_, err := io.WriteString(w, http.StatusText(http.StatusOK))
|
|
||||||
// io.WriteString should not fail but if it does, we want to know.
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -74,6 +74,7 @@ func Server(cfg *config.Config) *cli.Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
gr.Add(debugServer.ListenAndServe, func(_ error) {
|
gr.Add(debugServer.ListenAndServe, func(_ error) {
|
||||||
|
_ = debugServer.Shutdown(ctx)
|
||||||
cancel()
|
cancel()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -1,18 +1,22 @@
|
|||||||
package debug
|
package debug
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/owncloud/ocis/v2/ocis-pkg/handlers"
|
||||||
"github.com/owncloud/ocis/v2/ocis-pkg/service/debug"
|
"github.com/owncloud/ocis/v2/ocis-pkg/service/debug"
|
||||||
"github.com/owncloud/ocis/v2/ocis-pkg/version"
|
"github.com/owncloud/ocis/v2/ocis-pkg/version"
|
||||||
"github.com/owncloud/ocis/v2/services/storage-shares/pkg/config"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Server initializes the debug service and server.
|
// Server initializes the debug service and server.
|
||||||
func Server(opts ...Option) (*http.Server, error) {
|
func Server(opts ...Option) (*http.Server, error) {
|
||||||
options := newOptions(opts...)
|
options := newOptions(opts...)
|
||||||
|
|
||||||
|
checkHandler := handlers.NewCheckHandler(
|
||||||
|
handlers.NewCheckHandlerConfiguration().
|
||||||
|
WithLogger(options.Logger),
|
||||||
|
)
|
||||||
|
|
||||||
return debug.NewService(
|
return debug.NewService(
|
||||||
debug.Logger(options.Logger),
|
debug.Logger(options.Logger),
|
||||||
debug.Name(options.Config.Service.Name),
|
debug.Name(options.Config.Service.Name),
|
||||||
@@ -21,43 +25,11 @@ func Server(opts ...Option) (*http.Server, error) {
|
|||||||
debug.Token(options.Config.Debug.Token),
|
debug.Token(options.Config.Debug.Token),
|
||||||
debug.Pprof(options.Config.Debug.Pprof),
|
debug.Pprof(options.Config.Debug.Pprof),
|
||||||
debug.Zpages(options.Config.Debug.Zpages),
|
debug.Zpages(options.Config.Debug.Zpages),
|
||||||
debug.Health(health(options.Config)),
|
debug.Health(checkHandler),
|
||||||
debug.Ready(ready(options.Config)),
|
debug.Ready(checkHandler),
|
||||||
//debug.CorsAllowedOrigins(options.Config.HTTP.CORS.AllowedOrigins),
|
//debug.CorsAllowedOrigins(options.Config.HTTP.CORS.AllowedOrigins),
|
||||||
//debug.CorsAllowedMethods(options.Config.HTTP.CORS.AllowedMethods),
|
//debug.CorsAllowedMethods(options.Config.HTTP.CORS.AllowedMethods),
|
||||||
//debug.CorsAllowedHeaders(options.Config.HTTP.CORS.AllowedHeaders),
|
//debug.CorsAllowedHeaders(options.Config.HTTP.CORS.AllowedHeaders),
|
||||||
//debug.CorsAllowCredentials(options.Config.HTTP.CORS.AllowCredentials),
|
//debug.CorsAllowCredentials(options.Config.HTTP.CORS.AllowCredentials),
|
||||||
), nil
|
), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// health implements the health check.
|
|
||||||
func health(cfg *config.Config) func(http.ResponseWriter, *http.Request) {
|
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
w.Header().Set("Content-Type", "text/plain")
|
|
||||||
w.WriteHeader(http.StatusOK)
|
|
||||||
|
|
||||||
// TODO: check if services are up and running
|
|
||||||
|
|
||||||
_, err := io.WriteString(w, http.StatusText(http.StatusOK))
|
|
||||||
// io.WriteString should not fail but if it does, we want to know.
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ready implements the ready check.
|
|
||||||
func ready(cfg *config.Config) func(http.ResponseWriter, *http.Request) {
|
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
w.Header().Set("Content-Type", "text/plain")
|
|
||||||
w.WriteHeader(http.StatusOK)
|
|
||||||
|
|
||||||
// TODO: check if services are up and running
|
|
||||||
|
|
||||||
_, err := io.WriteString(w, http.StatusText(http.StatusOK))
|
|
||||||
// io.WriteString should not fail but if it does, we want to know.
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -74,6 +74,7 @@ func Server(cfg *config.Config) *cli.Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
gr.Add(debugServer.ListenAndServe, func(_ error) {
|
gr.Add(debugServer.ListenAndServe, func(_ error) {
|
||||||
|
_ = debugServer.Shutdown(ctx)
|
||||||
cancel()
|
cancel()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -1,18 +1,22 @@
|
|||||||
package debug
|
package debug
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/owncloud/ocis/v2/ocis-pkg/handlers"
|
||||||
"github.com/owncloud/ocis/v2/ocis-pkg/service/debug"
|
"github.com/owncloud/ocis/v2/ocis-pkg/service/debug"
|
||||||
"github.com/owncloud/ocis/v2/ocis-pkg/version"
|
"github.com/owncloud/ocis/v2/ocis-pkg/version"
|
||||||
"github.com/owncloud/ocis/v2/services/storage-system/pkg/config"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Server initializes the debug service and server.
|
// Server initializes the debug service and server.
|
||||||
func Server(opts ...Option) (*http.Server, error) {
|
func Server(opts ...Option) (*http.Server, error) {
|
||||||
options := newOptions(opts...)
|
options := newOptions(opts...)
|
||||||
|
|
||||||
|
checkHandler := handlers.NewCheckHandler(
|
||||||
|
handlers.NewCheckHandlerConfiguration().
|
||||||
|
WithLogger(options.Logger),
|
||||||
|
)
|
||||||
|
|
||||||
return debug.NewService(
|
return debug.NewService(
|
||||||
debug.Logger(options.Logger),
|
debug.Logger(options.Logger),
|
||||||
debug.Name(options.Config.Service.Name),
|
debug.Name(options.Config.Service.Name),
|
||||||
@@ -21,43 +25,11 @@ func Server(opts ...Option) (*http.Server, error) {
|
|||||||
debug.Token(options.Config.Debug.Token),
|
debug.Token(options.Config.Debug.Token),
|
||||||
debug.Pprof(options.Config.Debug.Pprof),
|
debug.Pprof(options.Config.Debug.Pprof),
|
||||||
debug.Zpages(options.Config.Debug.Zpages),
|
debug.Zpages(options.Config.Debug.Zpages),
|
||||||
debug.Health(health(options.Config)),
|
debug.Health(checkHandler),
|
||||||
debug.Ready(ready(options.Config)),
|
debug.Ready(checkHandler),
|
||||||
//debug.CorsAllowedOrigins(options.Config.HTTP.CORS.AllowedOrigins),
|
//debug.CorsAllowedOrigins(options.Config.HTTP.CORS.AllowedOrigins),
|
||||||
//debug.CorsAllowedMethods(options.Config.HTTP.CORS.AllowedMethods),
|
//debug.CorsAllowedMethods(options.Config.HTTP.CORS.AllowedMethods),
|
||||||
//debug.CorsAllowedHeaders(options.Config.HTTP.CORS.AllowedHeaders),
|
//debug.CorsAllowedHeaders(options.Config.HTTP.CORS.AllowedHeaders),
|
||||||
//debug.CorsAllowCredentials(options.Config.HTTP.CORS.AllowCredentials),
|
//debug.CorsAllowCredentials(options.Config.HTTP.CORS.AllowCredentials),
|
||||||
), nil
|
), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// health implements the health check.
|
|
||||||
func health(cfg *config.Config) func(http.ResponseWriter, *http.Request) {
|
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
w.Header().Set("Content-Type", "text/plain")
|
|
||||||
w.WriteHeader(http.StatusOK)
|
|
||||||
|
|
||||||
// TODO: check if services are up and running
|
|
||||||
|
|
||||||
_, err := io.WriteString(w, http.StatusText(http.StatusOK))
|
|
||||||
// io.WriteString should not fail but if it does, we want to know.
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ready implements the ready check.
|
|
||||||
func ready(cfg *config.Config) func(http.ResponseWriter, *http.Request) {
|
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
w.Header().Set("Content-Type", "text/plain")
|
|
||||||
w.WriteHeader(http.StatusOK)
|
|
||||||
|
|
||||||
// TODO: check if services are up and running
|
|
||||||
|
|
||||||
_, err := io.WriteString(w, http.StatusText(http.StatusOK))
|
|
||||||
// io.WriteString should not fail but if it does, we want to know.
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -76,15 +76,7 @@ func Server(cfg *config.Config) *cli.Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
gr.Add(debugServer.ListenAndServe, func(err error) {
|
gr.Add(debugServer.ListenAndServe, func(err error) {
|
||||||
logger.Error().Err(err).Str("server", cfg.Service.Name).
|
_ = debugServer.Shutdown(ctx)
|
||||||
Msg("Shutting down debug server")
|
|
||||||
if err := debugServer.Shutdown(context.Background()); err != nil {
|
|
||||||
logger.Error().
|
|
||||||
Err(err).
|
|
||||||
Str("server", cfg.Service.Name).
|
|
||||||
Msg("Error during debug server shutdown")
|
|
||||||
}
|
|
||||||
|
|
||||||
cancel()
|
cancel()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -1,18 +1,22 @@
|
|||||||
package debug
|
package debug
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/owncloud/ocis/v2/ocis-pkg/handlers"
|
||||||
"github.com/owncloud/ocis/v2/ocis-pkg/service/debug"
|
"github.com/owncloud/ocis/v2/ocis-pkg/service/debug"
|
||||||
"github.com/owncloud/ocis/v2/ocis-pkg/version"
|
"github.com/owncloud/ocis/v2/ocis-pkg/version"
|
||||||
"github.com/owncloud/ocis/v2/services/storage-users/pkg/config"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Server initializes the debug service and server.
|
// Server initializes the debug service and server.
|
||||||
func Server(opts ...Option) (*http.Server, error) {
|
func Server(opts ...Option) (*http.Server, error) {
|
||||||
options := newOptions(opts...)
|
options := newOptions(opts...)
|
||||||
|
|
||||||
|
checkHandler := handlers.NewCheckHandler(
|
||||||
|
handlers.NewCheckHandlerConfiguration().
|
||||||
|
WithLogger(options.Logger),
|
||||||
|
)
|
||||||
|
|
||||||
return debug.NewService(
|
return debug.NewService(
|
||||||
debug.Logger(options.Logger),
|
debug.Logger(options.Logger),
|
||||||
debug.Context(options.Context),
|
debug.Context(options.Context),
|
||||||
@@ -22,43 +26,11 @@ func Server(opts ...Option) (*http.Server, error) {
|
|||||||
debug.Token(options.Config.Debug.Token),
|
debug.Token(options.Config.Debug.Token),
|
||||||
debug.Pprof(options.Config.Debug.Pprof),
|
debug.Pprof(options.Config.Debug.Pprof),
|
||||||
debug.Zpages(options.Config.Debug.Zpages),
|
debug.Zpages(options.Config.Debug.Zpages),
|
||||||
debug.Health(health(options.Config)),
|
debug.Health(checkHandler),
|
||||||
debug.Ready(ready(options.Config)),
|
debug.Ready(checkHandler),
|
||||||
//debug.CorsAllowedOrigins(options.Config.HTTP.CORS.AllowedOrigins),
|
//debug.CorsAllowedOrigins(options.Config.HTTP.CORS.AllowedOrigins),
|
||||||
//debug.CorsAllowedMethods(options.Config.HTTP.CORS.AllowedMethods),
|
//debug.CorsAllowedMethods(options.Config.HTTP.CORS.AllowedMethods),
|
||||||
//debug.CorsAllowedHeaders(options.Config.HTTP.CORS.AllowedHeaders),
|
//debug.CorsAllowedHeaders(options.Config.HTTP.CORS.AllowedHeaders),
|
||||||
//debug.CorsAllowCredentials(options.Config.HTTP.CORS.AllowCredentials),
|
//debug.CorsAllowCredentials(options.Config.HTTP.CORS.AllowCredentials),
|
||||||
), nil
|
), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// health implements the health check.
|
|
||||||
func health(cfg *config.Config) func(http.ResponseWriter, *http.Request) {
|
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
w.Header().Set("Content-Type", "text/plain")
|
|
||||||
w.WriteHeader(http.StatusOK)
|
|
||||||
|
|
||||||
// TODO: check if services are up and running
|
|
||||||
|
|
||||||
_, err := io.WriteString(w, http.StatusText(http.StatusOK))
|
|
||||||
// io.WriteString should not fail but if it does, we want to know.
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ready implements the ready check.
|
|
||||||
func ready(cfg *config.Config) func(http.ResponseWriter, *http.Request) {
|
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
w.Header().Set("Content-Type", "text/plain")
|
|
||||||
w.WriteHeader(http.StatusOK)
|
|
||||||
|
|
||||||
// TODO: check if services are up and running
|
|
||||||
|
|
||||||
_, err := io.WriteString(w, http.StatusText(http.StatusOK))
|
|
||||||
// io.WriteString should not fail but if it does, we want to know.
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -74,6 +74,7 @@ func Server(cfg *config.Config) *cli.Command {
|
|||||||
server, err := debug.Server(
|
server, err := debug.Server(
|
||||||
debug.Logger(logger),
|
debug.Logger(logger),
|
||||||
debug.Config(cfg),
|
debug.Config(cfg),
|
||||||
|
debug.Context(ctx),
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Info().Err(err).Str("transport", "debug").Msg("Failed to initialize server")
|
logger.Info().Err(err).Str("transport", "debug").Msg("Failed to initialize server")
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package debug
|
package debug
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
"github.com/owncloud/ocis/v2/ocis-pkg/log"
|
"github.com/owncloud/ocis/v2/ocis-pkg/log"
|
||||||
"github.com/owncloud/ocis/v2/services/thumbnails/pkg/config"
|
"github.com/owncloud/ocis/v2/services/thumbnails/pkg/config"
|
||||||
)
|
)
|
||||||
@@ -13,6 +15,7 @@ type Options struct {
|
|||||||
Name string
|
Name string
|
||||||
Address string
|
Address string
|
||||||
Logger log.Logger
|
Logger log.Logger
|
||||||
|
Context context.Context
|
||||||
Config *config.Config
|
Config *config.Config
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -34,6 +37,13 @@ func Logger(val log.Logger) Option {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Context provides a function to set the context option.
|
||||||
|
func Context(val context.Context) Option {
|
||||||
|
return func(o *Options) {
|
||||||
|
o.Context = val
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Config provides a function to set the config option.
|
// Config provides a function to set the config option.
|
||||||
func Config(val *config.Config) Option {
|
func Config(val *config.Config) Option {
|
||||||
return func(o *Options) {
|
return func(o *Options) {
|
||||||
|
|||||||
@@ -1,18 +1,22 @@
|
|||||||
package debug
|
package debug
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/owncloud/ocis/v2/ocis-pkg/handlers"
|
||||||
"github.com/owncloud/ocis/v2/ocis-pkg/service/debug"
|
"github.com/owncloud/ocis/v2/ocis-pkg/service/debug"
|
||||||
"github.com/owncloud/ocis/v2/ocis-pkg/version"
|
"github.com/owncloud/ocis/v2/ocis-pkg/version"
|
||||||
"github.com/owncloud/ocis/v2/services/thumbnails/pkg/config"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Server initializes the debug service and server.
|
// Server initializes the debug service and server.
|
||||||
func Server(opts ...Option) (*http.Server, error) {
|
func Server(opts ...Option) (*http.Server, error) {
|
||||||
options := newOptions(opts...)
|
options := newOptions(opts...)
|
||||||
|
|
||||||
|
checkHandler := handlers.NewCheckHandler(
|
||||||
|
handlers.NewCheckHandlerConfiguration().
|
||||||
|
WithLogger(options.Logger),
|
||||||
|
)
|
||||||
|
|
||||||
return debug.NewService(
|
return debug.NewService(
|
||||||
debug.Logger(options.Logger),
|
debug.Logger(options.Logger),
|
||||||
debug.Name(options.Config.Service.Name),
|
debug.Name(options.Config.Service.Name),
|
||||||
@@ -21,43 +25,11 @@ func Server(opts ...Option) (*http.Server, error) {
|
|||||||
debug.Token(options.Config.Debug.Token),
|
debug.Token(options.Config.Debug.Token),
|
||||||
debug.Pprof(options.Config.Debug.Pprof),
|
debug.Pprof(options.Config.Debug.Pprof),
|
||||||
debug.Zpages(options.Config.Debug.Zpages),
|
debug.Zpages(options.Config.Debug.Zpages),
|
||||||
debug.Health(health(options.Config)),
|
debug.Health(checkHandler),
|
||||||
debug.Ready(ready(options.Config)),
|
debug.Ready(checkHandler),
|
||||||
debug.CorsAllowedOrigins(options.Config.HTTP.CORS.AllowedOrigins),
|
debug.CorsAllowedOrigins(options.Config.HTTP.CORS.AllowedOrigins),
|
||||||
debug.CorsAllowedMethods(options.Config.HTTP.CORS.AllowedMethods),
|
debug.CorsAllowedMethods(options.Config.HTTP.CORS.AllowedMethods),
|
||||||
debug.CorsAllowedHeaders(options.Config.HTTP.CORS.AllowedHeaders),
|
debug.CorsAllowedHeaders(options.Config.HTTP.CORS.AllowedHeaders),
|
||||||
debug.CorsAllowCredentials(options.Config.HTTP.CORS.AllowCredentials),
|
debug.CorsAllowCredentials(options.Config.HTTP.CORS.AllowCredentials),
|
||||||
), nil
|
), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// health implements the health check.
|
|
||||||
func health(_ *config.Config) func(http.ResponseWriter, *http.Request) {
|
|
||||||
return func(w http.ResponseWriter, _ *http.Request) {
|
|
||||||
w.Header().Set("Content-Type", "text/plain")
|
|
||||||
w.WriteHeader(http.StatusOK)
|
|
||||||
|
|
||||||
// TODO: check if services are up and running
|
|
||||||
|
|
||||||
_, err := io.WriteString(w, http.StatusText(http.StatusOK))
|
|
||||||
// io.WriteString should not fail but if it does, we want to know.
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ready implements the ready check.
|
|
||||||
func ready(_ *config.Config) func(http.ResponseWriter, *http.Request) {
|
|
||||||
return func(w http.ResponseWriter, _ *http.Request) {
|
|
||||||
w.Header().Set("Content-Type", "text/plain")
|
|
||||||
w.WriteHeader(http.StatusOK)
|
|
||||||
|
|
||||||
// TODO: check if services are up and running
|
|
||||||
|
|
||||||
_, err := io.WriteString(w, http.StatusText(http.StatusOK))
|
|
||||||
// io.WriteString should not fail but if it does, we want to know.
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -9,10 +9,11 @@ import (
|
|||||||
"github.com/cs3org/reva/v2/pkg/rgrpc/todo/pool"
|
"github.com/cs3org/reva/v2/pkg/rgrpc/todo/pool"
|
||||||
"github.com/cs3org/reva/v2/pkg/store"
|
"github.com/cs3org/reva/v2/pkg/store"
|
||||||
"github.com/oklog/run"
|
"github.com/oklog/run"
|
||||||
|
"github.com/urfave/cli/v2"
|
||||||
|
microstore "go-micro.dev/v4/store"
|
||||||
|
|
||||||
"github.com/owncloud/ocis/v2/ocis-pkg/config/configlog"
|
"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/registry"
|
||||||
"github.com/owncloud/ocis/v2/ocis-pkg/service/debug"
|
|
||||||
ogrpc "github.com/owncloud/ocis/v2/ocis-pkg/service/grpc"
|
ogrpc "github.com/owncloud/ocis/v2/ocis-pkg/service/grpc"
|
||||||
"github.com/owncloud/ocis/v2/ocis-pkg/tracing"
|
"github.com/owncloud/ocis/v2/ocis-pkg/tracing"
|
||||||
"github.com/owncloud/ocis/v2/ocis-pkg/version"
|
"github.com/owncloud/ocis/v2/ocis-pkg/version"
|
||||||
@@ -22,9 +23,8 @@ import (
|
|||||||
"github.com/owncloud/ocis/v2/services/userlog/pkg/config/parser"
|
"github.com/owncloud/ocis/v2/services/userlog/pkg/config/parser"
|
||||||
"github.com/owncloud/ocis/v2/services/userlog/pkg/logging"
|
"github.com/owncloud/ocis/v2/services/userlog/pkg/logging"
|
||||||
"github.com/owncloud/ocis/v2/services/userlog/pkg/metrics"
|
"github.com/owncloud/ocis/v2/services/userlog/pkg/metrics"
|
||||||
|
"github.com/owncloud/ocis/v2/services/userlog/pkg/server/debug"
|
||||||
"github.com/owncloud/ocis/v2/services/userlog/pkg/server/http"
|
"github.com/owncloud/ocis/v2/services/userlog/pkg/server/http"
|
||||||
"github.com/urfave/cli/v2"
|
|
||||||
microstore "go-micro.dev/v4/store"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// all events we care about
|
// all events we care about
|
||||||
@@ -144,20 +144,18 @@ func Server(cfg *config.Config) *cli.Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
server := debug.NewService(
|
debugServer, err := debug.Server(
|
||||||
debug.Logger(logger),
|
debug.Logger(logger),
|
||||||
debug.Name(cfg.Service.Name),
|
debug.Context(ctx),
|
||||||
debug.Version(version.GetString()),
|
debug.Config(cfg),
|
||||||
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),
|
|
||||||
)
|
)
|
||||||
|
if err != nil {
|
||||||
|
logger.Info().Err(err).Str("transport", "debug").Msg("Failed to initialize server")
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
gr.Add(server.ListenAndServe, func(_ error) {
|
gr.Add(debugServer.ListenAndServe, func(_ error) {
|
||||||
_ = server.Shutdown(ctx)
|
_ = debugServer.Shutdown(ctx)
|
||||||
cancel()
|
cancel()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,50 @@
|
|||||||
|
package debug
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"github.com/owncloud/ocis/v2/ocis-pkg/log"
|
||||||
|
"github.com/owncloud/ocis/v2/services/userlog/pkg/config"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Option defines a single option function.
|
||||||
|
type Option func(o *Options)
|
||||||
|
|
||||||
|
// Options defines the available options for this package.
|
||||||
|
type Options struct {
|
||||||
|
Logger log.Logger
|
||||||
|
Context context.Context
|
||||||
|
Config *config.Config
|
||||||
|
}
|
||||||
|
|
||||||
|
// newOptions initializes the available default options.
|
||||||
|
func newOptions(opts ...Option) Options {
|
||||||
|
opt := Options{}
|
||||||
|
|
||||||
|
for _, o := range opts {
|
||||||
|
o(&opt)
|
||||||
|
}
|
||||||
|
|
||||||
|
return opt
|
||||||
|
}
|
||||||
|
|
||||||
|
// Logger provides a function to set the logger option.
|
||||||
|
func Logger(val log.Logger) Option {
|
||||||
|
return func(o *Options) {
|
||||||
|
o.Logger = val
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Context provides a function to set the context option.
|
||||||
|
func Context(val context.Context) Option {
|
||||||
|
return func(o *Options) {
|
||||||
|
o.Context = val
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Config provides a function to set the config option.
|
||||||
|
func Config(val *config.Config) Option {
|
||||||
|
return func(o *Options) {
|
||||||
|
o.Config = val
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
package debug
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/owncloud/ocis/v2/ocis-pkg/handlers"
|
||||||
|
"github.com/owncloud/ocis/v2/ocis-pkg/service/debug"
|
||||||
|
"github.com/owncloud/ocis/v2/ocis-pkg/version"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Server initializes the debug service and server.
|
||||||
|
func Server(opts ...Option) (*http.Server, error) {
|
||||||
|
options := newOptions(opts...)
|
||||||
|
|
||||||
|
checkHandler := handlers.NewCheckHandler(
|
||||||
|
handlers.NewCheckHandlerConfiguration().
|
||||||
|
WithLogger(options.Logger),
|
||||||
|
)
|
||||||
|
|
||||||
|
return debug.NewService(
|
||||||
|
debug.Logger(options.Logger),
|
||||||
|
debug.Name(options.Config.Service.Name),
|
||||||
|
debug.Version(version.GetString()),
|
||||||
|
debug.Address(options.Config.Debug.Addr),
|
||||||
|
debug.Token(options.Config.Debug.Token),
|
||||||
|
debug.Pprof(options.Config.Debug.Pprof),
|
||||||
|
debug.Zpages(options.Config.Debug.Zpages),
|
||||||
|
debug.Health(checkHandler),
|
||||||
|
debug.Ready(checkHandler),
|
||||||
|
), nil
|
||||||
|
}
|
||||||
@@ -87,6 +87,7 @@ func Server(cfg *config.Config) *cli.Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
gr.Add(debugServer.ListenAndServe, func(_ error) {
|
gr.Add(debugServer.ListenAndServe, func(_ error) {
|
||||||
|
_ = debugServer.Shutdown(ctx)
|
||||||
cancel()
|
cancel()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -1,18 +1,22 @@
|
|||||||
package debug
|
package debug
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/owncloud/ocis/v2/ocis-pkg/handlers"
|
||||||
"github.com/owncloud/ocis/v2/ocis-pkg/service/debug"
|
"github.com/owncloud/ocis/v2/ocis-pkg/service/debug"
|
||||||
"github.com/owncloud/ocis/v2/ocis-pkg/version"
|
"github.com/owncloud/ocis/v2/ocis-pkg/version"
|
||||||
"github.com/owncloud/ocis/v2/services/users/pkg/config"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Server initializes the debug service and server.
|
// Server initializes the debug service and server.
|
||||||
func Server(opts ...Option) (*http.Server, error) {
|
func Server(opts ...Option) (*http.Server, error) {
|
||||||
options := newOptions(opts...)
|
options := newOptions(opts...)
|
||||||
|
|
||||||
|
checkHandler := handlers.NewCheckHandler(
|
||||||
|
handlers.NewCheckHandlerConfiguration().
|
||||||
|
WithLogger(options.Logger),
|
||||||
|
)
|
||||||
|
|
||||||
return debug.NewService(
|
return debug.NewService(
|
||||||
debug.Logger(options.Logger),
|
debug.Logger(options.Logger),
|
||||||
debug.Name(options.Config.Service.Name),
|
debug.Name(options.Config.Service.Name),
|
||||||
@@ -21,43 +25,11 @@ func Server(opts ...Option) (*http.Server, error) {
|
|||||||
debug.Token(options.Config.Debug.Token),
|
debug.Token(options.Config.Debug.Token),
|
||||||
debug.Pprof(options.Config.Debug.Pprof),
|
debug.Pprof(options.Config.Debug.Pprof),
|
||||||
debug.Zpages(options.Config.Debug.Zpages),
|
debug.Zpages(options.Config.Debug.Zpages),
|
||||||
debug.Health(health(options.Config)),
|
debug.Health(checkHandler),
|
||||||
debug.Ready(ready(options.Config)),
|
debug.Ready(checkHandler),
|
||||||
//debug.CorsAllowedOrigins(options.Config.HTTP.CORS.AllowedOrigins),
|
//debug.CorsAllowedOrigins(options.Config.HTTP.CORS.AllowedOrigins),
|
||||||
//debug.CorsAllowedMethods(options.Config.HTTP.CORS.AllowedMethods),
|
//debug.CorsAllowedMethods(options.Config.HTTP.CORS.AllowedMethods),
|
||||||
//debug.CorsAllowedHeaders(options.Config.HTTP.CORS.AllowedHeaders),
|
//debug.CorsAllowedHeaders(options.Config.HTTP.CORS.AllowedHeaders),
|
||||||
//debug.CorsAllowCredentials(options.Config.HTTP.CORS.AllowCredentials),
|
//debug.CorsAllowCredentials(options.Config.HTTP.CORS.AllowCredentials),
|
||||||
), nil
|
), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// health implements the health check.
|
|
||||||
func health(cfg *config.Config) func(http.ResponseWriter, *http.Request) {
|
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
w.Header().Set("Content-Type", "text/plain")
|
|
||||||
w.WriteHeader(http.StatusOK)
|
|
||||||
|
|
||||||
// TODO: check if services are up and running
|
|
||||||
|
|
||||||
_, err := io.WriteString(w, http.StatusText(http.StatusOK))
|
|
||||||
// io.WriteString should not fail but if it does, we want to know.
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ready implements the ready check.
|
|
||||||
func ready(cfg *config.Config) func(http.ResponseWriter, *http.Request) {
|
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
w.Header().Set("Content-Type", "text/plain")
|
|
||||||
w.WriteHeader(http.StatusOK)
|
|
||||||
|
|
||||||
// TODO: check if services are up and running
|
|
||||||
|
|
||||||
_, err := io.WriteString(w, http.StatusText(http.StatusOK))
|
|
||||||
// io.WriteString should not fail but if it does, we want to know.
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -93,7 +93,7 @@ func Server(cfg *config.Config) *cli.Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
server, err := debug.Server(
|
debugServer, err := debug.Server(
|
||||||
debug.Logger(logger),
|
debug.Logger(logger),
|
||||||
debug.Context(ctx),
|
debug.Context(ctx),
|
||||||
debug.Config(cfg),
|
debug.Config(cfg),
|
||||||
@@ -103,8 +103,8 @@ func Server(cfg *config.Config) *cli.Command {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
gr.Add(server.ListenAndServe, func(_ error) {
|
gr.Add(debugServer.ListenAndServe, func(_ error) {
|
||||||
_ = server.Shutdown(ctx)
|
_ = debugServer.Shutdown(ctx)
|
||||||
cancel()
|
cancel()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,18 +1,38 @@
|
|||||||
package debug
|
package debug
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io"
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/owncloud/ocis/v2/ocis-pkg/handlers"
|
||||||
"github.com/owncloud/ocis/v2/ocis-pkg/service/debug"
|
"github.com/owncloud/ocis/v2/ocis-pkg/service/debug"
|
||||||
"github.com/owncloud/ocis/v2/ocis-pkg/version"
|
"github.com/owncloud/ocis/v2/ocis-pkg/version"
|
||||||
"github.com/owncloud/ocis/v2/services/web/pkg/config"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Server initializes the debug service and server.
|
// Server initializes the debug service and server.
|
||||||
func Server(opts ...Option) (*http.Server, error) {
|
func Server(opts ...Option) (*http.Server, error) {
|
||||||
options := newOptions(opts...)
|
options := newOptions(opts...)
|
||||||
|
|
||||||
|
checkHandler := handlers.NewCheckHandler(
|
||||||
|
handlers.NewCheckHandlerConfiguration().
|
||||||
|
WithLogger(options.Logger).WithCheck("web reachability", func(ctx context.Context) error {
|
||||||
|
conn, err := net.Dial("tcp", options.Config.HTTP.Addr)
|
||||||
|
defer func(conn net.Conn) {
|
||||||
|
err := conn.Close()
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}(conn)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("could not connect to web server: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
|
||||||
return debug.NewService(
|
return debug.NewService(
|
||||||
debug.Logger(options.Logger),
|
debug.Logger(options.Logger),
|
||||||
debug.Name(options.Config.Service.Name),
|
debug.Name(options.Config.Service.Name),
|
||||||
@@ -21,39 +41,7 @@ func Server(opts ...Option) (*http.Server, error) {
|
|||||||
debug.Token(options.Config.Debug.Token),
|
debug.Token(options.Config.Debug.Token),
|
||||||
debug.Pprof(options.Config.Debug.Pprof),
|
debug.Pprof(options.Config.Debug.Pprof),
|
||||||
debug.Zpages(options.Config.Debug.Zpages),
|
debug.Zpages(options.Config.Debug.Zpages),
|
||||||
debug.Health(health(options.Config)),
|
debug.Health(checkHandler),
|
||||||
debug.Ready(ready(options.Config)),
|
debug.Ready(checkHandler),
|
||||||
), nil
|
), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// health implements the health check.
|
|
||||||
func health(_ *config.Config) func(http.ResponseWriter, *http.Request) {
|
|
||||||
return func(w http.ResponseWriter, _ *http.Request) {
|
|
||||||
w.Header().Set("Content-Type", "text/plain")
|
|
||||||
w.WriteHeader(http.StatusOK)
|
|
||||||
|
|
||||||
// TODO: check if services are up and running
|
|
||||||
|
|
||||||
_, err := io.WriteString(w, http.StatusText(http.StatusOK))
|
|
||||||
// io.WriteString should not fail but if it does, we want to know.
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ready implements the ready check.
|
|
||||||
func ready(_ *config.Config) func(http.ResponseWriter, *http.Request) {
|
|
||||||
return func(w http.ResponseWriter, _ *http.Request) {
|
|
||||||
w.Header().Set("Content-Type", "text/plain")
|
|
||||||
w.WriteHeader(http.StatusOK)
|
|
||||||
|
|
||||||
// TODO: check if services are up and running
|
|
||||||
|
|
||||||
_, err := io.WriteString(w, http.StatusText(http.StatusOK))
|
|
||||||
// io.WriteString should not fail but if it does, we want to know.
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ func Server(cfg *config.Config) *cli.Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
server, err := debug.Server(
|
debugServer, err := debug.Server(
|
||||||
debug.Logger(logger),
|
debug.Logger(logger),
|
||||||
debug.Context(ctx),
|
debug.Context(ctx),
|
||||||
debug.Config(cfg),
|
debug.Config(cfg),
|
||||||
@@ -93,9 +93,8 @@ func Server(cfg *config.Config) *cli.Command {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
gr.Add(server.ListenAndServe, func(err error) {
|
gr.Add(debugServer.ListenAndServe, func(err error) {
|
||||||
logger.Error().Err(err)
|
_ = debugServer.Shutdown(ctx)
|
||||||
_ = server.Shutdown(ctx)
|
|
||||||
cancel()
|
cancel()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,18 +1,22 @@
|
|||||||
package debug
|
package debug
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/owncloud/ocis/v2/ocis-pkg/handlers"
|
||||||
"github.com/owncloud/ocis/v2/ocis-pkg/service/debug"
|
"github.com/owncloud/ocis/v2/ocis-pkg/service/debug"
|
||||||
"github.com/owncloud/ocis/v2/ocis-pkg/version"
|
"github.com/owncloud/ocis/v2/ocis-pkg/version"
|
||||||
"github.com/owncloud/ocis/v2/services/webdav/pkg/config"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Server initializes the debug service and server.
|
// Server initializes the debug service and server.
|
||||||
func Server(opts ...Option) (*http.Server, error) {
|
func Server(opts ...Option) (*http.Server, error) {
|
||||||
options := newOptions(opts...)
|
options := newOptions(opts...)
|
||||||
|
|
||||||
|
checkHandler := handlers.NewCheckHandler(
|
||||||
|
handlers.NewCheckHandlerConfiguration().
|
||||||
|
WithLogger(options.Logger),
|
||||||
|
)
|
||||||
|
|
||||||
return debug.NewService(
|
return debug.NewService(
|
||||||
debug.Logger(options.Logger),
|
debug.Logger(options.Logger),
|
||||||
debug.Name(options.Config.Service.Name),
|
debug.Name(options.Config.Service.Name),
|
||||||
@@ -21,43 +25,11 @@ func Server(opts ...Option) (*http.Server, error) {
|
|||||||
debug.Token(options.Config.Debug.Token),
|
debug.Token(options.Config.Debug.Token),
|
||||||
debug.Pprof(options.Config.Debug.Pprof),
|
debug.Pprof(options.Config.Debug.Pprof),
|
||||||
debug.Zpages(options.Config.Debug.Zpages),
|
debug.Zpages(options.Config.Debug.Zpages),
|
||||||
debug.Health(health(options.Config)),
|
debug.Health(checkHandler),
|
||||||
debug.Ready(ready(options.Config)),
|
debug.Ready(checkHandler),
|
||||||
debug.CorsAllowedOrigins(options.Config.HTTP.CORS.AllowedOrigins),
|
debug.CorsAllowedOrigins(options.Config.HTTP.CORS.AllowedOrigins),
|
||||||
debug.CorsAllowedMethods(options.Config.HTTP.CORS.AllowedMethods),
|
debug.CorsAllowedMethods(options.Config.HTTP.CORS.AllowedMethods),
|
||||||
debug.CorsAllowedHeaders(options.Config.HTTP.CORS.AllowedHeaders),
|
debug.CorsAllowedHeaders(options.Config.HTTP.CORS.AllowedHeaders),
|
||||||
debug.CorsAllowCredentials(options.Config.HTTP.CORS.AllowCredentials),
|
debug.CorsAllowCredentials(options.Config.HTTP.CORS.AllowCredentials),
|
||||||
), nil
|
), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// health implements the health check.
|
|
||||||
func health(cfg *config.Config) func(http.ResponseWriter, *http.Request) {
|
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
w.Header().Set("Content-Type", "text/plain")
|
|
||||||
w.WriteHeader(http.StatusOK)
|
|
||||||
|
|
||||||
// TODO: check if services are up and running
|
|
||||||
|
|
||||||
_, err := io.WriteString(w, http.StatusText(http.StatusOK))
|
|
||||||
// io.WriteString should not fail but if it does, we want to know.
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ready implements the ready check.
|
|
||||||
func ready(cfg *config.Config) func(http.ResponseWriter, *http.Request) {
|
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
w.Header().Set("Content-Type", "text/plain")
|
|
||||||
w.WriteHeader(http.StatusOK)
|
|
||||||
|
|
||||||
// TODO: check if services are up and running
|
|
||||||
|
|
||||||
_, err := io.WriteString(w, http.StatusText(http.StatusOK))
|
|
||||||
// io.WriteString should not fail but if it does, we want to know.
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -95,7 +95,7 @@ func Server(cfg *config.Config) *cli.Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
server, err := debug.Server(
|
debugServer, err := debug.Server(
|
||||||
debug.Logger(logger),
|
debug.Logger(logger),
|
||||||
debug.Context(ctx),
|
debug.Context(ctx),
|
||||||
debug.Config(cfg),
|
debug.Config(cfg),
|
||||||
@@ -106,9 +106,8 @@ func Server(cfg *config.Config) *cli.Command {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
gr.Add(server.ListenAndServe, func(err error) {
|
gr.Add(debugServer.ListenAndServe, func(err error) {
|
||||||
logger.Error().Err(err)
|
_ = debugServer.Shutdown(ctx)
|
||||||
_ = server.Shutdown(ctx)
|
|
||||||
cancel()
|
cancel()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,18 +1,22 @@
|
|||||||
package debug
|
package debug
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/owncloud/ocis/v2/ocis-pkg/handlers"
|
||||||
"github.com/owncloud/ocis/v2/ocis-pkg/service/debug"
|
"github.com/owncloud/ocis/v2/ocis-pkg/service/debug"
|
||||||
"github.com/owncloud/ocis/v2/ocis-pkg/version"
|
"github.com/owncloud/ocis/v2/ocis-pkg/version"
|
||||||
"github.com/owncloud/ocis/v2/services/webfinger/pkg/config"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Server initializes the debug service and server.
|
// Server initializes the debug service and server.
|
||||||
func Server(opts ...Option) (*http.Server, error) {
|
func Server(opts ...Option) (*http.Server, error) {
|
||||||
options := newOptions(opts...)
|
options := newOptions(opts...)
|
||||||
|
|
||||||
|
checkHandler := handlers.NewCheckHandler(
|
||||||
|
handlers.NewCheckHandlerConfiguration().
|
||||||
|
WithLogger(options.Logger),
|
||||||
|
)
|
||||||
|
|
||||||
return debug.NewService(
|
return debug.NewService(
|
||||||
debug.Logger(options.Logger),
|
debug.Logger(options.Logger),
|
||||||
debug.Name(options.Config.Service.Name),
|
debug.Name(options.Config.Service.Name),
|
||||||
@@ -21,43 +25,11 @@ func Server(opts ...Option) (*http.Server, error) {
|
|||||||
debug.Token(options.Config.Debug.Token),
|
debug.Token(options.Config.Debug.Token),
|
||||||
debug.Pprof(options.Config.Debug.Pprof),
|
debug.Pprof(options.Config.Debug.Pprof),
|
||||||
debug.Zpages(options.Config.Debug.Zpages),
|
debug.Zpages(options.Config.Debug.Zpages),
|
||||||
debug.Health(health(options.Config)),
|
debug.Health(checkHandler),
|
||||||
debug.Ready(ready(options.Config)),
|
debug.Ready(checkHandler),
|
||||||
debug.CorsAllowedOrigins(options.Config.HTTP.CORS.AllowedOrigins),
|
debug.CorsAllowedOrigins(options.Config.HTTP.CORS.AllowedOrigins),
|
||||||
debug.CorsAllowedMethods(options.Config.HTTP.CORS.AllowedMethods),
|
debug.CorsAllowedMethods(options.Config.HTTP.CORS.AllowedMethods),
|
||||||
debug.CorsAllowedHeaders(options.Config.HTTP.CORS.AllowedHeaders),
|
debug.CorsAllowedHeaders(options.Config.HTTP.CORS.AllowedHeaders),
|
||||||
debug.CorsAllowCredentials(options.Config.HTTP.CORS.AllowCredentials),
|
debug.CorsAllowCredentials(options.Config.HTTP.CORS.AllowCredentials),
|
||||||
), nil
|
), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// health implements the health check.
|
|
||||||
func health(_ *config.Config) func(http.ResponseWriter, *http.Request) {
|
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
w.Header().Set("Content-Type", "text/plain")
|
|
||||||
w.WriteHeader(http.StatusOK)
|
|
||||||
|
|
||||||
// TODO: check if services are up and running
|
|
||||||
|
|
||||||
_, err := io.WriteString(w, http.StatusText(http.StatusOK))
|
|
||||||
// io.WriteString should not fail but if it does, we want to know.
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ready implements the ready check.
|
|
||||||
func ready(_ *config.Config) func(http.ResponseWriter, *http.Request) {
|
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
w.Header().Set("Content-Type", "text/plain")
|
|
||||||
w.WriteHeader(http.StatusOK)
|
|
||||||
|
|
||||||
// TODO: check if services are up and running
|
|
||||||
|
|
||||||
_, err := io.WriteString(w, http.StatusText(http.StatusOK))
|
|
||||||
// io.WriteString should not fail but if it does, we want to know.
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user