Load compiles and publishes a new immutable program revision.
(spec *charttpl.Spec, revision uint64)
| 49 | |
| 50 | // Load compiles and publishes a new immutable program revision. |
| 51 | func (e *Engine) Load(spec *charttpl.Spec, revision uint64) error { |
| 52 | if e == nil { |
| 53 | return fmt.Errorf("chartengine: nil engine") |
| 54 | } |
| 55 | |
| 56 | compiled, err := Compile(spec, revision) |
| 57 | if err != nil { |
| 58 | e.logWarningf("chartengine load failed revision=%d: %v", revision, err) |
| 59 | return err |
| 60 | } |
| 61 | |
| 62 | e.mu.RLock() |
| 63 | cfg := e.state.cfg |
| 64 | e.mu.RUnlock() |
| 65 | |
| 66 | autogenPolicy, selectorPolicy, err := resolveEffectivePolicy(cfg, spec.Engine) |
| 67 | if err != nil { |
| 68 | e.logWarningf("chartengine load failed revision=%d: %v", revision, err) |
| 69 | return err |
| 70 | } |
| 71 | |
| 72 | e.mu.Lock() |
| 73 | e.state.cfg.autogen = autogenPolicy |
| 74 | e.state.cfg.selector = selectorPolicy |
| 75 | e.state.program = compiled |
| 76 | e.state.matchIndex = buildMatchIndex(compiled.Charts()) |
| 77 | // Template revision change resets routing/materialization internals. |
| 78 | e.state.routeCache = newRouteCache() |
| 79 | e.state.materialized = newMaterializedState() |
| 80 | e.state.engineEpoch++ |
| 81 | e.state.outstanding = 0 |
| 82 | e.mu.Unlock() |
| 83 | e.logInfof("chartengine program loaded revision=%d charts=%d metrics=%d", revision, len(compiled.Charts()), len(compiled.MetricNames())) |
| 84 | return nil |
| 85 | } |
| 86 | |
| 87 | // LoadYAML decodes chart-template YAML, compiles it, and publishes the program. |
| 88 | func (e *Engine) LoadYAML(data []byte, revision uint64) error { |
no test coverage detected