diff --git a/cns/service/main.go b/cns/service/main.go index 19bf2dc06c..2cc00168e6 100644 --- a/cns/service/main.go +++ b/cns/service/main.go @@ -46,6 +46,7 @@ import ( "github.com/Azure/azure-container-networking/store" "github.com/avast/retry-go/v3" "github.com/pkg/errors" + "github.com/prometheus/client_golang/prometheus/promhttp" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/fields" "k8s.io/apimachinery/pkg/types" @@ -53,6 +54,8 @@ import ( ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/cache" "sigs.k8s.io/controller-runtime/pkg/client" + "sigs.k8s.io/controller-runtime/pkg/healthz" + "sigs.k8s.io/controller-runtime/pkg/metrics" ) const ( @@ -977,10 +980,9 @@ func InitializeCRDState(ctx context.Context, httpRestService cns.HTTPService, cn }) manager, err := ctrl.NewManager(kubeConfig, ctrl.Options{ - Scheme: nodenetworkconfig.Scheme, - MetricsBindAddress: cnsconfig.MetricsBindAddress, - Namespace: "kube-system", // TODO(rbtr): namespace should be in the cns config - NewCache: nodeScopedCache, + Scheme: nodenetworkconfig.Scheme, + Namespace: "kube-system", // TODO(rbtr): namespace should be in the cns config + NewCache: nodeScopedCache, }) if err != nil { return errors.Wrap(err, "failed to create manager") @@ -999,6 +1001,28 @@ func InitializeCRDState(ctx context.Context, httpRestService cns.HTTPService, cn return errors.Wrapf(err, "failed to setup reconciler with manager") } + mux := http.NewServeMux() + + /*pprof endpoints + mux.HandleFunc("/debug/pprof/", 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) + */ + + //to reduce + mux.Handle("/metrics", promhttp.HandlerFor(metrics.Registry, promhttp.HandlerOpts{ + ErrorHandling: promhttp.HTTPErrorOnError, + })) + healthzhandler := healthz.Handler{} + healthzhandler.Checks["ping"] = healthz.Ping + mux.Handle("/heathz", &healthzhandler) + + go func() { + http.ListenAndServe(cnsconfig.MetricsBindAddress, mux) + }() + // Start the Manager which starts the reconcile loop. // The Reconciler will send an initial NodeNetworkConfig update to the PoolMonitor, starting the // Monitor's internal loop. @@ -1043,6 +1067,7 @@ func InitializeCRDState(ctx context.Context, httpRestService cns.HTTPService, cn } } }() + logger.Printf("initialized and started SyncHostNCVersion loop") return nil