riemann.query

The query parser. Parses strings into ASTs, and converts ASTs to functions which match events.

antlr->ast

(antlr->ast [node-type & terms])

Converts a parse tree to an intermediate AST which is a little easier to analyze and work with. This is the AST we use for optimization and which is passed to various query compilers. Turns literals into their equivalent JVM types, and eliminates some unnecessary parser structure.

antlr-parser

ast

(ast string)

Takes a string to a general AST.

ast-predicate

(ast-predicate terms)

Rewrites predicates with and/or/not to normal Clojure forms.

ast-prefix

(ast-prefix sym [t1 _ t2])

Rewrites binary expressions from infix to prefix. Takes a symbol (e.g. '=) and a 3-element seq like (1 "=" 2) and emits (= 1 2), ignoring the middle term and transforming t1 and t2.

ast-regex

(ast-regex type [string _ pattern])

Takes a type of match (:like or :regex), a list of three string terms: an AST resolving to a string, the literal =~ (ignored), and a pattern. Returns (:regex pattern string-ast).

For :regex matches, emits a regular expression pattern. For :like matches, emits a string pattern.

clj-ast

(clj-ast ast)

Rewrites an AST to eval-able Clojure forms.

clj-ast-field

(clj-ast-field field)

Takes a keyword field name and emits an expression to extract that field from an ’event map, e.g. (:fieldname event).

clj-ast-guarded-prefix

(clj-ast-guarded-prefix f check [a b])

Like prefix, but inserts a predicate check around both terms.

clj-ast-regex-match

(clj-ast-regex-match pattern-transformer [pattern field])

Takes a pattern transformer, and a list of pattern string-ast, and emits code to match the string-ast’s results with a regex match, compiling pattern with pattern-transformer.

clj-ast-tagged

(clj-ast-tagged tag)

Takes a tag and emits an expression to match that tag in an event.

fun

(fun ast)

Transforms an AST into a fn event which returns true if the query matches that event. Example:

(def q (fun (ast "metric > 2")))
(q {:metric 1}) => false
(q {:metric 3}) => true

fun-cache

Speeds up the compilation of queries by caching map of ASTs to corresponding functions.

make-regex

(make-regex string)

Convert a string like “foo%” into /^foo.*$/