• 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

  • 相关阅读:
    一些小问题的解决
    JavaScript面向对象的支持
    HTML 5 会为 Flash 和 Silverlight 送终吗?
    Web Forms 2.0 行将被 HTML 5 代替
    XHTML 2: 出师未捷身先死, HTML 5:万千宠爱于一身
    Javascript 技巧大全
    深入了解 HTML 5
    HTML 5 令人期待的 5 项功能
    SQL SERVER 2005中的Schema详解
    VS2008 ,TFS2008破解序列号
  • 原文地址:https://www.cnblogs.com/it-worker365/p/15415791.html
Copyright © 2020-2023  润新知