apisix-ingress-controller rest调试帮助

1、从配置看

http_listen: ":8080"   # the HTTP Server listen address, default is ":8080"
enable_profiling: true # enable profiling via web interfaces
                       # host:port/debug/pprof, default is true.

2、ingress/controller中

apiSrv, err := api.NewServer(cfg)

    c := &Controller{
        name:              podName,
        namespace:         podNamespace,
        cfg:               cfg,
        apiServer:         apiSrv,
        apisix:            client,
        metricsCollector:  metrics.NewPrometheusCollector(podName, podNamespace),
        kubeClient:        kubeClient,
        watchingNamespace: watchingNamespace,
        secretSSLMap:      new(sync.Map),
        recorder:          eventBroadcaster.NewRecorder(scheme.Scheme, v1.EventSource{Component: _component}),

        podCache: types.NewPodCache(),
    }
。。。。。。

// Run launches the controller.
func (c *Controller) Run(stop chan struct{}) error {
    rootCtx, rootCancel := context.WithCancel(context.Background())
    defer rootCancel()
    go func() {
        <-stop
        rootCancel()
    }()
    c.metricsCollector.ResetLeader(false)

    go func() {
        if err := c.apiServer.Run(rootCtx.Done()); err != nil {
            log.Errorf("failed to launch API Server: %s", err)
        }
    }()

3、server中支持了那些项目,gin类型服务模型配置监听

package api

import (
    "net"
    "net/http"
    "net/http/pprof"

    "github.com/gin-gonic/gin"

    apirouter "github.com/apache/apisix-ingress-controller/pkg/api/router"
    "github.com/apache/apisix-ingress-controller/pkg/config"
    "github.com/apache/apisix-ingress-controller/pkg/log"
    "github.com/apache/apisix-ingress-controller/pkg/types"
)

// Server represents the API Server in ingress-apisix-controller.
type Server struct {
    router       *gin.Engine
    httpListener net.Listener
    pprofMu      *http.ServeMux
}

// NewServer initializes the API Server.
func NewServer(cfg *config.Config) (*Server, error) {
    httpListener, err := net.Listen("tcp", cfg.HTTPListen)
    if err != nil {
        return nil, err
    }
    gin.SetMode(gin.ReleaseMode)
    router := gin.New()
    router.Use(gin.Recovery(), gin.Logger())
    apirouter.Mount(router)

    srv := &Server{
        router:       router,
        httpListener: httpListener,
    }

    if cfg.EnableProfiling {
        srv.pprofMu = new(http.ServeMux)
        srv.pprofMu.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline)
        srv.pprofMu.HandleFunc("/debug/pprof/profile", pprof.Profile)
        srv.pprofMu.HandleFunc("/debug/pprof/symbol", pprof.Symbol)
        srv.pprofMu.HandleFunc("/debug/pprof/trace", pprof.Trace)
        srv.pprofMu.HandleFunc("/debug/pprof/", pprof.Index)
        router.GET("/debug/pprof/*profile", gin.WrapF(srv.pprofMu.ServeHTTP))
    }

    return srv, nil
}

// Run launches the API Server.
func (srv *Server) Run(stopCh <-chan struct{}) error {
    go func() {
        <-stopCh
        if err := srv.httpListener.Close(); err != nil {
            log.Errorf("failed to close http listener: %s", err)
        }
    }()
    if err := srv.router.RunListener(srv.httpListener); err != nil && !types.IsUseOfClosedNetConnErr(err) {
        log.Errorf("failed to start API Server: %s", err)
        return err
    }
    return nil
}

curl localhost:8080/debug/pprof/cmdline

原文地址:https://www.cnblogs.com/it-worker365/p/15415791.html