Files
ocis/services/proxy/pkg/server/debug/server.go
T
Roman PerekhodandClaude Opus 5.5 66342f5bf7 fix(proxy): [OCSRE-1629] use the events endpoint for the nats health check
The proxy health check used Events.Cluster, the cluster ID of the
event system, as the NATS address. The check thus never reached the
NATS server.

The check now uses Events.Endpoint. The proxy uses NATS only to
publish events, and an empty endpoint disables the events. So the
check returns no error when the endpoint is empty.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-23 15:34:32 +02:00

68 lines
2.1 KiB
Go

package debug
import (
"context"
"encoding/json"
"net/http"
"github.com/ggwhite/go-masker"
"github.com/owncloud/ocis/v2/ocis-pkg/checks"
"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/proxy/pkg/config"
"github.com/owncloud/reva/v2/pkg/events/stream"
)
// Server initializes the debug service and server.
func Server(opts ...Option) (*http.Server, error) {
options := newOptions(opts...)
healthHandlerConfiguration := handlers.NewCheckHandlerConfiguration().
WithLogger(options.Logger).
WithCheck("web reachability", checks.NewHTTPCheck(options.Config.HTTP.Addr))
readyHandlerConfiguration := healthHandlerConfiguration.
WithCheck("nats reachability", func(ctx context.Context) error {
// The proxy uses NATS only to publish events. An empty endpoint disables the events.
if options.Config.Events.Endpoint == "" {
return nil
}
return checks.NewNatsCheckWithConfig(options.Config.Events.Endpoint, stream.NatsConfig(options.Config.Events))(ctx)
})
var configDumpFunc http.HandlerFunc = configDump(options.Config)
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(handlers.NewCheckHandler(healthHandlerConfiguration)),
debug.Ready(handlers.NewCheckHandler(readyHandlerConfiguration)),
debug.ConfigDump(configDumpFunc),
), nil
}
// configDump implements the config dump
func configDump(cfg *config.Config) func(http.ResponseWriter, *http.Request) {
return func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
maskedCfg, err := masker.Struct(cfg)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
}
b, err := json.Marshal(maskedCfg)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
}
_, _ = w.Write(b)
}
}