MCPcopy
hub / github.com/netdata/netdata / compileChart

Method compileChart

src/go/plugin/framework/chartengine/compiler.go:92–186  ·  view source on GitHub ↗
(chart charttpl.Chart, scope compileScope, templateID string)

Source from the content-addressed store, hash-verified

90}
91
92func (c *compiler) compileChart(chart charttpl.Chart, scope compileScope, templateID string) (program.Chart, error) {
93 dimensions := make([]program.Dimension, 0, len(chart.Dimensions))
94 selectorKeySet := make(map[string]struct{})
95 dynamicDimensionKeys := make(map[string]struct{})
96
97 metricKinds := make(map[string]bool)
98 for i := range chart.Dimensions {
99 compiledDim, err := compileDimension(chart.Dimensions[i], scope.metrics)
100 if err != nil {
101 return program.Chart{}, fmt.Errorf("dimension[%d]: %w", i, err)
102 }
103 dimensions = append(dimensions, compiledDim.dimension)
104
105 for _, key := range compiledDim.selectorKeys {
106 selectorKeySet[key] = struct{}{}
107 }
108 for _, key := range compiledDim.dynamicLabelKeys {
109 dynamicDimensionKeys[key] = struct{}{}
110 }
111 for _, kind := range compiledDim.metricKinds {
112 metricKinds[kind] = true
113 }
114 }
115
116 algorithm, err := resolveAlgorithm(chart.Algorithm, metricKinds)
117 if err != nil {
118 return program.Chart{}, err
119 }
120
121 chartType, err := resolveChartType(chart.Type)
122 if err != nil {
123 return program.Chart{}, err
124 }
125
126 contextParts := append(append([]string(nil), scope.contextParts...), strings.TrimSpace(chart.Context))
127 context := strings.Join(filterEmpty(contextParts), ".")
128
129 baseID := strings.TrimSpace(chart.ID)
130 if baseID == "" {
131 // Phase-1 default when id is omitted: derive from chart context.
132 baseID = strings.ReplaceAll(context, ".", "_")
133 }
134
135 idTemplate, err := parseTemplate(baseID)
136 if err != nil {
137 return program.Chart{}, fmt.Errorf("id: %w", err)
138 }
139
140 instanceByLabels, err := compileInstanceByLabels(chart.Instances)
141 if err != nil {
142 return program.Chart{}, fmt.Errorf("instances.by_labels: %w", err)
143 }
144
145 labelMode := program.PromotionModeAutoIntersection
146 promote := normalizeUnique(chart.LabelPromoted)
147 if len(promote) > 0 {
148 labelMode = program.PromotionModeExplicitIntersection
149 }

Callers 1

compileGroupMethod · 0.95

Calls 12

compileDimensionFunction · 0.85
resolveAlgorithmFunction · 0.85
resolveChartTypeFunction · 0.85
filterEmptyFunction · 0.85
compileInstanceByLabelsFunction · 0.85
normalizeUniqueFunction · 0.85
composeFamilyFunction · 0.85
effectiveChartPriorityFunction · 0.85
compileLifecycleFunction · 0.85
parseTemplateFunction · 0.70
mapKeysSortedFunction · 0.70
ErrorfMethod · 0.65

Tested by

no test coverage detected