1
0
mirror of https://github.com/newnius/YAO-scheduler.git synced 2025-06-06 22:01:55 +00:00

add custom logger to support mute certain modules

This commit is contained in:
Newnius 2020-07-17 11:08:55 +08:00
parent 7d33c85a1a
commit 04e6dfd472
15 changed files with 38 additions and 23 deletions

View File

@ -2,7 +2,6 @@ package main
import ( import (
"sync" "sync"
log "github.com/sirupsen/logrus"
"math" "math"
"time" "time"
"github.com/MaxHalford/eaopt" "github.com/MaxHalford/eaopt"

View File

@ -4,7 +4,6 @@ import (
"sync" "sync"
"github.com/Shopify/sarama" "github.com/Shopify/sarama"
"encoding/json" "encoding/json"
log "github.com/sirupsen/logrus"
"time" "time"
) )

View File

@ -2,7 +2,6 @@ package main
import ( import (
"sync" "sync"
log "github.com/sirupsen/logrus"
"os" "os"
"strings" "strings"
"strconv" "strconv"
@ -126,24 +125,32 @@ func (config *Configuration) SetMockEnabled(enabled bool) bool {
} }
func (config *Configuration) SetShareRatio(ratio float64) bool { func (config *Configuration) SetShareRatio(ratio float64) bool {
config.mu.Lock()
defer config.mu.Unlock()
config.EnableShareRatio = ratio config.EnableShareRatio = ratio
log.Info("enableShareRatio is updated to ", ratio) log.Info("enableShareRatio is updated to ", ratio)
return true return true
} }
func (config *Configuration) SetPreScheduleRatio(ratio float64) bool { func (config *Configuration) SetPreScheduleRatio(ratio float64) bool {
config.mu.Lock()
defer config.mu.Unlock()
config.EnablePreScheduleRatio = ratio config.EnablePreScheduleRatio = ratio
log.Info("enablePreScheduleRatio is updated to ", ratio) log.Info("enablePreScheduleRatio is updated to ", ratio)
return true return true
} }
func (config *Configuration) SetShareMaxUtilization(value float64) bool { func (config *Configuration) SetShareMaxUtilization(value float64) bool {
config.mu.Lock()
defer config.mu.Unlock()
config.ShareMaxUtilization = value config.ShareMaxUtilization = value
log.Info("ShareMaxUtilization is set to ", value) log.Info("ShareMaxUtilization is set to ", value)
return true return true
} }
func (config *Configuration) Dump() map[string]interface{} { func (config *Configuration) Dump() map[string]interface{} {
config.mu.Lock()
defer config.mu.Unlock()
res := map[string]interface{}{} res := map[string]interface{}{}
res["KafkaBrokers"] = config.KafkaBrokers res["KafkaBrokers"] = config.KafkaBrokers
res["KafkaTopic"] = config.KafkaTopic res["KafkaTopic"] = config.KafkaTopic
@ -158,5 +165,7 @@ func (config *Configuration) Dump() map[string]interface{} {
res["EnablePreScheduleRatio"] = config.EnablePreScheduleRatio res["EnablePreScheduleRatio"] = config.EnablePreScheduleRatio
res["PreScheduleExtraTime"] = config.PreScheduleExtraTime res["PreScheduleExtraTime"] = config.PreScheduleExtraTime
res["PreScheduleTimeout"] = config.PreScheduleTimeout res["PreScheduleTimeout"] = config.PreScheduleTimeout
res["logger.level"] = log.LoggerLevel
res["logger.modules_disabled"] = log.LoggerModuleDisabled
return res return res
} }

View File

@ -4,7 +4,6 @@ import (
"math/rand" "math/rand"
"github.com/MaxHalford/eaopt" "github.com/MaxHalford/eaopt"
"math" "math"
log "github.com/sirupsen/logrus"
) )
// A resource allocation // A resource allocation

View File

@ -3,7 +3,6 @@ package main
import ( import (
"strconv" "strconv"
"time" "time"
log "github.com/sirupsen/logrus"
"testing" "testing"
) )
@ -50,8 +49,8 @@ func TestBestFit(t *testing.T) {
} }
s := time.Now() s := time.Now()
allocation := InstanceOfAllocator().fastBestFit(nodes, tasks) allocation := InstanceOfAllocator().fastBestFit(nodes, tasks)
log.Println(time.Since(s)) log.Info(time.Since(s))
log.Println(allocation) log.Info(allocation)
} }
func TestGA(t *testing.T) { func TestGA(t *testing.T) {

View File

@ -1,7 +1,6 @@
package main package main
import ( import (
log "github.com/sirupsen/logrus"
"sync" "sync"
) )

View File

@ -6,7 +6,6 @@ import (
"strings" "strings"
"io/ioutil" "io/ioutil"
"encoding/json" "encoding/json"
log "github.com/sirupsen/logrus"
"sync" "sync"
"strconv" "strconv"
"math/rand" "math/rand"
@ -346,7 +345,7 @@ func (jm *JobManager) logs(taskName string) MsgLog {
var res MsgLog var res MsgLog
err = json.Unmarshal([]byte(string(body)), &res) err = json.Unmarshal([]byte(string(body)), &res)
if err != nil { if err != nil {
log.Println(err) log.Warn(err)
return MsgLog{Code: 3, Error: "Unknown"} return MsgLog{Code: 3, Error: "Unknown"}
} }
return res return res

View File

@ -2,7 +2,6 @@ package main
import ( import (
"net/http" "net/http"
log "github.com/sirupsen/logrus"
"encoding/json" "encoding/json"
"time" "time"
"strconv" "strconv"
@ -10,6 +9,8 @@ import (
"os" "os"
) )
var log Logger
var scheduler Scheduler var scheduler Scheduler
func serverAPI(w http.ResponseWriter, r *http.Request) { func serverAPI(w http.ResponseWriter, r *http.Request) {
@ -332,6 +333,18 @@ func serverAPI(w http.ResponseWriter, r *http.Request) {
ok = InstanceOfAllocator().updateStrategy(value) ok = InstanceOfAllocator().updateStrategy(value)
break break
case "logger.level":
ok = log.SetLoggerLevel(value)
break
case "logger.enable_module":
ok = log.LoggerEnableModule(value)
break
case "logger.disable_module":
ok = log.LoggerDisableModule(value)
break
} }
var msg MsgConfUpdate var msg MsgConfUpdate
msg.Code = 0 msg.Code = 0
@ -365,7 +378,6 @@ func main() {
} }
log.SetOutput(f) log.SetOutput(f)
} }
//log.SetLevel(log.InfoLevel)
/* parse configuration */ /* parse configuration */
config := *InstanceOfConfiguration() config := *InstanceOfConfiguration()

View File

@ -1,7 +1,6 @@
package main package main
import ( import (
log "github.com/sirupsen/logrus"
"sync" "sync"
"strings" "strings"
"io/ioutil" "io/ioutil"

View File

@ -3,7 +3,6 @@ package main
import ( import (
"testing" "testing"
"strconv" "strconv"
log "github.com/sirupsen/logrus"
"time" "time"
) )

View File

@ -5,7 +5,6 @@ import (
"time" "time"
"net/url" "net/url"
"strings" "strings"
log "github.com/sirupsen/logrus"
"math/rand" "math/rand"
"strconv" "strconv"
"sort" "sort"
@ -30,7 +29,8 @@ type ResourcePool struct {
pools []PoolSeg pools []PoolSeg
poolsMu sync.Mutex poolsMu sync.Mutex
history []PoolStatus history []PoolStatus
historyMu sync.Mutex
heartBeat map[string]time.Time heartBeat map[string]time.Time
heartBeatMu sync.Mutex heartBeatMu sync.Mutex
@ -67,6 +67,8 @@ type ResourcePool struct {
func (pool *ResourcePool) init(conf Configuration) { func (pool *ResourcePool) init(conf Configuration) {
log.Info("RM started ") log.Info("RM started ")
InstanceOfConfiguration().LoggerEnableModule("RM")
pool.networks = map[string]bool{} pool.networks = map[string]bool{}
pool.networksFree = map[string]bool{} pool.networksFree = map[string]bool{}
@ -289,11 +291,12 @@ func (pool *ResourcePool) saveStatusHistory() {
summary.TotalMemGPU = TotalMemGPU summary.TotalMemGPU = TotalMemGPU
summary.AvailableMemGPU = AvailableMemGPU summary.AvailableMemGPU = AvailableMemGPU
pool.historyMu.Lock()
pool.history = append(pool.history, summary) pool.history = append(pool.history, summary)
if len(pool.history) > 60 { if len(pool.history) > 60 {
pool.history = pool.history[len(pool.history)-60:] pool.history = pool.history[len(pool.history)-60:]
} }
pool.historyMu.Unlock()
pool.TotalGPUMu.Lock() pool.TotalGPUMu.Lock()
pool.TotalGPU = TotalGPU pool.TotalGPU = TotalGPU
@ -490,7 +493,10 @@ func (pool *ResourcePool) list() MsgResource {
} }
func (pool *ResourcePool) statusHistory() MsgPoolStatusHistory { func (pool *ResourcePool) statusHistory() MsgPoolStatusHistory {
return MsgPoolStatusHistory{Code: 0, Data: pool.history} pool.historyMu.Lock()
defer pool.historyMu.Unlock()
history := pool.history
return MsgPoolStatusHistory{Code: 0, Data: history}
} }
func (pool *ResourcePool) getCounter() map[string]int { func (pool *ResourcePool) getCounter() map[string]int {
@ -514,7 +520,7 @@ func (pool *ResourcePool) acquireNetwork() string {
v.Set("name", network) v.Set("name", network)
resp, err := doRequest("POST", "http://yao-agent-master:8000/create", strings.NewReader(v.Encode()), "application/x-www-form-urlencoded", "") resp, err := doRequest("POST", "http://yao-agent-master:8000/create", strings.NewReader(v.Encode()), "application/x-www-form-urlencoded", "")
if err != nil { if err != nil {
log.Println(err.Error()) log.Warn(err.Error())
continue continue
} }
resp.Body.Close() resp.Body.Close()

View File

@ -3,7 +3,6 @@ package main
import ( import (
"sync" "sync"
"time" "time"
log "github.com/sirupsen/logrus"
) )
type SchedulerFCFS struct { type SchedulerFCFS struct {

View File

@ -3,7 +3,6 @@ package main
import ( import (
"sync" "sync"
"time" "time"
log "github.com/sirupsen/logrus"
"sort" "sort"
"math" "math"
) )

View File

@ -3,7 +3,6 @@ package main
import ( import (
"sync" "sync"
"time" "time"
log "github.com/sirupsen/logrus"
"math" "math"
"sort" "sort"
) )

View File

@ -3,7 +3,6 @@ package main
import ( import (
"sync" "sync"
"time" "time"
log "github.com/sirupsen/logrus"
"sort" "sort"
"math" "math"
) )