【问题标题】:Specify jwt token when fetch profile via "go tool pprof"通过 \"go tool pprof\" 获取配置文件时指定 jwt 令牌
【发布时间】:2023-02-20 16:35:25
【问题描述】:

我的 api 通过 jwt 保护,在通过 go tool pprof 获取配置文件时是否可以指定 jwt 令牌?

目前,我必须配置 jwt 中间件来绕过 /debug/pprof 路由。

【问题讨论】:

    标签: go jwt pprof


    【解决方案1】:

    我找不到直接通过 go tool pprof 传递令牌的方法,但由于您可以使用 curl 获取配置文件,因此有一个简单的解决方法:

    $ curl -o profile.out https://host/debug/pprof -H 'X-Authorization: $TOKEN'
    $ go tool pprof profile.out
    

    【讨论】:

    • 酷,这行得通。顺便说一句,在生成配置文件时,请求默认会等待 30 秒。 wget 的工作方式类似。
    • 是的,但是你可以通过“seconds”参数来控制收集数据的时间,例如:将时间减少到5秒:curl -o profile.out https://host/debug/pprof?seconds=5 -X 'X-Authorization: $TOKEN'
    • 这个想法可行,但您应该将带有 -H 标志的标头指定为 curl 而不是 -X。像这样:$ curl -o profile.out https://host/debug/pprof -H 'X-Authorization: $TOKEN'
    • @ezileli 你完全正确,谢谢你指出
    猜你喜欢
    • 1970-01-01
    • 2017-06-30
    • 1970-01-01
    • 2022-01-15
    • 2016-08-07
    • 2020-11-08
    • 2021-06-24
    • 2019-03-19
    • 2019-05-30
    相关资源
    最近更新 更多