CostObserver provides an observer that tracks runtime cost.
(opts ...costTrackPlanOption)
| 48 | |
| 49 | // CostObserver provides an observer that tracks runtime cost. |
| 50 | func CostObserver(opts ...costTrackPlanOption) PlannerOption { |
| 51 | ct := &costTrackerFactory{} |
| 52 | for _, o := range opts { |
| 53 | ct = o(ct) |
| 54 | } |
| 55 | return func(p *planner) (*planner, error) { |
| 56 | if ct.factory == nil { |
| 57 | return nil, errors.New("cost tracker factory not configured") |
| 58 | } |
| 59 | p.observers = append(p.observers, ct) |
| 60 | p.decorators = append(p.decorators, decObserveEval(ct.Observe)) |
| 61 | return p, nil |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | // costTrackerFactory holds a factory for producing new CostTracker instances on each Eval call. |
| 66 | type costTrackerFactory struct { |