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

Simplify handler registration and updates prometheus #2775

Merged
merged 2 commits into from
Jul 12, 2018
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
136 changes: 81 additions & 55 deletions Gopkg.lock

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@

[[constraint]]
name = "github.com/prometheus/client_golang"
version = "0.8.0"
branch = "master"

[[constraint]]
name = "github.com/spf13/pflag"
Expand All @@ -98,24 +98,24 @@

[[constraint]]
name = "k8s.io/kubernetes"
revision = "v1.10.3"
revision = "v1.11.0"

[[constraint]]
name = "k8s.io/api"
revision = "kubernetes-1.10.3"
revision = "kubernetes-1.11.0"

[[constraint]]
name = "k8s.io/apimachinery"
revision = "kubernetes-1.10.3"
revision = "kubernetes-1.11.0"

[[constraint]]
name = "k8s.io/client-go"
revision = "kubernetes-1.10.3"
revision = "kubernetes-1.11.0"

[[constraint]]
name = "k8s.io/apiextensions-apiserver"
revision = "kubernetes-1.10.3"
revision = "kubernetes-1.11.0"

[[constraint]]
name = "k8s.io/apiserver"
revision = "kubernetes-1.10.3"
revision = "kubernetes-1.11.0"
77 changes: 49 additions & 28 deletions cmd/nginx/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ func main() {
conf.Client = kubeClient

reg := prometheus.NewRegistry()

reg.MustRegister(prometheus.NewGoCollector())
reg.MustRegister(prometheus.NewProcessCollector(os.Getpid(), ""))

mc, err := metric.NewCollector(conf.ListenPorts.Status, reg)
if err != nil {
glog.Fatalf("Error creating prometheus collectos: %v", err)
Expand All @@ -131,7 +135,16 @@ func main() {
})

mux := http.NewServeMux()
go registerHandlers(conf.EnableProfiling, conf.ListenPorts.Health, ngx, mux, reg)

if conf.EnableProfiling {
registerProfiler(mux)
}

registerHealthz(ngx, mux)
registerMetrics(reg, mux)
registerHandlers(mux)

go startHTTPServer(conf.ListenPorts.Health, mux)

ngx.Start()
}
Expand Down Expand Up @@ -235,21 +248,7 @@ func handleFatalInitError(err error) {
err)
}

func registerHandlers(
enableProfiling bool,
port int,
ic *controller.NGINXController,
mux *http.ServeMux,
reg *prometheus.Registry) {

// expose health check endpoint (/healthz)
healthz.InstallHandler(mux,
healthz.PingHealthz,
ic,
)

mux.Handle("/metrics", promhttp.HandlerFor(reg, promhttp.HandlerOpts{}))

func registerHandlers(mux *http.ServeMux) {
mux.HandleFunc("/build", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
b, _ := json.Marshal(version.String())
Expand All @@ -262,20 +261,42 @@ func registerHandlers(
glog.Errorf("Unexpected error: %v", err)
}
})
}

if enableProfiling {
mux.HandleFunc("/debug/pprof/", pprof.Index)
mux.HandleFunc("/debug/pprof/heap", pprof.Index)
mux.HandleFunc("/debug/pprof/mutex", pprof.Index)
mux.HandleFunc("/debug/pprof/goroutine", pprof.Index)
mux.HandleFunc("/debug/pprof/threadcreate", pprof.Index)
mux.HandleFunc("/debug/pprof/block", pprof.Index)
mux.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline)
mux.HandleFunc("/debug/pprof/profile", pprof.Profile)
mux.HandleFunc("/debug/pprof/symbol", pprof.Symbol)
mux.HandleFunc("/debug/pprof/trace", pprof.Trace)
}
func registerHealthz(ic *controller.NGINXController, mux *http.ServeMux) {
// expose health check endpoint (/healthz)
healthz.InstallHandler(mux,
healthz.PingHealthz,
ic,
)
}

func registerMetrics(reg *prometheus.Registry, mux *http.ServeMux) {

mux.Handle(
"/metrics",
promhttp.InstrumentMetricHandler(
reg,
promhttp.HandlerFor(reg, promhttp.HandlerOpts{}),
),
)

}

func registerProfiler(mux *http.ServeMux) {
mux.HandleFunc("/debug/pprof/", pprof.Index)
mux.HandleFunc("/debug/pprof/heap", pprof.Index)
mux.HandleFunc("/debug/pprof/mutex", pprof.Index)
mux.HandleFunc("/debug/pprof/goroutine", pprof.Index)
mux.HandleFunc("/debug/pprof/threadcreate", pprof.Index)
mux.HandleFunc("/debug/pprof/block", pprof.Index)
mux.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline)
mux.HandleFunc("/debug/pprof/profile", pprof.Profile)
mux.HandleFunc("/debug/pprof/symbol", pprof.Symbol)
mux.HandleFunc("/debug/pprof/trace", pprof.Trace)
}

func startHTTPServer(port int, mux *http.ServeMux) {
server := &http.Server{
Addr: fmt.Sprintf(":%v", port),
Handler: mux,
Expand Down
2 changes: 2 additions & 0 deletions vendor/cloud.google.com/go/.travis.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 44 additions & 0 deletions vendor/cloud.google.com/go/CODE_OF_CONDUCT.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions vendor/cloud.google.com/go/CONTRIBUTING.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

142 changes: 37 additions & 105 deletions vendor/cloud.google.com/go/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading