Skip to content

Commit

Permalink
log error with usage
Browse files Browse the repository at this point in the history
  • Loading branch information
frostbyte73 committed Jan 8, 2024
1 parent c4ce014 commit 04ad939
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion pkg/errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (
var (
ErrNoConfig = psrpc.NewErrorf(psrpc.Internal, "missing config")
ErrGhostPadFailed = psrpc.NewErrorf(psrpc.Internal, "failed to add ghost pad to bin")
ErrStreamAlreadyExists = psrpc.NewErrorf(psrpc.AlreadyExists, "stream already exists")
ErrBinAlreadyAdded = psrpc.NewErrorf(psrpc.Internal, "bin already added to pipeline")
ErrWrongHierarchy = psrpc.NewErrorf(psrpc.Internal, "pipeline can contain bins or elements, not both")
ErrNonStreamingPipeline = psrpc.NewErrorf(psrpc.InvalidArgument, "UpdateStream called on non-streaming egress")
Expand All @@ -38,6 +37,7 @@ var (
ErrSubscriptionFailed = psrpc.NewErrorf(psrpc.Internal, "failed to subscribe to track")
ErrPipelineFrozen = psrpc.NewErrorf(psrpc.Internal, "pipeline frozen")
ErrSinkNotFound = psrpc.NewErrorf(psrpc.Internal, "sink not found")
ErrCPUExhausted = psrpc.NewErrorf(psrpc.Unavailable, "CPU exhausted")
)

func New(err string) error {
Expand Down
6 changes: 4 additions & 2 deletions pkg/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"google.golang.org/grpc"

"github.com/livekit/egress/pkg/config"
"github.com/livekit/egress/pkg/errors"
"github.com/livekit/egress/pkg/ipc"
"github.com/livekit/egress/pkg/stats"
"github.com/livekit/egress/version"
Expand Down Expand Up @@ -183,12 +184,13 @@ func (s *Service) KillAll() {
}
}

func (s *Service) killProcess(egressID string) {
func (s *Service) killProcess(egressID string, maxUsage float64) {
s.mu.RLock()
defer s.mu.RUnlock()

if h, ok := s.activeHandlers[egressID]; ok {
h.info.Error = "CPU exhausted"
logger.Errorw("killing egress", errors.ErrCPUExhausted, "egressID", egressID, "usage", maxUsage)
h.info.Error = errors.ErrCPUExhausted.Error()
h.kill()
}
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/stats/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ type Monitor struct {
mu sync.Mutex
highCPUDuration int
killThreshold float64
killProcess func(string)
killProcess func(string, float64)
pending map[string]*processStats
procStats map[int]*processStats
}
Expand Down Expand Up @@ -85,7 +85,7 @@ func (m *Monitor) Start(
conf *config.ServiceConfig,
isIdle func() float64,
canAcceptRequest func() float64,
killProcess func(string),
killProcess func(string, float64),
) error {
m.killProcess = killProcess

Expand Down Expand Up @@ -241,7 +241,7 @@ func (m *Monitor) updateEgressStats(idle float64, usage map[int]float64) {
if m.highCPUDuration < minKillDuration {
return
}
m.killProcess(maxEgress)
m.killProcess(maxEgress, maxUsage)
}
}

Expand Down

0 comments on commit 04ad939

Please sign in to comment.