-
Notifications
You must be signed in to change notification settings - Fork 183
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add debug server to activitylog & check web availability
Signed-off-by: Christian Richter <[email protected]>
- Loading branch information
1 parent
7ed5b9f
commit 956df08
Showing
4 changed files
with
118 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package debug | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"net/http" | ||
|
||
"github.com/cs3org/reva/v2/pkg/events/stream" | ||
"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).WithCheck("nats reachability", func(ctx context.Context) error { | ||
_, err := stream.NatsFromConfig("healthcheckfornats", false, stream.NatsConfig(options.Config.Events)) | ||
if err != nil { | ||
return fmt.Errorf("could not connect to nats server: %v", err) | ||
} | ||
return nil | ||
}), | ||
) | ||
|
||
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters