From cb6613197452fd3cbeba5f71decd192837eae989 Mon Sep 17 00:00:00 2001 From: Julius Volz Date: Fri, 6 Sep 2024 21:45:39 +0200 Subject: [PATCH] Rename and restructure AST-to-JSON file Signed-off-by: Julius Volz --- web/api/v1/{parse_expr.go => ast_to_json.go} | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) rename web/api/v1/{parse_expr.go => ast_to_json.go} (96%) diff --git a/web/api/v1/parse_expr.go b/web/api/v1/ast_to_json.go similarity index 96% rename from web/api/v1/parse_expr.go rename to web/api/v1/ast_to_json.go index ed14b6829..c5f0d08dc 100644 --- a/web/api/v1/parse_expr.go +++ b/web/api/v1/ast_to_json.go @@ -20,14 +20,8 @@ import ( "github.com/prometheus/prometheus/promql/parser" ) -func getStartOrEnd(startOrEnd parser.ItemType) interface{} { - if startOrEnd == 0 { - return nil - } - - return startOrEnd.String() -} - +// Take a Go PromQL AST and translate it to a JSON object for the tree view in the UI. +// TODO: Could it make sense to do this via the normal JSON marshalling methods? func translateAST(node parser.Expr) interface{} { if node == nil { return nil @@ -151,3 +145,11 @@ func translateMatchers(in []*labels.Matcher) interface{} { } return out } + +func getStartOrEnd(startOrEnd parser.ItemType) interface{} { + if startOrEnd == 0 { + return nil + } + + return startOrEnd.String() +}