MCPcopy Create free account
hub / github.com/netdata/netdata / ParseCompiled

Function ParseCompiled

src/go/pkg/selectorcore/compiled.go:36–80  ·  view source on GitHub ↗

ParseCompiled parses a selector expression and returns matcher + metadata.

(expr string)

Source from the content-addressed store, hash-verified

34
35// ParseCompiled parses a selector expression and returns matcher + metadata.
36func ParseCompiled(expr string) (Compiled, error) {
37 expanded := unsugarExpr(expr)
38 terms, err := splitSelectorTerms(expanded)
39 if err != nil {
40 return nil, err
41 }
42 if len(terms) == 0 {
43 return nil, fmt.Errorf("invalid selector syntax: %q", expr)
44 }
45
46 parts := make([]Selector, 0, len(terms))
47 metricNames := map[string]struct{}{}
48 keys := map[string]struct{}{}
49
50 for _, term := range terms {
51 sel, err := parseSelector(term)
52 if err != nil {
53 return nil, err
54 }
55 parts = append(parts, sel)
56
57 sub := reLV.FindStringSubmatch(strings.TrimSpace(term))
58 if sub == nil {
59 return nil, fmt.Errorf("invalid selector syntax: %q", term)
60 }
61 name, op, pattern := sub[1], sub[2], strings.Trim(sub[3], "\"")
62 if name == MetricNameLabel {
63 for _, mn := range metricNameCandidates(op, pattern) {
64 metricNames[mn] = struct{}{}
65 }
66 continue
67 }
68 keys[name] = struct{}{}
69 }
70
71 out := compiledSelector{Selector: parts[0]}
72 if len(parts) > 1 {
73 out.Selector = And(parts[0], parts[1], parts[2:]...)
74 }
75 out.meta = Meta{
76 MetricNames: mapKeysSorted(metricNames),
77 ConstrainedLabelKeys: mapKeysSorted(keys),
78 }
79 return out, nil
80}
81
82func metricNameCandidates(op, pattern string) []string {
83 switch op {

Callers 1

Calls 7

unsugarExprFunction · 0.85
splitSelectorTermsFunction · 0.85
metricNameCandidatesFunction · 0.85
parseSelectorFunction · 0.70
AndFunction · 0.70
mapKeysSortedFunction · 0.70
ErrorfMethod · 0.65

Tested by 1

Used in the wild real call sites across dependent graphs

searching dependent graphs…