Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/facetoe/promformat
PromQL formatter
https://github.com/facetoe/promformat
formatter promql
Last synced: about 2 months ago
JSON representation
PromQL formatter
- Host: GitHub
- URL: https://github.com/facetoe/promformat
- Owner: facetoe
- License: gpl-3.0
- Created: 2022-01-23T10:58:24.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2023-03-12T01:29:49.000Z (about 1 year ago)
- Last Synced: 2024-01-23T15:09:30.232Z (4 months ago)
- Topics: formatter, promql
- Language: Python
- Homepage:
- Size: 283 KB
- Stars: 29
- Watchers: 2
- Forks: 7
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Lists
- static-analysis - promformat
README
# 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:
```text
# Format a file containing PromQL
promformat# No arguments enters interpreter
promformat
```As library:
```text
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:
```text
(
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
```