Skip to content

Commit

Permalink
add info to status pages
Browse files Browse the repository at this point in the history
One-line description of each status page is shown on the main page.

GitOrigin-RevId: de0dfbe856b0f5f5fe19bff068c86f8bba394215
  • Loading branch information
sustrik authored and lukedirtwalker committed Nov 4, 2021
1 parent fcdcdf0 commit 310cb7a
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 23 deletions.
4 changes: 2 additions & 2 deletions go/daemon/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,9 @@ func realMain(ctx context.Context) error {
"info": service.NewInfoStatusPage(),
"config": service.NewConfigStatusPage(globalCfg),
"log/level": service.NewLogLevelStatusPage(),
"topology": service.StatusPage{Handler: itopo.TopologyHandler},
"topology": service.NewTopologyStatusPage(),
"digests/config": service.NewConfigDigestStatusPage(&globalCfg),
"digests/topology": service.StatusPage{Handler: itopo.TopologyDigestHandler},
"digests/topology": service.NewTopologyDigestStatusPage(),
}
if err := statusPages.Register(http.DefaultServeMux, globalCfg.General.ID); err != nil {
return serrors.WrapStr("registering status pages", err)
Expand Down
1 change: 0 additions & 1 deletion go/pkg/cs/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ go_library(
"//go/lib/ctrl/seg:go_default_library",
"//go/lib/env:go_default_library",
"//go/lib/infra:go_default_library",
"//go/lib/infra/modules/itopo:go_default_library",
"//go/lib/infra/modules/seghandler:go_default_library",
"//go/lib/keyconf:go_default_library",
"//go/lib/log:go_default_library",
Expand Down
20 changes: 14 additions & 6 deletions go/pkg/cs/observability.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import (
"github.com/scionproto/scion/go/lib/addr"
"github.com/scionproto/scion/go/lib/config"
"github.com/scionproto/scion/go/lib/env"
"github.com/scionproto/scion/go/lib/infra/modules/itopo"
"github.com/scionproto/scion/go/lib/prom"
"github.com/scionproto/scion/go/lib/scrypto"
"github.com/scionproto/scion/go/lib/scrypto/cppki"
Expand Down Expand Up @@ -240,10 +239,10 @@ func StartHTTPEndpoints(
"info": service.NewInfoStatusPage(),
"config": service.NewConfigStatusPage(cfg),
"log/level": service.NewLogLevelStatusPage(),
"topology": service.StatusPage{Handler: itopo.TopologyHandler},
"topology": service.NewTopologyStatusPage(),
"signer": signerStatusPage(signer),
"digests/config": service.NewConfigDigestStatusPage(cfg),
"digests/topology": service.StatusPage{Handler: itopo.TopologyDigestHandler},
"digests/topology": service.NewTopologyDigestStatusPage(),
"digests/policies": policyDigestsStatusPage(policyDigests),
}
if ca != (renewal.ChainBuilder{}) {
Expand Down Expand Up @@ -306,7 +305,10 @@ func signerStatusPage(signer cstrust.RenewingSigner) service.StatusPage {
return
}
}
return service.StatusPage{Handler: handler}
return service.StatusPage{
Info: "SCION signer info",
Handler: handler,
}
}

func caStatusPage(signer renewal.ChainBuilder) service.StatusPage {
Expand Down Expand Up @@ -357,7 +359,10 @@ func caStatusPage(signer renewal.ChainBuilder) service.StatusPage {
return
}
}
return service.StatusPage{Handler: handler}
return service.StatusPage{
Info: "CA status",
Handler: handler,
}
}

func policyDigestsStatusPage(digests map[string][]byte) service.StatusPage {
Expand All @@ -379,5 +384,8 @@ func policyDigestsStatusPage(digests map[string][]byte) service.StatusPage {
return
}
}
return service.StatusPage{Handler: handler}
return service.StatusPage{
Info: "sha256 policies digest",
Handler: handler,
}
}
6 changes: 6 additions & 0 deletions go/pkg/gateway/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,7 @@ func (g *Gateway) Run(ctx context.Context) error {
}()
logger.Debug("Session configurator started")
g.HTTPEndpoints["sessionconfigurator"] = service.StatusPage{
Info: "session configurator diagnostics",
Handler: func(w http.ResponseWriter, _ *http.Request) {
sessionConfigurator.DiagnosticsWrite(w)
},
Expand Down Expand Up @@ -630,27 +631,32 @@ func (g *Gateway) Run(ctx context.Context) error {
logger.Debug("Engine controller started")

g.HTTPEndpoints["engine"] = service.StatusPage{
Info: "gateway diagnostics",
Handler: func(w http.ResponseWriter, _ *http.Request) {
engineController.DiagnosticsWrite(w)
},
}
g.HTTPEndpoints["status"] = service.StatusPage{
Info: "gateway status (remote ASes, sessions, paths)",
Handler: func(w http.ResponseWriter, _ *http.Request) {
engineController.Status(w)
},
}
g.HTTPEndpoints["diagnostics/prefixwatcher"] = service.StatusPage{
Info: "IP prefixes incoming via SGRP",
Handler: func(w http.ResponseWriter, _ *http.Request) {
remoteMonitor.DiagnosticsWrite(w)
},
}
g.HTTPEndpoints["diagnostics/sgrp"] = service.StatusPage{
Info: "SGRP diagnostics",
Handler: g.diagnosticsSGRP(routePublisherFactory, configPublisher),
}

// XXX(scrye): Use an empty file here because the server often doesn't have
// write access to its configuration folder.
g.HTTPEndpoints["ip-routing/policy"] = service.StatusPage{
Info: "IP routing policy (supports PUT)",
Handler: routing.NewPolicyHandler(
RoutingPolicyPublisherAdapter{ConfigPublisher: configPublisher}, ""),
}
Expand Down
1 change: 1 addition & 0 deletions go/pkg/service/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ go_library(
deps = [
"//go/lib/config:go_default_library",
"//go/lib/env:go_default_library",
"//go/lib/infra/modules/itopo:go_default_library",
"//go/lib/log:go_default_library",
"//go/lib/serrors:go_default_library",
"//go/lib/util:go_default_library",
Expand Down
68 changes: 56 additions & 12 deletions go/pkg/service/statuspages.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (

"github.com/scionproto/scion/go/lib/config"
"github.com/scionproto/scion/go/lib/env"
"github.com/scionproto/scion/go/lib/infra/modules/itopo"
"github.com/scionproto/scion/go/lib/log"
"github.com/scionproto/scion/go/lib/serrors"
"github.com/scionproto/scion/go/lib/util"
Expand All @@ -42,20 +43,29 @@ const mainTmpl = `
</head>
<body style="font-family:sans-serif">
<h1>{{ .ElemId }}</h1>
<table>
{{ range .Pages }}
<a href="{{ . }}">[{{ . }}]</a><br>
<tr><td><a href="{{ .Endpoint }}">[{{ .Endpoint }}]</a></td><td>{{ .Info }}</td></tr>
{{ end }}
</table>
</body>
</html>
`

type pageData struct {
Info string
Endpoint string
}

type mainData struct {
ElemId string
Pages []string
Pages []pageData
}

// StatusPages describes a status page (HTTP endpoint exposed by the service).
type StatusPage struct {
// Short description on what the endpoint is for. It will be shown on the main page.
Info string
// Handler processes the HTTP request for this status page.
Handler http.HandlerFunc
// Special status page is one that should not be dumped via /all endpoint.
Expand All @@ -75,13 +85,21 @@ func (s StatusPages) Register(serveMux *http.ServeMux, elemId string) error {
if err != nil {
return err
}
var pages []string
for endpoint, page := range s {
pages = append(pages, endpoint)
serveMux.HandleFunc(fmt.Sprintf("/%s", endpoint), page.Handler)
var pages []pageData
for endpoint, p := range s {
pages = append(pages, pageData{
Info: p.Info,
Endpoint: endpoint,
})
serveMux.HandleFunc(fmt.Sprintf("/%s", endpoint), p.Handler)
}
pages = append(pages, "metrics")
sort.Strings(pages)
pages = append(pages, pageData{
Info: "prometheus metrics",
Endpoint: "metrics",
})
sort.Slice(pages, func(x, y int) bool {
return pages[x].Endpoint < pages[y].Endpoint
})
var mainBuf bytes.Buffer
if err := t.Execute(&mainBuf, mainData{ElemId: elemId, Pages: pages}); err != nil {
return serrors.WrapStr("executing template", err)
Expand Down Expand Up @@ -117,7 +135,10 @@ func NewConfigStatusPage(config interface{}) StatusPage {
toml.NewEncoder(&buf).Order(toml.OrderPreserve).Encode(config)
fmt.Fprint(w, buf.String())
}
return StatusPage{Handler: handler}
return StatusPage{
Info: "configuration of the service",
Handler: handler,
}
}

func NewConfigDigestStatusPage(cfg config.Config) StatusPage {
Expand All @@ -139,7 +160,17 @@ func NewConfigDigestStatusPage(cfg config.Config) StatusPage {
return
}
}
return StatusPage{Handler: handler}
return StatusPage{
Info: "sha256 digest of the configuration",
Handler: handler,
}
}

func NewTopologyDigestStatusPage() StatusPage {
return StatusPage{
Info: "sha256 digest of SCION topology",
Handler: itopo.TopologyDigestHandler,
}
}

// NewInfoStatusPage returns a page with basic info about the process.
Expand All @@ -156,10 +187,23 @@ func NewInfoStatusPage() StatusPage {
w.Header().Set("Content-Type", "text/plain")
fmt.Fprint(w, info)
}
return StatusPage{Handler: handler}
return StatusPage{
Info: "generic info about the process",
Handler: handler,
}
}

// NewLogLevelStatusPage returns a page with basic info about the process.
func NewLogLevelStatusPage() StatusPage {
return StatusPage{Handler: log.ConsoleLevel.ServeHTTP}
return StatusPage{
Info: "logging level (supports PUT)",
Handler: log.ConsoleLevel.ServeHTTP,
}
}

func NewTopologyStatusPage() StatusPage {
return StatusPage{
Info: "SCION topology",
Handler: itopo.TopologyHandler,
}
}
10 changes: 8 additions & 2 deletions go/posix-router/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,10 @@ func topologyHandler(topo topology.Topology) service.StatusPage {
}
fmt.Fprint(w, string(bytes)+"\n")
}
return service.StatusPage{Handler: handler}
return service.StatusPage{
Info: "SCION topology",
Handler: handler,
}
}

func topologyDigestHandler(topo topology.Topology) service.StatusPage {
Expand All @@ -154,5 +157,8 @@ func topologyDigestHandler(topo topology.Topology) service.StatusPage {
return
}
}
return service.StatusPage{Handler: handler}
return service.StatusPage{
Info: "sha256 of SCION topology",
Handler: handler,
}
}

0 comments on commit 310cb7a

Please sign in to comment.