mirror of
https://github.com/kemko/nomad.git
synced 2026-01-03 08:55:43 +03:00
scheduler: integrate metrics to context
This commit is contained in:
@@ -16,21 +16,29 @@ type Context interface {
|
||||
|
||||
// Logger provides a way to log
|
||||
Logger() *log.Logger
|
||||
|
||||
// Metrics returns the current metrics
|
||||
Metrics() *structs.AllocMetric
|
||||
|
||||
// Reset is invoked after making a placement
|
||||
Reset()
|
||||
}
|
||||
|
||||
// EvalContext is a Context used during an Evaluation
|
||||
type EvalContext struct {
|
||||
state State
|
||||
plan *structs.Plan
|
||||
logger *log.Logger
|
||||
state State
|
||||
plan *structs.Plan
|
||||
logger *log.Logger
|
||||
metrics *structs.AllocMetric
|
||||
}
|
||||
|
||||
// NewEvalContext constructs a new EvalContext
|
||||
func NewEvalContext(s State, p *structs.Plan, log *log.Logger) *EvalContext {
|
||||
ctx := &EvalContext{
|
||||
state: s,
|
||||
plan: p,
|
||||
logger: log,
|
||||
state: s,
|
||||
plan: p,
|
||||
logger: log,
|
||||
metrics: new(structs.AllocMetric),
|
||||
}
|
||||
return ctx
|
||||
}
|
||||
@@ -47,6 +55,14 @@ func (e *EvalContext) Logger() *log.Logger {
|
||||
return e.logger
|
||||
}
|
||||
|
||||
func (e *EvalContext) Metrics() *structs.AllocMetric {
|
||||
return e.metrics
|
||||
}
|
||||
|
||||
func (e *EvalContext) SetState(s State) {
|
||||
e.state = s
|
||||
}
|
||||
|
||||
func (e *EvalContext) Reset() {
|
||||
e.metrics = new(structs.AllocMetric)
|
||||
}
|
||||
|
||||
@@ -173,6 +173,7 @@ func (s *ServiceScheduler) computePlacements(job *structs.Job, place []allocTupl
|
||||
stack := NewServiceStack(ctx, nodes)
|
||||
|
||||
for _, missing := range place {
|
||||
ctx.Reset()
|
||||
stack.SetTaskGroup(missing.TaskGroup)
|
||||
option := stack.Select()
|
||||
if option == nil {
|
||||
@@ -189,7 +190,7 @@ func (s *ServiceScheduler) computePlacements(job *structs.Job, place []allocTupl
|
||||
JobID: job.ID,
|
||||
Job: job,
|
||||
Resources: nil, // TODO: size
|
||||
Metrics: nil,
|
||||
Metrics: ctx.Metrics(),
|
||||
Status: structs.AllocStatusPending,
|
||||
}
|
||||
s.plan.AppendAlloc(alloc)
|
||||
|
||||
Reference in New Issue
Block a user