Skip to content

Commit

Permalink
Add Debug handler with pprof support (#131)
Browse files Browse the repository at this point in the history
  • Loading branch information
biglittlebigben authored Jul 15, 2023
1 parent a941c25 commit b59b27f
Show file tree
Hide file tree
Showing 15 changed files with 760 additions and 120 deletions.
2 changes: 2 additions & 0 deletions cmd/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ func runService(c *cli.Context) error {
return err
}

svc.StartDebugHandlers()

err = setupHealthHandlers(conf, svc)
if err != nil {
return err
Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ require (
github.com/livekit/go-rtmp v0.0.0-20230317185657-6e9cfa387c7e
github.com/livekit/mageutil v0.0.0-20230125210925-54e8a70427c1
github.com/livekit/mediatransportutil v0.0.0-20230612070454-d5299b956135
github.com/livekit/protocol v1.5.10-0.20230711074119-b0d723aaa9a8
github.com/livekit/psrpc v0.3.1
github.com/livekit/protocol v1.5.10-0.20230714010226-3c53edc91962
github.com/livekit/psrpc v0.3.2
github.com/livekit/server-sdk-go v1.0.13
github.com/pion/interceptor v0.1.17
github.com/pion/rtcp v1.2.10
Expand All @@ -25,6 +25,7 @@ require (
github.com/yutopp/go-flv v0.2.0
go.uber.org/atomic v1.11.0
golang.org/x/image v0.7.0
google.golang.org/grpc v1.56.2
google.golang.org/protobuf v1.31.0
gopkg.in/yaml.v3 v3.0.1
)
Expand Down Expand Up @@ -92,5 +93,4 @@ require (
golang.org/x/sys v0.9.0 // indirect
golang.org/x/text v0.10.0 // indirect
google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1 // indirect
google.golang.org/grpc v1.56.2 // indirect
)
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@ github.com/livekit/mageutil v0.0.0-20230125210925-54e8a70427c1 h1:jm09419p0lqTkD
github.com/livekit/mageutil v0.0.0-20230125210925-54e8a70427c1/go.mod h1:Rs3MhFwutWhGwmY1VQsygw28z5bWcnEYmS1OG9OxjOQ=
github.com/livekit/mediatransportutil v0.0.0-20230612070454-d5299b956135 h1:lWYbsondvqG69czxoACDwaJ/BoyD57BahCo70ZH+m4U=
github.com/livekit/mediatransportutil v0.0.0-20230612070454-d5299b956135/go.mod h1:MRc0zSOSzXuFt0X218SgabzlaKevkvCckPgBEoHYc34=
github.com/livekit/protocol v1.5.10-0.20230711074119-b0d723aaa9a8 h1:FA7yPjXdsmVDOcMWMeucjLnDjlAo09sb7fAqDPWo+LI=
github.com/livekit/protocol v1.5.10-0.20230711074119-b0d723aaa9a8/go.mod h1:zqhhOl9Cw8R6lVR58DsYryjP1WqA/iPWItamJnnYy8M=
github.com/livekit/psrpc v0.3.1 h1:KfylgJHvoLQcc22t/oflwMOeSnx0c14G7cWsS+9MYS4=
github.com/livekit/psrpc v0.3.1/go.mod h1:n6JntEg+zT6Ji8InoyTpV7wusPNwGqqtxmHlkNhDN0U=
github.com/livekit/protocol v1.5.10-0.20230714010226-3c53edc91962 h1:y+rtYNMGmvpEgQlNG/wOUO16S497ygh83wQSUBKHpG4=
github.com/livekit/protocol v1.5.10-0.20230714010226-3c53edc91962/go.mod h1:eRzojAYSPJuNgDHMlvLji/CPauj9hrgvb6rVPUj6MoU=
github.com/livekit/psrpc v0.3.2 h1:eAaJhASme33gtoBhCRLH9jsnWcdm1tHWf0WzaDk56ew=
github.com/livekit/psrpc v0.3.2/go.mod h1:n6JntEg+zT6Ji8InoyTpV7wusPNwGqqtxmHlkNhDN0U=
github.com/livekit/server-sdk-go v1.0.13 h1:Rv+jQEqRy5pCto0TF0J0dweDQgLNH7NJiGWG+sHc8/o=
github.com/livekit/server-sdk-go v1.0.13/go.mod h1:2Q1KLiWyLjG1NGhe7y2r35qs8OVMwXzjyQeCXqGyAKU=
github.com/mackerelio/go-osstat v0.2.4 h1:qxGbdPkFo65PXOb/F/nhDKpF2nGmGaCFDLXoZjJTtUs=
Expand Down
46 changes: 46 additions & 0 deletions magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package main

import (
"context"
"encoding/json"
"fmt"
"go/build"
"os"
Expand All @@ -23,6 +24,51 @@ const (

var plugins = []string{"gstreamer", "gst-plugins-base", "gst-plugins-good", "gst-plugins-bad", "gst-plugins-ugly", "gst-libav"}

type packageInfo struct {
Dir string
}

func Proto() error {
ctx := context.Background()
fmt.Println("generating protobuf")

// parse go mod output
pkgOut, err := mageutil.Out(ctx, "go list -json -m github.com/livekit/protocol")
if err != nil {
return err
}
pi := packageInfo{}
if err = json.Unmarshal(pkgOut, &pi); err != nil {
return err
}

_, err = mageutil.GetToolPath("protoc")
if err != nil {
return err
}
protocGoPath, err := mageutil.GetToolPath("protoc-gen-go")
if err != nil {
return err
}
protocGrpcGoPath, err := mageutil.GetToolPath("protoc-gen-go-grpc")
if err != nil {
return err
}

// generate grpc-related protos
return mageutil.RunDir(ctx, "pkg/ipc", fmt.Sprintf(
"protoc"+
" --go_out ."+
" --go-grpc_out ."+
" --go_opt=paths=source_relative"+
" --go-grpc_opt=paths=source_relative"+
" --plugin=go=%s"+
" --plugin=go-grpc=%s"+
" -I%s -I=. ipc.proto",
protocGoPath, protocGrpcGoPath, pi.Dir,
))
}

func Bootstrap() error {
brewPrefix, err := getBrewPrefix()
if err != nil {
Expand Down
15 changes: 8 additions & 7 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,14 @@ type Config struct {
ApiSecret string `yaml:"api_secret"` // required (env LIVEKIT_API_SECRET)
WsUrl string `yaml:"ws_url"` // required (env LIVEKIT_WS_URL)

HealthPort int `yaml:"health_port"`
PrometheusPort int `yaml:"prometheus_port"`
RTMPPort int `yaml:"rtmp_port"` // -1 to disable RTMP
WHIPPort int `yaml:"whip_port"` // -1 to disable WHIP
HTTPRelayPort int `yaml:"http_relay_port"`
Logging logger.Config `yaml:"logging"`
Development bool `yaml:"development"`
HealthPort int `yaml:"health_port"`
DebugHandlerPort int `yaml:"debug_handler_port"`
PrometheusPort int `yaml:"prometheus_port"`
RTMPPort int `yaml:"rtmp_port"` // -1 to disable RTMP
WHIPPort int `yaml:"whip_port"` // -1 to disable WHIP
HTTPRelayPort int `yaml:"http_relay_port"`
Logging logger.Config `yaml:"logging"`
Development bool `yaml:"development"`

// Used for WHIP transport
RTCConfig rtcconfig.RTCConfig `yaml:"rtc_config"`
Expand Down
232 changes: 232 additions & 0 deletions pkg/ipc/ipc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions pkg/ipc/ipc.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
syntax = "proto3";

package ipc;
option go_package = "github.com/livekit/ingress/pkg/ipc";

service IngressHandler {
rpc GetPProf(PProfRequest) returns (PProfResponse) {};
}

message PProfRequest {
string profile_name = 1;
int32 timeout = 2;
int32 debug = 3;
}

message PProfResponse {
bytes pprof_file = 1;
}
Loading

0 comments on commit b59b27f

Please sign in to comment.