scheduler: integrate metrics to context

This commit is contained in:
Armon Dadgar
2015-08-13 18:34:04 -07:00
parent 74fa98ce64
commit fde32cc6ca
2 changed files with 24 additions and 7 deletions

View File

@@ -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)
}

View File

@@ -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)