Git Product home page Git Product logo

promformat's Introduction

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{fstype!~"tmpfs"}[1h], 24 * 3600) < 0 and ON (instance, device, mountpoint) node_filesystem_readonly == 0
(
  node_filesystem_avail_bytes * 100
) / node_filesystem_size_bytes < 10 and ON (
  instance,
  device,
  mountpoint
)
predict_linear (
  node_filesystem_avail_bytes
  {
    fstype!~"tmpfs"
  } [1h],
  24 * 3600
) < 0 and ON (
  instance,
  device,
  mountpoint
)
node_filesystem_readonly == 0

promformat's People

Contributors

alxric avatar facetoe avatar nicois avatar vadimpushtaev avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.