Merge pull request #3477 from tharun208/feat/profiling

Added profiling for controller
This commit is contained in:
jetstack-bot 2020-12-11 14:11:10 +00:00 committed by GitHub
commit 2c521609de
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 18 additions and 46 deletions

View File

@ -5996,41 +5996,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
================================================================================
================================================================================
= vendor/github.com/gorilla/mux licensed under: =
Copyright (c) 2012-2018 The Gorilla Authors. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the
distribution.
* Neither the name of Google Inc. nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
= vendor/github.com/gorilla/mux/LICENSE 33fa1116c45f9e8de714033f99edde13
================================================================================
================================================================================
= vendor/github.com/gregjones/httpcache licensed under: =

View File

@ -69,7 +69,7 @@ func Run(opts *options.ControllerOptions, stopCh <-chan struct{}) {
os.Exit(1)
}
metricsServer, err := ctx.Metrics.Start(opts.MetricsListenAddress)
metricsServer, err := ctx.Metrics.Start(opts.MetricsListenAddress, opts.EnablePprof)
if err != nil {
log.Error(err, "failed to listen on prometheus address", "address", opts.MetricsListenAddress)
os.Exit(1)

View File

@ -90,6 +90,9 @@ type ControllerOptions struct {
// The host and port address, separated by a ':', that the Prometheus server
// should expose metrics on.
MetricsListenAddress string
// EnablePprof controls whether net/http/pprof handlers are registered with
// the HTTP listener.
EnablePprof bool
DNS01CheckRetryPeriod time.Duration
}
@ -182,6 +185,7 @@ func NewControllerOptions() *ControllerOptions {
EnableCertificateOwnerRef: defaultEnableCertificateOwnerRef,
MetricsListenAddress: defaultPrometheusMetricsServerAddress,
DNS01CheckRetryPeriod: defaultDNS01CheckRetryPeriod,
EnablePprof: false,
}
}
@ -286,6 +290,8 @@ func (s *ControllerOptions) AddFlags(fs *pflag.FlagSet) {
fs.StringVar(&s.MetricsListenAddress, "metrics-listen-address", defaultPrometheusMetricsServerAddress, ""+
"The host and port that the metrics endpoint should listen on.")
fs.BoolVar(&s.EnablePprof, "enable-profiling", false, ""+
"Enable profiling for controller.")
}
func (o *ControllerOptions) Validate() error {

1
go.mod
View File

@ -21,7 +21,6 @@ require (
github.com/go-logr/zapr v0.1.1 // indirect
github.com/google/go-cmp v0.4.1 // indirect
github.com/google/gofuzz v1.2.0
github.com/gorilla/mux v1.8.0
github.com/hashicorp/vault/api v1.0.4
github.com/hashicorp/vault/sdk v0.1.13
github.com/kr/pretty v0.2.1

2
go.sum
View File

@ -334,8 +334,6 @@ github.com/gophercloud/gophercloud v0.1.0 h1:P/nh25+rzXouhytV2pUHBb65fnds26Ghl8/
github.com/gophercloud/gophercloud v0.1.0/go.mod h1:vxM41WHh5uqHVBMZHzuwNOHh8XEoIEcSTewFxm1c5g8=
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8=
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI=
github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So=
github.com/gorilla/websocket v0.0.0-20170926233335-4201258b820c/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
github.com/gorilla/websocket v1.4.0 h1:WDFjx/TMzVgy9VdMMQi2K2Emtwi2QcUQsztZ/zLaH/Q=
github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=

View File

@ -13,8 +13,8 @@ go_library(
"//pkg/apis/certmanager/v1:go_default_library",
"//pkg/apis/meta/v1:go_default_library",
"//pkg/logs:go_default_library",
"//pkg/util/profiling:go_default_library",
"@com_github_go_logr_logr//:go_default_library",
"@com_github_gorilla_mux//:go_default_library",
"@com_github_prometheus_client_golang//prometheus:go_default_library",
"@com_github_prometheus_client_golang//prometheus/promhttp:go_default_library",
"@io_k8s_client_go//tools/cache:go_default_library",

View File

@ -32,11 +32,12 @@ import (
logf "github.com/jetstack/cert-manager/pkg/logs"
"github.com/go-logr/logr"
"github.com/gorilla/mux"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
cmmeta "github.com/jetstack/cert-manager/pkg/apis/meta/v1"
"github.com/jetstack/cert-manager/pkg/util/profiling"
)
const (
@ -134,15 +135,18 @@ func New(log logr.Logger) *Metrics {
}
// Start will register the Prometheu metrics, and start the Prometheus server
func (m *Metrics) Start(listenAddress string) (*http.Server, error) {
func (m *Metrics) Start(listenAddress string, enablePprof bool) (*http.Server, error) {
m.registry.MustRegister(m.certificateExpiryTimeSeconds)
m.registry.MustRegister(m.certificateReadyStatus)
m.registry.MustRegister(m.acmeClientRequestDurationSeconds)
m.registry.MustRegister(m.acmeClientRequestCount)
m.registry.MustRegister(m.controllerSyncCallCount)
router := mux.NewRouter()
router.Handle("/metrics", promhttp.HandlerFor(m.registry, promhttp.HandlerOpts{}))
mux := http.NewServeMux()
mux.Handle("/metrics", promhttp.HandlerFor(m.registry, promhttp.HandlerOpts{}))
if enablePprof {
profiling.Install(mux)
}
ln, err := net.Listen("tcp", listenAddress)
if err != nil {
@ -154,7 +158,7 @@ func (m *Metrics) Start(listenAddress string) (*http.Server, error) {
ReadTimeout: prometheusMetricsServerReadTimeout,
WriteTimeout: prometheusMetricsServerWriteTimeout,
MaxHeaderBytes: prometheusMetricsServerMaxHeaderBytes,
Handler: router,
Handler: mux,
}
go func() {

View File

@ -51,7 +51,7 @@ func TestMetricsController(t *testing.T) {
kubernetesCl, factory, cmClient, cmFactory := framework.NewClients(t, config)
metricsHandler := metrics.New(logf.Log)
server, err := metricsHandler.Start("127.0.0.1:0")
server, err := metricsHandler.Start("127.0.0.1:0", false)
if err != nil {
t.Fatal(err)
}