Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add HTTP status pages #3608

Merged
merged 1 commit into from
Jan 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions go/beacon_srv/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@
package main

import (
"bytes"
"context"
"flag"
"fmt"
"hash"
"net"
"net/http"
"os"
"path/filepath"
"sync"
Expand Down Expand Up @@ -194,7 +196,12 @@ func realMain() int {
}),
)

// Setup metrics and status pages
http.HandleFunc("/config", configHandler)
http.HandleFunc("/info", env.InfoHandler)
http.HandleFunc("/topology", itopo.TopologyHandler)
cfg.Metrics.StartPrometheus()

go func() {
defer log.LogPanicAndExit()
msgr.ListenAndServe()
Expand Down Expand Up @@ -653,3 +660,10 @@ func checkFlags(cfg *config.Config) (int, bool) {
}
return env.CheckFlags(cfg)
}

func configHandler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/plain")
var buf bytes.Buffer
toml.NewEncoder(&buf).Encode(cfg)
fmt.Fprint(w, buf.String())
}
1 change: 1 addition & 0 deletions go/border/brconf/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ go_library(
go_test(
name = "go_default_test",
srcs = ["params_test.go"],
data = glob(["testdata/**"]),
embed = [":go_default_library"],
deps = [
"//go/lib/env/envtest:go_default_library",
Expand Down
13 changes: 13 additions & 0 deletions go/border/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@
package main

import (
"bytes"
"flag"
"fmt"
"net/http"
_ "net/http/pprof"
"os"
"os/user"
Expand All @@ -33,6 +35,7 @@ import (
"github.com/scionproto/scion/go/lib/common"
"github.com/scionproto/scion/go/lib/env"
"github.com/scionproto/scion/go/lib/fatal"
"github.com/scionproto/scion/go/lib/infra/modules/itopo"
"github.com/scionproto/scion/go/lib/log"
"github.com/scionproto/scion/go/lib/profile"
"github.com/scionproto/scion/go/lib/prom"
Expand Down Expand Up @@ -66,6 +69,9 @@ func realMain() int {
defer log.Flush()
defer env.LogAppStopped(common.BR, cfg.General.ID)
defer log.LogPanicAndExit()
http.HandleFunc("/config", configHandler)
http.HandleFunc("/info", env.InfoHandler)
http.HandleFunc("/topology", itopo.TopologyHandler)
if err := setup(); err != nil {
log.Crit("Setup failed", "err", err)
return 1
Expand Down Expand Up @@ -138,3 +144,10 @@ func checkPerms() error {
}
return nil
}

func configHandler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/plain")
var buf bytes.Buffer
toml.NewEncoder(&buf).Encode(cfg)
fmt.Fprint(w, buf.String())
}
15 changes: 15 additions & 0 deletions go/cert_srv/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@
package main

import (
"bytes"
"context"
"flag"
"fmt"
"net/http"
_ "net/http/pprof"
"os"
"path/filepath"
Expand Down Expand Up @@ -177,6 +179,12 @@ func realMain() int {
msgr.UpdateSigner(signer, []infra.MessageType{infra.ChainIssueRequest})
msgr.UpdateVerifier(trust.NewVerifier(trustStore))

// Setup metrics and status pages
http.HandleFunc("/config", configHandler)
http.HandleFunc("/info", env.InfoHandler)
http.HandleFunc("/topology", itopo.TopologyHandler)
cfg.Metrics.StartPrometheus()

// Start the messenger.
go func() {
defer log.LogPanicAndExit()
Expand Down Expand Up @@ -288,3 +296,10 @@ func setup() error {
infraenv.InitInfraEnvironment(cfg.General.Topology)
return nil
}

func configHandler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/plain")
var buf bytes.Buffer
toml.NewEncoder(&buf).Encode(cfg)
fmt.Fprint(w, buf.String())
}
12 changes: 12 additions & 0 deletions go/cs/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@
package main

import (
"bytes"
"context"
"flag"
"fmt"
"hash"
"net"
"net/http"
"os"
"path/filepath"
"sync"
Expand Down Expand Up @@ -265,6 +267,9 @@ func realMain() int {
},
})

// Setup metrics and status pages
http.HandleFunc("/config", configHandler)
http.HandleFunc("/info", env.InfoHandler)
cfg.Metrics.StartPrometheus()
go func() {
defer log.LogPanicAndExit()
Expand Down Expand Up @@ -794,3 +799,10 @@ func (h *chainedHandler) Handle(r *infra.Request) *infra.HandlerResult {
Status: prom.StatusOk,
}
}

func configHandler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/plain")
var buf bytes.Buffer
toml.NewEncoder(&buf).Encode(cfg)
fmt.Fprint(w, buf.String())
}
10 changes: 10 additions & 0 deletions go/godispatcher/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package main

import (
"bytes"
"flag"
"fmt"
"net/http"
Expand Down Expand Up @@ -96,6 +97,8 @@ func realMain() int {
}

env.SetupEnv(nil)
http.HandleFunc("/config", configHandler)
http.HandleFunc("/info", env.InfoHandler)
cfg.Metrics.StartPrometheus()

returnCode := waitForTeardown()
Expand Down Expand Up @@ -177,3 +180,10 @@ func checkPerms() error {
}
return nil
}

func configHandler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/plain")
var buf bytes.Buffer
toml.NewEncoder(&buf).Encode(cfg)
fmt.Fprint(w, buf.String())
}
13 changes: 13 additions & 0 deletions go/lib/env/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,3 +300,16 @@ func (cfg *QUIC) Sample(dst io.Writer, path config.Path, _ config.CtxMap) {
func (cfg *QUIC) ConfigName() string {
return "quic"
}

func InfoHandler(w http.ResponseWriter, r *http.Request) {
info := VersionInfo()
inDocker, err := util.RunsInDocker()
if err == nil {
info += fmt.Sprintf(" In docker: %v\n", inDocker)
}
info += fmt.Sprintf(" pid: %d\n", os.Getpid())
info += fmt.Sprintf(" euid/egid: %d %d\n", os.Geteuid(), os.Getegid())
info += fmt.Sprintf(" cmd line: %q\n", os.Args)
w.Header().Set("Content-Type", "text/plain")
fmt.Fprintf(w, info)
}
13 changes: 13 additions & 0 deletions go/lib/infra/modules/itopo/itopo.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
package itopo

import (
"encoding/json"
"fmt"
"net/http"
"sync"
"time"

Expand Down Expand Up @@ -370,3 +373,13 @@ func incUpdateMetric(l metrics.UpdateLabels) {
metrics.Updates.Last(l).SetToCurrentTime()
metrics.Updates.Total(l).Inc()
}

func TopologyHandler(w http.ResponseWriter, r *http.Request) {
st.RLock()
defer st.RUnlock()
w.Header().Set("Content-Type", "application/json")
bytes, err := json.MarshalIndent(st.topo.Get(), "", " ")
if err == nil {
fmt.Fprint(w, string(bytes)+"\n")
}
}
12 changes: 12 additions & 0 deletions go/path_srv/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@
package main

import (
"bytes"
"context"
"flag"
"fmt"
"net/http"
_ "net/http/pprof"
"os"
"path/filepath"
Expand Down Expand Up @@ -181,6 +183,9 @@ func realMain() int {
msger.AddHandler(infra.SegSync, handlers.NewSyncHandler(args))
}
msger.AddHandler(infra.SignedRev, handlers.NewRevocHandler(args))
http.HandleFunc("/config", configHandler)
http.HandleFunc("/info", env.InfoHandler)
http.HandleFunc("/topology", itopo.TopologyHandler)
cfg.Metrics.StartPrometheus()
// Start handling requests/messages
go func() {
Expand Down Expand Up @@ -309,3 +314,10 @@ func setup() error {
infraenv.InitInfraEnvironment(cfg.General.Topology)
return nil
}

func configHandler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/plain")
var buf bytes.Buffer
toml.NewEncoder(&buf).Encode(cfg)
fmt.Fprint(w, buf.String())
}
12 changes: 12 additions & 0 deletions go/sciond/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@
package main

import (
"bytes"
"context"
"flag"
"fmt"
"net"
"net/http"
_ "net/http/pprof"
"os"
"path/filepath"
Expand Down Expand Up @@ -202,6 +204,9 @@ func realMain() int {
unixpacketServer, shutdownF := NewServer("unixpacket", cfg.SD.Unix, handlers)
defer shutdownF()
StartServer("UnixServer", cfg.SD.Unix, unixpacketServer)
http.HandleFunc("/config", configHandler)
http.HandleFunc("/info", env.InfoHandler)
http.HandleFunc("/topology", itopo.TopologyHandler)
cfg.Metrics.StartPrometheus()
select {
case <-fatal.ShutdownChan():
Expand Down Expand Up @@ -285,3 +290,10 @@ func StartServer(name, sockPath string, server *servers.Server) {
}
}()
}

func configHandler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/plain")
var buf bytes.Buffer
toml.NewEncoder(&buf).Encode(cfg)
fmt.Fprint(w, buf.String())
}
11 changes: 11 additions & 0 deletions go/sig/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@
package main

import (
"bytes"
"flag"
"fmt"
"io"
"net/http"
_ "net/http/pprof"
"os"
"os/user"
Expand Down Expand Up @@ -104,6 +106,8 @@ func realMain() int {
}()
egress.Init(tunIO)
ingress.Init(tunIO)
http.HandleFunc("/config", configHandler)
http.HandleFunc("/info", env.InfoHandler)
cfg.Metrics.StartPrometheus()
select {
case <-fatal.ShutdownChan():
Expand Down Expand Up @@ -203,3 +207,10 @@ func loadConfig(path string) bool {
atomic.StoreUint64(&metrics.ConfigVersion, cfg.ConfigVersion)
return true
}

func configHandler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/plain")
var buf bytes.Buffer
toml.NewEncoder(&buf).Encode(cfg)
fmt.Fprint(w, buf.String())
}