Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not report instance as available while draining #124

Merged
merged 1 commit into from
Jun 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion pkg/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,11 +317,12 @@ func (s *Service) sendUpdate(ctx context.Context, info *livekit.IngressInfo, err
}

func (s *Service) CanAccept() bool {
return !s.shutdown.IsBroken() && s.monitor.CanAcceptIngress()
return s.monitor.CanAcceptIngress()
}

func (s *Service) Stop(kill bool) {
s.shutdown.Break()
s.monitor.Shutdown()

if kill {
s.manager.killAll()
Expand Down
17 changes: 16 additions & 1 deletion pkg/stats/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"sort"
"time"

"github.com/frostbyte73/core"
"github.com/prometheus/client_golang/prometheus"
"go.uber.org/atomic"

Expand All @@ -26,10 +27,14 @@ type Monitor struct {
cpuStats *utils.CPUStats

pendingCPUs atomic.Float64

shutdown core.Fuse
}

func NewMonitor() *Monitor {
return &Monitor{}
return &Monitor{
shutdown: core.NewFuse(),
}
}

func (m *Monitor) Start(conf *config.Config) error {
Expand Down Expand Up @@ -75,6 +80,12 @@ func (m *Monitor) Start(conf *config.Config) error {
return nil
}

// Server is shutting down, but may stay up for some time for draining
func (m *Monitor) Shutdown() {
m.shutdown.Break()
}

// Stop the monitor before server termination
func (m *Monitor) Stop() {
if m.cpuStats != nil {
m.cpuStats.Stop()
Expand Down Expand Up @@ -150,6 +161,10 @@ func (m *Monitor) GetCPULoad() float64 {
}

func (m *Monitor) CanAcceptIngress() bool {
if m.shutdown.IsBroken() {
return false
}

available := m.cpuStats.GetCPUIdle() - m.pendingCPUs.Load()

return available > m.maxCost
Expand Down