Compile converts a decoded/default-applied chart template spec into immutable chartengine IR. Callers should prefer charttpl.DecodeYAML, which applies chart_defaults inheritance before validation. Compile validates the provided spec but does not apply charttpl defaults or mutate the input.
(spec *charttpl.Spec, revision uint64)
| 21 | // inheritance before validation. Compile validates the provided spec but does |
| 22 | // not apply charttpl defaults or mutate the input. |
| 23 | func Compile(spec *charttpl.Spec, revision uint64) (*program.Program, error) { |
| 24 | if spec == nil { |
| 25 | return nil, fmt.Errorf("chartengine: nil template spec") |
| 26 | } |
| 27 | if err := spec.Validate(); err != nil { |
| 28 | return nil, fmt.Errorf("chartengine: invalid template spec: %w", err) |
| 29 | } |
| 30 | |
| 31 | c := compiler{ |
| 32 | metricsSet: make(map[string]struct{}), |
| 33 | } |
| 34 | |
| 35 | rootCtx := normalizeOptional(spec.ContextNamespace) |
| 36 | for i := range spec.Groups { |
| 37 | groupPath := []int{i} |
| 38 | if err := c.compileGroup(spec.Groups[i], compileScope{ |
| 39 | metrics: make(map[string]struct{}), |
| 40 | familyParts: nil, |
| 41 | contextParts: rootCtx, |
| 42 | }, groupPath); err != nil { |
| 43 | return nil, err |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | return program.New(spec.Version, revision, c.metricNames(), c.charts) |
| 48 | } |
| 49 | |
| 50 | type compiler struct { |
| 51 | charts []program.Chart |
searching dependent graphs…