Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✅ Upgrade metricsql #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
module promql-prettier

go 1.16
go 1.17

require github.com/VictoriaMetrics/metricsql v0.44.1

require (
github.com/VictoriaMetrics/metricsql v0.2.3
github.com/VictoriaMetrics/metrics v1.18.1 // indirect
github.com/valyala/fastrand v1.1.0 // indirect
github.com/valyala/histogram v1.2.0 // indirect
)

replace github.com/VictoriaMetrics/metricsql => github.com/jiacai2050/metricsql v0.2.4-0.20201117063355-2ca2689db947
16 changes: 8 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
github.com/VictoriaMetrics/metrics v1.12.2 h1:SG8iAmqavDNuh7GIdHPoGHUhDL23KeKfvSZSozucNeA=
github.com/VictoriaMetrics/metrics v1.12.2/go.mod h1:Z1tSfPfngDn12bTfZSCqArT3OPY3u88J12hSoOhuiRE=
github.com/jiacai2050/metricsql v0.2.4-0.20201117063355-2ca2689db947 h1:rUWLQSaA75TYOxL06XD/8QqhRcWCjGWUVbI5aA4IqIg=
github.com/jiacai2050/metricsql v0.2.4-0.20201117063355-2ca2689db947/go.mod h1:ylO7YITho/Iw6P71oEaGyHbO94bGoGtzWfLGqFhMIg8=
github.com/valyala/fastrand v1.0.0 h1:LUKT9aKer2dVQNUi3waewTbKV+7H17kvWFNKs2ObdkI=
github.com/valyala/fastrand v1.0.0/go.mod h1:HWqCzkrkg6QXT8V2EXWvXCoow7vLwOFN002oeRzjapQ=
github.com/valyala/histogram v1.1.2 h1:vOk5VrGjMBIoPR5k6wA8vBaC8toeJ8XO0yfRjFEc1h8=
github.com/valyala/histogram v1.1.2/go.mod h1:CZAr6gK9dbD7hYx2s8WSPh0p5x5wETjC+2b3PJVtEdg=
github.com/VictoriaMetrics/metrics v1.18.1 h1:OZ0+kTTto8oPfHnVAnTOoyl0XlRhRkoQrD2n2cOuRw0=
github.com/VictoriaMetrics/metrics v1.18.1/go.mod h1:ArjwVz7WpgpegX/JpB0zpNF2h2232kErkEnzH1sxMmA=
github.com/VictoriaMetrics/metricsql v0.44.1 h1:qGoRt0g84uMUscVjS7P3uDZKmjJubWKaIx9v0iHKgck=
github.com/VictoriaMetrics/metricsql v0.44.1/go.mod h1:6pP1ZeLVJHqJrHlF6Ij3gmpQIznSsgktEcZgsAWYel0=
github.com/valyala/fastrand v1.1.0 h1:f+5HkLW4rsgzdNoleUOB69hyT9IlD2ZQh9GyDMfb5G8=
github.com/valyala/fastrand v1.1.0/go.mod h1:HWqCzkrkg6QXT8V2EXWvXCoow7vLwOFN002oeRzjapQ=
github.com/valyala/histogram v1.2.0 h1:wyYGAZZt3CpwUiIb9AU/Zbllg1llXyrtApRS815OLoQ=
github.com/valyala/histogram v1.2.0/go.mod h1:Hb4kBwb4UxsaNbbbh+RRz8ZR6pdodR57tzWUS3BUzXY=
4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import (
)

var (
flVersion = flag.Bool("version", false, "print version")
flDebug = flag.Bool("debug", false, "enable debug")
flVersion = flag.Bool("version", false, "print version")
flDebug = flag.Bool("debug", false, "enable debug")

BuildTime string
BuildBranch string
Expand Down
9 changes: 5 additions & 4 deletions util.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,12 @@ func prettier(expr metricsql.Expr, ident int) []byte {
var b bytes.Buffer

wrapParensWhenNecesary(e.Expr, &b, ident)
if len(e.Window) > 0 || len(e.Step) > 0 {
b.WriteString(fmt.Sprintf("[%s:%s]", e.Window, e.Step))
if (*e.Window).Duration(1) > 0 || e.Step.Duration(1) > 0 {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this change?

// hack: cannot access `DurationExpr.s` directly, but can get it by appending empty bytes to `DurationExpr`
b.WriteString(fmt.Sprintf("[%s:%s]", e.Window.AppendString([]byte{}), e.Step.AppendString([]byte{})))
}
if len(e.Offset) > 0 {
b.WriteString(fmt.Sprintf(" offset %s", e.Offset))
if e.Offset.Duration(1) > 0 {
b.WriteString(fmt.Sprintf(" offset %s", e.Offset.AppendString([]byte{})))
}

buf = append(buf, b.Bytes()...)
Expand Down