| 1 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 2 | |
| 3 | package charttpl |
| 4 | |
| 5 | import metrixselector "github.com/netdata/netdata/go/plugins/pkg/metrix/selector" |
| 6 | |
| 7 | // VersionV1 is the supported chart-template schema version. |
| 8 | const VersionV1 = "v1" |
| 9 | |
| 10 | // Spec is the user-facing chart template file. |
| 11 | type Spec struct { |
| 12 | Version string `yaml:"version" json:"version"` |
| 13 | ContextNamespace string `yaml:"context_namespace,omitempty" json:"context_namespace,omitempty"` |
| 14 | Engine *Engine `yaml:"engine,omitempty" json:"engine,omitempty"` |
| 15 | Groups []Group `yaml:"groups" json:"groups"` |
| 16 | } |
| 17 | |
| 18 | // Engine declares template-level chartengine policy. |
| 19 | type Engine struct { |
| 20 | Selector *metrixselector.Expr `yaml:"selector,omitempty" json:"selector,omitempty"` |
| 21 | Autogen *EngineAutogen `yaml:"autogen,omitempty" json:"autogen,omitempty"` |
| 22 | } |
| 23 | |
| 24 | // EngineAutogen controls unmatched-series fallback behavior. |
| 25 | type EngineAutogen struct { |
| 26 | Enabled bool `yaml:"enabled,omitempty" json:"enabled,omitempty"` |
| 27 | |
| 28 | // MaxTypeIDLen is the max allowed full `type.id` length. |
| 29 | // Zero means default (1200). |
| 30 | MaxTypeIDLen int `yaml:"max_type_id_len,omitempty" json:"max_type_id_len,omitempty"` |
| 31 | // ExpireAfterSuccessCycles controls autogen chart/dimension expiry on |
| 32 | // successful collection cycles where the series is not seen. |
| 33 | // Zero disables expiry. |
| 34 | ExpireAfterSuccessCycles uint64 `yaml:"expire_after_success_cycles,omitempty" json:"expire_after_success_cycles,omitempty"` |
| 35 | } |
| 36 | |
| 37 | // Group is a recursive chart-group container. |
| 38 | type Group struct { |
| 39 | Family string `yaml:"family" json:"family"` |
| 40 | ContextNamespace string `yaml:"context_namespace,omitempty" json:"context_namespace,omitempty"` |
| 41 | Metrics []string `yaml:"metrics,omitempty" json:"metrics,omitempty"` |
| 42 | ChartDefaults *ChartDefaults `yaml:"chart_defaults,omitempty" json:"chart_defaults,omitempty"` |
| 43 | |
| 44 | Groups []Group `yaml:"groups,omitempty" json:"groups,omitempty"` |
| 45 | Charts []Chart `yaml:"charts,omitempty" json:"charts,omitempty"` |
| 46 | } |
| 47 | |
| 48 | // ChartDefaults defines inheritable chart fields on a group. |
| 49 | type ChartDefaults struct { |
| 50 | LabelPromoted []string `yaml:"label_promotion,omitempty" json:"label_promotion,omitempty"` |
| 51 | Instances *Instances `yaml:"instances,omitempty" json:"instances,omitempty"` |
| 52 | } |
| 53 | |
| 54 | // Chart describes one chart template in compact DSL form. |
| 55 | type Chart struct { |
| 56 | ID string `yaml:"id,omitempty" json:"id,omitempty"` |
| 57 | Title string `yaml:"title" json:"title"` |
| 58 | Family string `yaml:"family,omitempty" json:"family,omitempty"` |
| 59 | Context string `yaml:"context" json:"context"` |
| 60 | Units string `yaml:"units" json:"units"` |
| 61 | Algorithm string `yaml:"algorithm,omitempty" json:"algorithm,omitempty"` |
| 62 | Type string `yaml:"type,omitempty" json:"type,omitempty"` |
| 63 | Priority int `yaml:"priority,omitempty" json:"priority,omitempty"` |
| 64 | LabelPromoted []string `yaml:"label_promotion,omitempty" json:"label_promotion,omitempty"` |
| 65 | |
| 66 | Instances *Instances `yaml:"instances,omitempty" json:"instances,omitempty"` |
| 67 | |
| 68 | Lifecycle *Lifecycle `yaml:"lifecycle,omitempty" json:"lifecycle,omitempty"` |
| 69 | |
| 70 | Dimensions []Dimension `yaml:"dimensions" json:"dimensions"` |
| 71 | } |
| 72 | |
| 73 | // Instances defines chart instance identity labels. |
| 74 | type Instances struct { |
| 75 | ByLabels []string `yaml:"by_labels" json:"by_labels"` |
| 76 | } |
| 77 | |
| 78 | // Lifecycle controls chart and dimension cardinality/expiry limits. |
| 79 | type Lifecycle struct { |
| 80 | // MaxInstances is best-effort per chart template. |
| 81 | // Active instances in the current successful cycle are not evicted. |
| 82 | MaxInstances int `yaml:"max_instances,omitempty" json:"max_instances,omitempty"` |
| 83 | ExpireAfterCycles int `yaml:"expire_after_cycles,omitempty" json:"expire_after_cycles,omitempty"` |
| 84 | Dimensions *DimensionLifecycle `yaml:"dimensions,omitempty" json:"dimensions,omitempty"` |
| 85 | } |
| 86 | |
| 87 | // DimensionLifecycle controls materialized dimension lifecycle limits. |
| 88 | type DimensionLifecycle struct { |
| 89 | MaxDims int `yaml:"max_dims,omitempty" json:"max_dims,omitempty"` |
| 90 | ExpireAfterCycles int `yaml:"expire_after_cycles,omitempty" json:"expire_after_cycles,omitempty"` |
| 91 | } |
| 92 | |
| 93 | // Dimension describes one dimension template. |
| 94 | type Dimension struct { |
| 95 | Selector string `yaml:"selector" json:"selector"` |
| 96 | Name string `yaml:"name,omitempty" json:"name,omitempty"` |
| 97 | NameFromLabel string `yaml:"name_from_label,omitempty" json:"name_from_label,omitempty"` |
| 98 | Options *DimensionOptions `yaml:"options,omitempty" json:"options,omitempty"` |
| 99 | } |
| 100 | |
| 101 | // DimensionOptions controls DIMENSION options and update emission mode. |
| 102 | type DimensionOptions struct { |
| 103 | Multiplier int `yaml:"multiplier,omitempty" json:"multiplier,omitempty"` |
| 104 | Divisor int `yaml:"divisor,omitempty" json:"divisor,omitempty"` |
| 105 | Hidden bool `yaml:"hidden,omitempty" json:"hidden,omitempty"` |
| 106 | Float bool `yaml:"float,omitempty" json:"float,omitempty"` |
| 107 | } |