diff options
| author | Paul Buetow <paul@buetow.org> | 2026-05-22 10:49:43 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-05-22 10:49:43 +0300 |
| commit | c97587eea0abc2e8d3e7d81e1f1c64cd1b7c0ae2 (patch) | |
| tree | 601bf9664ebcf6f4f4b503aaf2c335289374399b /internal/rpn/rpn_parse.go | |
| parent | ac870d207e20d14753084d7c9b6f346f63f3b899 (diff) | |
feat(rpn): handle @-prefixed standalone metrics (@GB, @Mbps)
Token @GB pushes Number(1, mode, GB) onto the stack.
Uses FindWithAliases for metric lookup (exact, alias, case-insensitive).
Returns error for unknown metrics.
No conflict with : symbols (@ is distinct from : prefix).
Includes unit and integration tests.
Diffstat (limited to 'internal/rpn/rpn_parse.go')
| -rw-r--r-- | internal/rpn/rpn_parse.go | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/internal/rpn/rpn_parse.go b/internal/rpn/rpn_parse.go index 40ff432..f115090 100644 --- a/internal/rpn/rpn_parse.go +++ b/internal/rpn/rpn_parse.go @@ -335,6 +335,20 @@ func (r *RPN) evaluate(input string, tokens []string) (string, error) { continue } + // Check for @ prefix: standalone metric (e.g., @GB, @Mbps) + // Pushes a Number with value 1 and the looked-up metric + if len(token) > 1 && token[0] == '@' { + metricName := token[1:] + if metric, ok := GetMetricRegistry().FindWithAliases(metricName); ok { + if stack.Len() >= r.maxStack { + return "", fmt.Errorf("stack overflow") + } + stack.Push(NewNumber(1, r.mode, metric)) + continue + } + return "", fmt.Errorf("unknown metric %q in %q", metricName, token) + } + // Check if this is a variable name for assignment (:= or =:) // For := (right assignment): name value := - first token is always a variable name // For =: (left assignment): value name =: - token before =: is a variable name |
