From 380f8eb82119aea93e19e05f4647338293cbaf3b Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Thu, 3 Feb 2022 13:44:38 +0000 Subject: [PATCH] regexp filter: use modified package with optimisations See https://github.com/grafana/regexp/tree/speedup#readme Includes the following changes proposed upstream: * [regexp: allow patterns with no alternates to be one-pass](https://go-review.googlesource.com/c/go/+/353711) * [regexp: speed up onepass prefix check](https://go-review.googlesource.com/c/go/+/354909) * [regexp: handle prefix string with fold-case](https://go-review.googlesource.com/c/go/+/358756) * [regexp: avoid copying each instruction executed](https://go-review.googlesource.com/c/go/+/355789) * [regexp: allow prefix string anchored at beginning](https://go-review.googlesource.com/c/go/+/377294) --- CHANGELOG.md | 1 + go.mod | 1 + go.sum | 2 ++ pkg/logql/log/filter.go | 5 +++-- pkg/logql/log/fmt.go | 2 +- pkg/logql/log/parser.go | 2 +- 6 files changed, 9 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 272cc593fa5e7..fd6550e382dc6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -52,6 +52,7 @@ * [5077](https://github.com/grafana/loki/pull/5077) **trevorwhitney**: Change some default values for better out-of-the-box performance * [5204](https://github.com/grafana/loki/pull/5204) **trevorwhitney**: Default `max_outstanding_per_tenant` to `2048` * [5253](https://github.com/grafana/loki/pull/5253) **Juneezee**: refactor: use `T.TempDir` to create temporary test directory +* [5315](https://github.com/grafana/loki/pull/5315) **bboreham**: filters: use faster regexp package # 2.4.1 (2021/11/07) diff --git a/go.mod b/go.mod index e0a1fb5dfd6e0..5b04cf6aae094 100644 --- a/go.mod +++ b/go.mod @@ -288,6 +288,7 @@ require ( github.com/cloudflare/cloudflare-go v0.27.0 github.com/gofrs/flock v0.7.1 // indirect github.com/gogo/status v1.1.0 + github.com/grafana/regexp v0.0.0-20220202152701-6a046c4caf32 github.com/oklog/ulid v1.3.1 ) diff --git a/go.sum b/go.sum index 3e9740fb48c86..c3c220e5be307 100644 --- a/go.sum +++ b/go.sum @@ -1039,6 +1039,8 @@ github.com/grafana/go-gelf v0.0.0-20211112153804-126646b86de8 h1:aEOagXOTqtN9gd4 github.com/grafana/go-gelf v0.0.0-20211112153804-126646b86de8/go.mod h1:QAvS2C7TtQRhhv9Uf/sxD+BUhpkrPFm5jK/9MzUiDCY= github.com/grafana/gocql v0.0.0-20200605141915-ba5dc39ece85 h1:xLuzPoOzdfNb/RF/IENCw+oLVdZB4G21VPhkHBgwSHY= github.com/grafana/gocql v0.0.0-20200605141915-ba5dc39ece85/go.mod h1:crI9WX6p0IhrqB+DqIUHulRW853PaNFf7o4UprV//3I= +github.com/grafana/regexp v0.0.0-20220202152701-6a046c4caf32 h1:M3wP8Hwic62qJsiydSgXtev03d4f92uN1I52nVjRgw0= +github.com/grafana/regexp v0.0.0-20220202152701-6a046c4caf32/go.mod h1:M5qHK+eWfAv8VR/265dIuEpL3fNfeC21tXXp9itM24A= github.com/grafana/tail v0.0.0-20201004203643-7aa4e4a91f03 h1:fGgFrAraMB0BaPfYumu+iulfDXwHm+GFyHA4xEtBqI8= github.com/grafana/tail v0.0.0-20201004203643-7aa4e4a91f03/go.mod h1:GIMXMPB/lRAllP5rVDvcGif87ryO2hgD7tCtHMdHrho= github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7/go.mod h1:FecbI9+v66THATjSRHfNgh1IVFe/9kFxbXtjV0ctIMA= diff --git a/pkg/logql/log/filter.go b/pkg/logql/log/filter.go index 57e998cd930a6..e1530fec2c49e 100644 --- a/pkg/logql/log/filter.go +++ b/pkg/logql/log/filter.go @@ -3,11 +3,12 @@ package log import ( "bytes" "fmt" - "regexp" - "regexp/syntax" "unicode" "unicode/utf8" + "github.com/grafana/regexp" + "github.com/grafana/regexp/syntax" + "github.com/prometheus/prometheus/model/labels" ) diff --git a/pkg/logql/log/fmt.go b/pkg/logql/log/fmt.go index 243188663193e..600d12d7ab554 100644 --- a/pkg/logql/log/fmt.go +++ b/pkg/logql/log/fmt.go @@ -3,12 +3,12 @@ package log import ( "bytes" "fmt" - "regexp" "strings" "text/template" "text/template/parse" "github.com/Masterminds/sprig/v3" + "github.com/grafana/regexp" "github.com/grafana/loki/pkg/logqlmodel" ) diff --git a/pkg/logql/log/parser.go b/pkg/logql/log/parser.go index b75120b514240..e42dac8cb5b93 100644 --- a/pkg/logql/log/parser.go +++ b/pkg/logql/log/parser.go @@ -5,7 +5,6 @@ import ( "errors" "fmt" "io" - "regexp" "strings" "unicode/utf8" @@ -14,6 +13,7 @@ import ( "github.com/grafana/loki/pkg/logql/log/pattern" "github.com/grafana/loki/pkg/logqlmodel" + "github.com/grafana/regexp" jsoniter "github.com/json-iterator/go" "github.com/prometheus/common/model" )