Skip to content

facetoe/promformat

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

66 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Promformat

Promformat is a PromQL formatter written in Python. It works by building an AST from the CST provided by ANTLR4, and then using that to produce formatted code.

The result should be semantically identical to the unformatted version as promval compares the parse tree of the original and formatted expression and fails if they are not identical.

Usage

From command line:

# Format a file containing PromQL
promformat <path to file>

# No arguments enters interpreter
promformat

As library:

from promformat import format_query
print(format_query("1+1"))

Example

Given the PromQL:

job:request_latency_seconds:mean5m{job="myjob"} > 0.5

it will be formatted:

job:request_latency_seconds:mean5m
{
  job="myjob"
} > 0.5

A more complex example:

(
  node_filesystem_avail_bytes * 100
) / node_filesystem_size_bytes < 10 and ON
(
  instance,
  device,
  mountpoint
)
predict_linear
(
  node_filesystem_avail_bytes
  {
    # We don't care about tmpfs
    fstype!~"tmpfs"
  } [1h],
  24 * 3600
) < 0 and ON
(
  instance,
  device,
  mountpoint
)
node_filesystem_readonly == 0

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •